Skip to content

Commit fe7bdac

Browse files
authoredSep 28, 2021
'Kubernetes clusters should not use the default namespace' should not violate on default service account or kubernetes service (#783)
1 parent 44c9d2e commit fe7bdac

File tree

1 file changed

+17
-0
lines changed
  • built-in-references/Kubernetes/block-default-namespace

1 file changed

+17
-0
lines changed
 

‎built-in-references/Kubernetes/block-default-namespace/template.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ spec:
1515
violation[{"msg": msg}] {
1616
obj := input.review.object
1717
is_default_namespace(obj.metadata)
18+
not is_allowed(obj)
1819
msg := sprintf("Usage of the default namespace is not allowed, name: %v, kind: %v", [obj.metadata.name, obj.kind])
1920
}
2021
@@ -25,3 +26,19 @@ spec:
2526
is_default_namespace(metadata) {
2627
metadata.namespace == "default"
2728
}
29+
30+
is_allowed(obj) {
31+
obj.kind == "ServiceAccount"
32+
obj.metadata.name == "default"
33+
}
34+
35+
is_allowed(obj) {
36+
obj.kind == "Secret"
37+
obj.type == "kubernetes.io/service-account-token"
38+
obj.metadata.annotations["kubernetes.io/service-account.name"] == "default"
39+
}
40+
41+
is_allowed(obj) {
42+
obj.kind == "Service"
43+
obj.metadata.name == "kubernetes"
44+
}

0 commit comments

Comments
 (0)
Please sign in to comment.