-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added gatekeeper policy to require PSS labels
- Loading branch information
1 parent
65080a8
commit 94440ba
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
charts/gatekeeper/chart-constraints/templates/c-namespace-pss.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
apiVersion: constraints.gatekeeper.sh/v1beta1 | ||
kind: K8sNamespacePSS | ||
metadata: | ||
name: namespace-must-have-pss-labels | ||
spec: | ||
enforcementAction: warn | ||
match: | ||
kinds: | ||
- apiGroups: [""] | ||
kinds: ["Namespace"] | ||
parameters: | ||
|
||
exemptNamespaces: | ||
# privileged | ||
- kube-system | ||
- falco | ||
- promstack | ||
# baseline | ||
- helm-exporter | ||
- robusta | ||
- vault | ||
- default | ||
# other | ||
- cert-manater | ||
- default | ||
- kube-node-lease | ||
- kube-public |
31 changes: 31 additions & 0 deletions
31
charts/gatekeeper/chart-templates/templates/t-namespace-pss.yaml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apiVersion: templates.gatekeeper.sh/v1beta1 | ||
kind: ConstraintTemplate | ||
metadata: | ||
name: k8snamespacepss | ||
spec: | ||
crd: | ||
spec: | ||
names: | ||
kind: K8sNamespacePSS | ||
targets: | ||
- target: admission.k8s.gatekeeper.sh | ||
rego: | | ||
package k8snamespacepss | ||
namespace_exempt(obj, parameters) { | ||
parameters.exemptNamespaces[_] == obj.metadata.name | ||
} | ||
violation[{"msg": msg, "details": {}}] { | ||
not namespace_exempt(input.review.object, input.parameters) | ||
# Violation if object doesn't have pss enforce label | ||
not input.review.object.metadata.labels["pod-security.kubernetes.io/enforce"] | ||
msg := sprintf("namespace '%v' not allowed, it must PSS label 'pod-security.kubernetes.io/enforce'", [input.review.object.metadata.name]) | ||
} | ||
violation[{"msg": msg, "details": {}}] { | ||
not namespace_exempt(input.review.object, input.parameters) | ||
# Violation if object doesn't have pss enforce label to restricted | ||
input.review.object.metadata.labels["pod-security.kubernetes.io/enforce"]!="restricted" | ||
msg := sprintf("namespace '%v' not allowed, PSS label 'pod-security.kubernetes.io/enforce' requires value 'privileged', found '%v'", | ||
[input.review.object.metadata.name, input.review.object.metadata.labels["pod-security.kubernetes.io/enforce"]]) | ||
} | ||