blob: 0b6cba822a268c4c89debbad12dc6233e9e7b515 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v1beta1
18
19import (
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.
33type 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.
47type TokenReviewSpec struct {
48 // Token is the opaque bearer token.
49 // +optional
50 Token string `json:"token,omitempty" protobuf:"bytes,1,opt,name=token"`
51 // Audiences is a list of the identifiers that the resource server presented
52 // with the token identifies as. Audience-aware token authenticators will
53 // verify that the token was intended for at least one of the audiences in
54 // this list. If no audiences are provided, the audience will default to the
55 // audience of the Kubernetes apiserver.
56 // +optional
57 Audiences []string `json:"audiences,omitempty" protobuf:"bytes,2,rep,name=audiences"`
58}
59
60// TokenReviewStatus is the result of the token authentication request.
61type TokenReviewStatus struct {
62 // Authenticated indicates that the token was associated with a known user.
63 // +optional
64 Authenticated bool `json:"authenticated,omitempty" protobuf:"varint,1,opt,name=authenticated"`
65 // User is the UserInfo associated with the provided token.
66 // +optional
67 User UserInfo `json:"user,omitempty" protobuf:"bytes,2,opt,name=user"`
68 // Audiences are audience identifiers chosen by the authenticator that are
69 // compatible with both the TokenReview and token. An identifier is any
70 // identifier in the intersection of the TokenReviewSpec audiences and the
71 // token's audiences. A client of the TokenReview API that sets the
72 // spec.audiences field should validate that a compatible audience identifier
73 // is returned in the status.audiences field to ensure that the TokenReview
74 // server is audience aware. If a TokenReview returns an empty
75 // status.audience field where status.authenticated is "true", the token is
76 // valid against the audience of the Kubernetes API server.
77 // +optional
78 Audiences []string `json:"audiences,omitempty" protobuf:"bytes,4,rep,name=audiences"`
79 // Error indicates that the token couldn't be checked
80 // +optional
81 Error string `json:"error,omitempty" protobuf:"bytes,3,opt,name=error"`
82}
83
84// UserInfo holds the information about the user needed to implement the
85// user.Info interface.
86type UserInfo struct {
87 // The name that uniquely identifies this user among all active users.
88 // +optional
89 Username string `json:"username,omitempty" protobuf:"bytes,1,opt,name=username"`
90 // A unique value that identifies this user across time. If this user is
91 // deleted and another user by the same name is added, they will have
92 // different UIDs.
93 // +optional
94 UID string `json:"uid,omitempty" protobuf:"bytes,2,opt,name=uid"`
95 // The names of groups this user is a part of.
96 // +optional
97 Groups []string `json:"groups,omitempty" protobuf:"bytes,3,rep,name=groups"`
98 // Any additional information provided by the authenticator.
99 // +optional
100 Extra map[string]ExtraValue `json:"extra,omitempty" protobuf:"bytes,4,rep,name=extra"`
101}
102
103// ExtraValue masks the value so protobuf can generate
104// +protobuf.nullable=true
105// +protobuf.options.(gogoproto.goproto_stringer)=false
106type ExtraValue []string
107
108func (t ExtraValue) String() string {
109 return fmt.Sprintf("%v", []string(t))
110}