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

browsersafe reason #18

Closed
wants to merge 3 commits into from
Closed
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
}
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