blob: 17163cbb269e84fe8a1e501560224b3435cc7eaa [file] [log] [blame]
sslobodrd046be82019-01-16 10:02:22 -05001/*
2Copyright 2017 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 v1
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,2,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,3,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,4,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 // Since non-resource URLs are not namespaced, this field is only applicable for ClusterRoles referenced from a ClusterRoleBinding.
66 // Rules can either apply to API resources (such as "pods" or "secrets") or non-resource URL paths (such as "/api"), but not both.
67 // +optional
68 NonResourceURLs []string `json:"nonResourceURLs,omitempty" protobuf:"bytes,5,rep,name=nonResourceURLs"`
69}
70
71// Subject contains a reference to the object or user identities a role binding applies to. This can either hold a direct API object reference,
72// or a value for non-objects such as user and group names.
73type Subject struct {
74 // Kind of object being referenced. Values defined by this API group are "User", "Group", and "ServiceAccount".
75 // If the Authorizer does not recognized the kind value, the Authorizer should report an error.
76 Kind string `json:"kind" protobuf:"bytes,1,opt,name=kind"`
77 // APIGroup holds the API group of the referenced subject.
78 // Defaults to "" for ServiceAccount subjects.
79 // Defaults to "rbac.authorization.k8s.io" for User and Group subjects.
80 // +optional
81 APIGroup string `json:"apiGroup,omitempty" protobuf:"bytes,2,opt.name=apiGroup"`
82 // Name of the object being referenced.
83 Name string `json:"name" protobuf:"bytes,3,opt,name=name"`
84 // Namespace of the referenced object. If the object kind is non-namespace, such as "User" or "Group", and this value is not empty
85 // the Authorizer should report an error.
86 // +optional
87 Namespace string `json:"namespace,omitempty" protobuf:"bytes,4,opt,name=namespace"`
88}
89
90// RoleRef contains information that points to the role being used
91type RoleRef struct {
92 // APIGroup is the group for the resource being referenced
93 APIGroup string `json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup"`
94 // Kind is the type of resource being referenced
95 Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
96 // Name is the name of resource being referenced
97 Name string `json:"name" protobuf:"bytes,3,opt,name=name"`
98}
99
100// +genclient
101// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
102
103// Role is a namespaced, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding.
104type Role struct {
105 metav1.TypeMeta `json:",inline"`
106 // Standard object's metadata.
107 // +optional
108 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
109
110 // Rules holds all the PolicyRules for this Role
111 Rules []PolicyRule `json:"rules" protobuf:"bytes,2,rep,name=rules"`
112}
113
114// +genclient
115// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
116
117// 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.
118// It adds who information via Subjects and namespace information by which namespace it exists in. RoleBindings in a given
119// namespace only have effect in that namespace.
120type RoleBinding struct {
121 metav1.TypeMeta `json:",inline"`
122 // Standard object's metadata.
123 // +optional
124 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
125
126 // Subjects holds references to the objects the role applies to.
127 // +optional
128 Subjects []Subject `json:"subjects,omitempty" protobuf:"bytes,2,rep,name=subjects"`
129
130 // RoleRef can reference a Role in the current namespace or a ClusterRole in the global namespace.
131 // If the RoleRef cannot be resolved, the Authorizer must return an error.
132 RoleRef RoleRef `json:"roleRef" protobuf:"bytes,3,opt,name=roleRef"`
133}
134
135// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
136
137// RoleBindingList is a collection of RoleBindings
138type RoleBindingList struct {
139 metav1.TypeMeta `json:",inline"`
140 // Standard object's metadata.
141 // +optional
142 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
143
144 // Items is a list of RoleBindings
145 Items []RoleBinding `json:"items" protobuf:"bytes,2,rep,name=items"`
146}
147
148// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
149
150// RoleList is a collection of Roles
151type RoleList struct {
152 metav1.TypeMeta `json:",inline"`
153 // Standard object's metadata.
154 // +optional
155 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
156
157 // Items is a list of Roles
158 Items []Role `json:"items" protobuf:"bytes,2,rep,name=items"`
159}
160
161// +genclient
162// +genclient:nonNamespaced
163// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
164
165// ClusterRole is a cluster level, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding or ClusterRoleBinding.
166type ClusterRole struct {
167 metav1.TypeMeta `json:",inline"`
168 // Standard object's metadata.
169 // +optional
170 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
171
172 // Rules holds all the PolicyRules for this ClusterRole
173 Rules []PolicyRule `json:"rules" protobuf:"bytes,2,rep,name=rules"`
174
175 // AggregationRule is an optional field that describes how to build the Rules for this ClusterRole.
176 // If AggregationRule is set, then the Rules are controller managed and direct changes to Rules will be
177 // stomped by the controller.
178 // +optional
179 AggregationRule *AggregationRule `json:"aggregationRule,omitempty" protobuf:"bytes,3,opt,name=aggregationRule"`
180}
181
182// AggregationRule describes how to locate ClusterRoles to aggregate into the ClusterRole
183type AggregationRule struct {
184 // ClusterRoleSelectors holds a list of selectors which will be used to find ClusterRoles and create the rules.
185 // If any of the selectors match, then the ClusterRole's permissions will be added
186 // +optional
187 ClusterRoleSelectors []metav1.LabelSelector `json:"clusterRoleSelectors,omitempty" protobuf:"bytes,1,rep,name=clusterRoleSelectors"`
188}
189
190// +genclient
191// +genclient:nonNamespaced
192// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
193
194// ClusterRoleBinding references a ClusterRole, but not contain it. It can reference a ClusterRole in the global namespace,
195// and adds who information via Subject.
196type ClusterRoleBinding struct {
197 metav1.TypeMeta `json:",inline"`
198 // Standard object's metadata.
199 // +optional
200 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
201
202 // Subjects holds references to the objects the role applies to.
203 // +optional
204 Subjects []Subject `json:"subjects,omitempty" protobuf:"bytes,2,rep,name=subjects"`
205
206 // RoleRef can only reference a ClusterRole in the global namespace.
207 // If the RoleRef cannot be resolved, the Authorizer must return an error.
208 RoleRef RoleRef `json:"roleRef" protobuf:"bytes,3,opt,name=roleRef"`
209}
210
211// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
212
213// ClusterRoleBindingList is a collection of ClusterRoleBindings
214type ClusterRoleBindingList struct {
215 metav1.TypeMeta `json:",inline"`
216 // Standard object's metadata.
217 // +optional
218 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
219
220 // Items is a list of ClusterRoleBindings
221 Items []ClusterRoleBinding `json:"items" protobuf:"bytes,2,rep,name=items"`
222}
223
224// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
225
226// ClusterRoleList is a collection of ClusterRoles
227type ClusterRoleList struct {
228 metav1.TypeMeta `json:",inline"`
229 // Standard object's metadata.
230 // +optional
231 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
232
233 // Items is a list of ClusterRoles
234 Items []ClusterRole `json:"items" protobuf:"bytes,2,rep,name=items"`
235}