Scoping to multiple resource types⚓︎
Block workloads with the forbidden test label. The rule serves as an example to demonstrate how to restrict a rule to a set of resource types.
Use rule⚓︎
In order to use this rule:
- Adjust the label mapping to the target value.
- Adjust metavariable regular expression for
$KIND
to your target resource types. - Create
configmap
via:
Rule⚓︎
rules/forbidden-workload-label.yaml
rules:
- id: forbidden-workload-label
message: Kubernetes workload with forbidden label. Any workload resource with label "semgr8s-test=forbidden-test-label-e3b0c44298fc1c" is denied. This label carries no meaning beyond testing and demonstration purposes.
languages: [yaml]
severity: INFO
patterns:
- pattern-inside: |
...
kind: $KIND
...
- metavariable-regex:
metavariable: $KIND
regex: (Pod|Deployment|ReplicaSet|DaemonSet|StatefulSet)
# remaining pattern as normal
- pattern-inside: |
metadata:
...
- pattern-inside: |
labels:
...
- pattern: |
semgr8s-test: forbidden-test-label-e3b0c44298fc1c
fix: "semgr8s-test: allowed-test-label"