mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +00:00
Merge pull request #53722 from deads2k/rbac-01-allow-star
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. allow */subresource in rbac policy rules xref #29698 xref #38756 xref #49504 xref #38810 Allow `*/subresource` format in RBAC policy rules to support polymorphic subresources like `*/scale` for HPA. @DirectXMan12 fyi ```release-note RBAC PolicyRules now allow resource=`*/<subresource>` to cover `any-resource/<subresource>`. For example, `*/scale` covers `replicationcontroller/scale`. ```
This commit is contained in:
@@ -156,10 +156,7 @@ func buildControllerRoles() ([]rbac.ClusterRole, []rbac.ClusterRoleBinding) {
|
||||
Rules: []rbac.PolicyRule{
|
||||
rbac.NewRule("get", "list", "watch").Groups(autoscalingGroup).Resources("horizontalpodautoscalers").RuleOrDie(),
|
||||
rbac.NewRule("update").Groups(autoscalingGroup).Resources("horizontalpodautoscalers/status").RuleOrDie(),
|
||||
rbac.NewRule("get", "update").Groups(legacyGroup).Resources("replicationcontrollers/scale").RuleOrDie(),
|
||||
// TODO this should be removable when the HPA contoller is fixed
|
||||
rbac.NewRule("get", "update").Groups(extensionsGroup).Resources("replicationcontrollers/scale").RuleOrDie(),
|
||||
rbac.NewRule("get", "update").Groups(extensionsGroup, appsGroup).Resources("deployments/scale", "replicasets/scale").RuleOrDie(),
|
||||
rbac.NewRule("get", "update").Groups("*").Resources("*/scale").RuleOrDie(),
|
||||
rbac.NewRule("list").Groups(legacyGroup).Resources("pods").RuleOrDie(),
|
||||
// TODO: restrict this to the appropriate namespace
|
||||
rbac.NewRule("get").Groups(legacyGroup).Resources("services/proxy").Names("https:heapster:", "http:heapster:").RuleOrDie(),
|
||||
|
||||
@@ -445,25 +445,9 @@ items:
|
||||
verbs:
|
||||
- update
|
||||
- apiGroups:
|
||||
- ""
|
||||
- '*'
|
||||
resources:
|
||||
- replicationcontrollers/scale
|
||||
verbs:
|
||||
- get
|
||||
- update
|
||||
- apiGroups:
|
||||
- extensions
|
||||
resources:
|
||||
- replicationcontrollers/scale
|
||||
verbs:
|
||||
- get
|
||||
- update
|
||||
- apiGroups:
|
||||
- apps
|
||||
- extensions
|
||||
resources:
|
||||
- deployments/scale
|
||||
- replicasets/scale
|
||||
- '*/scale'
|
||||
verbs:
|
||||
- get
|
||||
- update
|
||||
|
||||
@@ -174,14 +174,14 @@ func RulesAllow(requestAttributes authorizer.Attributes, rules ...rbac.PolicyRul
|
||||
|
||||
func RuleAllows(requestAttributes authorizer.Attributes, rule *rbac.PolicyRule) bool {
|
||||
if requestAttributes.IsResourceRequest() {
|
||||
resource := requestAttributes.GetResource()
|
||||
combinedResource := requestAttributes.GetResource()
|
||||
if len(requestAttributes.GetSubresource()) > 0 {
|
||||
resource = requestAttributes.GetResource() + "/" + requestAttributes.GetSubresource()
|
||||
combinedResource = requestAttributes.GetResource() + "/" + requestAttributes.GetSubresource()
|
||||
}
|
||||
|
||||
return rbac.VerbMatches(rule, requestAttributes.GetVerb()) &&
|
||||
rbac.APIGroupMatches(rule, requestAttributes.GetAPIGroup()) &&
|
||||
rbac.ResourceMatches(rule, resource) &&
|
||||
rbac.ResourceMatches(rule, combinedResource, requestAttributes.GetSubresource()) &&
|
||||
rbac.ResourceNameMatches(rule, requestAttributes.GetName())
|
||||
}
|
||||
|
||||
|
||||
@@ -224,13 +224,19 @@ func TestAuthorizer(t *testing.T) {
|
||||
{
|
||||
// test subresource resolution
|
||||
clusterRoles: []*rbac.ClusterRole{
|
||||
newClusterRole("admin", newRule("*", "*", "pods/status", "*")),
|
||||
newClusterRole("admin",
|
||||
newRule("*", "*", "pods/status", "*"),
|
||||
newRule("*", "*", "*/scale", "*"),
|
||||
),
|
||||
},
|
||||
roleBindings: []*rbac.RoleBinding{
|
||||
newRoleBinding("ns1", "admin", bindToClusterRole, "User:admin", "Group:admins"),
|
||||
},
|
||||
shouldPass: []authorizer.Attributes{
|
||||
&defaultAttributes{"admin", "", "get", "pods", "status", "ns1", ""},
|
||||
&defaultAttributes{"admin", "", "get", "pods", "scale", "ns1", ""},
|
||||
&defaultAttributes{"admin", "", "get", "deployments", "scale", "ns1", ""},
|
||||
&defaultAttributes{"admin", "", "get", "anything", "scale", "ns1", ""},
|
||||
},
|
||||
shouldFail: []authorizer.Attributes{
|
||||
&defaultAttributes{"admin", "", "get", "pods", "", "ns1", ""},
|
||||
|
||||
Reference in New Issue
Block a user