Skip to content

Commit

Permalink
extend priv'd ns protection to ns itself
Browse files Browse the repository at this point in the history
  • Loading branch information
yjst2012 committed Jul 6, 2023
1 parent 90db317 commit 5761127
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
"ServiceAccount",
"ReplicationController",
"ResourceQuota",
"Namespace",
]
- apiGroups: ["apps"]
kinds: ["Deployment", "ReplicaSet", "StatefulSet", "DaemonSet"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ import data.lib.common.is_exempted_account
import data.lib.common.get_username

violation[{"msg": msg}] {
is_namespace(input.review)
ns := input.review.name
is_priv_namespace(ns)
not is_exempted_account(input.review)
username := get_username(input.review)
msg := sprintf("user %v not allowed to operate namespace %v", [username, ns])
} {
not is_namespace(input.review)
ns := input.review.object.metadata.namespace
is_priv_namespace(ns)
not is_exempted_account(input.review)
username := get_username(input.review)
msg := sprintf("user %v not allowed to operate in namespace %v", [username, ns])
}

is_namespace(review) {
review.kind.kind == "Namespace"
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,24 @@ spec:
import data.lib.common.get_username
violation[{"msg": msg}] {
is_namespace(input.review)
ns := input.review.name
is_priv_namespace(ns)
not is_exempted_account(input.review)
username := get_username(input.review)
msg := sprintf("user %v not allowed to operate namespace %v", [username, ns])
} {
not is_namespace(input.review)
ns := input.review.object.metadata.namespace
is_priv_namespace(ns)
not is_exempted_account(input.review)
username := get_username(input.review)
msg := sprintf("user %v not allowed to operate in namespace %v", [username, ns])
}
is_namespace(review) {
review.kind.kind == "Namespace"
}
libs:
- |
package lib.common
Expand Down

0 comments on commit 5761127

Please sign in to comment.