Skip to content

Commit

Permalink
browsersafe reason
Browse files Browse the repository at this point in the history
Signed-off-by: Monis Khan <[email protected]>
  • Loading branch information
enj authored and simo5 committed Aug 6, 2018
1 parent 7c57a53 commit fcf6cae
Showing 1 changed file with 29 additions and 2 deletions.
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
}

0 comments on commit fcf6cae

Please sign in to comment.