Skip to content

Commit d08d28a

Browse files
author
OpenShift Bot
authoredMar 21, 2017
Merge pull request #13466 from enj/enj/f/disallow_attribute_restrictions
Merged by openshift-bot
2 parents 7379f54 + 847e3fc commit d08d28a

8 files changed

+63
-39
lines changed
 

‎pkg/authorization/api/helpers.go

+4
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ func (r *PolicyRuleBuilder) RuleOrDie() PolicyRule {
366366
}
367367

368368
func (r *PolicyRuleBuilder) Rule() (PolicyRule, error) {
369+
if r.PolicyRule.AttributeRestrictions != nil {
370+
return PolicyRule{}, fmt.Errorf("rule may not have attributeRestrictions because they are deprecated and ignored: %#v", r.PolicyRule)
371+
}
372+
369373
if len(r.PolicyRule.Verbs) == 0 {
370374
return PolicyRule{}, fmt.Errorf("verbs are required: %#v", r.PolicyRule)
371375
}

‎pkg/authorization/api/validation/validation.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,13 @@ func ValidateRole(role *authorizationapi.Role, isNamespaced bool) field.ErrorLis
252252
}
253253

254254
func validateRole(role *authorizationapi.Role, isNamespaced bool, fldPath *field.Path) field.ErrorList {
255-
return validation.ValidateObjectMeta(&role.ObjectMeta, isNamespaced, path.ValidatePathSegmentName, fldPath.Child("metadata"))
255+
allErrs := validation.ValidateObjectMeta(&role.ObjectMeta, isNamespaced, path.ValidatePathSegmentName, fldPath.Child("metadata"))
256+
for i, rule := range role.Rules {
257+
if rule.AttributeRestrictions != nil {
258+
allErrs = append(allErrs, field.Invalid(fldPath.Child("rules").Index(i).Child("attributeRestrictions"), rule.AttributeRestrictions, "must be null"))
259+
}
260+
}
261+
return allErrs
256262
}
257263

258264
func ValidateRoleUpdate(role *authorizationapi.Role, oldRole *authorizationapi.Role, isNamespaced bool) field.ErrorList {

‎pkg/authorization/api/validation/validation_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ func TestValidatePolicy(t *testing.T) {
5858
T: field.ErrorTypeInvalid,
5959
F: "roles[any1].metadata.name",
6060
},
61+
"invalid role": {
62+
A: authorizationapi.Policy{
63+
ObjectMeta: kapi.ObjectMeta{Namespace: kapi.NamespaceDefault, Name: authorizationapi.PolicyName},
64+
Roles: map[string]*authorizationapi.Role{
65+
"any1": {
66+
ObjectMeta: kapi.ObjectMeta{Namespace: kapi.NamespaceDefault, Name: "any1"},
67+
Rules: []authorizationapi.PolicyRule{
68+
{AttributeRestrictions: &authorizationapi.RoleBinding{}},
69+
},
70+
},
71+
},
72+
},
73+
T: field.ErrorTypeInvalid,
74+
F: "roles[any1].rules[0].attributeRestrictions",
75+
},
6176
}
6277
for k, v := range errorCases {
6378
errs := ValidatePolicy(&v.A, true)
@@ -370,6 +385,16 @@ func TestValidateRole(t *testing.T) {
370385
T: field.ErrorTypeRequired,
371386
F: "metadata.name",
372387
},
388+
"invalid rule": {
389+
A: authorizationapi.Role{
390+
ObjectMeta: kapi.ObjectMeta{Name: authorizationapi.PolicyName, Namespace: kapi.NamespaceDefault},
391+
Rules: []authorizationapi.PolicyRule{
392+
{AttributeRestrictions: &authorizationapi.IsPersonalSubjectAccessReview{}},
393+
},
394+
},
395+
T: field.ErrorTypeInvalid,
396+
F: "rules[0].attributeRestrictions",
397+
},
373398
}
374399
for k, v := range errorCases {
375400
errs := ValidateRole(&v.A, true)

‎test/extended/testdata/bindata.go

+10-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/extended/testdata/roles/policy-clusterroles.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ items:
3333
- projects
3434
verbs:
3535
- list
36-
- apiGroups: null
37-
attributeRestrictions:
38-
apiVersion: v1
39-
kind: IsPersonalSubjectAccessReview
36+
- apiGroups:
37+
- authorization.k8s.io
38+
attributeRestrictions: null
4039
resources:
41-
- localsubjectaccessreviews
42-
- subjectaccessreviews
40+
- selfsubjectaccessreviews
4341
verbs:
4442
- create
4543
- apiVersion: v1

‎test/extended/testdata/roles/policy-roles.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ objects:
4242
- projects
4343
verbs:
4444
- list
45-
- apiGroups: null
46-
attributeRestrictions:
47-
apiVersion: v1
48-
kind: IsPersonalSubjectAccessReview
45+
- apiGroups:
46+
- authorization.k8s.io
47+
attributeRestrictions: null
4948
resources:
50-
- localsubjectaccessreviews
51-
- subjectaccessreviews
49+
- selfsubjectaccessreviews
5250
verbs:
5351
- create
5452
- apiVersion: v1
@@ -72,4 +70,4 @@ objects:
7270
subjects:
7371
- kind: SystemGroup
7472
name: system:authenticated
75-
userNames: null
73+
userNames: null

‎test/testdata/basic-user-with-annotations-labels-groups-without-projectrequests.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@ rules:
4040
verbs:
4141
- list
4242
- watch
43-
- apiGroups: null
44-
attributeRestrictions:
45-
apiVersion: v1
46-
kind: IsPersonalSubjectAccessReview
43+
- apiGroups:
44+
- authorization.k8s.io
45+
attributeRestrictions: null
4746
resources:
48-
- localsubjectaccessreviews
49-
- subjectaccessreviews
47+
- selfsubjectaccessreviews
5048
verbs:
5149
- create
5250
- apiGroups: null

‎test/testdata/basic-user-with-groups-without-projectrequests.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ rules:
3434
verbs:
3535
- list
3636
- watch
37-
- apiGroups: null
38-
attributeRestrictions:
39-
apiVersion: v1
40-
kind: IsPersonalSubjectAccessReview
37+
- apiGroups:
38+
- authorization.k8s.io
39+
attributeRestrictions: null
4140
resources:
42-
- localsubjectaccessreviews
43-
- subjectaccessreviews
41+
- selfsubjectaccessreviews
4442
verbs:
4543
- create
4644
- apiGroups: null

0 commit comments

Comments
 (0)
Please sign in to comment.