Skip to content

switch to kube authorization attributes #13286

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 4 commits into from
Mar 10, 2017

Conversation

deads2k
Copy link
Contributor

@deads2k deads2k commented Mar 7, 2017

Builds on #13259.

This pull removes our existing attributes and uses the upstream kube attributes. At this point our interfaces should overlap. I'm planning one more to remove our authorizer interface altogether.

@liggitt @enj

@deads2k
Copy link
Contributor Author

deads2k commented Mar 7, 2017

[test]

@@ -16,28 +17,36 @@ func NewAuthorizationAttributeBuilder(contextMapper kapi.RequestContextMapper, i
return &openshiftAuthorizationAttributeBuilder{contextMapper, infoFactory}
}

func (a *openshiftAuthorizationAttributeBuilder) GetAttributes(req *http.Request) (Action, error) {
func (a *openshiftAuthorizationAttributeBuilder) GetAttributes(req *http.Request) (authorizer.Attributes, error) {
attribs := authorizer.AttributesRecord{}
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 down before line 32?

keyData["namespace"] = namespace
}
if user, ok := kapi.UserFrom(ctx); ok {
keyData["namespace"] = a.GetNamespace()
Copy link
Contributor

Choose a reason for hiding this comment

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

Move up into the map declaration?

Resource: "r",
Subresource: "sub",
Name: "rn",
ResourceRequest: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't really matter, but NonResourceURL: true is the opposite of ResourceRequest: true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't really matter, but NonResourceURL: true is the opposite of ResourceRequest: true

Didn't matter in the test. I thought it better to test something other than zero values.

@@ -59,7 +56,7 @@ func TestCacheKey(t *testing.T) {
}

func TestCacheKeyFields(t *testing.T) {
keyJSON, err := cacheKey(kapi.NewContext(), &authorizer.DefaultAuthorizationAttributes{})
keyJSON, err := cacheKey(authorizer.AttributesRecord{User: &user.DefaultInfo{Name: "me"}})
Copy link
Contributor

Choose a reason for hiding this comment

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

why was the default user needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, to exercise all the cache keys

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.

Still reviewing...

NonResourceURL bool
URL string
}

// ToDefaultAuthorizationAttributes coerces Action to DefaultAuthorizationAttributes. Namespace is not included
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of date comment.

var localSARAttributes kauthorizer.AttributesRecord
// if they are running a personalSAR, create synthentic check for selfSAR
if authorizer.IsPersonalAccessReviewFromSAR(sar) {
localSARAttributes = kauthorizer.AttributesRecord{
Copy link
Contributor

Choose a reason for hiding this comment

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

This and every other AttributesRecord that is manually built is incorrect. ResourceRequest needs to be explicitly set to true.

I0309 01:03:37.003518   13555 messages.go:126] User "developer" cannot "create" on "" <nil> authorizer.AttributesRecord{User:(*user.DefaultInfo)(0xc4277905c0), Verb:"create", Namespace:"", APIGroup:"authorization.k8s.io", APIVersion:"", Resource:"selfsubjectaccessreviews", Subresource:"", Name:"", ResourceRequest:false, Path:""}

Copy link
Contributor

Choose a reason for hiding this comment

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

Well. That's a painful default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well. That's a painful default.

Yeah, guess I missed a couple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, glad our tests exercise many of these. Go us :)

// GetURL returns the URL path being requested, including the leading '/'
GetURL() string
}

// ForbiddenMessageMaker creates a forbidden message from a MessageContext
type ForbiddenMessageMaker interface {
MakeMessage(ctx MessageContext) (string, error)
}

// MessageContext contains sufficient information to create a forbidden message. It is bundled in this one object to make it easy and obvious how to build a golang template
type MessageContext struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Drop MessageContext and use authorizer.Attributes directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drop MessageContext and use authorizer.Attributes directly?

If you want to do it as a followup, sure. Not needed to collapse interfaces ahead of the rebase.

"k8s.io/kubernetes/pkg/util/sets"
)

