Skip to content

Commit 107e7b2

Browse files
Merge pull request #54005 from deads2k/rbac-02-aggregation
Automatic merge from submit-queue (batch tested with PRs 54005, 55127, 53850, 55486, 53440). 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>. aggregate cluster roles xref kubernetes/community#1219 kubernetes/enhancements#502 This is a pull with API types, a controller, and a demonstration of how to move admin, edit, and view. Once we agree on the shape, I'll I added ```yaml aggregationRule: clusterRoleSelectors: - matchLabels: rbac.authorization.k8s.io/aggregate-to-admin: true ``` to the `ClusterRole`. A controller then goes and gathers all the matching ClusterRoles and sets the `rules` to the union of matching cluster roles. @kubernetes/sig-auth-pr-reviews ```release-note RBAC ClusterRoles can now select other roles to aggregate ``` Kubernetes-commit: f575c55589db84ef4d392823120f0238fd19ad93
2 parents 746eb1a + 5766bec commit 107e7b2

16 files changed

+1262
-465
lines changed

Godeps/Godeps.json

+224-224
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rbac/v1/generated.pb.go

+271-77
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rbac/v1/generated.proto

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rbac/v1/types.go

+14
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ type ClusterRole struct {
170170

171171
// Rules holds all the PolicyRules for this ClusterRole
172172
Rules []PolicyRule `json:"rules" protobuf:"bytes,2,rep,name=rules"`
173+
174+
// AggregationRule is an optional field that describes how to build the Rules for this ClusterRole.
175+
// If AggregationRule is set, then the Rules are controller managed and direct changes to Rules will be
176+
// stomped by the controller.
177+
// +optional
178+
AggregationRule *AggregationRule `json:"aggregationRule,omitempty" protobuf:"bytes,3,opt,name=aggregationRule"`
179+
}
180+
181+
// AggregationRule describes how to locate ClusterRoles to aggregate into the ClusterRole
182+
type AggregationRule struct {
183+
// ClusterRoleSelectors holds a list of selectors which will be used to find ClusterRoles and create the rules.
184+
// If any of the selectors match, then the ClusterRole's permissions will be added
185+
// +optional
186+
ClusterRoleSelectors []metav1.LabelSelector `json:"clusterRoleSelectors,omitempty" protobuf:"bytes,1,rep,name=clusterRoleSelectors"`
173187
}
174188

175189
// +genclient

rbac/v1/types_swagger_doc_generated.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,20 @@ package v1
2727
// Those methods can be generated by using hack/update-generated-swagger-docs.sh
2828

2929
// AUTO-GENERATED FUNCTIONS START HERE
30+
var map_AggregationRule = map[string]string{
31+
"": "AggregationRule describes how to locate ClusterRoles to aggregate into the ClusterRole",
32+
"clusterRoleSelectors": "ClusterRoleSelectors holds a list of selectors which will be used to find ClusterRoles and create the rules. If any of the selectors match, then the ClusterRole's permissions will be added",
33+
}
34+
35+
func (AggregationRule) SwaggerDoc() map[string]string {
36+
return map_AggregationRule
37+
}
38+
3039
var map_ClusterRole = map[string]string{
31-
"": "ClusterRole is a cluster level, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding or ClusterRoleBinding.",
32-
"metadata": "Standard object's metadata.",
33-
"rules": "Rules holds all the PolicyRules for this ClusterRole",
40+
"": "ClusterRole is a cluster level, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding or ClusterRoleBinding.",
41+
"metadata": "Standard object's metadata.",
42+
"rules": "Rules holds all the PolicyRules for this ClusterRole",
43+
"aggregationRule": "AggregationRule is an optional field that describes how to build the Rules for this ClusterRole. If AggregationRule is set, then the Rules are controller managed and direct changes to Rules will be stomped by the controller.",
3444
}
3545

3646
func (ClusterRole) SwaggerDoc() map[string]string {

rbac/v1/zz_generated.deepcopy.go

+33
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,33 @@ limitations under the License.
2121
package v1
2222

2323
import (
24+
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
runtime "k8s.io/apimachinery/pkg/runtime"
2526
)
2627

28+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
29+
func (in *AggregationRule) DeepCopyInto(out *AggregationRule) {
30+
*out = *in
31+
if in.ClusterRoleSelectors != nil {
32+
in, out := &in.ClusterRoleSelectors, &out.ClusterRoleSelectors
33+
*out = make([]meta_v1.LabelSelector, len(*in))
34+
for i := range *in {
35+
(*in)[i].DeepCopyInto(&(*out)[i])
36+
}
37+
}
38+
return
39+
}
40+
41+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AggregationRule.
42+
func (in *AggregationRule) DeepCopy() *AggregationRule {
43+
if in == nil {
44+
return nil
45+
}
46+
out := new(AggregationRule)
47+
in.DeepCopyInto(out)
48+
return out
49+
}
50+
2751
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
2852
func (in *ClusterRole) DeepCopyInto(out *ClusterRole) {
2953
*out = *in
@@ -36,6 +60,15 @@ func (in *ClusterRole) DeepCopyInto(out *ClusterRole) {
3660
(*in)[i].DeepCopyInto(&(*out)[i])
3761
}
3862
}
63+
if in.AggregationRule != nil {
64+
in, out := &in.AggregationRule, &out.AggregationRule
65+
if *in == nil {
66+
*out = nil
67+
} else {
68+
*out = new(AggregationRule)
69+
(*in).DeepCopyInto(*out)
70+
}
71+
}
3972
return
4073
}
4174

0 commit comments

Comments
 (0)