-
Notifications
You must be signed in to change notification settings - Fork 4.7k
RBAC Migration Followup #4: Use upstream subject locator directly #16034
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
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: abstractj Assign the PR to them by writing 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 |
/retest |
groups := sets.String{} | ||
for _, subject := range subjects { | ||
switch subject.Kind { | ||
case rbac.UserKind: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to handle ServiceAccount and map to a username
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liggitt I was wondering if we should take the code from here https://github.com/openshift/origin/pull/16034/files#diff-5654e020d459e05c8fcca57d5675ece4R59 and move to an utility function. In this way would be possible to reuse here and also at reviewer.go
Does it make sense? If yes, which place would be the best for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, a utility function to go from subjects to users/groups is fine
pkg/project/auth/reviewer.go
Outdated
users := sets.String{} | ||
groups := sets.String{} | ||
for _, subject := range subjects { | ||
switch subject.Kind { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -62,6 +61,7 @@ import ( | |||
securityapiv1 "github.com/openshift/origin/pkg/security/apis/security/v1" | |||
templateapiv1 "github.com/openshift/origin/pkg/template/apis/template/v1" | |||
userapiv1 "github.com/openshift/origin/pkg/user/apis/user/v1" | |||
"k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
group with kube imports
scopeLimitedAuthorizer := scope.NewAuthorizer(roleBasedAuthorizer, clusterRoleGetter, messageMaker) | ||
|
||
authorizer := authorizerunion.New( | ||
authorizerfactory.NewPrivilegedGroups(user.SystemPrivilegedGroup), // authorizes system:masters to do anything, just like upstream | ||
scopeLimitedAuthorizer) | ||
|
||
return authorizer, subjectLocator | ||
return authorizer, kubeSubjectLocator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should no longer take or return the kubeSubjectLocator
// users := sets.String{} | ||
// groups := sets.String{} | ||
// namespace := attributes.GetNamespace() | ||
// subjects, err := a.delegate.AllowedSubjects(attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abstractj sync with @tiran to use this as the foundation for two public functions:
[]rbac.Subject -> users, groups []string
users, groups []string -> []rbac.Subject
Put those in a new file at pkg/authorization/registry/util/subject.go
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]rbac.Subject, defaultServiceAccountNamespace
-> users, groups []string
do we need the reverse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/retest |
3 similar comments
/retest |
/retest |
/retest |
@abstractj you broke it 😄
|
@enj I just did a rebase, but I've been banging my head against the wall with Now that I changed the test I get the following output running
Which I believe, the cause is exclusively my ignorance about it. |
/retest |
1 similar comment
/retest |
All the changes requested were already included, I believe.
@simo5 could you please give it a try and let me know what do you think? Now |
This is the error:
|
/retest |
4 similar comments
/retest |
/retest |
/retest |
/retest |
/retest |
1 similar comment
/retest |
/hold This is not a bug, docs or tests so cannot be merged until 3.8. I still need to review it though. |
return a.users, a.groups, nil | ||
} | ||
return a.users, a.groups, errors.New(a.err) | ||
subjects := authorizationutil.BuildRBACSubjects(a.users.List(), a.groups.List()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine if the goal is to keep the diff small. But in reality the test authorizer should just return RBAC subject directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@enj I rebased/updated this PR with the changes you request. But this is the only part of your review which I'm not following.
The goal of this change was to keep the diff small as possible, plus I couldn't find any examples of usage to include RBAC subject directly. But I will be more than happy to look at this if you have any pointers of snippets.
@@ -4,29 +4,30 @@ import ( | |||
"errors" | |||
"fmt" | |||
|
|||
authorizationutil "github.com/openshift/origin/pkg/authorization/util" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move import to openshfit block.
return a.users, a.groups, nil | ||
} | ||
return a.users, a.groups, errors.New(a.err) | ||
subjects := authorizationutil.BuildRBACSubjects(a.users.List(), a.groups.List()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as earlier.
This is fine if the goal is to keep the diff small. But in reality the test authorizer should just return RBAC subject directly.
pkg/authorization/util/subject.go
Outdated
@@ -23,3 +25,35 @@ func BuildRBACSubjects(users, groups []string) []rbac.Subject { | |||
|
|||
return subjects | |||
} | |||
|
|||
func ExpandSubjects(namespace string, subjects []rbac.Subject) (sets.String, sets.String, error) { | |||
var err error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list of errors
pkg/authorization/util/subject.go
Outdated
users.Insert(name) | ||
} | ||
default: | ||
err = fmt.Errorf("Unrecognized kinds for subjects: %s. "+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
append to list of errors
pkg/authorization/util/subject.go
Outdated
} | ||
|
||
} | ||
return users, groups, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewAggregate on the errors
pkg/project/auth/reviewer.go
Outdated
users, groups, expandSubjectError := authorizationutil.ExpandSubjects(namespaceName, subjects) | ||
|
||
if expandSubjectError != nil { | ||
return nil, expandSubjectError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be fatal, it should add to review.evaluationError
pkg/project/auth/reviewer.go
Outdated
@@ -73,7 +74,9 @@ func (r *authorizerReviewer) Review(namespaceName string) (Review, error) { | |||
ResourceRequest: true, | |||
} | |||
|
|||
users, groups, err := r.policyChecker.GetAllowedSubjects(attributes) | |||
subjects, err := r.policyChecker.AllowedSubjects(attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this:
func (r *authorizerReviewer) Review(namespaceName string) (Review, error) {
attributes := kauthorizer.AttributesRecord{
Verb: "get",
Namespace: namespaceName,
Resource: "namespaces",
Name: namespaceName,
ResourceRequest: true,
}
// err is non fatal and partial success is possible
subjects, err := r.policyChecker.AllowedSubjects(attributes)
// expandSubjectError is non fatal and partial success is possible
users, groups, expandSubjectError := authorizationutil.ExpandSubjects(namespaceName, subjects)
review := &defaultReview{
users: users.List(),
groups: groups.List(),
}
if err != nil {
review.evaluationError = err.Error()
}
if expandSubjectError != nil {
review.evaluationError += " " + expandSubjectError.Error()
}
return review, nil
}
@@ -63,7 +63,9 @@ func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, _ bool) (runti | |||
} | |||
|
|||
attributes := util.ToDefaultAuthorizationAttributes(nil, resourceAccessReview.Action.Namespace, resourceAccessReview.Action) | |||
users, groups, err := r.subjectLocator.GetAllowedSubjects(attributes) | |||
subjects, err := r.subjectLocator.AllowedSubjects(attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like:
func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, _ bool) (runtime.Object, error) {
resourceAccessReview, ok := obj.(*authorizationapi.ResourceAccessReview)
if !ok {
return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a resourceAccessReview: %#v", obj))
}
if errs := authorizationvalidation.ValidateResourceAccessReview(resourceAccessReview); len(errs) > 0 {
return nil, kapierrors.NewInvalid(authorizationapi.Kind(resourceAccessReview.Kind), "", errs)
}
user, ok := apirequest.UserFrom(ctx)
if !ok {
return nil, kapierrors.NewInternalError(errors.New("missing user on request"))
}
// if a namespace is present on the request, then the namespace on the on the RAR is overwritten.
// This is to support backwards compatibility. To have gotten here in this state, it means that
// the authorizer decided that a user could run an RAR against this namespace
if namespace := apirequest.NamespaceValue(ctx); len(namespace) > 0 {
resourceAccessReview.Action.Namespace = namespace
} else if err := r.isAllowed(user, resourceAccessReview); err != nil {
// this check is mutually exclusive to the condition above. localSAR and localRAR both clear the namespace before delegating their calls
// We only need to check if the RAR is allowed **again** if the authorizer didn't already approve the request for a legacy call.
return nil, err
}
attributes := util.ToDefaultAuthorizationAttributes(nil, resourceAccessReview.Action.Namespace, resourceAccessReview.Action)
// err is non fatal and partial success is possible
subjects, err := r.subjectLocator.AllowedSubjects(attributes)
// expandSubjectError is non fatal and partial success is possible
users, groups, expandSubjectError := authorizationutil.ExpandSubjects(resourceAccessReview.Action.Namespace, subjects)
response := &authorizationapi.ResourceAccessReviewResponse{
Namespace: resourceAccessReview.Action.Namespace,
Users: users,
Groups: groups,
}
if err != nil {
response.EvaluationError = err.Error()
}
if err != nil {
response.EvaluationError += " " + expandSubjectError.Error()
}
return response, nil
}
Fixing the build....hold on |
/retest |
/hold cancel |
/hold Needs to wait until Monday at the earliest. |
@abstractj: The following tests 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. 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. |
@abstractj PR needs rebase |
Superseded by #18152 |
This PR attempts to fix the follow up #4 from RBAC migration.
Remaining task:
[]string