Skip to content

Make openshift authorizer.GetResoruce match upstream #13259

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

Merged
merged 3 commits into from
Mar 10, 2017

Conversation

deads2k
Copy link
Contributor

@deads2k deads2k commented Mar 6, 2017

Builds on #13256 .

This switches us to use our own interface for authorization evaluation and updates our GetResource to match upstreams and adds the GetSubresource to have complete information.

@liggitt fyi
@enj ptal.

@deads2k
Copy link
Contributor Author

deads2k commented Mar 6, 2017

[test]

@@ -22,11 +23,24 @@ type DefaultAuthorizationAttributes struct {
// ToDefaultAuthorizationAttributes coerces Action to DefaultAuthorizationAttributes. Namespace is not included
// because the authorizer takes that information on the context
func ToDefaultAuthorizationAttributes(in authorizationapi.Action) Action {
// to match the RequestInfoFactory assuming an in.resource of one/two/three, one==resource, two==subresource, three=nothing
tokens := strings.Split(in.Resource, "/")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any code paths where we put more than two segments in the resource field, but if we did, I don't think we should discard extra segments. I'd expect SplitN and let the subresource have the remainder, including any extra slashes.

return allowedResourceTypes.Has(strings.ToLower(a.GetResource()))
}

return allowedResourceTypes.Has(strings.ToLower(a.GetResource() + "/" + a.GetSubresource()))
Copy link
Contributor

Choose a reason for hiding this comment

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

this is going to get called a lot... should find a way to avoid allocating on every call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is going to get called a lot... should find a way to avoid allocating on every call

I don't see this as a blocker for merge. The interfaces need to be right for the rebase, the call path optimization only needs to be done by release.

@@ -60,7 +60,8 @@ func (n NodeAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *htt
APIVersion: "v1",
APIGroup: "",
Verb: apiVerb,
Resource: "nodes/proxy",
Resource: "nodes",
Subresource: "proxy",
Copy link
Contributor

Choose a reason for hiding this comment

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

the ones below referenced as constants need changing as well

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, all the references to the joined resources in synthetic.go need review :-/

Copy link
Contributor

Choose a reason for hiding this comment

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

heh, just saw you hit that in #13286

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, all the references to the joined resources in synthetic.go need review :-/

I renamed them to find them. Interestingly enough, the authorization comparison still works because resource is opaque and still compares the entire thing.


func (a authorizationAttributesAdapter) GetSubresource() string {
// to match the RequestInfoFactory assuming an in.resource of one/two/three, one==resource, two==subresource, three=nothing
tokens := strings.Split(a.attrs.Resource, "/")
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, I'd expect SplitN

if !requestInfo.IsResourceRequest {
return requestInfo, nil
}
if strings.ToLower(requestInfo.Verb) != "create" {
Copy link
Contributor

Choose a reason for hiding this comment

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

are we getting verbs of mixed case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are we getting verbs of mixed case?

Not sure. If at some point we want to inspect every possible call path to avoid the tolower, we can see about changing it later.

if strings.ToLower(requestInfo.Verb) != "create" {
return requestInfo, nil
}
if len(requestInfo.APIGroup) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

do the API groupies know the grouped version won't support the special self SubjectAccessReview behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do the API groupies know the grouped version won't support the special self SubjectAccessReview behavior?

One of us merges first. We'll discover it either way.

@@ -817,8 +817,9 @@ func newAuthorizationAttributeBuilder(requestContextMapper kapi.RequestContextMa
sets.NewString(bootstrappolicy.AuthenticatedGroup),
requestInfoFactory,
)
personalSARRequestInfoResolveer := authorizer.NewPersonalSARRequestInfoResolver(browserSafeRequestInfoResolver)
Copy link
Contributor

Choose a reason for hiding this comment

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

typo personalSARRequestInfoResolveer

@@ -21,7 +21,7 @@ type DefaultAuthorizationAttributes struct {

// ToDefaultAuthorizationAttributes coerces Action to DefaultAuthorizationAttributes. Namespace is not included
// because the authorizer takes that information on the context
func ToDefaultAuthorizationAttributes(in authorizationapi.Action) DefaultAuthorizationAttributes {
func ToDefaultAuthorizationAttributes(in authorizationapi.Action) Action {
return DefaultAuthorizationAttributes{
Copy link
Contributor

Choose a reason for hiding this comment

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

huh... this is a chunky struct to copy around (either as an arg or as a receiver). not new, but worth making a pointer in a follow up.

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.

More nits

messageResolver.addRootScopedForbiddenMessageMaker("update", authorizationapi.ResourceAll, newTemplateForbiddenMessageMaker(`User "{{.User.GetName}}" cannot update `+apiGroupIfNotEmpty+`{{.Attributes.GetResource}} at the cluster scope`))
messageResolver.addNamespacedForbiddenMessageMaker("delete", authorizationapi.ResourceAll, newTemplateForbiddenMessageMaker(`User "{{.User.GetName}}" cannot delete `+apiGroupIfNotEmpty+`{{.Attributes.GetResource}} in project "{{.Namespace}}"`))
messageResolver.addRootScopedForbiddenMessageMaker("delete", authorizationapi.ResourceAll, newTemplateForbiddenMessageMaker(`User "{{.User.GetName}}" cannot delete `+apiGroupIfNotEmpty+`{{.Attributes.GetResource}} at the cluster scope`))
messageResolver.addNamespacedForbiddenMessageMaker("create", authorizationapi.ResourceAll, newTemplateForbiddenMessageMaker(`User "{{.User.GetName}}" cannot create `+apiGroupIfNotEmpty+resourceWithSubresourceIfNotEmpty+` in project "{{.Namespace}}"`))
Copy link
Contributor

Choose a reason for hiding this comment

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

These should be ... resourceWithSubresourceIfNotEmpty+apiGroupIfNotEmpty ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These should be ... resourceWithSubresourceIfNotEmpty+apiGroupIfNotEmpty

If you want to change the message formats (which I'd agree with), that's a separate thing to do.

@@ -21,27 +21,28 @@ type ForbiddenMessageResolver struct {

func NewForbiddenMessageResolver(projectRequestForbiddenTemplate string) *ForbiddenMessageResolver {
apiGroupIfNotEmpty := "{{if len .Attributes.GetAPIGroup }}{{.Attributes.GetAPIGroup}}.{{end}}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the . before the group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The dot is a separator for display. It could be removed entirely and the messages reworked, but it can't move before.

@@ -93,21 +93,19 @@ func (r *RemoteAuthorizer) GetAllowedSubjects(ctx kapi.Context, attributes autho
}

func getAction(namespace string, attributes authorizer.Action) authzapi.Action {
resource := attributes.GetResource()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have tests for round tripping authorizer.Action <-> authzapi.Action. Maybe we don't need them if we completely use kube stuff...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have tests for round tripping authorizer.Action <-> authzapi.Action. Maybe we don't need them if we completely use kube stuff...

We're two pulls (already open from removal). I think this is a gimme.

@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

Opened #13316 for potential performance related followup.

@deads2k deads2k force-pushed the auth-05-interface branch from 37191a4 to 10e2e6c Compare March 9, 2017 12:55
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.

More nits... once tests pass I think this is good to go.

resource := ""
subresource := ""
switch {
case len(tokens) >= 2:
Copy link
Contributor

Choose a reason for hiding this comment

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

case len(tokens) == 2?

@@ -22,11 +23,24 @@ type DefaultAuthorizationAttributes struct {
// ToDefaultAuthorizationAttributes coerces Action to DefaultAuthorizationAttributes. Namespace is not included
// because the authorizer takes that information on the context
func ToDefaultAuthorizationAttributes(in authorizationapi.Action) Action {
// to match the RequestInfoFactory assuming an in.resource of one/two/three, one==resource, two==subresource, three=nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment is wrong.

@deads2k deads2k force-pushed the auth-05-interface branch from 10e2e6c to c3bb1dd Compare March 9, 2017 15:05
@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

More nits... once tests pass I think this is good to go.

comments addressed.

@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

re[test]

@deads2k deads2k force-pushed the auth-05-interface branch from 185060d to c3bb1dd Compare March 9, 2017 18:46
@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

re[test]

1 similar comment
@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

re[test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to c3bb1dd

@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to c3bb1dd

@openshift-bot
Copy link
Contributor

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

@openshift-bot
Copy link
Contributor

openshift-bot commented Mar 10, 2017

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin/25/) (Base Commit: 18a751b) (Image: devenv-rhel7_6062)

@openshift-bot openshift-bot merged commit 5602529 into openshift:master Mar 10, 2017
@deads2k deads2k deleted the auth-05-interface branch August 3, 2017 19:24
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