PageRenderTime 70ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/staging/src/k8s.io/api/authorization/v1beta1/types.go

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