Created
March 22, 2020 19:39
-
-
Save onelittlenightmusic/a4f1cfd0d17c455eb1e750981600ddb8 to your computer and use it in GitHub Desktop.
Simple OPA mutation policy by Mr. Torin Sandall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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