...

Source file src/k8s.io/api/authorization/v1/types.go

Documentation: k8s.io/api/authorization/v1

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

View as plain text