Matteo Scandolo | a428586 | 2020-12-01 18:10:10 -0800 | [diff] [blame] | 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 v1beta1 |
| 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 | // +k8s:prerelease-lifecycle-gen:introduced=1.4 |
| 30 | // +k8s:prerelease-lifecycle-gen:deprecated=1.19 |
| 31 | // +k8s:prerelease-lifecycle-gen:replacement=authentication.k8s.io,v1,TokenReview |
| 32 | |
| 33 | // TokenReview attempts to authenticate a token to a known user. |
| 34 | // Note: TokenReview requests may be cached by the webhook token authenticator |
| 35 | // plugin in the kube-apiserver. |
| 36 | type TokenReview struct { |
| 37 | metav1.TypeMeta `json:",inline"` |
| 38 | // +optional |
| 39 | metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 40 | |
| 41 | // Spec holds information about the request being evaluated |
| 42 | Spec TokenReviewSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"` |
| 43 | |
| 44 | // Status is filled in by the server and indicates whether the request can be authenticated. |
| 45 | // +optional |
| 46 | Status TokenReviewStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` |
| 47 | } |
| 48 | |
| 49 | // TokenReviewSpec is a description of the token authentication request. |
| 50 | type TokenReviewSpec struct { |
| 51 | // Token is the opaque bearer token. |
| 52 | // +optional |
| 53 | Token string `json:"token,omitempty" protobuf:"bytes,1,opt,name=token"` |
| 54 | // Audiences is a list of the identifiers that the resource server presented |
| 55 | // with the token identifies as. Audience-aware token authenticators will |
| 56 | // verify that the token was intended for at least one of the audiences in |
| 57 | // this list. If no audiences are provided, the audience will default to the |
| 58 | // audience of the Kubernetes apiserver. |
| 59 | // +optional |
| 60 | Audiences []string `json:"audiences,omitempty" protobuf:"bytes,2,rep,name=audiences"` |
| 61 | } |
| 62 | |
| 63 | // TokenReviewStatus is the result of the token authentication request. |
| 64 | type TokenReviewStatus struct { |
| 65 | // Authenticated indicates that the token was associated with a known user. |
| 66 | // +optional |
| 67 | Authenticated bool `json:"authenticated,omitempty" protobuf:"varint,1,opt,name=authenticated"` |
| 68 | // User is the UserInfo associated with the provided token. |
| 69 | // +optional |
| 70 | User UserInfo `json:"user,omitempty" protobuf:"bytes,2,opt,name=user"` |
| 71 | // Audiences are audience identifiers chosen by the authenticator that are |
| 72 | // compatible with both the TokenReview and token. An identifier is any |
| 73 | // identifier in the intersection of the TokenReviewSpec audiences and the |
| 74 | // token's audiences. A client of the TokenReview API that sets the |
| 75 | // spec.audiences field should validate that a compatible audience identifier |
| 76 | // is returned in the status.audiences field to ensure that the TokenReview |
| 77 | // server is audience aware. If a TokenReview returns an empty |
| 78 | // status.audience field where status.authenticated is "true", the token is |
| 79 | // valid against the audience of the Kubernetes API server. |
| 80 | // +optional |
| 81 | Audiences []string `json:"audiences,omitempty" protobuf:"bytes,4,rep,name=audiences"` |
| 82 | // Error indicates that the token couldn't be checked |
| 83 | // +optional |
| 84 | Error string `json:"error,omitempty" protobuf:"bytes,3,opt,name=error"` |
| 85 | } |
| 86 | |
| 87 | // UserInfo holds the information about the user needed to implement the |
| 88 | // user.Info interface. |
| 89 | type UserInfo struct { |
| 90 | // The name that uniquely identifies this user among all active users. |
| 91 | // +optional |
| 92 | Username string `json:"username,omitempty" protobuf:"bytes,1,opt,name=username"` |
| 93 | // A unique value that identifies this user across time. If this user is |
| 94 | // deleted and another user by the same name is added, they will have |
| 95 | // different UIDs. |
| 96 | // +optional |
| 97 | UID string `json:"uid,omitempty" protobuf:"bytes,2,opt,name=uid"` |
| 98 | // The names of groups this user is a part of. |
| 99 | // +optional |
| 100 | Groups []string `json:"groups,omitempty" protobuf:"bytes,3,rep,name=groups"` |
| 101 | // Any additional information provided by the authenticator. |
| 102 | // +optional |
| 103 | Extra map[string]ExtraValue `json:"extra,omitempty" protobuf:"bytes,4,rep,name=extra"` |
| 104 | } |
| 105 | |
| 106 | // ExtraValue masks the value so protobuf can generate |
| 107 | // +protobuf.nullable=true |
| 108 | // +protobuf.options.(gogoproto.goproto_stringer)=false |
| 109 | type ExtraValue []string |
| 110 | |
| 111 | func (t ExtraValue) String() string { |
| 112 | return fmt.Sprintf("%v", []string(t)) |
| 113 | } |