Skip to content

Instantly share code, notes, and snippets.

@bikram20
Created November 30, 2019 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bikram20/3b85438c691ecf3a0626f24b26aa9fd3 to your computer and use it in GitHub Desktop.
Save bikram20/3b85438c691ecf3a0626f24b26aa9fd3 to your computer and use it in GitHub Desktop.
Rego example and input - for rego playground
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"
}
]
}
}
}
}
@bikram20
Copy link
Author

@bikram20
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment