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

Add parity check for Openshift policy and Kube RBAC #14429

Merged
merged 3 commits into from
Jun 12, 2017

Conversation

enj
Copy link
Contributor

@enj enj commented May 31, 2017

This change adds the oadm migrate authorization command:

A controller is used to keep Openshift authorization objects and Kubernetes RBAC in sync. This command checks for parity between those objects across all namespaces and reports all objects that are out of sync. These objects require manual intervention to sync as the controller handles all cases where automatic sync is possible.

The following resource types are checked by this command:

  • clusterrole
  • role
  • clusterrolebinding
  • rolebinding

No resources are mutated.

Signed-off-by: Monis Khan [email protected]

Fixes #14139
Prerequisite #14365 #14475

TODO

[test]

@@ -93,6 +94,7 @@ func NewCommandAdmin(name, fullName string, in io.Reader, out io.Writer, errout
// Migration commands
migrateimages.NewCmdMigrateImageReferences("image-references", fullName+" "+migrate.MigrateRecommendedName+" image-references", f, in, out, errout),
migratestorage.NewCmdMigrateAPIStorage("storage", fullName+" "+migrate.MigrateRecommendedName+" storage", f, in, out, errout),
migratepolicy.NewCmdMigratePolicy("policy", fullName+" "+migrate.MigrateRecommendedName+" policy", f, in, out, errout),
Copy link
Contributor

Choose a reason for hiding this comment

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

authorization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// ReporterBool implements the Reporter interface for a boolean.
type ReporterBool bool

func (r ReporterBool) Changed() bool { return bool(r) }
Copy link
Contributor

Choose a reason for hiding this comment

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

separate lines please

Copy link
Contributor Author

@enj enj Jun 6, 2017

Choose a reason for hiding this comment

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

Blah missed this one, will clean up later since #14365 is already 9 deep in the merge queue.

)

type MigratePolicyOptions struct {
migrate.ResourceOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

anonymously including this for some reason? I dislike anonymous includes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just following the pattern for every other migrate command.

// compare the results if there have been no errors so far
if len(errlist) == 0 {
// there's one wrinkle. If `openshift.io/reconcile-protect` is to true, then we must set rbac.authorization.kubernetes.io/autoupdate to false
if convertedClusterRole.Annotations["openshift.io/reconcile-protect"] == "true" {
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks very familiar. Restructure enough to be able to re-use the implementation for this with the controllers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are just different enough to not warrant trying to refactor, especially since we will delete the controller soon.

@enj enj force-pushed the enj/i/parity_rbac/14139 branch from b25b87f to e7c982e Compare June 6, 2017 21:13
@enj
Copy link
Contributor Author

enj commented Jun 6, 2017

@deads2k addressed comments as possible. Let me know if you want anything else changed. This is waiting on #14365 and #14475

@enj enj force-pushed the enj/i/parity_rbac/14139 branch from e7c982e to a2cd085 Compare June 6, 2017 21:29
Out: out,
ErrOut: errout,
AllNamespaces: true,
Include: []string{"clusterrole", "role", "clusterrolebinding", "rolebinding"},
Copy link
Contributor

Choose a reason for hiding this comment

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

clusterrole.authorization.openshift.io, right? This could never successfully be run on a prior version since the RBAC side would be missing.

@fabianofranz
Copy link
Member

lgtm from a cli perspective.

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 8, 2017
@enj enj force-pushed the enj/i/parity_rbac/14139 branch from a2cd085 to 3e7035f Compare June 8, 2017 18:55
@enj
Copy link
Contributor Author

enj commented Jun 8, 2017

@deads2k PTAL @ 3e7035f

@enj enj removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 8, 2017
@enj enj force-pushed the enj/i/parity_rbac/14139 branch from 3e7035f to 057ec4d Compare June 8, 2017 21:58
@enj
Copy link
Contributor Author

enj commented Jun 8, 2017

@deads2k 057ec4d

)

// NormalizePolicyRules mutates the given rules and lowercases verbs, resources and API groups.
func PrepareForCreateClusterRole(originClusterRole *authorizationapi.ClusterRole) (*rbac.ClusterRole, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ConvertToRBACClusterRole

return equivalentClusterRole, nil
}

func PrepareForUpdateClusterRole(equivalentClusterRole, rbacClusterRole *rbac.ClusterRole) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

godoc, particularly the mutation bit.

(newClusterRole, existingClusterRole *rbac.ClusterRole)

Copy link
Contributor

Choose a reason for hiding this comment

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

Invert the bool. Return true if an update is needed and doc it.

return apiequality.Semantic.DeepEqual(equivalentRoleBinding, rbacRoleBinding)
}

func normalizeObjectMeta(a *v1.ObjectMeta, b v1.ObjectMeta) {
Copy link
Contributor

Choose a reason for hiding this comment

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

godoc explaining why you're doing this to these particular fields. Also, this could all be non mutating given shallow copies. Take value objects and return a value object.

return apiequality.Semantic.DeepEqual(equivalentRoleBinding, rbacRoleBinding)
}

func normalizeObjectMeta(a *v1.ObjectMeta, b v1.ObjectMeta) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't normalization. This is "prepareObjectMetaForUpdate"

glog.V(1).Infof("writing RBAC role %v/%v", namespace, name)
_, err = c.rbacClient.Roles(namespace).Update(equivalentRole)
// if the update was invalid, we're probably changing an immutable field or something like that
// either way, the existing object is wrong. Delete it and try again.
if apierrors.IsInvalid(err) {
c.rbacClient.Roles(namespace).Delete(name, nil)
c.rbacClient.Roles(namespace).Delete(name, nil) // ignore delete error
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll trust you as a reader, but you really think it needs a comment?

@enj enj force-pushed the enj/i/parity_rbac/14139 branch from 057ec4d to 171b08c Compare June 10, 2017 08:53
@enj
Copy link
Contributor Author

enj commented Jun 10, 2017

Comments addressed.

[merge]

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 10, 2017
enj added 2 commits June 10, 2017 11:37
This change adds the `oadm migrate authorization` command:

A controller is used to keep Openshift authorization objects and
Kubernetes RBAC in sync.  This command checks for parity between those
objects across all namespaces and reports all objects that are out of
sync.  These objects require manual intervention to sync as the
controller handles all cases where automatic sync is possible.

The following resource types are checked by this command:

* clusterrole
* role
* clusterrolebinding
* rolebinding

No resources are mutated.

Signed-off-by: Monis Khan <[email protected]>
This change adds functions that handle all normalization, conversion and
comparison for the authorization objects.  These are now shared between
authorizationsync and `oadm migrate authorization` to prevent any logic
drift.

Signed-off-by: Monis Khan <[email protected]>
@enj enj force-pushed the enj/i/parity_rbac/14139 branch from 171b08c to 46af0f1 Compare June 10, 2017 15:38
@enj enj removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 10, 2017
@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 46af0f1

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/2096/) (Base Commit: a659cf7)

@enj
Copy link
Contributor Author

enj commented Jun 10, 2017

Flake #14496

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 46af0f1

@openshift-bot
Copy link
Contributor

openshift-bot commented Jun 12, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin/969/) (Base Commit: aed6393) (Image: devenv-rhel7_6338)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants