1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-28 10:28:36 +00:00

fix: validate subject kind (#7582)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-06-19 12:56:50 +02:00 committed by GitHub
parent b4e863e075
commit bc35700e29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 0 deletions

View file

@ -35,6 +35,8 @@ func (u *UserInfo) ValidateSubjects(path *field.Path) (errs field.ErrorList) {
entry := path.Index(index)
if subject.Kind == "" {
errs = append(errs, field.Required(entry.Child("kind"), ""))
} else if subject.Kind != rbacv1.GroupKind && subject.Kind != rbacv1.ServiceAccountKind && subject.Kind != rbacv1.UserKind {
errs = append(errs, field.Invalid(entry.Child("kind"), subject.Kind, "kind must be 'User', 'Group', or 'ServiceAccount'"))
}
if subject.Name == "" {
errs = append(errs, field.Required(entry.Child("name"), ""))

View file

@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- file: policy.yaml
shouldFail: true

View file

@ -0,0 +1,12 @@
## Description
This test tries to create a policy with invalid an invalid subject kind (`Foo`).
Only kinds supported are `User`, `Group`, or `ServiceAccount`.
## Expected Behavior
Policy should be rejected.
## Related Issue
https://github.com/kyverno/kyverno/issues/7052

View file

@ -0,0 +1,18 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: temp
spec:
background: false
rules:
- name: test-rule
match:
any:
- resources:
kinds:
- ConfigMap
subjects:
- name: foo
kind: Foo
validate:
deny: {}