-
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
Open
puertomontt
wants to merge
20
commits into
kgateway-dev:main
Choose a base branch
from
puertomontt:envoy-jwt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Envoy jwt #12811
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fbacd5d
jwt wip
puertomontt 7923b1d
jwt per provider
puertomontt e0f2aaf
wip
puertomontt 3483987
tests
puertomontt ca23c3f
e2e test
puertomontt 7f41ea6
Merge branch 'main' of github.com:kgateway-dev/kgateway into envoy-jwt
puertomontt d3740ac
fixes
puertomontt f337862
fix
puertomontt 1a136fb
rename
puertomontt b650b54
fix comments
puertomontt 5bccb99
add test file
puertomontt 5d2c3f5
use base test suite
puertomontt c79de32
fix equals
puertomontt b230261
gosec:disable G101
puertomontt ce91d6c
lint: noKrtEquals for JwtProviders
puertomontt 0909445
Merge branch 'main' of github.com:kgateway-dev/kgateway into envoy-jwt
puertomontt 4353452
rbac test
puertomontt 1259db7
remove file
puertomontt 62ce14b
remove unused provider names
puertomontt 0e0b13c
configmap instead of secret for JWKS
puertomontt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| 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) | ||
|
|
||
| // TODO(npolshak): Add option to disable all jwt filters. | ||
| } | ||
|
|
||
| // 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 forwarded upstream. if false, the header containing the token will be removed. | ||
puertomontt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
puertomontt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // +kubebuilder:validation:Enum=Forward;Remove | ||
| // +kubebuilder:default=Remove | ||
| // +optional | ||
| KeepToken *KeepToken `json:"keepToken,omitempty"` | ||
| } | ||
|
|
||
| // KeepToken configures if the token forwarded behavior. | ||
| 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"` | ||
| // 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"` | ||
|
|
||
| // 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 provide a PEM-formatted public key or file to verify the JWT token. | ||
| // +optional | ||
| LocalJWKS *LocalJWKS `json:"local,omitempty"` | ||
|
|
||
| // TODO: Add support RemoteJWKs here in the future | ||
| } | ||
|
|
||
| // LocalJWKS configures getting the public keys to validate the JWT from a local source, such as a Kubernetes secret, | ||
| // inline, raw string JWKS or file source. | ||
| // +kubebuilder:validation:XValidation:message="exactly one of file, key, or secretRef must be set",rule="(has(self.file) && !has(self.key) && !has(self.secretRef)) || (!has(self.file) && has(self.key) && !has(self.secretRef)) || (!has(self.file) && !has(self.key) && has(self.secretRef))" | ||
| type LocalJWKS struct { | ||
| // File is the path to the file containing the JWKS | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=2048 | ||
| // +optional | ||
| File *string `json:"file,omitempty"` | ||
|
|
||
| // 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"` | ||
|
|
||
| // SecretRef configures storing the JWK in a Kubernetes secret in the same namespace as the JWTValidationPolicy. | ||
| // +optional | ||
| SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"` | ||
| } | ||
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
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