| 1 |
/* |
| 2 |
Copyright 2017 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 v1alpha1 |
| 18 |
|
| 19 |
import ( |
| 20 |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 |
"k8s.io/apimachinery/pkg/runtime" |
| 22 |
tracingapi "k8s.io/component-base/tracing/api/v1" |
| 23 |
) |
| 24 |
|
| 25 |
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 26 |
|
| 27 |
// AdmissionConfiguration provides versioned configuration for admission controllers. |
| 28 |
type AdmissionConfiguration struct { |
| 29 |
metav1.TypeMeta `json:",inline"` |
| 30 |
|
| 31 |
// Plugins allows specifying a configuration per admission control plugin. |
| 32 |
// +optional |
| 33 |
Plugins []AdmissionPluginConfiguration `json:"plugins"` |
| 34 |
} |
| 35 |
|
| 36 |
// AdmissionPluginConfiguration provides the configuration for a single plug-in. |
| 37 |
type AdmissionPluginConfiguration struct { |
| 38 |
// Name is the name of the admission controller. |
| 39 |
// It must match the registered admission plugin name. |
| 40 |
Name string `json:"name"` |
| 41 |
|
| 42 |
// Path is the path to a configuration file that contains the plugin's |
| 43 |
// configuration |
| 44 |
// +optional |
| 45 |
Path string `json:"path"` |
| 46 |
|
| 47 |
// Configuration is an embedded configuration object to be used as the plugin's |
| 48 |
// configuration. If present, it will be used instead of the path to the configuration file. |
| 49 |
// +optional |
| 50 |
Configuration *runtime.Unknown `json:"configuration"` |
| 51 |
} |
| 52 |
|
| 53 |
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 54 |
|
| 55 |
// EgressSelectorConfiguration provides versioned configuration for egress selector clients. |
| 56 |
type EgressSelectorConfiguration struct { |
| 57 |
metav1.TypeMeta `json:",inline"` |
| 58 |
|
| 59 |
// connectionServices contains a list of egress selection client configurations |
| 60 |
EgressSelections []EgressSelection `json:"egressSelections"` |
| 61 |
} |
| 62 |
|
| 63 |
// EgressSelection provides the configuration for a single egress selection client. |
| 64 |
type EgressSelection struct { |
| 65 |
// name is the name of the egress selection. |
| 66 |
// Currently supported values are "controlplane", "master", "etcd" and "cluster" |
| 67 |
// The "master" egress selector is deprecated in favor of "controlplane" |
| 68 |
Name string `json:"name"` |
| 69 |
|
| 70 |
// connection is the exact information used to configure the egress selection |
| 71 |
Connection Connection `json:"connection"` |
| 72 |
} |
| 73 |
|
| 74 |
// Connection provides the configuration for a single egress selection client. |
| 75 |
type Connection struct { |
| 76 |
// Protocol is the protocol used to connect from client to the konnectivity server. |
| 77 |
ProxyProtocol ProtocolType `json:"proxyProtocol,omitempty"` |
| 78 |
|
| 79 |
// Transport defines the transport configurations we use to dial to the konnectivity server. |
| 80 |
// This is required if ProxyProtocol is HTTPConnect or GRPC. |
| 81 |
// +optional |
| 82 |
Transport *Transport `json:"transport,omitempty"` |
| 83 |
} |
| 84 |
|
| 85 |
// ProtocolType is a set of valid values for Connection.ProtocolType |
| 86 |
type ProtocolType string |
| 87 |
|
| 88 |
// Valid types for ProtocolType for konnectivity server |
| 89 |
const ( |
| 90 |
// Use HTTPConnect to connect to konnectivity server |
| 91 |
ProtocolHTTPConnect ProtocolType = "HTTPConnect" |
| 92 |
// Use grpc to connect to konnectivity server |
| 93 |
ProtocolGRPC ProtocolType = "GRPC" |
| 94 |
// Connect directly (skip konnectivity server) |
| 95 |
ProtocolDirect ProtocolType = "Direct" |
| 96 |
) |
| 97 |
|
| 98 |
// Transport defines the transport configurations we use to dial to the konnectivity server |
| 99 |
type Transport struct { |
| 100 |
// TCP is the TCP configuration for communicating with the konnectivity server via TCP |
| 101 |
// ProxyProtocol of GRPC is not supported with TCP transport at the moment |
| 102 |
// Requires at least one of TCP or UDS to be set |
| 103 |
// +optional |
| 104 |
TCP *TCPTransport `json:"tcp,omitempty"` |
| 105 |
|
| 106 |
// UDS is the UDS configuration for communicating with the konnectivity server via UDS |
| 107 |
// Requires at least one of TCP or UDS to be set |
| 108 |
// +optional |
| 109 |
UDS *UDSTransport `json:"uds,omitempty"` |
| 110 |
} |
| 111 |
|
| 112 |
// TCPTransport provides the information to connect to konnectivity server via TCP |
| 113 |
type TCPTransport struct { |
| 114 |
// URL is the location of the konnectivity server to connect to. |
| 115 |
// As an example it might be "https://127.0.0.1:8131" |
| 116 |
URL string `json:"url,omitempty"` |
| 117 |
|
| 118 |
// TLSConfig is the config needed to use TLS when connecting to konnectivity server |
| 119 |
// +optional |
| 120 |
TLSConfig *TLSConfig `json:"tlsConfig,omitempty"` |
| 121 |
} |
| 122 |
|
| 123 |
// UDSTransport provides the information to connect to konnectivity server via UDS |
| 124 |
type UDSTransport struct { |
| 125 |
// UDSName is the name of the unix domain socket to connect to konnectivity server |
| 126 |
// This does not use a unix:// prefix. (Eg: /etc/srv/kubernetes/konnectivity-server/konnectivity-server.socket) |
| 127 |
UDSName string `json:"udsName,omitempty"` |
| 128 |
} |
| 129 |
|
| 130 |
// TLSConfig provides the authentication information to connect to konnectivity server |
| 131 |
// Only used with TCPTransport |
| 132 |
type TLSConfig struct { |
| 133 |
// caBundle is the file location of the CA to be used to determine trust with the konnectivity server. |
| 134 |
// Must be absent/empty if TCPTransport.URL is prefixed with http:// |
| 135 |
// If absent while TCPTransport.URL is prefixed with https://, default to system trust roots. |
| 136 |
// +optional |
| 137 |
CABundle string `json:"caBundle,omitempty"` |
| 138 |
|
| 139 |
// clientKey is the file location of the client key to be used in mtls handshakes with the konnectivity server. |
| 140 |
// Must be absent/empty if TCPTransport.URL is prefixed with http:// |
| 141 |
// Must be configured if TCPTransport.URL is prefixed with https:// |
| 142 |
// +optional |
| 143 |
ClientKey string `json:"clientKey,omitempty"` |
| 144 |
|
| 145 |
// clientCert is the file location of the client certificate to be used in mtls handshakes with the konnectivity server. |
| 146 |
// Must be absent/empty if TCPTransport.URL is prefixed with http:// |
| 147 |
// Must be configured if TCPTransport.URL is prefixed with https:// |
| 148 |
// +optional |
| 149 |
ClientCert string `json:"clientCert,omitempty"` |
| 150 |
} |
| 151 |
|
| 152 |
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 153 |
|
| 154 |
// TracingConfiguration provides versioned configuration for tracing clients. |
| 155 |
type TracingConfiguration struct { |
| 156 |
metav1.TypeMeta `json:",inline"` |
| 157 |
|
| 158 |
// Embed the component config tracing configuration struct |
| 159 |
tracingapi.TracingConfiguration `json:",inline"` |
| 160 |
} |
| 161 |
|
| 162 |
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 163 |
|
| 164 |
// AuthenticationConfiguration provides versioned configuration for authentication. |
| 165 |
type AuthenticationConfiguration struct { |
| 166 |
metav1.TypeMeta |
| 167 |
|
| 168 |
// jwt is a list of authenticator to authenticate Kubernetes users using |
| 169 |
// JWT compliant tokens. The authenticator will attempt to parse a raw ID token, |
| 170 |
// verify it's been signed by the configured issuer. The public key to verify the |
| 171 |
// signature is discovered from the issuer's public endpoint using OIDC discovery. |
| 172 |
// For an incoming token, each JWT authenticator will be attempted in |
| 173 |
// the order in which it is specified in this list. Note however that |
| 174 |
// other authenticators may run before or after the JWT authenticators. |
| 175 |
// The specific position of JWT authenticators in relation to other |
| 176 |
// authenticators is neither defined nor stable across releases. Since |
| 177 |
// each JWT authenticator must have a unique issuer URL, at most one |
| 178 |
// JWT authenticator will attempt to cryptographically validate the token. |
| 179 |
// |
| 180 |
// The minimum valid JWT payload must contain the following claims: |
| 181 |
// { |
| 182 |
// "iss": "https://issuer.example.com", |
| 183 |
// "aud": ["audience"], |
| 184 |
// "exp": 1234567890, |
| 185 |
// "<username claim>": "username" |
| 186 |
// } |
| 187 |
JWT []JWTAuthenticator `json:"jwt"` |
| 188 |
|
| 189 |
// If present --anonymous-auth must not be set |
| 190 |
Anonymous *AnonymousAuthConfig `json:"anonymous,omitempty"` |
| 191 |
} |
| 192 |
|
| 193 |
// AnonymousAuthConfig provides the configuration for the anonymous authenticator. |
| 194 |
type AnonymousAuthConfig struct { |
| 195 |
Enabled bool `json:"enabled"` |
| 196 |
|
| 197 |
// If set, anonymous auth is only allowed if the request meets one of the |
| 198 |
// conditions. |
| 199 |
Conditions []AnonymousAuthCondition `json:"conditions,omitempty"` |
| 200 |
} |
| 201 |
|
| 202 |
// AnonymousAuthCondition describes the condition under which anonymous auth |
| 203 |
// should be enabled. |
| 204 |
type AnonymousAuthCondition struct { |
| 205 |
// Path for which anonymous auth is enabled. |
| 206 |
Path string `json:"path"` |
| 207 |
} |
| 208 |
|
| 209 |
// JWTAuthenticator provides the configuration for a single JWT authenticator. |
| 210 |
type JWTAuthenticator struct { |
| 211 |
// issuer contains the basic OIDC provider connection options. |
| 212 |
// +required |
| 213 |
Issuer Issuer `json:"issuer"` |
| 214 |
|
| 215 |
// claimValidationRules are rules that are applied to validate token claims to authenticate users. |
| 216 |
// +optional |
| 217 |
ClaimValidationRules []ClaimValidationRule `json:"claimValidationRules,omitempty"` |
| 218 |
|
| 219 |
// claimMappings points claims of a token to be treated as user attributes. |
| 220 |
// +required |
| 221 |
ClaimMappings ClaimMappings `json:"claimMappings"` |
| 222 |
|
| 223 |
// userValidationRules are rules that are applied to final user before completing authentication. |
| 224 |
// These allow invariants to be applied to incoming identities such as preventing the |
| 225 |
// use of the system: prefix that is commonly used by Kubernetes components. |
| 226 |
// The validation rules are logically ANDed together and must all return true for the validation to pass. |
| 227 |
// +optional |
| 228 |
UserValidationRules []UserValidationRule `json:"userValidationRules,omitempty"` |
| 229 |
} |
| 230 |
|
| 231 |
// Issuer provides the configuration for an external provider's specific settings. |
| 232 |
type Issuer struct { |
| 233 |
// url points to the issuer URL in a format https://url or https://url/path. |
| 234 |
// This must match the "iss" claim in the presented JWT, and the issuer returned from discovery. |
| 235 |
// Same value as the --oidc-issuer-url flag. |
| 236 |
// Discovery information is fetched from "{url}/.well-known/openid-configuration" unless overridden by discoveryURL. |
| 237 |
// Required to be unique across all JWT authenticators. |
| 238 |
// Note that egress selection configuration is not used for this network connection. |
| 239 |
// +required |
| 240 |
URL string `json:"url"` |
| 241 |
|
| 242 |
// discoveryURL, if specified, overrides the URL used to fetch discovery |
| 243 |
// information instead of using "{url}/.well-known/openid-configuration". |
| 244 |
// The exact value specified is used, so "/.well-known/openid-configuration" |
| 245 |
// must be included in discoveryURL if needed. |
| 246 |
// |
| 247 |
// The "issuer" field in the fetched discovery information must match the "issuer.url" field |
| 248 |
// in the AuthenticationConfiguration and will be used to validate the "iss" claim in the presented JWT. |
| 249 |
// This is for scenarios where the well-known and jwks endpoints are hosted at a different |
| 250 |
// location than the issuer (such as locally in the cluster). |
| 251 |
// |
| 252 |
// Example: |
| 253 |
// A discovery url that is exposed using kubernetes service 'oidc' in namespace 'oidc-namespace' |
| 254 |
// and discovery information is available at '/.well-known/openid-configuration'. |
| 255 |
// discoveryURL: "https://oidc.oidc-namespace/.well-known/openid-configuration" |
| 256 |
// certificateAuthority is used to verify the TLS connection and the hostname on the leaf certificate |
| 257 |
// must be set to 'oidc.oidc-namespace'. |
| 258 |
// |
| 259 |
// curl https://oidc.oidc-namespace/.well-known/openid-configuration (.discoveryURL field) |
| 260 |
// { |
| 261 |
// issuer: "https://oidc.example.com" (.url field) |
| 262 |
// } |
| 263 |
// |
| 264 |
// discoveryURL must be different from url. |
| 265 |
// Required to be unique across all JWT authenticators. |
| 266 |
// Note that egress selection configuration is not used for this network connection. |
| 267 |
// +optional |
| 268 |
DiscoveryURL *string `json:"discoveryURL,omitempty"` |
| 269 |
|
| 270 |
// certificateAuthority contains PEM-encoded certificate authority certificates |
| 271 |
// used to validate the connection when fetching discovery information. |
| 272 |
// If unset, the system verifier is used. |
| 273 |
// Same value as the content of the file referenced by the --oidc-ca-file flag. |
| 274 |
// +optional |
| 275 |
CertificateAuthority string `json:"certificateAuthority,omitempty"` |
| 276 |
|
| 277 |
// audiences is the set of acceptable audiences the JWT must be issued to. |
| 278 |
// At least one of the entries must match the "aud" claim in presented JWTs. |
| 279 |
// Same value as the --oidc-client-id flag (though this field supports an array). |
| 280 |
// Required to be non-empty. |
| 281 |
// +required |
| 282 |
Audiences []string `json:"audiences"` |
| 283 |
|
| 284 |
// audienceMatchPolicy defines how the "audiences" field is used to match the "aud" claim in the presented JWT. |
| 285 |
// Allowed values are: |
| 286 |
// 1. "MatchAny" when multiple audiences are specified and |
| 287 |
// 2. empty (or unset) or "MatchAny" when a single audience is specified. |
| 288 |
// |
| 289 |
// - MatchAny: the "aud" claim in the presented JWT must match at least one of the entries in the "audiences" field. |
| 290 |
// For example, if "audiences" is ["foo", "bar"], the "aud" claim in the presented JWT must contain either "foo" or "bar" (and may contain both). |
| 291 |
// |
| 292 |
// - "": The match policy can be empty (or unset) when a single audience is specified in the "audiences" field. The "aud" claim in the presented JWT must contain the single audience (and may contain others). |
| 293 |
// |
| 294 |
// For more nuanced audience validation, use claimValidationRules. |
| 295 |
// example: claimValidationRule[].expression: 'sets.equivalent(claims.aud, ["bar", "foo", "baz"])' to require an exact match. |
| 296 |
// +optional |
| 297 |
AudienceMatchPolicy AudienceMatchPolicyType `json:"audienceMatchPolicy,omitempty"` |
| 298 |
} |
| 299 |
|
| 300 |
// AudienceMatchPolicyType is a set of valid values for issuer.audienceMatchPolicy |
| 301 |
type AudienceMatchPolicyType string |
| 302 |
|
| 303 |
// Valid types for AudienceMatchPolicyType |
| 304 |
const ( |
| 305 |
// MatchAny means the "aud" claim in the presented JWT must match at least one of the entries in the "audiences" field. |
| 306 |
AudienceMatchPolicyMatchAny AudienceMatchPolicyType = "MatchAny" |
| 307 |
) |
| 308 |
|
| 309 |
// ClaimValidationRule provides the configuration for a single claim validation rule. |
| 310 |
type ClaimValidationRule struct { |
| 311 |
// claim is the name of a required claim. |
| 312 |
// Same as --oidc-required-claim flag. |
| 313 |
// Only string claim keys are supported. |
| 314 |
// Mutually exclusive with expression and message. |
| 315 |
// +optional |
| 316 |
Claim string `json:"claim,omitempty"` |
| 317 |
// requiredValue is the value of a required claim. |
| 318 |
// Same as --oidc-required-claim flag. |
| 319 |
// Only string claim values are supported. |
| 320 |
// If claim is set and requiredValue is not set, the claim must be present with a value set to the empty string. |
| 321 |
// Mutually exclusive with expression and message. |
| 322 |
// +optional |
| 323 |
RequiredValue string `json:"requiredValue,omitempty"` |
| 324 |
|
| 325 |
// expression represents the expression which will be evaluated by CEL. |
| 326 |
// Must produce a boolean. |
| 327 |
// |
| 328 |
// CEL expressions have access to the contents of the token claims, organized into CEL variable: |
| 329 |
// - 'claims' is a map of claim names to claim values. |
| 330 |
// For example, a variable named 'sub' can be accessed as 'claims.sub'. |
| 331 |
// Nested claims can be accessed using dot notation, e.g. 'claims.foo.bar'. |
| 332 |
// Must return true for the validation to pass. |
| 333 |
// |
| 334 |
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ |
| 335 |
// |
| 336 |
// Mutually exclusive with claim and requiredValue. |
| 337 |
// +optional |
| 338 |
Expression string `json:"expression,omitempty"` |
| 339 |
// message customizes the returned error message when expression returns false. |
| 340 |
// message is a literal string. |
| 341 |
// Mutually exclusive with claim and requiredValue. |
| 342 |
// +optional |
| 343 |
Message string `json:"message,omitempty"` |
| 344 |
} |
| 345 |
|
| 346 |
// ClaimMappings provides the configuration for claim mapping |
| 347 |
type ClaimMappings struct { |
| 348 |
// username represents an option for the username attribute. |
| 349 |
// The claim's value must be a singular string. |
| 350 |
// Same as the --oidc-username-claim and --oidc-username-prefix flags. |
| 351 |
// If username.expression is set, the expression must produce a string value. |
| 352 |
// If username.expression uses 'claims.email', then 'claims.email_verified' must be used in |
| 353 |
// username.expression or extra[*].valueExpression or claimValidationRules[*].expression. |
| 354 |
// An example claim validation rule expression that matches the validation automatically |
| 355 |
// applied when username.claim is set to 'email' is 'claims.?email_verified.orValue(true) == true'. By explicitly comparing |
| 356 |
// the value to true, we let type-checking see the result will be a boolean, and to make sure a non-boolean email_verified |
| 357 |
// claim will be caught at runtime. |
| 358 |
// |
| 359 |
// In the flag based approach, the --oidc-username-claim and --oidc-username-prefix are optional. If --oidc-username-claim is not set, |
| 360 |
// the default value is "sub". For the authentication config, there is no defaulting for claim or prefix. The claim and prefix must be set explicitly. |
| 361 |
// For claim, if --oidc-username-claim was not set with legacy flag approach, configure username.claim="sub" in the authentication config. |
| 362 |
// For prefix: |
| 363 |
// (1) --oidc-username-prefix="-", no prefix was added to the username. For the same behavior using authentication config, |
| 364 |
// set username.prefix="" |
| 365 |
// (2) --oidc-username-prefix="" and --oidc-username-claim != "email", prefix was "<value of --oidc-issuer-url>#". For the same |
| 366 |
// behavior using authentication config, set username.prefix="<value of issuer.url>#" |
| 367 |
// (3) --oidc-username-prefix="<value>". For the same behavior using authentication config, set username.prefix="<value>" |
| 368 |
// +required |
| 369 |
Username PrefixedClaimOrExpression `json:"username"` |
| 370 |
// groups represents an option for the groups attribute. |
| 371 |
// The claim's value must be a string or string array claim. |
| 372 |
// If groups.claim is set, the prefix must be specified (and can be the empty string). |
| 373 |
// If groups.expression is set, the expression must produce a string or string array value. |
| 374 |
// "", [], and null values are treated as the group mapping not being present. |
| 375 |
// +optional |
| 376 |
Groups PrefixedClaimOrExpression `json:"groups,omitempty"` |
| 377 |
|
| 378 |
// uid represents an option for the uid attribute. |
| 379 |
// Claim must be a singular string claim. |
| 380 |
// If uid.expression is set, the expression must produce a string value. |
| 381 |
// +optional |
| 382 |
UID ClaimOrExpression `json:"uid"` |
| 383 |
|
| 384 |
// extra represents an option for the extra attribute. |
| 385 |
// expression must produce a string or string array value. |
| 386 |
// If the value is empty, the extra mapping will not be present. |
| 387 |
// |
| 388 |
// hard-coded extra key/value |
| 389 |
// - key: "foo" |
| 390 |
// valueExpression: "'bar'" |
| 391 |
// This will result in an extra attribute - foo: ["bar"] |
| 392 |
// |
| 393 |
// hard-coded key, value copying claim value |
| 394 |
// - key: "foo" |
| 395 |
// valueExpression: "claims.some_claim" |
| 396 |
// This will result in an extra attribute - foo: [value of some_claim] |
| 397 |
// |
| 398 |
// hard-coded key, value derived from claim value |
| 399 |
// - key: "admin" |
| 400 |
// valueExpression: '(has(claims.is_admin) && claims.is_admin) ? "true":""' |
| 401 |
// This will result in: |
| 402 |
// - if is_admin claim is present and true, extra attribute - admin: ["true"] |
| 403 |
// - if is_admin claim is present and false or is_admin claim is not present, no extra attribute will be added |
| 404 |
// |
| 405 |
// +optional |
| 406 |
Extra []ExtraMapping `json:"extra,omitempty"` |
| 407 |
} |
| 408 |
|
| 409 |
// PrefixedClaimOrExpression provides the configuration for a single prefixed claim or expression. |
| 410 |
type PrefixedClaimOrExpression struct { |
| 411 |
// claim is the JWT claim to use. |
| 412 |
// Mutually exclusive with expression. |
| 413 |
// +optional |
| 414 |
Claim string `json:"claim,omitempty"` |
| 415 |
// prefix is prepended to claim's value to prevent clashes with existing names. |
| 416 |
// prefix needs to be set if claim is set and can be the empty string. |
| 417 |
// Mutually exclusive with expression. |
| 418 |
// +optional |
| 419 |
Prefix *string `json:"prefix,omitempty"` |
| 420 |
|
| 421 |
// expression represents the expression which will be evaluated by CEL. |
| 422 |
// |
| 423 |
// CEL expressions have access to the contents of the token claims, organized into CEL variable: |
| 424 |
// - 'claims' is a map of claim names to claim values. |
| 425 |
// For example, a variable named 'sub' can be accessed as 'claims.sub'. |
| 426 |
// Nested claims can be accessed using dot notation, e.g. 'claims.foo.bar'. |
| 427 |
// |
| 428 |
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ |
| 429 |
// |
| 430 |
// Mutually exclusive with claim and prefix. |
| 431 |
// +optional |
| 432 |
Expression string `json:"expression,omitempty"` |
| 433 |
} |
| 434 |
|
| 435 |
// ClaimOrExpression provides the configuration for a single claim or expression. |
| 436 |
type ClaimOrExpression struct { |
| 437 |
// claim is the JWT claim to use. |
| 438 |
// Either claim or expression must be set. |
| 439 |
// Mutually exclusive with expression. |
| 440 |
// +optional |
| 441 |
Claim string `json:"claim,omitempty"` |
| 442 |
|
| 443 |
// expression represents the expression which will be evaluated by CEL. |
| 444 |
// |
| 445 |
// CEL expressions have access to the contents of the token claims, organized into CEL variable: |
| 446 |
// - 'claims' is a map of claim names to claim values. |
| 447 |
// For example, a variable named 'sub' can be accessed as 'claims.sub'. |
| 448 |
// Nested claims can be accessed using dot notation, e.g. 'claims.foo.bar'. |
| 449 |
// |
| 450 |
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ |
| 451 |
// |
| 452 |
// Mutually exclusive with claim. |
| 453 |
// +optional |
| 454 |
Expression string `json:"expression,omitempty"` |
| 455 |
} |
| 456 |
|
| 457 |
// ExtraMapping provides the configuration for a single extra mapping. |
| 458 |
type ExtraMapping struct { |
| 459 |
// key is a string to use as the extra attribute key. |
| 460 |
// key must be a domain-prefix path (e.g. example.org/foo). All characters before the first "/" must be a valid |
| 461 |
// subdomain as defined by RFC 1123. All characters trailing the first "/" must |
| 462 |
// be valid HTTP Path characters as defined by RFC 3986. |
| 463 |
// key must be lowercase. |
| 464 |
// Required to be unique. |
| 465 |
// +required |
| 466 |
Key string `json:"key"` |
| 467 |
|
| 468 |
// valueExpression is a CEL expression to extract extra attribute value. |
| 469 |
// valueExpression must produce a string or string array value. |
| 470 |
// "", [], and null values are treated as the extra mapping not being present. |
| 471 |
// Empty string values contained within a string array are filtered out. |
| 472 |
// |
| 473 |
// CEL expressions have access to the contents of the token claims, organized into CEL variable: |
| 474 |
// - 'claims' is a map of claim names to claim values. |
| 475 |
// For example, a variable named 'sub' can be accessed as 'claims.sub'. |
| 476 |
// Nested claims can be accessed using dot notation, e.g. 'claims.foo.bar'. |
| 477 |
// |
| 478 |
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ |
| 479 |
// |
| 480 |
// +required |
| 481 |
ValueExpression string `json:"valueExpression"` |
| 482 |
} |
| 483 |
|
| 484 |
// UserValidationRule provides the configuration for a single user info validation rule. |
| 485 |
type UserValidationRule struct { |
| 486 |
// expression represents the expression which will be evaluated by CEL. |
| 487 |
// Must return true for the validation to pass. |
| 488 |
// |
| 489 |
// CEL expressions have access to the contents of UserInfo, organized into CEL variable: |
| 490 |
// - 'user' - authentication.k8s.io/v1, Kind=UserInfo object |
| 491 |
// Refer to https://github.com/kubernetes/api/blob/release-1.28/authentication/v1/types.go#L105-L122 for the definition. |
| 492 |
// API documentation: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#userinfo-v1-authentication-k8s-io |
| 493 |
// |
| 494 |
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ |
| 495 |
// |
| 496 |
// +required |
| 497 |
Expression string `json:"expression"` |
| 498 |
|
| 499 |
// message customizes the returned error message when rule returns false. |
| 500 |
// message is a literal string. |
| 501 |
// +optional |
| 502 |
Message string `json:"message,omitempty"` |
| 503 |
} |
| 504 |
|
| 505 |
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 506 |
|
| 507 |
type AuthorizationConfiguration struct { |
| 508 |
metav1.TypeMeta |
| 509 |
|
| 510 |
// Authorizers is an ordered list of authorizers to |
| 511 |
// authorize requests against. |
| 512 |
// This is similar to the --authorization-modes kube-apiserver flag |
| 513 |
// Must be at least one. |
| 514 |
Authorizers []AuthorizerConfiguration `json:"authorizers"` |
| 515 |
} |
| 516 |
|
| 517 |
const ( |
| 518 |
TypeWebhook AuthorizerType = "Webhook" |
| 519 |
FailurePolicyNoOpinion string = "NoOpinion" |
| 520 |
FailurePolicyDeny string = "Deny" |
| 521 |
AuthorizationWebhookConnectionInfoTypeKubeConfigFile string = "KubeConfigFile" |
| 522 |
AuthorizationWebhookConnectionInfoTypeInCluster string = "InClusterConfig" |
| 523 |
) |
| 524 |
|
| 525 |
type AuthorizerType string |
| 526 |
|
| 527 |
type AuthorizerConfiguration struct { |
| 528 |
// Type refers to the type of the authorizer |
| 529 |
// "Webhook" is supported in the generic API server |
| 530 |
// Other API servers may support additional authorizer |
| 531 |
// types like Node, RBAC, ABAC, etc. |
| 532 |
Type string `json:"type"` |
| 533 |
|
| 534 |
// Name used to describe the webhook |
| 535 |
// This is explicitly used in monitoring machinery for metrics |
| 536 |
// Note: Names must be DNS1123 labels like `myauthorizername` or |
| 537 |
// subdomains like `myauthorizer.example.domain` |
| 538 |
// Required, with no default |
| 539 |
Name string `json:"name"` |
| 540 |
|
| 541 |
// Webhook defines the configuration for a Webhook authorizer |
| 542 |
// Must be defined when Type=Webhook |
| 543 |
// Must not be defined when Type!=Webhook |
| 544 |
Webhook *WebhookConfiguration `json:"webhook,omitempty"` |
| 545 |
} |
| 546 |
|
| 547 |
type WebhookConfiguration struct { |
| 548 |
// The duration to cache 'authorized' responses from the webhook |
| 549 |
// authorizer. |
| 550 |
// Same as setting `--authorization-webhook-cache-authorized-ttl` flag |
| 551 |
// Default: 5m0s |
| 552 |
AuthorizedTTL metav1.Duration `json:"authorizedTTL"` |
| 553 |
// The duration to cache 'unauthorized' responses from the webhook |
| 554 |
// authorizer. |
| 555 |
// Same as setting `--authorization-webhook-cache-unauthorized-ttl` flag |
| 556 |
// Default: 30s |
| 557 |
UnauthorizedTTL metav1.Duration `json:"unauthorizedTTL"` |
| 558 |
// Timeout for the webhook request |
| 559 |
// Maximum allowed value is 30s. |
| 560 |
// Required, no default value. |
| 561 |
Timeout metav1.Duration `json:"timeout"` |
| 562 |
// The API version of the authorization.k8s.io SubjectAccessReview to |
| 563 |
// send to and expect from the webhook. |
| 564 |
// Same as setting `--authorization-webhook-version` flag |
| 565 |
// Valid values: v1beta1, v1 |
| 566 |
// Required, no default value |
| 567 |
SubjectAccessReviewVersion string `json:"subjectAccessReviewVersion"` |
| 568 |
// MatchConditionSubjectAccessReviewVersion specifies the SubjectAccessReview |
| 569 |
// version the CEL expressions are evaluated against |
| 570 |
// Valid values: v1 |
| 571 |
// Required, no default value |
| 572 |
MatchConditionSubjectAccessReviewVersion string `json:"matchConditionSubjectAccessReviewVersion"` |
| 573 |
// Controls the authorization decision when a webhook request fails to |
| 574 |
// complete or returns a malformed response or errors evaluating |
| 575 |
// matchConditions. |
| 576 |
// Valid values: |
| 577 |
// - NoOpinion: continue to subsequent authorizers to see if one of |
| 578 |
// them allows the request |
| 579 |
// - Deny: reject the request without consulting subsequent authorizers |
| 580 |
// Required, with no default. |
| 581 |
FailurePolicy string `json:"failurePolicy"` |
| 582 |
|
| 583 |
// ConnectionInfo defines how we talk to the webhook |
| 584 |
ConnectionInfo WebhookConnectionInfo `json:"connectionInfo"` |
| 585 |
|
| 586 |
// matchConditions is a list of conditions that must be met for a request to be sent to this |
| 587 |
// webhook. An empty list of matchConditions matches all requests. |
| 588 |
// There are a maximum of 64 match conditions allowed. |
| 589 |
// |
| 590 |
// The exact matching logic is (in order): |
| 591 |
// 1. If at least one matchCondition evaluates to FALSE, then the webhook is skipped. |
| 592 |
// 2. If ALL matchConditions evaluate to TRUE, then the webhook is called. |
| 593 |
// 3. If at least one matchCondition evaluates to an error (but none are FALSE): |
| 594 |
// - If failurePolicy=Deny, then the webhook rejects the request |
| 595 |
// - If failurePolicy=NoOpinion, then the error is ignored and the webhook is skipped |
| 596 |
MatchConditions []WebhookMatchCondition `json:"matchConditions"` |
| 597 |
} |
| 598 |
|
| 599 |
type WebhookConnectionInfo struct { |
| 600 |
// Controls how the webhook should communicate with the server. |
| 601 |
// Valid values: |
| 602 |
// - KubeConfigFile: use the file specified in kubeConfigFile to locate the |
| 603 |
// server. |
| 604 |
// - InClusterConfig: use the in-cluster configuration to call the |
| 605 |
// SubjectAccessReview API hosted by kube-apiserver. This mode is not |
| 606 |
// allowed for kube-apiserver. |
| 607 |
Type string `json:"type"` |
| 608 |
|
| 609 |
// Path to KubeConfigFile for connection info |
| 610 |
// Required, if connectionInfo.Type is KubeConfig |
| 611 |
KubeConfigFile *string `json:"kubeConfigFile"` |
| 612 |
} |
| 613 |
|
| 614 |
type WebhookMatchCondition struct { |
| 615 |
// expression represents the expression which will be evaluated by CEL. Must evaluate to bool. |
| 616 |
// CEL expressions have access to the contents of the SubjectAccessReview in v1 version. |
| 617 |
// If version specified by subjectAccessReviewVersion in the request variable is v1beta1, |
| 618 |
// the contents would be converted to the v1 version before evaluating the CEL expression. |
| 619 |
// |
| 620 |
// - 'resourceAttributes' describes information for a resource access request and is unset for non-resource requests. e.g. has(request.resourceAttributes) && request.resourceAttributes.namespace == 'default' |
| 621 |
// - 'nonResourceAttributes' describes information for a non-resource access request and is unset for resource requests. e.g. has(request.nonResourceAttributes) && request.nonResourceAttributes.path == '/healthz'. |
| 622 |
// - 'user' is the user to test for. e.g. request.user == 'alice' |
| 623 |
// - 'groups' is the groups to test for. e.g. ('group1' in request.groups) |
| 624 |
// - 'extra' corresponds to the user.Info.GetExtra() method from the authenticator. |
| 625 |
// - 'uid' is the information about the requesting user. e.g. request.uid == '1' |
| 626 |
// |
| 627 |
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ |
| 628 |
Expression string `json:"expression"` |
| 629 |
} |