type Authorizer interface {
Authorize(ctx kapi.Context, a Action) (allowed bool, reason string, err error)
GetAllowedSubjects(ctx kapi.Context, attributes Action) (sets.String, sets.String, error)
Authorize(a authorizer.Attributes) (allowed bool, reason string, err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

a -> attributes

@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

Oh, the cool one was the subtle namespace problem. We hacked the namespace into the context in a filter for projects. When I eliminated using context, we lost that value for project authorization which made everything go haywire.

@deads2k deads2k force-pushed the auth-06-collapse branch from 9139921 to e38baf1 Compare March 9, 2017 13:23
@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

comments addressed.

@ncdc
Copy link
Contributor

ncdc commented Mar 9, 2017

These look like they might be caused by this PR?

09:22:16 === BEGIN TEST CASE ===
09:22:16 test/cmd/images_tests.sh:204: executing 'oc tag cmd-images-old-policy/mysql:5.5 newrepo:latest' expecting success
09:22:16 
FAILURE after 0.722s: test/cmd/images_tests.sh:204: executing 'oc tag cmd-images-old-policy/mysql:5.5 newrepo:latest' expecting success: the command returned the wrong error code
09:22:16 There was no output from the command.
09:22:16 Standard error from the command:
09:22:16 The ImageStream "newrepo" is invalid: []: Internal error: imagestreams "newrepo" is invalid: spec.tags[latest].from: Forbidden: cmd-images-old-policy/mysql
09:22:16 === END TEST CASE ===
09:22:16 In suite "github.com/openshift/origin/test/cmd/policy", test case "test/cmd/policy.sh:113: executing 'oc policy scc-subject-review -f ${OS_ROOT}/test/testdata/job.yaml -o=jsonpath={.status.AllowedBy.name}' expecting success and text 'restricted'" failed:
09:22:16 === BEGIN TEST CASE ===
09:22:16 test/cmd/policy.sh:113: executing 'oc policy scc-subject-review -f ${OS_ROOT}/test/testdata/job.yaml -o=jsonpath={.status.AllowedBy.name}' expecting success and text 'restricted'
09:22:16 FAILURE after 0.194s: test/cmd/policy.sh:113: executing 'oc policy scc-subject-review -f ${OS_ROOT}/test/testdata/job.yaml -o=jsonpath={.status.AllowedBy.name}' expecting success and text 'restricted': the command returned the wrong error code; the output content test failed
09:22:16 There was no output from the command.
09:22:16 Standard error from the command:
09:22:16 error: unable to compute Pod Security Policy Subject Review for "hello": User "bob" cannot create podsecuritypolicyselfsubjectreviews in project "bob"
09:22:16 === END TEST CASE ===

@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

These look like they might be caused by this PR?

Yeah, I'll make it through.

@@ -827,8 +827,9 @@ func newAuthorizationAttributeBuilder(requestContextMapper kapi.RequestContextMa
requestInfoFactory,
)
personalSARRequestInfoResolver := authorizer.NewPersonalSARRequestInfoResolver(browserSafeRequestInfoResolver)
projectRequestInfoResolver := authorizer.NewProjectRequestInfoResolver(personalSARRequestInfoResolver)
Copy link
Contributor

Choose a reason for hiding this comment

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

final := chainFunc(
    browserSafeRequestInfoResolver,  // base info
    authorizer.NewPersonalSARRequestInfoResolver,  // wrapper funcs
    authorizer.NewProjectRequestInfoResolver,
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

final := chainFunc(
browserSafeRequestInfoResolver, // base info
authorizer.NewPersonalSARRequestInfoResolver, // wrapper funcs
authorizer.NewProjectRequestInfoResolver,
)

No real disagreement, but I suspect this gets reswizzled in the rebase. You want the related updates now?

Copy link
Contributor

Choose a reason for hiding this comment

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

After rebase sounds good to me.

@enj
Copy link
Contributor

enj commented Mar 9, 2017

LGTM if tests pass.

@deads2k deads2k force-pushed the auth-06-collapse branch from 35173c8 to 52e4858 Compare March 9, 2017 16:56
@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]

@deads2k
Copy link
Contributor Author

deads2k commented Mar 9, 2017

[merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 52e4858

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 52e4858

@openshift-bot
Copy link
Contributor

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

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge ABORTED (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin/26/) (Base Commit: 5602529)

@openshift-bot openshift-bot merged commit 52e4858 into openshift:master Mar 10, 2017
@deads2k deads2k deleted the auth-06-collapse 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.

5 participants