Skip to content

Instantly share code, notes, and snippets.

@onelittlenightmusic
Created March 22, 2020 19:39
Show Gist options
  • Save onelittlenightmusic/a4f1cfd0d17c455eb1e750981600ddb8 to your computer and use it in GitHub Desktop.
Save onelittlenightmusic/a4f1cfd0d17c455eb1e750981600ddb8 to your computer and use it in GitHub Desktop.
Simple OPA mutation policy by Mr. Torin Sandall
package system
main = {
"apiVersion": "admission.k8s.io/v1beta1",
"kind": "AdmissionReview",
"response": {
"allowed": true,
"patchType": "JSONPatch",
"patch": patch_bytes,
}
} {
is_create_or_update
input.request.object.metadata.annotations["test-mutation"]
patch = [
{"op": "add", "path": "/metadata/annotations/foo", "value": "bar"},
]
patch_json = json.marshal(patch)
patch_bytes = base64url.encode(patch_json)
}
is_create_or_update { is_create }
is_create_or_update { is_update }
is_create { input.request.operation == "CREATE" }
is_update { input.request.operation == "UPDATE" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment