Skip to content
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

Drop authorizer wrapper #20379

Merged
merged 3 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions pkg/authorization/authorizer/authorizer.go

This file was deleted.

31 changes: 29 additions & 2 deletions pkg/authorization/authorizer/browsersafe/authorizer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package browsersafe

import (
"fmt"

"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apiserver/pkg/authorization/authorizer"
)
Expand All @@ -25,8 +27,17 @@ func NewBrowserSafeAuthorizer(delegate authorizer.Authorizer, authenticatedGroup
}

func (a *browserSafeAuthorizer) Authorize(attributes authorizer.Attributes) (authorizer.Decision, string, error) {
browserSafeAttributes := a.getBrowserSafeAttributes(attributes)
return a.delegate.Authorize(browserSafeAttributes)
attrs := a.getBrowserSafeAttributes(attributes)
decision, reason, err := a.delegate.Authorize(attrs)
safeAttributes, changed := attrs.(*browserSafeAttributes)

// check if the request was not allowed and we changed the attributes
if decision == authorizer.DecisionAllow || !changed {
return decision, reason, err
}

// if so, use this information to update the reason
return decision, safeAttributes.reason(reason), err
}

func (a *browserSafeAuthorizer) getBrowserSafeAttributes(attributes authorizer.Attributes) authorizer.Attributes {
Expand Down Expand Up @@ -77,3 +88,19 @@ func (b *browserSafeAttributes) GetSubresource() string {
}
return b.Attributes.GetSubresource()
}

func (b *browserSafeAttributes) reason(reason string) string {
if b.isProxyVerb {
if len(reason) != 0 {
reason += ", "
}
reason += fmt.Sprintf("%s verb changed to %s", proxyAction, unsafeProxy)
}
if b.isProxySubresource {
if len(reason) != 0 {
reason += ", "
}
reason += fmt.Sprintf("%s subresource changed to %s", proxyAction, unsafeProxy)
}
return reason
}
12 changes: 8 additions & 4 deletions pkg/authorization/authorizer/browsersafe/authorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func TestBrowserSafeAuthorizer(t *testing.T) {

expectedVerb string
expectedSubresource string
expectedReason string
}{
"non-resource": {
attributes: authorizer.AttributesRecord{ResourceRequest: false, Verb: "GET"},
Expand All @@ -29,15 +30,18 @@ func TestBrowserSafeAuthorizer(t *testing.T) {
attributes: authorizer.AttributesRecord{ResourceRequest: true, Verb: "get", Resource: "pods", Subresource: "proxy"},
expectedVerb: "get",
expectedSubresource: "unsafeproxy",
expectedReason: "proxy subresource changed to unsafeproxy",
},
"unsafe proxy verb": {
attributes: authorizer.AttributesRecord{ResourceRequest: true, Verb: "proxy", Resource: "nodes"},
expectedVerb: "unsafeproxy",
attributes: authorizer.AttributesRecord{ResourceRequest: true, Verb: "proxy", Resource: "nodes"},
expectedVerb: "unsafeproxy",
expectedReason: "proxy verb changed to unsafeproxy",
},
"unsafe proxy verb anonymous": {
attributes: authorizer.AttributesRecord{ResourceRequest: true, Verb: "proxy", Resource: "nodes",
User: &user.DefaultInfo{Name: "system:anonymous", Groups: []string{"system:unauthenticated"}}},
expectedVerb: "unsafeproxy",
expectedVerb: "unsafeproxy",
expectedReason: "proxy verb changed to unsafeproxy",
},

"proxy subresource authenticated": {
Expand All @@ -51,7 +55,7 @@ func TestBrowserSafeAuthorizer(t *testing.T) {
safeAuthorizer := NewBrowserSafeAuthorizer(delegateAuthorizer, "system:authenticated")

authorized, reason, err := safeAuthorizer.Authorize(tc.attributes)
if authorized == authorizer.DecisionAllow || len(reason) != 0 || err != nil {
if authorized == authorizer.DecisionAllow || reason != tc.expectedReason || err != nil {
t.Errorf("%s: unexpected output: %v %s %v", name, authorized, reason, err)
continue
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/authorization/authorizer/interfaces.go

This file was deleted.

128 changes: 0 additions & 128 deletions pkg/authorization/authorizer/messages.go

This file was deleted.

Loading