blob: c62b5ea21375d9a71ae8a75f15d2cb3cdb389ce7 [file] [log] [blame]
Matteo Scandoloa4285862020-12-01 18:10:10 -08001/*
2Copyright 2015 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 v1beta1
18
19import (
20 "fmt"
21
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23)
24
25// +genclient
26// +genclient:nonNamespaced
27// +genclient:onlyVerbs=create
28// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
29// +k8s:prerelease-lifecycle-gen:introduced=1.2
30// +k8s:prerelease-lifecycle-gen:deprecated=1.19
31// +k8s:prerelease-lifecycle-gen:replacement=authorization.k8s.io,v1,SubjectAccessReview
32
33// SubjectAccessReview checks whether or not a user or group can perform an action.
34type SubjectAccessReview struct {
35 metav1.TypeMeta `json:",inline"`
36 // +optional
37 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
38
39 // Spec holds information about the request being evaluated
40 Spec SubjectAccessReviewSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
41
42 // Status is filled in by the server and indicates whether the request is allowed or not
43 // +optional
44 Status SubjectAccessReviewStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
45}
46
47// +genclient
48// +genclient:nonNamespaced
49// +genclient:onlyVerbs=create
50// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
51// +k8s:prerelease-lifecycle-gen:introduced=1.2
52// +k8s:prerelease-lifecycle-gen:deprecated=1.19
53// +k8s:prerelease-lifecycle-gen:replacement=authorization.k8s.io,v1,SelfSubjectAccessReview
54
55// SelfSubjectAccessReview checks whether or the current user can perform an action. Not filling in a
56// spec.namespace means "in all namespaces". Self is a special case, because users should always be able
57// to check whether they can perform an action
58type SelfSubjectAccessReview struct {
59 metav1.TypeMeta `json:",inline"`
60 // +optional
61 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
62
63 // Spec holds information about the request being evaluated. user and groups must be empty
64 Spec SelfSubjectAccessReviewSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
65
66 // Status is filled in by the server and indicates whether the request is allowed or not
67 // +optional
68 Status SubjectAccessReviewStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
69}
70
71// +genclient
72// +genclient:onlyVerbs=create
73// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
74// +k8s:prerelease-lifecycle-gen:introduced=1.2
75// +k8s:prerelease-lifecycle-gen:deprecated=1.19
76// +k8s:prerelease-lifecycle-gen:replacement=authorization.k8s.io,v1,LocalSubjectAccessReview
77
78// LocalSubjectAccessReview checks whether or not a user or group can perform an action in a given namespace.
79// Having a namespace scoped resource makes it much easier to grant namespace scoped policy that includes permissions
80// checking.
81type LocalSubjectAccessReview struct {
82 metav1.TypeMeta `json:",inline"`
83 // +optional
84 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
85
86 // Spec holds information about the request being evaluated. spec.namespace must be equal to the namespace
87 // you made the request against. If empty, it is defaulted.
88 Spec SubjectAccessReviewSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
89
90 // Status is filled in by the server and indicates whether the request is allowed or not
91 // +optional
92 Status SubjectAccessReviewStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
93}
94
95// ResourceAttributes includes the authorization attributes available for resource requests to the Authorizer interface
96type ResourceAttributes struct {
97 // Namespace is the namespace of the action being requested. Currently, there is no distinction between no namespace and all namespaces
98 // "" (empty) is defaulted for LocalSubjectAccessReviews
99 // "" (empty) is empty for cluster-scoped resources
100 // "" (empty) means "all" for namespace scoped resources from a SubjectAccessReview or SelfSubjectAccessReview
101 // +optional
102 Namespace string `json:"namespace,omitempty" protobuf:"bytes,1,opt,name=namespace"`
103 // Verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy. "*" means all.
104 // +optional
105 Verb string `json:"verb,omitempty" protobuf:"bytes,2,opt,name=verb"`
106 // Group is the API Group of the Resource. "*" means all.
107 // +optional
108 Group string `json:"group,omitempty" protobuf:"bytes,3,opt,name=group"`
109 // Version is the API Version of the Resource. "*" means all.
110 // +optional
111 Version string `json:"version,omitempty" protobuf:"bytes,4,opt,name=version"`
112 // Resource is one of the existing resource types. "*" means all.
113 // +optional
114 Resource string `json:"resource,omitempty" protobuf:"bytes,5,opt,name=resource"`
115 // Subresource is one of the existing resource types. "" means none.
116 // +optional
117 Subresource string `json:"subresource,omitempty" protobuf:"bytes,6,opt,name=subresource"`
118 // Name is the name of the resource being requested for a "get" or deleted for a "delete". "" (empty) means all.
119 // +optional
120 Name string `json:"name,omitempty" protobuf:"bytes,7,opt,name=name"`
121}
122
123// NonResourceAttributes includes the authorization attributes available for non-resource requests to the Authorizer interface
124type NonResourceAttributes struct {
125 // Path is the URL path of the request
126 // +optional
127 Path string `json:"path,omitempty" protobuf:"bytes,1,opt,name=path"`
128 // Verb is the standard HTTP verb
129 // +optional
130 Verb string `json:"verb,omitempty" protobuf:"bytes,2,opt,name=verb"`
131}
132
133// SubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAuthorizationAttributes
134// and NonResourceAuthorizationAttributes must be set
135type SubjectAccessReviewSpec struct {
136 // ResourceAuthorizationAttributes describes information for a resource access request
137 // +optional
138 ResourceAttributes *ResourceAttributes `json:"resourceAttributes,omitempty" protobuf:"bytes,1,opt,name=resourceAttributes"`
139 // NonResourceAttributes describes information for a non-resource access request
140 // +optional
141 NonResourceAttributes *NonResourceAttributes `json:"nonResourceAttributes,omitempty" protobuf:"bytes,2,opt,name=nonResourceAttributes"`
142
143 // User is the user you're testing for.
144 // If you specify "User" but not "Group", then is it interpreted as "What if User were not a member of any groups
145 // +optional
146 User string `json:"user,omitempty" protobuf:"bytes,3,opt,name=user"`
147 // Groups is the groups you're testing for.
148 // +optional
149 Groups []string `json:"group,omitempty" protobuf:"bytes,4,rep,name=group"`
150 // Extra corresponds to the user.Info.GetExtra() method from the authenticator. Since that is input to the authorizer
151 // it needs a reflection here.
152 // +optional
153 Extra map[string]ExtraValue `json:"extra,omitempty" protobuf:"bytes,5,rep,name=extra"`
154 // UID information about the requesting user.
155 // +optional
156 UID string `json:"uid,omitempty" protobuf:"bytes,6,opt,name=uid"`
157}
158
159// ExtraValue masks the value so protobuf can generate
160// +protobuf.nullable=true
161// +protobuf.options.(gogoproto.goproto_stringer)=false
162type ExtraValue []string
163
164func (t ExtraValue) String() string {
165 return fmt.Sprintf("%v", []string(t))
166}
167
168// SelfSubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAuthorizationAttributes
169// and NonResourceAuthorizationAttributes must be set
170type SelfSubjectAccessReviewSpec struct {
171 // ResourceAuthorizationAttributes describes information for a resource access request
172 // +optional
173 ResourceAttributes *ResourceAttributes `json:"resourceAttributes,omitempty" protobuf:"bytes,1,opt,name=resourceAttributes"`
174 // NonResourceAttributes describes information for a non-resource access request
175 // +optional
176 NonResourceAttributes *NonResourceAttributes `json:"nonResourceAttributes,omitempty" protobuf:"bytes,2,opt,name=nonResourceAttributes"`
177}
178
179// SubjectAccessReviewStatus
180type SubjectAccessReviewStatus struct {
181 // Allowed is required. True if the action would be allowed, false otherwise.
182 Allowed bool `json:"allowed" protobuf:"varint,1,opt,name=allowed"`
183 // Denied is optional. True if the action would be denied, otherwise
184 // false. If both allowed is false and denied is false, then the
185 // authorizer has no opinion on whether to authorize the action. Denied
186 // may not be true if Allowed is true.
187 // +optional
188 Denied bool `json:"denied,omitempty" protobuf:"varint,4,opt,name=denied"`
189 // Reason is optional. It indicates why a request was allowed or denied.
190 // +optional
191 Reason string `json:"reason,omitempty" protobuf:"bytes,2,opt,name=reason"`
192 // EvaluationError is an indication that some error occurred during the authorization check.
193 // It is entirely possible to get an error and be able to continue determine authorization status in spite of it.
194 // For instance, RBAC can be missing a role, but enough roles are still present and bound to reason about the request.
195 // +optional
196 EvaluationError string `json:"evaluationError,omitempty" protobuf:"bytes,3,opt,name=evaluationError"`
197}
198
199// +genclient
200// +genclient:nonNamespaced
201// +genclient:onlyVerbs=create
202// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
203// +k8s:prerelease-lifecycle-gen:introduced=1.8
204// +k8s:prerelease-lifecycle-gen:deprecated=1.19
205// +k8s:prerelease-lifecycle-gen:replacement=authorization.k8s.io,v1,SelfSubjectRulesReview
206
207// SelfSubjectRulesReview enumerates the set of actions the current user can perform within a namespace.
208// The returned list of actions may be incomplete depending on the server's authorization mode,
209// and any errors experienced during the evaluation. SelfSubjectRulesReview should be used by UIs to show/hide actions,
210// or to quickly let an end user reason about their permissions. It should NOT Be used by external systems to
211// drive authorization decisions as this raises confused deputy, cache lifetime/revocation, and correctness concerns.
212// SubjectAccessReview, and LocalAccessReview are the correct way to defer authorization decisions to the API server.
213type SelfSubjectRulesReview struct {
214 metav1.TypeMeta `json:",inline"`
215 // +optional
216 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
217
218 // Spec holds information about the request being evaluated.
219 Spec SelfSubjectRulesReviewSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
220
221 // Status is filled in by the server and indicates the set of actions a user can perform.
222 // +optional
223 Status SubjectRulesReviewStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
224}
225
226type SelfSubjectRulesReviewSpec struct {
227 // Namespace to evaluate rules for. Required.
228 Namespace string `json:"namespace,omitempty" protobuf:"bytes,1,opt,name=namespace"`
229}
230
231// SubjectRulesReviewStatus contains the result of a rules check. This check can be incomplete depending on
232// the set of authorizers the server is configured with and any errors experienced during evaluation.
233// Because authorization rules are additive, if a rule appears in a list it's safe to assume the subject has that permission,
234// even if that list is incomplete.
235type SubjectRulesReviewStatus struct {
236 // ResourceRules is the list of actions the subject is allowed to perform on resources.
237 // The list ordering isn't significant, may contain duplicates, and possibly be incomplete.
238 ResourceRules []ResourceRule `json:"resourceRules" protobuf:"bytes,1,rep,name=resourceRules"`
239 // NonResourceRules is the list of actions the subject is allowed to perform on non-resources.
240 // The list ordering isn't significant, may contain duplicates, and possibly be incomplete.
241 NonResourceRules []NonResourceRule `json:"nonResourceRules" protobuf:"bytes,2,rep,name=nonResourceRules"`
242 // Incomplete is true when the rules returned by this call are incomplete. This is most commonly
243 // encountered when an authorizer, such as an external authorizer, doesn't support rules evaluation.
244 Incomplete bool `json:"incomplete" protobuf:"bytes,3,rep,name=incomplete"`
245 // EvaluationError can appear in combination with Rules. It indicates an error occurred during
246 // rule evaluation, such as an authorizer that doesn't support rule evaluation, and that
247 // ResourceRules and/or NonResourceRules may be incomplete.
248 // +optional
249 EvaluationError string `json:"evaluationError,omitempty" protobuf:"bytes,4,opt,name=evaluationError"`
250}
251
252// ResourceRule is the list of actions the subject is allowed to perform on resources. The list ordering isn't significant,
253// may contain duplicates, and possibly be incomplete.
254type ResourceRule struct {
255 // Verb is a list of kubernetes resource API verbs, like: get, list, watch, create, update, delete, proxy. "*" means all.
256 Verbs []string `json:"verbs" protobuf:"bytes,1,rep,name=verbs"`
257
258 // APIGroups is the name of the APIGroup that contains the resources. If multiple API groups are specified, any action requested against one of
259 // the enumerated resources in any API group will be allowed. "*" means all.
260 // +optional
261 APIGroups []string `json:"apiGroups,omitempty" protobuf:"bytes,2,rep,name=apiGroups"`
262 // Resources is a list of resources this rule applies to. "*" means all in the specified apiGroups.
263 // "*/foo" represents the subresource 'foo' for all resources in the specified apiGroups.
264 // +optional
265 Resources []string `json:"resources,omitempty" protobuf:"bytes,3,rep,name=resources"`
266 // ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed. "*" means all.
267 // +optional
268 ResourceNames []string `json:"resourceNames,omitempty" protobuf:"bytes,4,rep,name=resourceNames"`
269}
270
271// NonResourceRule holds information that describes a rule for the non-resource
272type NonResourceRule struct {
273 // Verb is a list of kubernetes non-resource API verbs, like: get, post, put, delete, patch, head, options. "*" means all.
274 Verbs []string `json:"verbs" protobuf:"bytes,1,rep,name=verbs"`
275
276 // NonResourceURLs is a set of partial urls that a user should have access to. *s are allowed, but only as the full,
277 // final step in the path. "*" means all.
278 // +optional
279 NonResourceURLs []string `json:"nonResourceURLs,omitempty" protobuf:"bytes,2,rep,name=nonResourceURLs"`
280}