mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
add missing attributes to authorization interface
This commit is contained in:
parent
e01feae75a
commit
02578a7ea7
@ -398,17 +398,12 @@ func (r *requestAttributeGetter) GetAttribs(req *http.Request) authorizer.Attrib
|
|||||||
attribs.Path = requestInfo.Path
|
attribs.Path = requestInfo.Path
|
||||||
attribs.Verb = requestInfo.Verb
|
attribs.Verb = requestInfo.Verb
|
||||||
|
|
||||||
// If the request was for a resource in an API group, include that info
|
|
||||||
attribs.APIGroup = requestInfo.APIGroup
|
attribs.APIGroup = requestInfo.APIGroup
|
||||||
|
attribs.APIVersion = requestInfo.APIVersion
|
||||||
// If a path follows the conventions of the REST object store, then
|
|
||||||
// we can extract the resource. Otherwise, not.
|
|
||||||
attribs.Resource = requestInfo.Resource
|
attribs.Resource = requestInfo.Resource
|
||||||
|
attribs.Subresource = requestInfo.Subresource
|
||||||
// If the request specifies a namespace, then the namespace is filled in.
|
|
||||||
// Assumes there is no empty string namespace. Unspecified results
|
|
||||||
// in empty (does not understand defaulting rules.)
|
|
||||||
attribs.Namespace = requestInfo.Namespace
|
attribs.Namespace = requestInfo.Namespace
|
||||||
|
attribs.Name = requestInfo.Name
|
||||||
|
|
||||||
return &attribs
|
return &attribs
|
||||||
}
|
}
|
||||||
|
@ -284,6 +284,8 @@ func TestGetAttribs(t *testing.T) {
|
|||||||
Path: "/api/v1/nodes/mynode",
|
Path: "/api/v1/nodes/mynode",
|
||||||
ResourceRequest: true,
|
ResourceRequest: true,
|
||||||
Resource: "nodes",
|
Resource: "nodes",
|
||||||
|
APIVersion: "v1",
|
||||||
|
Name: "mynode",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"namespaced resource": {
|
"namespaced resource": {
|
||||||
@ -295,6 +297,8 @@ func TestGetAttribs(t *testing.T) {
|
|||||||
ResourceRequest: true,
|
ResourceRequest: true,
|
||||||
Namespace: "myns",
|
Namespace: "myns",
|
||||||
Resource: "pods",
|
Resource: "pods",
|
||||||
|
APIVersion: "v1",
|
||||||
|
Name: "mypod",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"API group resource": {
|
"API group resource": {
|
||||||
@ -305,6 +309,7 @@ func TestGetAttribs(t *testing.T) {
|
|||||||
Path: "/apis/extensions/v1beta1/namespaces/myns/jobs",
|
Path: "/apis/extensions/v1beta1/namespaces/myns/jobs",
|
||||||
ResourceRequest: true,
|
ResourceRequest: true,
|
||||||
APIGroup: extensions.GroupName,
|
APIGroup: extensions.GroupName,
|
||||||
|
APIVersion: "v1beta1",
|
||||||
Namespace: "myns",
|
Namespace: "myns",
|
||||||
Resource: "jobs",
|
Resource: "jobs",
|
||||||
},
|
},
|
||||||
|
@ -48,9 +48,19 @@ type Attributes interface {
|
|||||||
// The kind of object, if a request is for a REST object.
|
// The kind of object, if a request is for a REST object.
|
||||||
GetResource() string
|
GetResource() string
|
||||||
|
|
||||||
|
// GetSubresource returns the subresource being requested, if present
|
||||||
|
GetSubresource() string
|
||||||
|
|
||||||
|
// GetName returns the name of the object as parsed off the request. This will not be present for all request types, but
|
||||||
|
// will be present for: get, update, delete
|
||||||
|
GetName() string
|
||||||
|
|
||||||
// The group of the resource, if a request is for a REST object.
|
// The group of the resource, if a request is for a REST object.
|
||||||
GetAPIGroup() string
|
GetAPIGroup() string
|
||||||
|
|
||||||
|
// GetAPIVersion returns the version of the group requested, if a request is for a REST object.
|
||||||
|
GetAPIVersion() string
|
||||||
|
|
||||||
// IsResourceRequest returns true for requests to API resources, like /api/v1/nodes,
|
// IsResourceRequest returns true for requests to API resources, like /api/v1/nodes,
|
||||||
// and false for non-resource endpoints like /api, /healthz, and /swaggerapi
|
// and false for non-resource endpoints like /api, /healthz, and /swaggerapi
|
||||||
IsResourceRequest() bool
|
IsResourceRequest() bool
|
||||||
@ -83,7 +93,10 @@ type AttributesRecord struct {
|
|||||||
Verb string
|
Verb string
|
||||||
Namespace string
|
Namespace string
|
||||||
APIGroup string
|
APIGroup string
|
||||||
|
APIVersion string
|
||||||
Resource string
|
Resource string
|
||||||
|
Subresource string
|
||||||
|
Name string
|
||||||
ResourceRequest bool
|
ResourceRequest bool
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
@ -112,10 +125,22 @@ func (a AttributesRecord) GetResource() string {
|
|||||||
return a.Resource
|
return a.Resource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a AttributesRecord) GetSubresource() string {
|
||||||
|
return a.Subresource
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a AttributesRecord) GetName() string {
|
||||||
|
return a.Name
|
||||||
|
}
|
||||||
|
|
||||||
func (a AttributesRecord) GetAPIGroup() string {
|
func (a AttributesRecord) GetAPIGroup() string {
|
||||||
return a.APIGroup
|
return a.APIGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a AttributesRecord) GetAPIVersion() string {
|
||||||
|
return a.APIVersion
|
||||||
|
}
|
||||||
|
|
||||||
func (a AttributesRecord) IsResourceRequest() bool {
|
func (a AttributesRecord) IsResourceRequest() bool {
|
||||||
return a.ResourceRequest
|
return a.ResourceRequest
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user