Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken exclude any all #2990

Merged
merged 10 commits into from
Jan 20, 2022
4 changes: 3 additions & 1 deletion pkg/webhooks/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ func containsRBACInfo(policies ...[]*kyverno.ClusterPolicy) bool {
for _, policySlice := range policies {
for _, policy := range policySlice {
for _, rule := range policy.Spec.Rules {
checkForRBACInfo(rule)
if checkForRBACInfo(rule) {
return true
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/cli/test-fail/invalid-ns/kyverno-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: test-exclude
policies:
- policy.yaml
resources:
- resources.yaml
results:
- policy: restrict-labels
rule: restrict-labels
resource: kyverno-system-tst
kind: Namespace
result: fail
35 changes: 35 additions & 0 deletions test/cli/test-fail/invalid-ns/policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: restrict-labels
labels:
policy.schiff.telekom.de: enforced
annotations:
policies.kyverno.io/title: Restrict Labels on Namespaces
policies.kyverno.io/category: Labels
policies.kyverno.io/minversion: 1.3.0
policies.kyverno.io/description: >-
This policy prevents the use of an label beginning with a common
key name (in this case "platform.das-schiff.telekom.de/owner | owner"). This can be useful to ensure users either
don't set reserved labels or to force them to
use a newer version of an label.
spec:
validationFailureAction: enforce
background: false
rules:
- name: restrict-labels
match:
resources:
kinds:
- Namespace
exclude:
clusterRoles:
- cluster-admin
validate:
message: 'Every namespace has to have `platform.das-schiff.telekom.de/owner` label. It must not have value `das-schiff` which is reserved for system namespaces'
pattern:
metadata:
labels:
platform.das-schiff.telekom.de/owner: "!das-schiff"
# For forward compatibility
=(schiff.telekom.de/owner): "!schiff"
8 changes: 8 additions & 0 deletions test/cli/test-fail/invalid-ns/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Namespace
metadata:
name: kyverno-system-tst
labels:
name: kyverno-system-tst
schiff.telekom.de/owner: schiff
platform.das-schiff.telekom.de/owner: das-schiff