Repository navigation
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. DetailsNeeds 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.
need to handle ServiceAccount and map to a username
There was a problem hiding this comment.
@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.
sure, a utility function to go from subjects to users/groups is fine
| users := sets.String{} | ||
| groups := sets.String{} | ||
| for _, subject := range subjects { | ||
| switch subject.Kind { |
| 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" |
| scopeLimitedAuthorizer) | ||
|
|
||
| return authorizer, subjectLocator | ||
| return authorizer, kubeSubjectLocator |
There was a problem hiding this comment.
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.
@abstractj sync with @tiran to use this as the foundation for two public functions:
[]rbac.Subject -> users, groups []stringusers, 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.
[]rbac.Subject, defaultServiceAccountNamespace -> users, groups []string
do we need the reverse?
There was a problem hiding this comment.
|
/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.
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.
@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.
| "errors" | ||
| "fmt" | ||
|
|
||
| authorizationutil "github.com/openshift/origin/pkg/authorization/util" |
There was a problem hiding this comment.
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.
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.
| } | ||
|
|
||
| func ExpandSubjects(namespace string, subjects []rbac.Subject) (sets.String, sets.String, error) { | ||
| var err error |
| users.Insert(name) | ||
| } | ||
| default: | ||
| err = fmt.Errorf("Unrecognized kinds for subjects: %s. "+ |
| } | ||
|
|
||
| } | ||
| return users, groups, err |
| users, groups, expandSubjectError := authorizationutil.ExpandSubjects(namespaceName, subjects) | ||
|
|
||
| if expandSubjectError != nil { | ||
| return nil, expandSubjectError |
There was a problem hiding this comment.
This should not be fatal, it should add to review.evaluationError
| } | ||
|
|
||
| users, groups, err := r.policyChecker.GetAllowedSubjects(attributes) | ||
| subjects, err := r.policyChecker.AllowedSubjects(attributes) |
There was a problem hiding this comment.
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
}|
|
||
| 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.
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. 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. |
|
@abstractj PR needs rebase |
|
Superseded by #18152 |
This PR attempts to fix the follow up #4 from RBAC migration.
Remaining task:
[]string