Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

subjectreviewaccess call as a namespaced resource #1

Open
wants to merge 1 commit into
base: v0.11.0-tilda
Choose a base branch
from
Open
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
50 changes: 47 additions & 3 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ func (n krpAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *http

if n.authzConfig.ResourceAttributes == nil {
// Default attributes mirror the API attributes that would allow this access to kube-rbac-proxy
allAttrs := append(allAttrs, authorizer.AttributesRecord{

// following canonical URL formats are suggested
// /apis/<apiGroup>/<apiVersion>/namespaces/<namespaceName>/<resourceType>
// /apis/<apiGroup>/<apiVersion>/namespaces/<namespaceName>/<resourceType>/<resourceName>
// /apis/<apiGroup>/<apiVersion>/namespaces/<namespaceName>/<resourceType>/<subResource>/<resourceName>
// depending on whether there are 8 or 9 parts in the URL path, appropriate subjectaccessreview
// request is made.
attr := authorizer.AttributesRecord{
User: u,
Verb: apiVerb,
Namespace: "",
Expand All @@ -159,9 +166,46 @@ func (n krpAuthorizerAttributesGetter) GetRequestAttributes(u user.Info, r *http
Resource: "",
Subresource: "",
Name: "",
ResourceRequest: false,
ResourceRequest: true,
Path: r.URL.Path,
})
}

parts := strings.Split(
strings.TrimRight(r.URL.Path, "/"),
"/",
)

if len(parts) >= 3 {
attr.APIGroup = parts[2]
}

if len(parts) >= 4 {
attr.APIVersion = parts[3]
}

// ensure namespaces exists in URL
if len(parts) >= 6 && parts[4] == "namespaces" {
attr.Namespace = parts[5]
} else {
allAttrs = append(allAttrs, attr)
return allAttrs
}

if len(parts) >= 7 {
attr.Resource = parts[6]
}

if len(parts) == 8 {
attr.Name = parts[7]
}

if len(parts) == 9 {
attr.Subresource = parts[7]
attr.Name = parts[8]
}

// append to the list and then return
allAttrs = append(allAttrs, attr)
return allAttrs
}

Expand Down