Skip to content

Commit

Permalink
Merge pull request #20379 from simo5/kill401MsgMkr
Browse files Browse the repository at this point in the history
Drop authorizer wrapper
  • Loading branch information
openshift-merge-robot authored Aug 7, 2018
2 parents 7285788 + feb2c85 commit f0fba65
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 456 deletions.
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

0 comments on commit f0fba65

Please sign in to comment.