Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [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:noVerbs |
| 28 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 29 | |
| 30 | // TokenReview attempts to authenticate a token to a known user. |
| 31 | // Note: TokenReview requests may be cached by the webhook token authenticator |
| 32 | // plugin in the kube-apiserver. |
| 33 | type TokenReview struct { |
| 34 | metav1.TypeMeta `json:",inline"` |
| 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 TokenReviewSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"` |
| 40 | |
| 41 | // Status is filled in by the server and indicates whether the request can be authenticated. |
| 42 | // +optional |
| 43 | Status TokenReviewStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` |
| 44 | } |
| 45 | |
| 46 | // TokenReviewSpec is a description of the token authentication request. |
| 47 | type TokenReviewSpec struct { |
| 48 | // Token is the opaque bearer token. |
| 49 | // +optional |
| 50 | Token string `json:"token,omitempty" protobuf:"bytes,1,opt,name=token"` |
| 51 | } |
| 52 | |
| 53 | // TokenReviewStatus is the result of the token authentication request. |
| 54 | type TokenReviewStatus struct { |
| 55 | // Authenticated indicates that the token was associated with a known user. |
| 56 | // +optional |
| 57 | Authenticated bool `json:"authenticated,omitempty" protobuf:"varint,1,opt,name=authenticated"` |
| 58 | // User is the UserInfo associated with the provided token. |
| 59 | // +optional |
| 60 | User UserInfo `json:"user,omitempty" protobuf:"bytes,2,opt,name=user"` |
| 61 | // Error indicates that the token couldn't be checked |
| 62 | // +optional |
| 63 | Error string `json:"error,omitempty" protobuf:"bytes,3,opt,name=error"` |
| 64 | } |
| 65 | |
| 66 | // UserInfo holds the information about the user needed to implement the |
| 67 | // user.Info interface. |
| 68 | type UserInfo struct { |
| 69 | // The name that uniquely identifies this user among all active users. |
| 70 | // +optional |
| 71 | Username string `json:"username,omitempty" protobuf:"bytes,1,opt,name=username"` |
| 72 | // A unique value that identifies this user across time. If this user is |
| 73 | // deleted and another user by the same name is added, they will have |
| 74 | // different UIDs. |
| 75 | // +optional |
| 76 | UID string `json:"uid,omitempty" protobuf:"bytes,2,opt,name=uid"` |
| 77 | // The names of groups this user is a part of. |
| 78 | // +optional |
| 79 | Groups []string `json:"groups,omitempty" protobuf:"bytes,3,rep,name=groups"` |
| 80 | // Any additional information provided by the authenticator. |
| 81 | // +optional |
| 82 | Extra map[string]ExtraValue `json:"extra,omitempty" protobuf:"bytes,4,rep,name=extra"` |
| 83 | } |
| 84 | |
| 85 | // ExtraValue masks the value so protobuf can generate |
| 86 | // +protobuf.nullable=true |
| 87 | // +protobuf.options.(gogoproto.goproto_stringer)=false |
| 88 | type ExtraValue []string |
| 89 | |
| 90 | func (t ExtraValue) String() string { |
| 91 | return fmt.Sprintf("%v", []string(t)) |
| 92 | } |