Namespaced rules⚓︎
Block resources with the forbidden test label in specific namespaces. The rule serves as an example to demonstrate how to restrict a rule to namespaces.
Use rule⚓︎
In order to use this rule:
- Adjust the label mapping to the target value.
- Adjust metavariable regular expression for
$NS
to your target namespaces. - Create
configmap
via:
Rule⚓︎
rules/forbidden-namespaced-label.yaml
rules:
- id: forbidden-namespaced-label
message: Kubernetes resource with label forbidden in designated namespace. Any resource with label "semgr8s-test=forbidden-test-label-e3b0c44298fc1c" is denied for this namespace. This label carries no meaning beyond testing and demonstration purposes.
languages: [yaml]
severity: INFO
patterns:
- pattern-inside: |
metadata:
...
namespace: $NS
...
- metavariable-regex:
metavariable: $NS
regex: (test-semgr8s|audit-semgr8s)
# remaining pattern as normal
- pattern-inside: |
metadata:
...
- pattern-inside: |
labels:
...
- pattern: |
semgr8s-test: forbidden-test-label-e3b0c44298fc1c
fix: "semgr8s-test: allowed-test-label"