...

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

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

     1  /*
     2  Copyright 2016 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 authentication
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  	"k8s.io/apimachinery/pkg/types"
    22  )
    23  
    24  const (
    25  	// ImpersonateUserHeader is used to impersonate a particular user during an API server request
    26  	ImpersonateUserHeader = "Impersonate-User"
    27  
    28  	// ImpersonateUIDHeader is used to impersonate a particular UID during an API server request.
    29  	ImpersonateUIDHeader = "Impersonate-Uid"
    30  
    31  	// ImpersonateGroupHeader is used to impersonate a particular group during an API server request.
    32  	// It can be repeated multiplied times for multiple groups.
    33  	ImpersonateGroupHeader = "Impersonate-Group"
    34  
    35  	// ImpersonateUserExtraHeaderPrefix is a prefix for any header used to impersonate an entry in the
    36  	// extra map[string][]string for user.Info.  The key will be every after the prefix.
    37  	// It can be repeated multiplied times for multiple map keys and the same key can be repeated multiple
    38  	// times to have multiple elements in the slice under a single key
    39  	ImpersonateUserExtraHeaderPrefix = "Impersonate-Extra-"
    40  )
    41  
    42  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    43  
    44  // TokenReview attempts to authenticate a token to a known user.
    45  type TokenReview struct {
    46  	metav1.TypeMeta
    47  	// ObjectMeta fulfills the metav1.ObjectMetaAccessor interface so that the stock
    48  	// REST handler paths work
    49  	metav1.ObjectMeta
    50  
    51  	// Spec holds information about the request being evaluated
    52  	Spec TokenReviewSpec
    53  
    54  	// Status is filled in by the server and indicates whether the request can be authenticated.
    55  	Status TokenReviewStatus
    56  }
    57  
    58  // TokenReviewSpec is a description of the token authentication request.
    59  type TokenReviewSpec struct {
    60  	// Token is the opaque bearer token.
    61  	Token string `datapolicy:"token"`
    62  	// Audiences is a list of the identifiers that the resource server presented
    63  	// with the token identifies as. Audience-aware token authenticators will
    64  	// verify that the token was intended for at least one of the audiences in
    65  	// this list. If no audiences are provided, the audience will default to the
    66  	// audience of the Kubernetes apiserver.
    67  	Audiences []string
    68  }
    69  
    70  // TokenReviewStatus is the result of the token authentication request.
    71  // This type mirrors the authentication.Token interface
    72  type TokenReviewStatus struct {
    73  	// Authenticated indicates that the token was associated with a known user.
    74  	Authenticated bool
    75  	// User is the UserInfo associated with the provided token.
    76  	User UserInfo
    77  	// Audiences are audience identifiers chosen by the authenticator that are
    78  	// compatible with both the TokenReview and token. An identifier is any
    79  	// identifier in the intersection of the TokenReviewSpec audiences and the
    80  	// token's audiences. A client of the TokenReview API that sets the
    81  	// spec.audiences field should validate that a compatible audience identifier
    82  	// is returned in the status.audiences field to ensure that the TokenReview
    83  	// server is audience aware. If a TokenReview returns an empty
    84  	// status.audience field where status.authenticated is "true", the token is
    85  	// valid against the audience of the Kubernetes API server.
    86  	Audiences []string
    87  	// Error indicates that the token couldn't be checked
    88  	Error string
    89  }
    90  
    91  // UserInfo holds the information about the user needed to implement the
    92  // user.Info interface.
    93  type UserInfo struct {
    94  	// The name that uniquely identifies this user among all active users.
    95  	Username string
    96  	// A unique value that identifies this user across time. If this user is
    97  	// deleted and another user by the same name is added, they will have
    98  	// different UIDs.
    99  	UID string
   100  	// The names of groups this user is a part of.
   101  	Groups []string
   102  	// Any additional information provided by the authenticator.
   103  	Extra map[string]ExtraValue
   104  }
   105  
   106  // ExtraValue masks the value so protobuf can generate
   107  type ExtraValue []string
   108  
   109  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   110  
   111  // TokenRequest requests a token for a given service account.
   112  type TokenRequest struct {
   113  	metav1.TypeMeta
   114  	// ObjectMeta fulfills the metav1.ObjectMetaAccessor interface so that the stock
   115  	// REST handler paths work
   116  	metav1.ObjectMeta
   117  
   118  	Spec   TokenRequestSpec
   119  	Status TokenRequestStatus
   120  }
   121  
   122  // TokenRequestSpec contains client provided parameters of a token request.
   123  type TokenRequestSpec struct {
   124  	// Audiences are the intended audiences of the token. A recipient of a
   125  	// token must identify themself with an identifier in the list of
   126  	// audiences of the token, and otherwise should reject the token. A
   127  	// token issued for multiple audiences may be used to authenticate
   128  	// against any of the audiences listed but implies a high degree of
   129  	// trust between the target audiences.
   130  	Audiences []string
   131  
   132  	// ExpirationSeconds is the requested duration of validity of the request. The
   133  	// token issuer may return a token with a different validity duration so a
   134  	// client needs to check the 'expiration' field in a response.
   135  	ExpirationSeconds int64
   136  
   137  	// BoundObjectRef is a reference to an object that the token will be bound to.
   138  	// The token will only be valid for as long as the bound object exists.
   139  	// NOTE: The API server's TokenReview endpoint will validate the
   140  	// BoundObjectRef, but other audiences may not. Keep ExpirationSeconds
   141  	// small if you want prompt revocation.
   142  	BoundObjectRef *BoundObjectReference
   143  }
   144  
   145  // TokenRequestStatus is the result of a token request.
   146  type TokenRequestStatus struct {
   147  	// Token is the opaque bearer token.
   148  	Token string `datapolicy:"token"`
   149  	// ExpirationTimestamp is the time of expiration of the returned token.
   150  	ExpirationTimestamp metav1.Time
   151  }
   152  
   153  // BoundObjectReference is a reference to an object that a token is bound to.
   154  type BoundObjectReference struct {
   155  	// Kind of the referent. Valid kinds are 'Pod' and 'Secret'.
   156  	Kind string
   157  	// API version of the referent.
   158  	APIVersion string
   159  
   160  	// Name of the referent.
   161  	Name string
   162  	// UID of the referent.
   163  	UID types.UID
   164  }
   165  
   166  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   167  
   168  // SelfSubjectReview contains the user information that the kube-apiserver has about the user making this request.
   169  // When using impersonation, users will receive the user info of the user being impersonated.  If impersonation or
   170  // request header authentication is used, any extra keys will have their case ignored and returned as lowercase.
   171  type SelfSubjectReview struct {
   172  	metav1.TypeMeta
   173  	// ObjectMeta fulfills the metav1.ObjectMetaAccessor interface so that the stock.
   174  	// REST handler paths work.
   175  	metav1.ObjectMeta
   176  	// Status is filled in by the server with the user attributes.
   177  	Status SelfSubjectReviewStatus
   178  }
   179  
   180  // SelfSubjectReviewStatus is filled by the kube-apiserver and sent back to a user.
   181  type SelfSubjectReviewStatus struct {
   182  	// User attributes of the user making this request.
   183  	UserInfo UserInfo
   184  }
   185  

View as plain text