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

Update RoleBindingRestriction admission to handle RBAC #16163

Merged
merged 1 commit into from Sep 9, 2017

Conversation

simo5
Copy link
Contributor

@simo5 simo5 commented Sep 6, 2017

Fixes #16042

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 6, 2017
@simo5 simo5 requested a review from enj September 6, 2017 03:15
@simo5
Copy link
Contributor Author

simo5 commented Sep 6, 2017

/retest

@csrwng csrwng removed their assignment Sep 6, 2017
enj
enj previously requested changes Sep 6, 2017
@@ -98,7 +99,12 @@ func (q *restrictUsersAdmission) Admit(a admission.Attributes) (err error) {
// We only care about rolebindings and policybindings; ignore anything else.
gr := a.GetResource().GroupResource()
switch {
case authorizationapi.IsResourceOrLegacy("policybindings", gr), authorizationapi.IsResourceOrLegacy("rolebindings", gr):
case authorizationapi.IsResourceOrLegacy("policybindings", gr):
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm maybe we do not need this anymore. During HA upgrade if you talk with a new master about policy bindings it will simply say it does not know what that is. Old masters will continue to work for policy bindings and origin role bindings. Old masters also do not allow messing with RBAC by normal users. @deads2k do you agree that we are safe in dropping this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't care about the policybinding case because new masters (where this admission plugin will be running) will 404 before they get to admission.

for _, tc := range testCases {
switch tc.object.(type) {
case *authorizationapi.RoleBinding:
newObj := rbac.RoleBinding{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Declare these as pointers.

// object
convTestCases := []testCase{}
for _, tc := range testCases {
switch tc.object.(type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

x := tc.object.(type) to save you one of the type casts.

case *authorizationapi.RoleBinding:
newObj := rbac.RoleBinding{}
oldObj := rbac.RoleBinding{}
if err := authorizationapi.Convert_authorization_RoleBinding_To_rbac_RoleBinding(tc.object.(*authorizationapi.RoleBinding), &newObj, nil); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want to use the helpers to have deep copies just in case.

@@ -569,6 +572,40 @@ func TestAdmission(t *testing.T) {
stopCh := make(chan struct{})
defer close(stopCh)

// for each testCase that involves an authorizationapi rolebinding also
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like one command line based test for each type (i.e. I want this verified with a real server).

@@ -127,7 +130,7 @@ func TestAdmission(t *testing.T) {
Name: "rolebinding",
},
Subjects: []kapi.ObjectReference{userAliceRef},
RoleRef: kapi.ObjectReference{Namespace: authorizationapi.PolicyName},
RoleRef: kapi.ObjectReference{Namespace: "namespace"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this matter?

}
}

glog.V(4).Infof("Handling rolebinding %s/%s",
Copy link
Contributor

Choose a reason for hiding this comment

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

Handling RBAC rolebinding

case authorizationapi.IsResourceOrLegacy("policybindings", gr), authorizationapi.IsResourceOrLegacy("rolebindings", gr):
case authorizationapi.IsResourceOrLegacy("policybindings", gr):
// legacy policy bindings
case authorizationapi.IsResourceOrLegacy("rolebindings", gr):
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're proxying through to RBAC rolebindings as the original user, yoiu probably don't care about this case, right? Admission will run on the RBAC resource.


glog.V(4).Infof("Handling rolebinding %s/%s",
rolebinding.Namespace, rolebinding.Name)

case authorizationapi.IsResourceOrLegacy("rolebindings", gr):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just enforce on the RBAC resource you proxied to?

Copy link
Contributor

Choose a reason for hiding this comment

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

That is probably what we want to do, though at that point we may need to rewrite most of the logic in this file and the tests to be RBAC specific. We may want to take a half step and have this working using conversions so that it no longer blocks deployment to online. Then we can continue to work on this for 3.7 release without rushing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I think it's fair, I'll go ahead and actually drop all authorization api related stuff in RBR and tests, and only base on RBAC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@enj, I am still using the conversion functions to convert subjects, as I am not rewriting subjectchecker at this time, we'll probably open a followup issue for that one for now

enj
enj previously requested changes Sep 7, 2017
Copy link
Contributor

@enj enj left a comment

Choose a reason for hiding this comment

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

Nits.

@@ -22,6 +23,19 @@ import (
userapi "github.com/openshift/origin/pkg/user/apis/user"
)

type testCase struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this back.

@@ -114,66 +113,39 @@ func (q *restrictUsersAdmission) Admit(a admission.Attributes) (err error) {
return nil
}

var subjects, oldSubjects []kapi.ObjectReference
var subjects, oldSubjects []rbac.Subject
Copy link
Contributor

Choose a reason for hiding this comment

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

Use rolebinding.Subjects and remove the subjects var.


systemuserRef = kapi.ObjectReference{
Kind: authorizationapi.SystemUserKind,
Name: "system user",
Copy link
Contributor

Choose a reason for hiding this comment

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

@deads2k we OK dropping this?

name: "prohibit a user in a policybinding without a matching selector",
expectedErr: fmt.Sprintf("rolebindings to %s %q are not allowed",
userBobRef.Kind, userBobRef.Name),
object: &authorizationapi.PolicyBinding{
Copy link
Contributor

Choose a reason for hiding this comment

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

I do enjoy deleting policy code.

@enj
Copy link
Contributor

enj commented Sep 7, 2017

@simo5 please add command level tests for this (both proxied and direct RBAC). I want confirmation this works in a real setup.

@simo5 simo5 force-pushed the updateRBR branch 2 times, most recently from 33cc2ac to 479f306 Compare September 8, 2017 19:27
@simo5
Copy link
Contributor Author

simo5 commented Sep 8, 2017

@enj added a native rbac test in integration, other "real" tests were already there and working. PTAL

Signed-off-by: Simo Sorce <simo@redhat.com>
@enj
Copy link
Contributor

enj commented Sep 8, 2017

/lgtm

@simo5 please tag this will the followup issue to remove the conversions and use RBAC directly (and drop all the system kind bits).

@deads2k feel free to block if #16163 (comment) is an issue.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 8, 2017
@openshift-merge-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enj, simo5

The full list of commands accepted by this bot can be found here.

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 8, 2017
@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue

@openshift-merge-robot openshift-merge-robot merged commit 2a02f4b into openshift:master Sep 9, 2017
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.

None yet

6 participants