Skip to content

Drop double conversion in boostrap policy - #16033

Merged
openshift-merge-robot merged 1 commit into
openshift:masterfrom
tiran:remove_converttoorigin
Sep 21, 2017
Merged

openshift-merge-robot merged 1 commit into
openshift:masterfrom
tiran:remove_converttoorigin

Conversation

@tiran

@tiran tiran commented Aug 29, 2017

Copy link
Copy Markdown
Contributor

Drop ConvertToOriginClusterRolesOrDie and ConvertToOriginClusterRoleBindingsOrDie. Additional conversion like ClusterRoleBindingFromRBAC and ClusterRoleBindingToRBAC will be replaced once rbac.ClusterRoleInterface client is available.

@openshift/sig-security

Closes: #15827
Signed-off-by: Christian Heimes [email protected]

@openshift-merge-robot openshift-merge-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 29, 2017
return subjects
}

func BuildRBACSubjects(users, groups []string) []rbac.Subject {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used in one spot. move it to the point of use to prevent proliferation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deads2k I moved the function and made it private.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

if err != nil {
r.Error("CRBD1002", err, fmt.Sprintf("Unable to get clusterrolebinding/%s: %v", changedClusterRoleBinding.Name, err))
}
actualRBACClusterRole, err := util.ClusterRoleBindingToRBAC(actualClusterRole)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added error check

Is it OK to introduce a new error id?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liggitt @deads2k @sosiouxme may be able to advise better on the new error id.

@sosiouxme sosiouxme Sep 12, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the empty line.


roleBinding.Subjects = changedRoleBindings[i].Subjects
rbacRoleBinding.Subjects = changedRoleBindings[i].Subjects
roleBinding, err = util.ClusterRoleBindingFromRBAC(rbacRoleBinding)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

}

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this make shallow copies?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DiffSubjects

"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
osutil "github.com/openshift/origin/pkg/cmd/util"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line.

}

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shallow copies?

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())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did testgroup come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My eyes hurt.

@tiran
tiran force-pushed the remove_converttoorigin branch 2 times, most recently from fda491f to b25859c Compare August 30, 2017 11:02

@tiran tiran left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

}

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) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want the data from actualRBACClusterRoleBinding.

@tiran
tiran force-pushed the remove_converttoorigin branch from b25859c to bf9c42a Compare August 30, 2017 19:01
@tiran
tiran force-pushed the remove_converttoorigin branch from bf9c42a to f23169f Compare September 11, 2017 12:44
enj
enj previously requested changes Sep 11, 2017
Comment thread pkg/diagnostics/cluster/rolebindings.go Outdated
}
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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actualClusterRole.Name seems more appropriate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No continue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No continue?

Comment thread pkg/diagnostics/cluster/roles.go Outdated
_, 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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No continue?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actualClusterRole.Name

@@ -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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No continue?

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())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liggitt I do not understand why these 2 lines exist at all. Maybe they were never supposed to be inside the if statement?

@simo5

simo5 commented Sep 12, 2017 •

Copy link
Copy Markdown

@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.

@sosiouxme

Copy link
Copy Markdown
Member

@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.

@simo5

simo5 commented Sep 14, 2017

Copy link
Copy Markdown

@sosiouxme gonna open an issue for ya ...
... #16364

@tiran
tiran force-pushed the remove_converttoorigin branch from f847c16 to b8bd009 Compare September 20, 2017 18:42
@simo5

simo5 commented Sep 20, 2017

Copy link
Copy Markdown

/retest

1 similar comment
@simo5

simo5 commented Sep 20, 2017

Copy link
Copy Markdown

/retest

@enj

enj commented Sep 20, 2017

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 20, 2017
@enj

enj commented Sep 20, 2017

Copy link
Copy Markdown
Contributor

@smarterclayton can you approve?

@tiran
tiran force-pushed the remove_converttoorigin branch from b8bd009 to 85030a3 Compare September 21, 2017 14:38
@openshift-merge-robot openshift-merge-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 21, 2017
@enj

enj commented Sep 21, 2017

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 21, 2017
@smarterclayton

Copy link
Copy Markdown
Contributor

/approve

@openshift-merge-robot

Copy link
Copy Markdown
Contributor

[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.

Details Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 21, 2017
@openshift-merge-robot

Copy link
Copy Markdown
Contributor

/test all [submit-queue is verifying that this PR is safe to merge]

@openshift-merge-robot

Copy link
Copy Markdown
Contributor

Automatic merge from submit-queue (batch tested with PRs 13840, 16033, 16322, 16441)

@openshift-merge-robot
openshift-merge-robot merged commit 8602aca into openshift:master Sep 21, 2017
@openshift-ci-robot

openshift-ci-robot commented Sep 21, 2017 •

Copy link
Copy Markdown

@tiran: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/openshift-jenkins/cmd 85030a3 link /test cmd

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.

Details

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants