...

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

Documentation: k8s.io/api/authentication/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  	"k8s.io/apimachinery/pkg/types"
    24  )
    25  
    26  const (
    27  	// ImpersonateUserHeader is used to impersonate a particular user during an API server request
    28  	ImpersonateUserHeader = "Impersonate-User"
    29  
    30  	// ImpersonateGroupHeader is used to impersonate a particular group during an API server request.
    31  	// It can be repeated multiplied times for multiple groups.
    32  	ImpersonateGroupHeader = "Impersonate-Group"
    33  
    34  	// ImpersonateUIDHeader is used to impersonate a particular UID during an API server request
    35  	ImpersonateUIDHeader = "Impersonate-Uid"
    36  
    37  	// ImpersonateUserExtraHeaderPrefix is a prefix for any header used to impersonate an entry in the
    38  	// extra map[string][]string for user.Info.  The key will be every after the prefix.
    39  	// It can be repeated multiplied times for multiple map keys and the same key can be repeated multiple
    40  	// times to have multiple elements in the slice under a single key
    41  	ImpersonateUserExtraHeaderPrefix = "Impersonate-Extra-"
    42  )
    43  
    44  // +genclient
    45  // +genclient:nonNamespaced
    46  // +genclient:onlyVerbs=create
    47  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    48  
    49  // TokenReview attempts to authenticate a token to a known user.
    50  // Note: TokenReview requests may be cached by the webhook token authenticator
    51  // plugin in the kube-apiserver.
    52  type TokenReview struct {
    53  	metav1.TypeMeta `json:",inline"`
    54  	// Standard object's metadata.
    55  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    56  	// +optional
    57  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    58  
    59  	// Spec holds information about the request being evaluated
    60  	Spec TokenReviewSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
    61  
    62  	// Status is filled in by the server and indicates whether the request can be authenticated.
    63  	// +optional
    64  	Status TokenReviewStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
    65  }
    66  
    67  // TokenReviewSpec is a description of the token authentication request.
    68  type TokenReviewSpec struct {
    69  	// Token is the opaque bearer token.
    70  	// +optional
    71  	Token string `json:"token,omitempty" protobuf:"bytes,1,opt,name=token"`
    72  	// Audiences is a list of the identifiers that the resource server presented
    73  	// with the token identifies as. Audience-aware token authenticators will
    74  	// verify that the token was intended for at least one of the audiences in
    75  	// this list. If no audiences are provided, the audience will default to the
    76  	// audience of the Kubernetes apiserver.
    77  	// +optional
    78  	// +listType=atomic
    79  	Audiences []string `json:"audiences,omitempty" protobuf:"bytes,2,rep,name=audiences"`
    80  }
    81  
    82  // TokenReviewStatus is the result of the token authentication request.
    83  type TokenReviewStatus struct {
    84  	// Authenticated indicates that the token was associated with a known user.
    85  	// +optional
    86  	Authenticated bool `json:"authenticated,omitempty" protobuf:"varint,1,opt,name=authenticated"`
    87  	// User is the UserInfo associated with the provided token.
    88  	// +optional
    89  	User UserInfo `json:"user,omitempty" protobuf:"bytes,2,opt,name=user"`
    90  	// Audiences are audience identifiers chosen by the authenticator that are
    91  	// compatible with both the TokenReview and token. An identifier is any
    92  	// identifier in the intersection of the TokenReviewSpec audiences and the
    93  	// token's audiences. A client of the TokenReview API that sets the
    94  	// spec.audiences field should validate that a compatible audience identifier
    95  	// is returned in the status.audiences field to ensure that the TokenReview
    96  	// server is audience aware. If a TokenReview returns an empty
    97  	// status.audience field where status.authenticated is "true", the token is
    98  	// valid against the audience of the Kubernetes API server.
    99  	// +optional
   100  	// +listType=atomic
   101  	Audiences []string `json:"audiences,omitempty" protobuf:"bytes,4,rep,name=audiences"`
   102  	// Error indicates that the token couldn't be checked
   103  	// +optional
   104  	Error string `json:"error,omitempty" protobuf:"bytes,3,opt,name=error"`
   105  }
   106  
   107  // UserInfo holds the information about the user needed to implement the
   108  // user.Info interface.
   109  type UserInfo struct {
   110  	// The name that uniquely identifies this user among all active users.
   111  	// +optional
   112  	Username string `json:"username,omitempty" protobuf:"bytes,1,opt,name=username"`
   113  	// A unique value that identifies this user across time. If this user is
   114  	// deleted and another user by the same name is added, they will have
   115  	// different UIDs.
   116  	// +optional
   117  	UID string `json:"uid,omitempty" protobuf:"bytes,2,opt,name=uid"`
   118  	// The names of groups this user is a part of.
   119  	// +optional
   120  	// +listType=atomic
   121  	Groups []string `json:"groups,omitempty" protobuf:"bytes,3,rep,name=groups"`
   122  	// Any additional information provided by the authenticator.
   123  	// +optional
   124  	Extra map[string]ExtraValue `json:"extra,omitempty" protobuf:"bytes,4,rep,name=extra"`
   125  }
   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  
   132  func (t ExtraValue) String() string {
   133  	return fmt.Sprintf("%v", []string(t))
   134  }
   135  
   136  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   137  
   138  // TokenRequest requests a token for a given service account.
   139  type TokenRequest struct {
   140  	metav1.TypeMeta `json:",inline"`
   141  	// Standard object's metadata.
   142  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   143  	// +optional
   144  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
   145  
   146  	// Spec holds information about the request being evaluated
   147  	Spec TokenRequestSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
   148  
   149  	// Status is filled in by the server and indicates whether the token can be authenticated.
   150  	// +optional
   151  	Status TokenRequestStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
   152  }
   153  
   154  // TokenRequestSpec contains client provided parameters of a token request.
   155  type TokenRequestSpec struct {
   156  	// Audiences are the intendend audiences of the token. A recipient of a
   157  	// token must identify themself with an identifier in the list of
   158  	// audiences of the token, and otherwise should reject the token. A
   159  	// token issued for multiple audiences may be used to authenticate
   160  	// against any of the audiences listed but implies a high degree of
   161  	// trust between the target audiences.
   162  	// +listType=atomic
   163  	Audiences []string `json:"audiences" protobuf:"bytes,1,rep,name=audiences"`
   164  
   165  	// ExpirationSeconds is the requested duration of validity of the request. The
   166  	// token issuer may return a token with a different validity duration so a
   167  	// client needs to check the 'expiration' field in a response.
   168  	// +optional
   169  	ExpirationSeconds *int64 `json:"expirationSeconds" protobuf:"varint,4,opt,name=expirationSeconds"`
   170  
   171  	// BoundObjectRef is a reference to an object that the token will be bound to.
   172  	// The token will only be valid for as long as the bound object exists.
   173  	// NOTE: The API server's TokenReview endpoint will validate the
   174  	// BoundObjectRef, but other audiences may not. Keep ExpirationSeconds
   175  	// small if you want prompt revocation.
   176  	// +optional
   177  	BoundObjectRef *BoundObjectReference `json:"boundObjectRef" protobuf:"bytes,3,opt,name=boundObjectRef"`
   178  }
   179  
   180  // TokenRequestStatus is the result of a token request.
   181  type TokenRequestStatus struct {
   182  	// Token is the opaque bearer token.
   183  	Token string `json:"token" protobuf:"bytes,1,opt,name=token"`
   184  	// ExpirationTimestamp is the time of expiration of the returned token.
   185  	ExpirationTimestamp metav1.Time `json:"expirationTimestamp" protobuf:"bytes,2,opt,name=expirationTimestamp"`
   186  }
   187  
   188  // BoundObjectReference is a reference to an object that a token is bound to.
   189  type BoundObjectReference struct {
   190  	// Kind of the referent. Valid kinds are 'Pod' and 'Secret'.
   191  	// +optional
   192  	Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"`
   193  	// API version of the referent.
   194  	// +optional
   195  	APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,2,opt,name=apiVersion"`
   196  
   197  	// Name of the referent.
   198  	// +optional
   199  	Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"`
   200  	// UID of the referent.
   201  	// +optional
   202  	UID types.UID `json:"uid,omitempty" protobuf:"bytes,4,opt,name=uID,casttype=k8s.io/apimachinery/pkg/types.UID"`
   203  }
   204  
   205  // +genclient
   206  // +genclient:nonNamespaced
   207  // +genclient:onlyVerbs=create
   208  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   209  
   210  // SelfSubjectReview contains the user information that the kube-apiserver has about the user making this request.
   211  // When using impersonation, users will receive the user info of the user being impersonated.  If impersonation or
   212  // request header authentication is used, any extra keys will have their case ignored and returned as lowercase.
   213  type SelfSubjectReview struct {
   214  	metav1.TypeMeta `json:",inline"`
   215  	// Standard object's metadata.
   216  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   217  	// +optional
   218  	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
   219  	// Status is filled in by the server with the user attributes.
   220  	Status SelfSubjectReviewStatus `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"`
   221  }
   222  
   223  // SelfSubjectReviewStatus is filled by the kube-apiserver and sent back to a user.
   224  type SelfSubjectReviewStatus struct {
   225  	// User attributes of the user making this request.
   226  	// +optional
   227  	UserInfo UserInfo `json:"userInfo,omitempty" protobuf:"bytes,1,opt,name=userInfo"`
   228  }
   229  

View as plain text