-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement CEL for StructuredAuthenticationConfig #121078
Merged
k8s-ci-robot
merged 3 commits into
kubernetes:master
from
aramase:aramase/f/kep_3331_cel_integration
Oct 31, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aramase marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,13 @@ type JWTAuthenticator struct { | |
// claimMappings points claims of a token to be treated as user attributes. | ||
// +required | ||
ClaimMappings ClaimMappings `json:"claimMappings"` | ||
|
||
// userValidationRules are rules that are applied to final user before completing authentication. | ||
// These allow invariants to be applied to incoming identities such as preventing the | ||
// use of the system: prefix that is commonly used by Kubernetes components. | ||
// The validation rules are logically ANDed together and must all return true for the validation to pass. | ||
// +optional | ||
UserValidationRules []UserValidationRule `json:"userValidationRules,omitempty"` | ||
} | ||
|
||
// Issuer provides the configuration for a external provider specific settings. | ||
|
@@ -225,21 +232,44 @@ type ClaimValidationRule struct { | |
// claim is the name of a required claim. | ||
// Same as --oidc-required-claim flag. | ||
// Only string claim keys are supported. | ||
// +required | ||
Claim string `json:"claim"` | ||
// Mutually exclusive with expression and message. | ||
// +optional | ||
Claim string `json:"claim,omitempty"` | ||
// requiredValue is the value of a required claim. | ||
// Same as --oidc-required-claim flag. | ||
// Only string claim values are supported. | ||
// If claim is set and requiredValue is not set, the claim must be present with a value set to the empty string. | ||
// Mutually exclusive with expression and message. | ||
// +optional | ||
RequiredValue string `json:"requiredValue,omitempty"` | ||
|
||
// expression represents the expression which will be evaluated by CEL. | ||
// Must produce a boolean. | ||
// | ||
// CEL expressions have access to the contents of the token claims, organized into CEL variable: | ||
// - 'claims' is a map of claim names to claim values. | ||
// For example, a variable named 'sub' can be accessed as 'claims.sub'. | ||
// Nested claims can be accessed using dot notation, e.g. 'claims.email.verified'. | ||
// Must return true for the validation to pass. | ||
// | ||
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ | ||
// | ||
// Mutually exclusive with claim and requiredValue. | ||
aramase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// +optional | ||
Expression string `json:"expression,omitempty"` | ||
// message customizes the returned error message when expression returns false. | ||
aramase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// message is a literal string. | ||
// Mutually exclusive with claim and requiredValue. | ||
// +optional | ||
RequiredValue string `json:"requiredValue"` | ||
Message string `json:"message,omitempty"` | ||
} | ||
|
||
// ClaimMappings provides the configuration for claim mapping | ||
type ClaimMappings struct { | ||
// username represents an option for the username attribute. | ||
// The claim's value must be a singular string. | ||
// Same as the --oidc-username-claim and --oidc-username-prefix flags. | ||
// If username.expression is set, the expression must produce a string value. | ||
// | ||
// In the flag based approach, the --oidc-username-claim and --oidc-username-prefix are optional. If --oidc-username-claim is not set, | ||
// 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. | ||
|
@@ -254,19 +284,136 @@ type ClaimMappings struct { | |
Username PrefixedClaimOrExpression `json:"username"` | ||
// groups represents an option for the groups attribute. | ||
// The claim's value must be a string or string array claim. | ||
// // If groups.claim is set, the prefix must be specified (and can be the empty string). | ||
// If groups.claim is set, the prefix must be specified (and can be the empty string). | ||
// If groups.expression is set, the expression must produce a string or string array value. | ||
// "", [], and null values are treated as the group mapping not being present. | ||
// +optional | ||
Groups PrefixedClaimOrExpression `json:"groups,omitempty"` | ||
aramase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// uid represents an option for the uid attribute. | ||
// Claim must be a singular string claim. | ||
// If uid.expression is set, the expression must produce a string value. | ||
// +optional | ||
UID ClaimOrExpression `json:"uid"` | ||
|
||
// extra represents an option for the extra attribute. | ||
// expression must produce a string or string array value. | ||
// If the value is empty, the extra mapping will not be present. | ||
// | ||
// hard-coded extra key/value | ||
// - key: "foo" | ||
// valueExpression: "'bar'" | ||
// This will result in an extra attribute - foo: ["bar"] | ||
// | ||
// hard-coded key, value copying claim value | ||
// - key: "foo" | ||
// valueExpression: "claims.some_claim" | ||
// This will result in an extra attribute - foo: [value of some_claim] | ||
// | ||
// hard-coded key, value derived from claim value | ||
// - key: "admin" | ||
// valueExpression: '(has(claims.is_admin) && claims.is_admin) ? "true":""' | ||
aramase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// This will result in: | ||
// - if is_admin claim is present and true, extra attribute - admin: ["true"] | ||
// - if is_admin claim is present and false or is_admin claim is not present, no extra attribute will be added | ||
// | ||
// +optional | ||
Extra []ExtraMapping `json:"extra,omitempty"` | ||
} | ||
|
||
// PrefixedClaimOrExpression provides the configuration for a single prefixed claim or expression. | ||
type PrefixedClaimOrExpression struct { | ||
// claim is the JWT claim to use. | ||
// Mutually exclusive with expression. | ||
// +optional | ||
Claim string `json:"claim"` | ||
Claim string `json:"claim,omitempty"` | ||
// prefix is prepended to claim's value to prevent clashes with existing names. | ||
// prefix needs to be set if claim is set and can be the empty string. | ||
// Mutually exclusive with expression. | ||
// +optional | ||
Prefix *string `json:"prefix,omitempty"` | ||
|
||
// expression represents the expression which will be evaluated by CEL. | ||
// | ||
// CEL expressions have access to the contents of the token claims, organized into CEL variable: | ||
// - 'claims' is a map of claim names to claim values. | ||
// For example, a variable named 'sub' can be accessed as 'claims.sub'. | ||
// Nested claims can be accessed using dot notation, e.g. 'claims.email.verified'. | ||
// | ||
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also provide some semi complex examples where CEL is required over the simple claim/prefix approach. |
||
// | ||
// Mutually exclusive with claim and prefix. | ||
// +optional | ||
Expression string `json:"expression,omitempty"` | ||
} | ||
|
||
// ClaimOrExpression provides the configuration for a single claim or expression. | ||
type ClaimOrExpression struct { | ||
// claim is the JWT claim to use. | ||
// Either claim or expression must be set. | ||
aramase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Mutually exclusive with expression. | ||
// +optional | ||
Claim string `json:"claim,omitempty"` | ||
|
||
// expression represents the expression which will be evaluated by CEL. | ||
// | ||
// CEL expressions have access to the contents of the token claims, organized into CEL variable: | ||
// - 'claims' is a map of claim names to claim values. | ||
// For example, a variable named 'sub' can be accessed as 'claims.sub'. | ||
// Nested claims can be accessed using dot notation, e.g. 'claims.email.verified'. | ||
// | ||
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ | ||
// | ||
// Mutually exclusive with claim. | ||
// +optional | ||
Expression string `json:"expression,omitempty"` | ||
} | ||
|
||
// ExtraMapping provides the configuration for a single extra mapping. | ||
type ExtraMapping struct { | ||
// key is a string to use as the extra attribute key. | ||
// key must be a domain-prefix path (e.g. example.org/foo). All characters before the first "/" must be a valid | ||
// subdomain as defined by RFC 1123. All characters trailing the first "/" must | ||
// be valid HTTP Path characters as defined by RFC 3986. | ||
// key must be lowercase. | ||
// +required | ||
Prefix *string `json:"prefix"` | ||
Key string `json:"key"` | ||
aramase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// valueExpression is a CEL expression to extract extra attribute value. | ||
// valueExpression must produce a string or string array value. | ||
// "", [], and null values are treated as the extra mapping not being present. | ||
// Empty string values contained within a string array are filtered out. | ||
// | ||
// CEL expressions have access to the contents of the token claims, organized into CEL variable: | ||
// - 'claims' is a map of claim names to claim values. | ||
// For example, a variable named 'sub' can be accessed as 'claims.sub'. | ||
// Nested claims can be accessed using dot notation, e.g. 'claims.email.verified'. | ||
// | ||
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ | ||
// | ||
// +required | ||
ValueExpression string `json:"valueExpression"` | ||
} | ||
|
||
// UserValidationRule provides the configuration for a single user info validation rule. | ||
type UserValidationRule struct { | ||
// expression represents the expression which will be evaluated by CEL. | ||
// Must return true for the validation to pass. | ||
// | ||
// CEL expressions have access to the contents of UserInfo, organized into CEL variable: | ||
// - 'user' - authentication.k8s.io/v1, Kind=UserInfo object | ||
// Refer to https://github.com/kubernetes/api/blob/release-1.28/authentication/v1/types.go#L105-L122 for the definition. | ||
// API documentation: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#userinfo-v1-authentication-k8s-io | ||
// | ||
// Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ | ||
// | ||
// +required | ||
Expression string `json:"expression"` | ||
|
||
// message customizes the returned error message when rule returns false. | ||
// message is a literal string. | ||
// +optional | ||
Message string `json:"message,omitempty"` | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liggitt PTAL