k8s.io/apiserver@v0.31.1/pkg/apis/apiserver/v1alpha1/types.go (about)

     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)'.
   356  	//
   357  	// In the flag based approach, the --oidc-username-claim and --oidc-username-prefix are optional. If --oidc-username-claim is not set,
   358  	// 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.
   359  	// For claim, if --oidc-username-claim was not set with legacy flag approach, configure username.claim="sub" in the authentication config.
   360  	// For prefix:
   361  	//     (1) --oidc-username-prefix="-", no prefix was added to the username. For the same behavior using authentication config,
   362  	//         set username.prefix=""
   363  	//     (2) --oidc-username-prefix="" and  --oidc-username-claim != "email", prefix was "<value of --oidc-issuer-url>#". For the same
   364  	//         behavior using authentication config, set username.prefix="<value of issuer.url>#"
   365  	//     (3) --oidc-username-prefix="<value>". For the same behavior using authentication config, set username.prefix="<value>"
   366  	// +required
   367  	Username PrefixedClaimOrExpression `json:"username"`
   368  	// groups represents an option for the groups attribute.
   369  	// The claim's value must be a string or string array claim.
   370  	// If groups.claim is set, the prefix must be specified (and can be the empty string).
   371  	// If groups.expression is set, the expression must produce a string or string array value.
   372  	//  "", [], and null values are treated as the group mapping not being present.
   373  	// +optional
   374  	Groups PrefixedClaimOrExpression `json:"groups,omitempty"`
   375  
   376  	// uid represents an option for the uid attribute.
   377  	// Claim must be a singular string claim.
   378  	// If uid.expression is set, the expression must produce a string value.
   379  	// +optional
   380  	UID ClaimOrExpression `json:"uid"`
   381  
   382  	// extra represents an option for the extra attribute.
   383  	// expression must produce a string or string array value.
   384  	// If the value is empty, the extra mapping will not be present.
   385  	//
   386  	// hard-coded extra key/value
   387  	// - key: "foo"
   388  	//   valueExpression: "'bar'"
   389  	// This will result in an extra attribute - foo: ["bar"]
   390  	//
   391  	// hard-coded key, value copying claim value
   392  	// - key: "foo"
   393  	//   valueExpression: "claims.some_claim"
   394  	// This will result in an extra attribute - foo: [value of some_claim]
   395  	//
   396  	// hard-coded key, value derived from claim value
   397  	// - key: "admin"
   398  	//   valueExpression: '(has(claims.is_admin) && claims.is_admin) ? "true":""'
   399  	// This will result in:
   400  	//  - if is_admin claim is present and true, extra attribute - admin: ["true"]
   401  	//  - if is_admin claim is present and false or is_admin claim is not present, no extra attribute will be added
   402  	//
   403  	// +optional
   404  	Extra []ExtraMapping `json:"extra,omitempty"`
   405  }
   406  
   407  // PrefixedClaimOrExpression provides the configuration for a single prefixed claim or expression.
   408  type PrefixedClaimOrExpression struct {
   409  	// claim is the JWT claim to use.
   410  	// Mutually exclusive with expression.
   411  	// +optional
   412  	Claim string `json:"claim,omitempty"`
   413  	// prefix is prepended to claim's value to prevent clashes with existing names.
   414  	// prefix needs to be set if claim is set and can be the empty string.
   415  	// Mutually exclusive with expression.
   416  	// +optional
   417  	Prefix *string `json:"prefix,omitempty"`
   418  
   419  	// expression represents the expression which will be evaluated by CEL.
   420  	//
   421  	// CEL expressions have access to the contents of the token claims, organized into CEL variable:
   422  	// - 'claims' is a map of claim names to claim values.
   423  	//   For example, a variable named 'sub' can be accessed as 'claims.sub'.
   424  	//   Nested claims can be accessed using dot notation, e.g. 'claims.foo.bar'.
   425  	//
   426  	// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/
   427  	//
   428  	// Mutually exclusive with claim and prefix.
   429  	// +optional
   430  	Expression string `json:"expression,omitempty"`
   431  }
   432  
   433  // ClaimOrExpression provides the configuration for a single claim or expression.
   434  type ClaimOrExpression struct {
   435  	// claim is the JWT claim to use.
   436  	// Either claim or expression must be set.
   437  	// Mutually exclusive with expression.
   438  	// +optional
   439  	Claim string `json:"claim,omitempty"`
   440  
   441  	// expression represents the expression which will be evaluated by CEL.
   442  	//
   443  	// CEL expressions have access to the contents of the token claims, organized into CEL variable:
   444  	// - 'claims' is a map of claim names to claim values.
   445  	//   For example, a variable named 'sub' can be accessed as 'claims.sub'.
   446  	//   Nested claims can be accessed using dot notation, e.g. 'claims.foo.bar'.
   447  	//
   448  	// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/
   449  	//
   450  	// Mutually exclusive with claim.
   451  	// +optional
   452  	Expression string `json:"expression,omitempty"`
   453  }
   454  
   455  // ExtraMapping provides the configuration for a single extra mapping.
   456  type ExtraMapping struct {
   457  	// key is a string to use as the extra attribute key.
   458  	// key must be a domain-prefix path (e.g. example.org/foo). All characters before the first "/" must be a valid
   459  	// subdomain as defined by RFC 1123. All characters trailing the first "/" must
   460  	// be valid HTTP Path characters as defined by RFC 3986.
   461  	// key must be lowercase.
   462  	// Required to be unique.
   463  	// +required
   464  	Key string `json:"key"`
   465  
   466  	// valueExpression is a CEL expression to extract extra attribute value.
   467  	// valueExpression must produce a string or string array value.
   468  	// "", [], and null values are treated as the extra mapping not being present.
   469  	// Empty string values contained within a string array are filtered out.
   470  	//
   471  	// CEL expressions have access to the contents of the token claims, organized into CEL variable:
   472  	// - 'claims' is a map of claim names to claim values.
   473  	//   For example, a variable named 'sub' can be accessed as 'claims.sub'.
   474  	//   Nested claims can be accessed using dot notation, e.g. 'claims.foo.bar'.
   475  	//
   476  	// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/
   477  	//
   478  	// +required
   479  	ValueExpression string `json:"valueExpression"`
   480  }
   481  
   482  // UserValidationRule provides the configuration for a single user info validation rule.
   483  type UserValidationRule struct {
   484  	// expression represents the expression which will be evaluated by CEL.
   485  	// Must return true for the validation to pass.
   486  	//
   487  	// CEL expressions have access to the contents of UserInfo, organized into CEL variable:
   488  	// - 'user' - authentication.k8s.io/v1, Kind=UserInfo object
   489  	//    Refer to https://github.com/kubernetes/api/blob/release-1.28/authentication/v1/types.go#L105-L122 for the definition.
   490  	//    API documentation: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#userinfo-v1-authentication-k8s-io
   491  	//
   492  	// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/
   493  	//
   494  	// +required
   495  	Expression string `json:"expression"`
   496  
   497  	// message customizes the returned error message when rule returns false.
   498  	// message is a literal string.
   499  	// +optional
   500  	Message string `json:"message,omitempty"`
   501  }
   502  
   503  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   504  
   505  type AuthorizationConfiguration struct {
   506  	metav1.TypeMeta
   507  
   508  	// Authorizers is an ordered list of authorizers to
   509  	// authorize requests against.
   510  	// This is similar to the --authorization-modes kube-apiserver flag
   511  	// Must be at least one.
   512  	Authorizers []AuthorizerConfiguration `json:"authorizers"`
   513  }
   514  
   515  const (
   516  	TypeWebhook                                          AuthorizerType = "Webhook"
   517  	FailurePolicyNoOpinion                               string         = "NoOpinion"
   518  	FailurePolicyDeny                                    string         = "Deny"
   519  	AuthorizationWebhookConnectionInfoTypeKubeConfigFile string         = "KubeConfigFile"
   520  	AuthorizationWebhookConnectionInfoTypeInCluster      string         = "InClusterConfig"
   521  )
   522  
   523  type AuthorizerType string
   524  
   525  type AuthorizerConfiguration struct {
   526  	// Type refers to the type of the authorizer
   527  	// "Webhook" is supported in the generic API server
   528  	// Other API servers may support additional authorizer
   529  	// types like Node, RBAC, ABAC, etc.
   530  	Type string `json:"type"`
   531  
   532  	// Name used to describe the webhook
   533  	// This is explicitly used in monitoring machinery for metrics
   534  	// Note: Names must be DNS1123 labels like `myauthorizername` or
   535  	//		 subdomains like `myauthorizer.example.domain`
   536  	// Required, with no default
   537  	Name string `json:"name"`
   538  
   539  	// Webhook defines the configuration for a Webhook authorizer
   540  	// Must be defined when Type=Webhook
   541  	// Must not be defined when Type!=Webhook
   542  	Webhook *WebhookConfiguration `json:"webhook,omitempty"`
   543  }
   544  
   545  type WebhookConfiguration struct {
   546  	// The duration to cache 'authorized' responses from the webhook
   547  	// authorizer.
   548  	// Same as setting `--authorization-webhook-cache-authorized-ttl` flag
   549  	// Default: 5m0s
   550  	AuthorizedTTL metav1.Duration `json:"authorizedTTL"`
   551  	// The duration to cache 'unauthorized' responses from the webhook
   552  	// authorizer.
   553  	// Same as setting `--authorization-webhook-cache-unauthorized-ttl` flag
   554  	// Default: 30s
   555  	UnauthorizedTTL metav1.Duration `json:"unauthorizedTTL"`
   556  	// Timeout for the webhook request
   557  	// Maximum allowed value is 30s.
   558  	// Required, no default value.
   559  	Timeout metav1.Duration `json:"timeout"`
   560  	// The API version of the authorization.k8s.io SubjectAccessReview to
   561  	// send to and expect from the webhook.
   562  	// Same as setting `--authorization-webhook-version` flag
   563  	// Valid values: v1beta1, v1
   564  	// Required, no default value
   565  	SubjectAccessReviewVersion string `json:"subjectAccessReviewVersion"`
   566  	// MatchConditionSubjectAccessReviewVersion specifies the SubjectAccessReview
   567  	// version the CEL expressions are evaluated against
   568  	// Valid values: v1
   569  	// Required, no default value
   570  	MatchConditionSubjectAccessReviewVersion string `json:"matchConditionSubjectAccessReviewVersion"`
   571  	// Controls the authorization decision when a webhook request fails to
   572  	// complete or returns a malformed response or errors evaluating
   573  	// matchConditions.
   574  	// Valid values:
   575  	//   - NoOpinion: continue to subsequent authorizers to see if one of
   576  	//     them allows the request
   577  	//   - Deny: reject the request without consulting subsequent authorizers
   578  	// Required, with no default.
   579  	FailurePolicy string `json:"failurePolicy"`
   580  
   581  	// ConnectionInfo defines how we talk to the webhook
   582  	ConnectionInfo WebhookConnectionInfo `json:"connectionInfo"`
   583  
   584  	// matchConditions is a list of conditions that must be met for a request to be sent to this
   585  	// webhook. An empty list of matchConditions matches all requests.
   586  	// There are a maximum of 64 match conditions allowed.
   587  	//
   588  	// The exact matching logic is (in order):
   589  	//   1. If at least one matchCondition evaluates to FALSE, then the webhook is skipped.
   590  	//   2. If ALL matchConditions evaluate to TRUE, then the webhook is called.
   591  	//   3. If at least one matchCondition evaluates to an error (but none are FALSE):
   592  	//      - If failurePolicy=Deny, then the webhook rejects the request
   593  	//      - If failurePolicy=NoOpinion, then the error is ignored and the webhook is skipped
   594  	MatchConditions []WebhookMatchCondition `json:"matchConditions"`
   595  }
   596  
   597  type WebhookConnectionInfo struct {
   598  	// Controls how the webhook should communicate with the server.
   599  	// Valid values:
   600  	// - KubeConfigFile: use the file specified in kubeConfigFile to locate the
   601  	//   server.
   602  	// - InClusterConfig: use the in-cluster configuration to call the
   603  	//   SubjectAccessReview API hosted by kube-apiserver. This mode is not
   604  	//   allowed for kube-apiserver.
   605  	Type string `json:"type"`
   606  
   607  	// Path to KubeConfigFile for connection info
   608  	// Required, if connectionInfo.Type is KubeConfig
   609  	KubeConfigFile *string `json:"kubeConfigFile"`
   610  }
   611  
   612  type WebhookMatchCondition struct {
   613  	// expression represents the expression which will be evaluated by CEL. Must evaluate to bool.
   614  	// CEL expressions have access to the contents of the SubjectAccessReview in v1 version.
   615  	// If version specified by subjectAccessReviewVersion in the request variable is v1beta1,
   616  	// the contents would be converted to the v1 version before evaluating the CEL expression.
   617  	//
   618  	// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/
   619  	Expression string `json:"expression"`
   620  }