-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
[test] |
4b54e2b
to
9139921
Compare
@@ -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{} |
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 this down before line 32?
keyData["namespace"] = namespace | ||
} | ||
if user, ok := kapi.UserFrom(ctx); ok { | ||
keyData["namespace"] = a.GetNamespace() |
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 up into the map declaration?
Resource: "r", | ||
Subresource: "sub", | ||
Name: "rn", | ||
ResourceRequest: true, |
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.
doesn't really matter, but NonResourceURL: true
is the opposite of ResourceRequest: true
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.
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"}}) |
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.
why was the default user needed?
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.
oh, to exercise all the cache keys
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.
Still reviewing...
NonResourceURL bool | ||
URL string | ||
} | ||
|
||
// ToDefaultAuthorizationAttributes coerces Action to DefaultAuthorizationAttributes. Namespace is not included |
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.
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{ |
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 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:""}
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.
Well. That's a painful default.
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.
Well. That's a painful default.
Yeah, guess I missed a couple.
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.
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 { |
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.
Drop MessageContext
and use authorizer.Attributes
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.
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) |
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.
a
-> attributes
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. |
9139921
to
e38baf1
Compare
comments addressed. |
These look like they might be caused by this PR?
|
Yeah, I'll make it through. |
e38baf1
to
35173c8
Compare
@@ -827,8 +827,9 @@ func newAuthorizationAttributeBuilder(requestContextMapper kapi.RequestContextMa | |||
requestInfoFactory, | |||
) | |||
personalSARRequestInfoResolver := authorizer.NewPersonalSARRequestInfoResolver(browserSafeRequestInfoResolver) | |||
projectRequestInfoResolver := authorizer.NewProjectRequestInfoResolver(personalSARRequestInfoResolver) |
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.
final := chainFunc(
browserSafeRequestInfoResolver, // base info
authorizer.NewPersonalSARRequestInfoResolver, // wrapper funcs
authorizer.NewProjectRequestInfoResolver,
)
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.
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?
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.
After rebase sounds good to me.
LGTM if tests pass. |
35173c8
to
52e4858
Compare
re[test] |
1 similar comment
re[test] |
[merge] |
Evaluated for origin merge up to 52e4858 |
Evaluated for origin test up to 52e4858 |
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin/86/) (Base Commit: d3a3181) |
continuous-integration/openshift-jenkins/merge ABORTED (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin/26/) (Base Commit: 5602529) |
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