blob: 0395f860f3676e82d10fec15e5bca19e9346e67a [file] [log] [blame]
Matteo Scandoloa4285862020-12-01 18:10:10 -08001/*
2Copyright 2014 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 v1
18
19import (
20 "k8s.io/apimachinery/pkg/runtime"
21)
22
23// Where possible, json tags match the cli argument names.
24// Top level config objects and all values required for proper functioning are not "omitempty". Any truly optional piece of config is allowed to be omitted.
25
26// Config holds the information needed to build connect to remote kubernetes clusters as a given user
27// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
28type Config struct {
29 // Legacy field from pkg/api/types.go TypeMeta.
30 // TODO(jlowdermilk): remove this after eliminating downstream dependencies.
31 // +k8s:conversion-gen=false
32 // +optional
33 Kind string `json:"kind,omitempty"`
34 // Legacy field from pkg/api/types.go TypeMeta.
35 // TODO(jlowdermilk): remove this after eliminating downstream dependencies.
36 // +k8s:conversion-gen=false
37 // +optional
38 APIVersion string `json:"apiVersion,omitempty"`
39 // Preferences holds general information to be use for cli interactions
40 Preferences Preferences `json:"preferences"`
41 // Clusters is a map of referencable names to cluster configs
42 Clusters []NamedCluster `json:"clusters"`
43 // AuthInfos is a map of referencable names to user configs
44 AuthInfos []NamedAuthInfo `json:"users"`
45 // Contexts is a map of referencable names to context configs
46 Contexts []NamedContext `json:"contexts"`
47 // CurrentContext is the name of the context that you would like to use by default
48 CurrentContext string `json:"current-context"`
49 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
50 // +optional
51 Extensions []NamedExtension `json:"extensions,omitempty"`
52}
53
54type Preferences struct {
55 // +optional
56 Colors bool `json:"colors,omitempty"`
57 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
58 // +optional
59 Extensions []NamedExtension `json:"extensions,omitempty"`
60}
61
62// Cluster contains information about how to communicate with a kubernetes cluster
63type Cluster struct {
64 // Server is the address of the kubernetes cluster (https://hostname:port).
65 Server string `json:"server"`
66 // TLSServerName is used to check server certificate. If TLSServerName is empty, the hostname used to contact the server is used.
67 // +optional
68 TLSServerName string `json:"tls-server-name,omitempty"`
69 // InsecureSkipTLSVerify skips the validity check for the server's certificate. This will make your HTTPS connections insecure.
70 // +optional
71 InsecureSkipTLSVerify bool `json:"insecure-skip-tls-verify,omitempty"`
72 // CertificateAuthority is the path to a cert file for the certificate authority.
73 // +optional
74 CertificateAuthority string `json:"certificate-authority,omitempty"`
75 // CertificateAuthorityData contains PEM-encoded certificate authority certificates. Overrides CertificateAuthority
76 // +optional
77 CertificateAuthorityData []byte `json:"certificate-authority-data,omitempty"`
78 // ProxyURL is the URL to the proxy to be used for all requests made by this
79 // client. URLs with "http", "https", and "socks5" schemes are supported. If
80 // this configuration is not provided or the empty string, the client
81 // attempts to construct a proxy configuration from http_proxy and
82 // https_proxy environment variables. If these environment variables are not
83 // set, the client does not attempt to proxy requests.
84 //
85 // socks5 proxying does not currently support spdy streaming endpoints (exec,
86 // attach, port forward).
87 // +optional
88 ProxyURL string `json:"proxy-url,omitempty"`
89 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
90 // +optional
91 Extensions []NamedExtension `json:"extensions,omitempty"`
92}
93
94// AuthInfo contains information that describes identity information. This is use to tell the kubernetes cluster who you are.
95type AuthInfo struct {
96 // ClientCertificate is the path to a client cert file for TLS.
97 // +optional
98 ClientCertificate string `json:"client-certificate,omitempty"`
99 // ClientCertificateData contains PEM-encoded data from a client cert file for TLS. Overrides ClientCertificate
100 // +optional
101 ClientCertificateData []byte `json:"client-certificate-data,omitempty"`
102 // ClientKey is the path to a client key file for TLS.
103 // +optional
104 ClientKey string `json:"client-key,omitempty"`
105 // ClientKeyData contains PEM-encoded data from a client key file for TLS. Overrides ClientKey
106 // +optional
107 ClientKeyData []byte `json:"client-key-data,omitempty"`
108 // Token is the bearer token for authentication to the kubernetes cluster.
109 // +optional
110 Token string `json:"token,omitempty"`
111 // TokenFile is a pointer to a file that contains a bearer token (as described above). If both Token and TokenFile are present, Token takes precedence.
112 // +optional
113 TokenFile string `json:"tokenFile,omitempty"`
114 // Impersonate is the username to imperonate. The name matches the flag.
115 // +optional
116 Impersonate string `json:"as,omitempty"`
117 // ImpersonateGroups is the groups to imperonate.
118 // +optional
119 ImpersonateGroups []string `json:"as-groups,omitempty"`
120 // ImpersonateUserExtra contains additional information for impersonated user.
121 // +optional
122 ImpersonateUserExtra map[string][]string `json:"as-user-extra,omitempty"`
123 // Username is the username for basic authentication to the kubernetes cluster.
124 // +optional
125 Username string `json:"username,omitempty"`
126 // Password is the password for basic authentication to the kubernetes cluster.
127 // +optional
128 Password string `json:"password,omitempty"`
129 // AuthProvider specifies a custom authentication plugin for the kubernetes cluster.
130 // +optional
131 AuthProvider *AuthProviderConfig `json:"auth-provider,omitempty"`
132 // Exec specifies a custom exec-based authentication plugin for the kubernetes cluster.
133 // +optional
134 Exec *ExecConfig `json:"exec,omitempty"`
135 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
136 // +optional
137 Extensions []NamedExtension `json:"extensions,omitempty"`
138}
139
140// Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster), a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)
141type Context struct {
142 // Cluster is the name of the cluster for this context
143 Cluster string `json:"cluster"`
144 // AuthInfo is the name of the authInfo for this context
145 AuthInfo string `json:"user"`
146 // Namespace is the default namespace to use on unspecified requests
147 // +optional
148 Namespace string `json:"namespace,omitempty"`
149 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
150 // +optional
151 Extensions []NamedExtension `json:"extensions,omitempty"`
152}
153
154// NamedCluster relates nicknames to cluster information
155type NamedCluster struct {
156 // Name is the nickname for this Cluster
157 Name string `json:"name"`
158 // Cluster holds the cluster information
159 Cluster Cluster `json:"cluster"`
160}
161
162// NamedContext relates nicknames to context information
163type NamedContext struct {
164 // Name is the nickname for this Context
165 Name string `json:"name"`
166 // Context holds the context information
167 Context Context `json:"context"`
168}
169
170// NamedAuthInfo relates nicknames to auth information
171type NamedAuthInfo struct {
172 // Name is the nickname for this AuthInfo
173 Name string `json:"name"`
174 // AuthInfo holds the auth information
175 AuthInfo AuthInfo `json:"user"`
176}
177
178// NamedExtension relates nicknames to extension information
179type NamedExtension struct {
180 // Name is the nickname for this Extension
181 Name string `json:"name"`
182 // Extension holds the extension information
183 Extension runtime.RawExtension `json:"extension"`
184}
185
186// AuthProviderConfig holds the configuration for a specified auth provider.
187type AuthProviderConfig struct {
188 Name string `json:"name"`
189 Config map[string]string `json:"config"`
190}
191
192// ExecConfig specifies a command to provide client credentials. The command is exec'd
193// and outputs structured stdout holding credentials.
194//
195// See the client.authentication.k8s.io API group for specifications of the exact input
196// and output format
197type ExecConfig struct {
198 // Command to execute.
199 Command string `json:"command"`
200 // Arguments to pass to the command when executing it.
201 // +optional
202 Args []string `json:"args"`
203 // Env defines additional environment variables to expose to the process. These
204 // are unioned with the host's environment, as well as variables client-go uses
205 // to pass argument to the plugin.
206 // +optional
207 Env []ExecEnvVar `json:"env"`
208
209 // Preferred input version of the ExecInfo. The returned ExecCredentials MUST use
210 // the same encoding version as the input.
211 APIVersion string `json:"apiVersion,omitempty"`
212
213 // This text is shown to the user when the executable doesn't seem to be
214 // present. For example, `brew install foo-cli` might be a good InstallHint for
215 // foo-cli on Mac OS systems.
216 InstallHint string `json:"installHint,omitempty"`
217}
218
219// ExecEnvVar is used for setting environment variables when executing an exec-based
220// credential plugin.
221type ExecEnvVar struct {
222 Name string `json:"name"`
223 Value string `json:"value"`
224}