Repository navigation
Drop double conversion in boostrap policy - #16033
Conversation
| return subjects | ||
| } | ||
|
|
||
| func BuildRBACSubjects(users, groups []string) []rbac.Subject { |
There was a problem hiding this comment.
This is only used in one spot. move it to the point of use to prevent proliferation.
There was a problem hiding this comment.
@deads2k I moved the function and made it private.
| kapi "k8s.io/kubernetes/pkg/api" | ||
| "k8s.io/kubernetes/pkg/api/validation" | ||
| "k8s.io/kubernetes/pkg/apis/rbac" | ||
| // uservalidation "github.com/openshift/origin/pkg/user/apis/user/validation" |
| if err != nil { | ||
| r.Error("CRBD1002", err, fmt.Sprintf("Unable to get clusterrolebinding/%s: %v", changedClusterRoleBinding.Name, err)) | ||
| } | ||
| actualRBACClusterRole, err := util.ClusterRoleBindingToRBAC(actualClusterRole) |
There was a problem hiding this comment.
Added error check
Is it OK to introduce a new error id?
There was a problem hiding this comment.
@liggitt @deads2k @sosiouxme may be able to advise better on the new error id.
There was a problem hiding this comment.
@tiran Absolutely. The only purpose of an error ID is to be able to identify the problem uniquely in automation even if the text changes. So just make any new ones unique.
| @@ -23,7 +24,7 @@ import ( | |||
| cmdutil "github.com/openshift/origin/pkg/cmd/util" | |||
| "github.com/openshift/origin/pkg/cmd/util/clientcmd" | |||
|
|
|||
|
|
||
| roleBinding.Subjects = changedRoleBindings[i].Subjects | ||
| rbacRoleBinding.Subjects = changedRoleBindings[i].Subjects | ||
| roleBinding, err = util.ClusterRoleBindingFromRBAC(rbacRoleBinding) |
| } | ||
|
|
||
| func computeUpdatedBinding(expected authorizationapi.ClusterRoleBinding, actual authorizationapi.ClusterRoleBinding, excludeSubjects []kapi.ObjectReference, union bool) (*authorizationapi.ClusterRoleBinding, bool) { | ||
| func computeUpdatedBinding(expected rbac.ClusterRoleBinding, actual rbac.ClusterRoleBinding, excludeSubjects []rbac.Subject, union bool) (*rbac.ClusterRoleBinding, bool) { |
There was a problem hiding this comment.
Why does this make shallow copies?
There was a problem hiding this comment.
Why are shallow copies a problem and how do I avoid a shallow copy?
| // list2Only = list2 - list1 | ||
| // if both returned lists are empty, the provided lists are equal | ||
| func DiffObjectReferenceLists(list1 []kapi.ObjectReference, list2 []kapi.ObjectReference) (list1Only []kapi.ObjectReference, list2Only []kapi.ObjectReference) { | ||
| func DiffObjectReferenceLists(list1 []rbac.Subject, list2 []rbac.Subject) (list1Only []rbac.Subject, list2Only []rbac.Subject) { |
| "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" | ||
| cmdutil "github.com/openshift/origin/pkg/cmd/util" | ||
| osutil "github.com/openshift/origin/pkg/cmd/util" | ||
|
|
| } | ||
|
|
||
| func computeReconciledRole(expected authorizationapi.ClusterRole, actual authorizationapi.ClusterRole, union bool) (*authorizationapi.ClusterRole, bool) { | ||
| func computeReconciledRole(expected rbac.ClusterRole, actual rbac.ClusterRole, union bool) (*rbac.ClusterRole, bool) { |
| r := []rbac.PolicyRule{} | ||
| for _, resource := range resources { | ||
| r = append(r, authorizationapi.PolicyRule{Verbs: sets.NewString("get"), Resources: sets.NewString(resource)}) | ||
| r = append(r, rbac.NewRule("get").Groups("testgroup").Resources(resource).RuleOrDie()) |
There was a problem hiding this comment.
Where did testgroup come from?
There was a problem hiding this comment.
rbac.PolicyRule requires a group for resource policies. The test won't pass without a group. I came up with an arbitrary group name. Do we have preferred names for tests?
There was a problem hiding this comment.
Just build the rbac.PolicyRule{} directly instead of using RuleOrDie
| "match without union": { | ||
| ExpectedBinding: binding(ref("role"), refs("a")), | ||
| ActualBinding: binding(ref("role"), refs("a")), | ||
| ExpectedBinding: binding(roleref("role"), subjects("a")), |
fda491f to
b25859c
Compare
tiran
left a comment
There was a problem hiding this comment.
I addressed most of your comments.
| if err != nil { | ||
| r.Error("CRBD1002", err, fmt.Sprintf("Unable to get clusterrolebinding/%s: %v", changedClusterRoleBinding.Name, err)) | ||
| } | ||
| actualRBACClusterRole, err := util.ClusterRoleBindingToRBAC(actualClusterRole) |
There was a problem hiding this comment.
Added error check
Is it OK to introduce a new error id?
|
|
||
| roleBinding.Subjects = changedRoleBindings[i].Subjects | ||
| rbacRoleBinding.Subjects = changedRoleBindings[i].Subjects | ||
| roleBinding, err = util.ClusterRoleBindingFromRBAC(rbacRoleBinding) |
| } | ||
|
|
||
| func computeUpdatedBinding(expected authorizationapi.ClusterRoleBinding, actual authorizationapi.ClusterRoleBinding, excludeSubjects []kapi.ObjectReference, union bool) (*authorizationapi.ClusterRoleBinding, bool) { | ||
| func computeUpdatedBinding(expected rbac.ClusterRoleBinding, actual rbac.ClusterRoleBinding, excludeSubjects []rbac.Subject, union bool) (*rbac.ClusterRoleBinding, bool) { |
There was a problem hiding this comment.
Why are shallow copies a problem and how do I avoid a shallow copy?
| "match without union": { | ||
| ExpectedBinding: binding(ref("role"), refs("a")), | ||
| ActualBinding: binding(ref("role"), refs("a")), | ||
| ExpectedBinding: binding("role", subjects("a")), |
There was a problem hiding this comment.
I made the bindings() helper function a bit more friendlier. It now takes a role name and creates the role object internally.
| r := []rbac.PolicyRule{} | ||
| for _, resource := range resources { | ||
| r = append(r, authorizationapi.PolicyRule{Verbs: sets.NewString("get"), Resources: sets.NewString(resource)}) | ||
| r = append(r, rbac.NewRule("get").Groups("testgroup").Resources(resource).RuleOrDie()) |
There was a problem hiding this comment.
rbac.PolicyRule requires a group for resource policies. The test won't pass without a group. I came up with an arbitrary group name. Do we have preferred names for tests?
| // This assumes bootstrap role bindings will not set any labels/annotations | ||
| // These aren't actually used during update; the latest labels/annotations are pulled from the existing object again | ||
| expectedClusterRoleBinding.Labels = actualClusterRoleBinding.Labels | ||
| expectedClusterRoleBinding.Annotations = actualClusterRoleBinding.Annotations |
There was a problem hiding this comment.
You probably want the data from actualRBACClusterRoleBinding.
b25859c to
bf9c42a
Compare
bf9c42a to
f23169f
Compare
| } | ||
| actualRBACClusterRole, err := util.ClusterRoleBindingToRBAC(actualClusterRole) | ||
| if err != nil { | ||
| r.Error("CRBD1008", err, fmt.Sprintf("Unable to convert clusterrolebinding/%s to RBAC: %v", changedClusterRoleBinding.Name, err)) |
There was a problem hiding this comment.
actualClusterRole.Name seems more appropriate.
There was a problem hiding this comment.
Case "CRBD1002" does not use continue, too. Now that you are pointing out the issue, both branches should probably use continue
| if err != nil { | ||
| r.Error("CRBD1002", err, fmt.Sprintf("Unable to get clusterrolebinding/%s: %v", changedClusterRoleBinding.Name, err)) | ||
| } | ||
| actualRBACClusterRole, err := util.ClusterRoleBindingToRBAC(actualClusterRole) |
There was a problem hiding this comment.
@liggitt @deads2k @sosiouxme may be able to advise better on the new error id.
| @@ -80,8 +81,12 @@ func (d *ClusterRoleBindings) Check() types.DiagnosticResult { | |||
| if err != nil { | |||
| r.Error("CRBD1002", err, fmt.Sprintf("Unable to get clusterrolebinding/%s: %v", changedClusterRoleBinding.Name, err)) | |||
| _, missingRules := rulevalidation.Covers(actualClusterRole.Rules, changedClusterRole.Rules) | ||
| actualRBACClusterRole, err := util.ClusterRoleToRBAC(actualClusterRole) | ||
| if err != nil { | ||
| r.Error("CRD1009", err, fmt.Sprintf("Unable to convert clusterrole/%s to RBAC cluster role: %v", changedClusterRole.Name, err)) |
| @@ -105,10 +106,15 @@ func (d *ClusterRoles) Check() types.DiagnosticResult { | |||
| r.Error("CRD1001", err, fmt.Sprintf("Unable to get clusterrole/%s: %v", changedClusterRole.Name, err)) | |||
| r := []rbac.PolicyRule{} | ||
| for _, resource := range resources { | ||
| r = append(r, authorizationapi.PolicyRule{Verbs: sets.NewString("get"), Resources: sets.NewString(resource)}) | ||
| r = append(r, rbac.NewRule("get").Groups("testgroup").Resources(resource).RuleOrDie()) |
There was a problem hiding this comment.
Just build the rbac.PolicyRule{} directly instead of using RuleOrDie
| if !kapihelper.Semantic.DeepEqual(roleBinding.RoleRef, changedRoleBindings[i].RoleRef) { | ||
| roleBinding.RoleRef = changedRoleBindings[i].RoleRef | ||
| roleBinding.Subjects = changedRoleBindings[i].Subjects | ||
| rbacRoleBinding.RoleRef = changedRoleBindings[i].RoleRef |
There was a problem hiding this comment.
@liggitt I do not understand why these 2 lines exist at all. Maybe they were never supposed to be inside the if statement?
|
@sosiouxme this calls for a verify script that fails a test if there are duplicate codes, we shouldn't rely on manual checks to guarantee the codes are unique, or errors will happen, humans are not good at this. |
|
@simo5 errr... patches welcome :) I agree that would be ideal but with the incredibly rapid pace of diagnostics development (har har) it hasn't been a priority. |
|
@sosiouxme gonna open an issue for ya ... |
f847c16 to
b8bd009
Compare
|
/retest |
1 similar comment
|
/retest |
|
/lgtm |
|
@smarterclayton can you approve? |
Closes: openshift#15827 Signed-off-by: Christian Heimes <[email protected]>
b8bd009 to
85030a3
Compare
|
/lgtm |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: enj, smarterclayton, tiran The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
|
/test all [submit-queue is verifying that this PR is safe to merge] |
|
Automatic merge from submit-queue (batch tested with PRs 13840, 16033, 16322, 16441) |
|
@tiran: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Drop
ConvertToOriginClusterRolesOrDieandConvertToOriginClusterRoleBindingsOrDie. Additional conversion likeClusterRoleBindingFromRBACandClusterRoleBindingToRBACwill be replaced oncerbac.ClusterRoleInterfaceclient is available.@openshift/sig-security
Closes: #15827
Signed-off-by: Christian Heimes [email protected]