Created
November 30, 2019 00:21
-
-
Save bikram20/3b85438c691ecf3a0626f24b26aa9fd3 to your computer and use it in GitHub Desktop.
Rego example and input - for rego playground
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 kubernetes.admission | |
block_latest_image_tag[explanation] { | |
input.request.kind.kind == "Pod" | |
containers := input.request.object.spec.containers | |
image_name := containers[_].image | |
is_image_tag_latest(image_name) | |
explanation := sprintf("resources should not use latest tag: %v", [image_name]) | |
} | |
block_user_not_in_list[explanation] { | |
username := input.request.userInfo.username | |
not is_user_authorized(username) | |
explanation := sprintf("resources should not use user: %v", [username]) | |
} | |
is_image_tag_latest(image) { | |
[_, image_tag] := split(image, ":") | |
image_tag == "latest" | |
} | |
is_image_tag_latest(image) { | |
not contains(image, ":") | |
} | |
is_user_authorized(user) { | |
some userid | |
userlist := ["admin", "secadmin", "platformadmin"] | |
userlist[userid] == user | |
} | |
################################### | |
{ | |
"request": { | |
"kind": { | |
"kind": "Pod" | |
}, | |
"userInfo": { | |
"username": "secadmin", | |
"group": "sec" | |
}, | |
"object": { | |
"spec": { | |
"containers": [ | |
{ | |
"image": "nginx:1.1", | |
"name": "nginx" | |
}, | |
{ | |
"image": "busybox:1.0", | |
"name": "busybox" | |
} | |
] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://play.openpolicyagent.org/p/JPqInwSJdQ