/pkg/apis/authorization/types.go

https://gitlab.com/CORP-RESELLER/kubernetes · Go · 140 lines · 53 code · 19 blank · 68 comment · 0 complexity · 9321a952cf389a6fd37e2ca56ab4aefa 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 authorization
  14. import (
  15. "k8s.io/kubernetes/pkg/api"
  16. "k8s.io/kubernetes/pkg/api/unversioned"
  17. )
  18. // +genclient=true
  19. // +nonNamespaced=true
  20. // +noMethods=true
  21. // SubjectAccessReview checks whether or not a user or group can perform an action. Not filling in a
  22. // spec.namespace means "in all namespaces".
  23. type SubjectAccessReview struct {
  24. unversioned.TypeMeta
  25. api.ObjectMeta
  26. // Spec holds information about the request being evaluated
  27. Spec SubjectAccessReviewSpec
  28. // Status is filled in by the server and indicates whether the request is allowed or not
  29. Status SubjectAccessReviewStatus
  30. }
  31. // SelfSubjectAccessReview checks whether or the current user can perform an action. Not filling in a
  32. // spec.namespace means "in all namespaces". Self is a special case, because users should always be able
  33. // to check whether they can perform an action
  34. type SelfSubjectAccessReview struct {
  35. unversioned.TypeMeta
  36. api.ObjectMeta
  37. // Spec holds information about the request being evaluated.
  38. Spec SelfSubjectAccessReviewSpec
  39. // Status is filled in by the server and indicates whether the request is allowed or not
  40. Status SubjectAccessReviewStatus
  41. }
  42. // LocalSubjectAccessReview checks whether or not a user or group can perform an action in a given namespace.
  43. // Having a namespace scoped resource makes it much easier to grant namespace scoped policy that includes permissions
  44. // checking.
  45. type LocalSubjectAccessReview struct {
  46. unversioned.TypeMeta
  47. api.ObjectMeta
  48. // Spec holds information about the request being evaluated. spec.namespace must be equal to the namespace
  49. // you made the request against. If empty, it is defaulted.
  50. Spec SubjectAccessReviewSpec
  51. // Status is filled in by the server and indicates whether the request is allowed or not
  52. Status SubjectAccessReviewStatus
  53. }
  54. // ResourceAttributes includes the authorization attributes available for resource requests to the Authorizer interface
  55. type ResourceAttributes struct {
  56. // Namespace is the namespace of the action being requested. Currently, there is no distinction between no namespace and all namespaces
  57. // "" (empty) is defaulted for LocalSubjectAccessReviews
  58. // "" (empty) is empty for cluster-scoped resources
  59. // "" (empty) means "all" for namespace scoped resources from a SubjectAccessReview or SelfSubjectAccessReview
  60. Namespace string
  61. // Verb is a kubernetes resource API verb, like: get, list, watch, create, update, delete, proxy. "*" means all.
  62. Verb string
  63. // Group is the API Group of the Resource. "*" means all.
  64. Group string
  65. // Version is the API Version of the Resource. "*" means all.
  66. Version string
  67. // Resource is one of the existing resource types. "*" means all.
  68. Resource string
  69. // Subresource is one of the existing resource types. "" means none.
  70. Subresource string
  71. // Name is the name of the resource being requested for a "get" or deleted for a "delete". "" (empty) means all.
  72. Name string
  73. }
  74. // NonResourceAttributes includes the authorization attributes available for non-resource requests to the Authorizer interface
  75. type NonResourceAttributes struct {
  76. // Path is the URL path of the request
  77. Path string
  78. // Verb is the standard HTTP verb
  79. Verb string
  80. }
  81. // SubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAttributes
  82. // and NonResourceAttributes must be set
  83. type SubjectAccessReviewSpec struct {
  84. // ResourceAttributes describes information for a resource access request
  85. ResourceAttributes *ResourceAttributes
  86. // NonResourceAttributes describes information for a non-resource access request
  87. NonResourceAttributes *NonResourceAttributes
  88. // User is the user you're testing for.
  89. // If you specify "User" but not "Group", then is it interpreted as "What if User were not a member of any groups
  90. User string
  91. // Groups is the groups you're testing for.
  92. Groups []string
  93. // Extra corresponds to the user.Info.GetExtra() method from the authenticator. Since that is input to the authorizer
  94. // it needs a reflection here.
  95. Extra map[string]ExtraValue
  96. }
  97. // ExtraValue masks the value so protobuf can generate
  98. // +protobuf.nullable=true
  99. type ExtraValue []string
  100. // SelfSubjectAccessReviewSpec is a description of the access request. Exactly one of ResourceAttributes
  101. // and NonResourceAttributes must be set
  102. type SelfSubjectAccessReviewSpec struct {
  103. // ResourceAttributes describes information for a resource access request
  104. ResourceAttributes *ResourceAttributes
  105. // NonResourceAttributes describes information for a non-resource access request
  106. NonResourceAttributes *NonResourceAttributes
  107. }
  108. // SubjectAccessReviewStatus
  109. type SubjectAccessReviewStatus struct {
  110. // Allowed is required. True if the action would be allowed, false otherwise.
  111. Allowed bool
  112. // Reason is optional. It indicates why a request was allowed or denied.
  113. Reason string
  114. // EvaluationError is an indication that some error occurred during the authorization check.
  115. // It is entirely possible to get an error and be able to continue determine authorization status in spite of it.
  116. // For instance, RBAC can be missing a role, but enough roles are still present and bound to reason about the request.
  117. EvaluationError string
  118. }