...

Source file src/k8s.io/kubernetes/pkg/apis/authorization/types.go

Documentation: k8s.io/kubernetes/pkg/apis/authorization

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

View as plain text