blob: 521cce4f31d3fc2ba239b0166408b8c7cec7306b [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v1alpha1
18
19import (
20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21)
22
23// Authorization is calculated against
24// 1. evaluation of ClusterRoleBindings - short circuit on match
25// 2. evaluation of RoleBindings in the namespace requested - short circuit on match
26// 3. deny by default
27
28const (
29 APIGroupAll = "*"
30 ResourceAll = "*"
31 VerbAll = "*"
32 NonResourceAll = "*"
33
34 GroupKind = "Group"
35 ServiceAccountKind = "ServiceAccount"
36 UserKind = "User"
37
38 // AutoUpdateAnnotationKey is the name of an annotation which prevents reconciliation if set to "false"
39 AutoUpdateAnnotationKey = "rbac.authorization.kubernetes.io/autoupdate"
40)
41
42// Authorization is calculated against
43// 1. evaluation of ClusterRoleBindings - short circuit on match
44// 2. evaluation of RoleBindings in the namespace requested - short circuit on match
45// 3. deny by default
46
47// PolicyRule holds information that describes a policy rule, but does not contain information
48// about who the rule applies to or which namespace the rule applies to.
49type PolicyRule struct {
50 // Verbs is a list of Verbs that apply to ALL the ResourceKinds and AttributeRestrictions contained in this rule. VerbAll represents all kinds.
51 Verbs []string `json:"verbs" protobuf:"bytes,1,rep,name=verbs"`
52
53 // APIGroups is the name of the APIGroup that contains the resources. If multiple API groups are specified, any action requested against one of
54 // the enumerated resources in any API group will be allowed.
55 // +optional
56 APIGroups []string `json:"apiGroups,omitempty" protobuf:"bytes,3,rep,name=apiGroups"`
57 // Resources is a list of resources this rule applies to. ResourceAll represents all resources.
58 // +optional
59 Resources []string `json:"resources,omitempty" protobuf:"bytes,4,rep,name=resources"`
60 // ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed.
61 // +optional
62 ResourceNames []string `json:"resourceNames,omitempty" protobuf:"bytes,5,rep,name=resourceNames"`
63
64 // NonResourceURLs is a set of partial urls that a user should have access to. *s are allowed, but only as the full, final step in the path
65 // This name is intentionally different than the internal type so that the DefaultConvert works nicely and because the ordering may be different.
66 // Since non-resource URLs are not namespaced, this field is only applicable for ClusterRoles referenced from a ClusterRoleBinding.
67 // Rules can either apply to API resources (such as "pods" or "secrets") or non-resource URL paths (such as "/api"), but not both.
68 // +optional
69 NonResourceURLs []string `json:"nonResourceURLs,omitempty" protobuf:"bytes,6,rep,name=nonResourceURLs"`
70}
71
72// Subject contains a reference to the object or user identities a role binding applies to. This can either hold a direct API object reference,
73// or a value for non-objects such as user and group names.
74type Subject struct {
75 // Kind of object being referenced. Values defined by this API group are "User", "Group", and "ServiceAccount".
76 // If the Authorizer does not recognized the kind value, the Authorizer should report an error.
77 Kind string `json:"kind" protobuf:"bytes,1,opt,name=kind"`
78 // APIVersion holds the API group and version of the referenced subject.
79 // Defaults to "v1" for ServiceAccount subjects.
80 // Defaults to "rbac.authorization.k8s.io/v1alpha1" for User and Group subjects.
81 // +k8s:conversion-gen=false
82 // +optional
83 APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,2,opt.name=apiVersion"`
84 // Name of the object being referenced.
85 Name string `json:"name" protobuf:"bytes,3,opt,name=name"`
86 // Namespace of the referenced object. If the object kind is non-namespace, such as "User" or "Group", and this value is not empty
87 // the Authorizer should report an error.
88 // +optional
89 Namespace string `json:"namespace,omitempty" protobuf:"bytes,4,opt,name=namespace"`
90}
91
92// RoleRef contains information that points to the role being used
93type RoleRef struct {
94 // APIGroup is the group for the resource being referenced
95 APIGroup string `json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup"`
96 // Kind is the type of resource being referenced
97 Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
98 // Name is the name of resource being referenced
99 Name string `json:"name" protobuf:"bytes,3,opt,name=name"`
100}
101
102// +genclient
103// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
104
105// Role is a namespaced, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding.
106type Role struct {
107 metav1.TypeMeta `json:",inline"`
108 // Standard object's metadata.
109 // +optional
110 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
111
112 // Rules holds all the PolicyRules for this Role
113 // +optional
114 Rules []PolicyRule `json:"rules" protobuf:"bytes,2,rep,name=rules"`
115}
116
117// +genclient
118// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
119
120// RoleBinding references a role, but does not contain it. It can reference a Role in the same namespace or a ClusterRole in the global namespace.
121// It adds who information via Subjects and namespace information by which namespace it exists in. RoleBindings in a given
122// namespace only have effect in that namespace.
123type RoleBinding struct {
124 metav1.TypeMeta `json:",inline"`
125 // Standard object's metadata.
126 // +optional
127 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
128
129 // Subjects holds references to the objects the role applies to.
130 // +optional
131 Subjects []Subject `json:"subjects,omitempty" protobuf:"bytes,2,rep,name=subjects"`
132
133 // RoleRef can reference a Role in the current namespace or a ClusterRole in the global namespace.
134 // If the RoleRef cannot be resolved, the Authorizer must return an error.
135 RoleRef RoleRef `json:"roleRef" protobuf:"bytes,3,opt,name=roleRef"`
136}
137
138// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
139
140// RoleBindingList is a collection of RoleBindings
141type RoleBindingList struct {
142 metav1.TypeMeta `json:",inline"`
143 // Standard object's metadata.
144 // +optional
145 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
146
147 // Items is a list of RoleBindings
148 Items []RoleBinding `json:"items" protobuf:"bytes,2,rep,name=items"`
149}
150
151// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
152
153// RoleList is a collection of Roles
154type RoleList struct {
155 metav1.TypeMeta `json:",inline"`
156 // Standard object's metadata.
157 // +optional
158 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
159
160 // Items is a list of Roles
161 Items []Role `json:"items" protobuf:"bytes,2,rep,name=items"`
162}
163
164// +genclient
165// +genclient:nonNamespaced
166// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
167
168// ClusterRole is a cluster level, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding or ClusterRoleBinding.
169type ClusterRole struct {
170 metav1.TypeMeta `json:",inline"`
171 // Standard object's metadata.
172 // +optional
173 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
174
175 // Rules holds all the PolicyRules for this ClusterRole
176 // +optional
177 Rules []PolicyRule `json:"rules" protobuf:"bytes,2,rep,name=rules"`
178
179 // AggregationRule is an optional field that describes how to build the Rules for this ClusterRole.
180 // If AggregationRule is set, then the Rules are controller managed and direct changes to Rules will be
181 // stomped by the controller.
182 // +optional
183 AggregationRule *AggregationRule `json:"aggregationRule,omitempty" protobuf:"bytes,3,opt,name=aggregationRule"`
184}
185
186// AggregationRule describes how to locate ClusterRoles to aggregate into the ClusterRole
187type AggregationRule struct {
188 // ClusterRoleSelectors holds a list of selectors which will be used to find ClusterRoles and create the rules.
189 // If any of the selectors match, then the ClusterRole's permissions will be added
190 // +optional
191 ClusterRoleSelectors []metav1.LabelSelector `json:"clusterRoleSelectors,omitempty" protobuf:"bytes,1,rep,name=clusterRoleSelectors"`
192}
193
194// +genclient
195// +genclient:nonNamespaced
196// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
197
198// ClusterRoleBinding references a ClusterRole, but not contain it. It can reference a ClusterRole in the global namespace,
199// and adds who information via Subject.
200type ClusterRoleBinding struct {
201 metav1.TypeMeta `json:",inline"`
202 // Standard object's metadata.
203 // +optional
204 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
205
206 // Subjects holds references to the objects the role applies to.
207 // +optional
208 Subjects []Subject `json:"subjects,omitempty" protobuf:"bytes,2,rep,name=subjects"`
209
210 // RoleRef can only reference a ClusterRole in the global namespace.
211 // If the RoleRef cannot be resolved, the Authorizer must return an error.
212 RoleRef RoleRef `json:"roleRef" protobuf:"bytes,3,opt,name=roleRef"`
213}
214
215// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
216
217// ClusterRoleBindingList is a collection of ClusterRoleBindings
218type ClusterRoleBindingList struct {
219 metav1.TypeMeta `json:",inline"`
220 // Standard object's metadata.
221 // +optional
222 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
223
224 // Items is a list of ClusterRoleBindings
225 Items []ClusterRoleBinding `json:"items" protobuf:"bytes,2,rep,name=items"`
226}
227
228// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
229
230// ClusterRoleList is a collection of ClusterRoles
231type ClusterRoleList struct {
232 metav1.TypeMeta `json:",inline"`
233 // Standard object's metadata.
234 // +optional
235 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
236
237 // Items is a list of ClusterRoles
238 Items []ClusterRole `json:"items" protobuf:"bytes,2,rep,name=items"`
239}