-
Notifications
You must be signed in to change notification settings - Fork 596
Envoy jwt #12811
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
base: main
Are you sure you want to change the base?
Envoy jwt #12811
Changes from all commits
fbacd5d
7923b1d
e0f2aaf
3483987
ca23c3f
7f41ea6
d3740ac
f337862
1a136fb
b650b54
5bccb99
5d2c3f5
c79de32
b230261
ce91d6c
0909445
4353452
1259db7
62ce14b
0e0b13c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package v1alpha1 | ||
|
|
||
| import corev1 "k8s.io/api/core/v1" | ||
|
|
||
| // JWTValidation defines the providers used to configure JWT validation | ||
| type JWTValidation struct { | ||
| // ExtensionRef references a GatewayExtension that provides the jwt providers | ||
| // +required | ||
| ExtensionRef *NamespacedObjectReference `json:"extensionRef"` | ||
|
|
||
| // TODO: add support for ValidationMode here (REQUIRE_VALID,ALLOW_MISSING,ALLOW_MISSING_OR_FAILED) | ||
|
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. I think we should add the allow_missing.required/allow_missing_or_failed option here as well. |
||
|
|
||
| // TODO(npolshak): Add option to disable all jwt filters. | ||
|
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. We probably want this as well now that there is a pattern for it: https://github.com/kgateway-dev/kgateway/blob/main/api/v1alpha1/ext_auth_types.go#L27 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. this isn't straightforward for jwt. would require composite filter similar to extproc. the alternative is to disable using RBAC |
||
| } | ||
|
|
||
| // JWTProvider configures the JWT Provider | ||
| // If multiple providers are specified for a given JWT policy, the providers will be `OR`-ed together and will allow validation to any of the providers. | ||
| type JWTProvider struct { | ||
| // Issuer of the JWT. the 'iss' claim of the JWT must match this. | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=2048 | ||
| // +optional | ||
| Issuer string `json:"issuer"` | ||
|
|
||
| // Audiences is the list of audiences to be used for the JWT provider. | ||
| // If specified an incoming JWT must have an 'aud' claim, and it must be in this list. | ||
| // If not specified, the audiences will not be checked in the token. | ||
| // +kubebuilder:validation:MinItems=1 | ||
| // +kubebuilder:validation:MaxItems=100 | ||
| // +optional | ||
| Audiences []string `json:"audiences,omitempty"` | ||
|
|
||
| // TokenSource configures where to find the JWT of the current provider. | ||
| // +optional | ||
| TokenSource *JWTTokenSource `json:"tokenSource,omitempty"` | ||
|
|
||
| // ClaimsToHeaders is the list of claims to headers to be used for the JWT provider. | ||
| // Optionally set the claims from the JWT payload that you want to extract and add as headers | ||
| // to the request before the request is forwarded to the upstream destination. | ||
| // +kubebuilder:validation:MinItems=1 | ||
| // +kubebuilder:validation:MaxItems=100 | ||
| // +optional | ||
| ClaimsToHeaders []JWTClaimToHeader `json:"claimsToHeaders,omitempty"` | ||
|
|
||
| // JWKS is the source for the JSON Web Keys to be used to validate the JWT. | ||
| JWKS JWKS `json:"jwks"` | ||
|
|
||
| // KeepToken configures if the token is forwarded upstream. | ||
| // If Remove, the header containing the token will be removed. | ||
| // If Forward, the header containing the token will be forwarded upstream. | ||
| // +kubebuilder:validation:Enum=Forward;Remove | ||
| // +kubebuilder:default=Remove | ||
| // +optional | ||
| KeepToken *KeepToken `json:"keepToken,omitempty"` | ||
| } | ||
|
|
||
| // KeepToken configures if the token is forwarded upstream. | ||
| type KeepToken string | ||
|
|
||
| const ( | ||
| TokenForward KeepToken = "Forward" | ||
| TokenRemove KeepToken = "Remove" | ||
| ) | ||
|
|
||
| // HeaderSource configures how to retrieve a JWT from a header | ||
| type HeaderSource struct { | ||
| // Header is the name of the header. for example, "Authorization" | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=2048 | ||
| // +optional | ||
| Header *string `json:"header,omitempty"` | ||
| // Prefix before the token. for example, "Bearer " | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=2048 | ||
| // +optional | ||
| Prefix *string `json:"prefix,omitempty"` | ||
| } | ||
|
|
||
| // JWTTokenSource configures the source for the JWTToken | ||
| type JWTTokenSource struct { | ||
| // HeaderSource configures retrieving token from the headers | ||
| // +kubebuilder:validation:MinItems=1 | ||
| // +kubebuilder:validation:MaxItems=100 | ||
| // +optional | ||
| HeaderSource []HeaderSource `json:"headers,omitempty"` | ||
|
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. do we need a list for this and query params? seems like you only want to fetch from one place generally? |
||
| // QueryParams configures retrieving token from these query params | ||
| // +kubebuilder:validation:MinItems=1 | ||
| // +kubebuilder:validation:MaxItems=100 | ||
| // +optional | ||
| QueryParams []string `json:"queryParams,omitempty"` | ||
| } | ||
|
|
||
| // JWTClaimToHeader allows copying verified claims to headers sent upstream | ||
| type JWTClaimToHeader struct { | ||
| // Name is the JWT claim name, for example, "sub". | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=2048 | ||
| Name string `json:"name"` | ||
|
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. claims can be nested (they are JSON). do we support that? 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. I think it technically would work using dot-separated paths |
||
|
|
||
| // Header is the header the claim will be copied to, for example, "x-sub". | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=2048 | ||
| Header string `json:"header"` | ||
| } | ||
|
|
||
| // JWKS (JSON Web Key Set) configures the source for the JWKS | ||
| type JWKS struct { | ||
| // LocalJWKS configures getting the public keys to validate the JWT from a Kubernetes configmap, | ||
| // or inline (raw string) JWKS. | ||
| // +optional | ||
| LocalJWKS *LocalJWKS `json:"local,omitempty"` | ||
|
|
||
| // TODO: Add support for remote JWKS | ||
| } | ||
|
|
||
| // LocalJWKS configures getting the public keys to validate the JWT from a Kubernetes ConfigMap, | ||
| // or inline (raw string) JWKS. | ||
| // +kubebuilder:validation:ExactlyOneOf=key;configMapRef | ||
| type LocalJWKS struct { | ||
| // InlineKey is the JWKS key as the raw, inline JWKS string | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=2048 | ||
| // +optional | ||
| InlineKey *string `json:"key,omitempty"` | ||
|
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. nit: 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. do we support PEM format here? or only JWKS format? |
||
|
|
||
| // ConfigMapRef configures storing the JWK in a Kubernetes ConfigMap in the same namespace as the JWTValidationPolicy. | ||
| // +optional | ||
| ConfigMapRef *corev1.LocalObjectReference `json:"configMapRef,omitempty"` | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
what is the name used for here?
can we use a list of map type instead of map? i think it renders more consistently?
is there a way to configure if this is pre or post ext auth?
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.
I think the provider name needs to be unique, but that can be enforced at the plugin level. We might want to add a way to configure pre/post ext auth using the
kgateway.dev/policy-weight?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.
you can validate uniqueness of a list in CEL as well FWIW