-
Notifications
You must be signed in to change notification settings - Fork 630
Add support for API key authN in TrafficPolicy #12962
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
Changes from 14 commits
fd44ae2
d16cab0
7d8b1b8
1699f45
8718f8e
fa97d62
43bdc0d
5877f3f
3dfc517
da8d09d
343705d
a532c41
b4df3ea
a7b6517
51ea7a8
1b2c33f
181b515
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 |
|---|---|---|
|
|
@@ -139,6 +139,10 @@ type TrafficPolicySpec struct { | |
| // This controls authentication using username/password credentials in the Authorization header. | ||
| // +optional | ||
| BasicAuth *BasicAuthPolicy `json:"basicAuth,omitempty"` | ||
|
|
||
| // APIKeyAuthentication authenticates users based on a configured API Key. | ||
| // +optional | ||
| APIKeyAuthentication *APIKeyAuthentication `json:"apiKeyAuthentication,omitempty"` | ||
| } | ||
|
|
||
| // URLRewrite specifies URL rewrite rules using regular expressions. | ||
|
|
@@ -416,6 +420,118 @@ type CSRFPolicy struct { | |
| AdditionalOrigins []shared.StringMatcher `json:"additionalOrigins,omitempty"` | ||
| } | ||
|
|
||
| // APIKeySource defines where to extract the API key from within a single key source. | ||
| // Within a single key source, if multiple types are specified, precedence is: | ||
| // header > query parameter > cookie. The header is checked first, and only falls back | ||
| // to query parameter if the header is not present, then to cookie if both header and query | ||
| // are not present. | ||
| // +kubebuilder:validation:AtLeastOneOf=header;query;cookie | ||
| type APIKeySource struct { | ||
| // header specifies the name of the header that contains the API key. | ||
| // +optional | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=256 | ||
| Header *string `json:"header,omitempty"` | ||
|
|
||
| // query specifies the name of the query parameter that contains the API key. | ||
| // +optional | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=256 | ||
| Query *string `json:"query,omitempty"` | ||
|
|
||
| // cookie specifies the name of the cookie that contains the API key. | ||
| // +optional | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=256 | ||
| Cookie *string `json:"cookie,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:validation:ExactlyOneOf=secretRef;secretSelector | ||
| type APIKeyAuthentication struct { | ||
|
Contributor
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. Just realized this after the EP has merged, but we don't expose a We may need to in order to be consistent with our other policies.
Contributor
Author
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. Unfortunately the envoy api doesn't have a
Contributor
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 can do this in a follow up, but we have general pattern we can use to handle global disable for various policies by using Envoy's generic filter disable mechanism and a specifically configured composite filter. See #12945 for more details on how we did it for JWT.
Contributor
Author
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 didn't manage to add it to this PR. Will open a follow-up an issue for that.
Contributor
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. Let's be sure to not lose sight of this one |
||
| // keySources specifies the list of key sources to extract the API key from. | ||
| // Key sources are processed in array order and the first one that successfully | ||
| // extracts a key is used. Within each key source, if multiple types (header, query, cookie) are | ||
| // specified, precedence is: header > query parameter > cookie. | ||
| // | ||
| // If empty, defaults to a single key source with header "api-key". | ||
| // | ||
| // Example: | ||
| // keySources: | ||
| // - header: "X-API-KEY" | ||
| // - query: "api_key" | ||
| // - header: "Authorization" | ||
| // query: "token" | ||
| // cookie: "auth_token" | ||
| // | ||
| // In this example, the system will: | ||
| // 1. First try header "X-API-KEY" | ||
| // 2. If not found, try query parameter "api_key" | ||
| // 3. If not found, try header "Authorization" (then query "token", then cookie "auth_token" within that key source) | ||
| // | ||
| // +kubebuilder:validation:MinItems=0 | ||
| // +kubebuilder:validation:MaxItems=16 | ||
| // +optional | ||
| KeySources []APIKeySource `json:"keySources,omitempty"` | ||
|
|
||
| // forwardCredential controls whether the API key is included in the request sent to the upstream. | ||
| // If false (default), the API key is removed from the request before sending to upstream. | ||
| // If true, the API key is included in the request sent to upstream. | ||
| // This applies to all configured key sources (header, query parameter, or cookie). | ||
| // +optional | ||
| ForwardCredential *bool `json:"forwardCredential,omitempty"` | ||
|
|
||
| // clientIdHeader specifies the header name to forward the authenticated client identifier. | ||
| // If not specified, the client identifier will not be forwarded in any header. | ||
| // Example: "x-client-id" | ||
| // +optional | ||
| ClientIdHeader *string `json:"clientIdHeader,omitempty"` | ||
|
|
||
| // secretRef references a Kubernetes secret storing a set of API Keys. If there are many keys, 'secretSelector' can be | ||
| // used instead. | ||
| // | ||
| // Each entry in the Secret represents one API Key. The key is an arbitrary identifier. | ||
| // The value is a string, representing the API Key. | ||
| // | ||
| // Example: | ||
| // | ||
| // apiVersion: v1 | ||
| // kind: Secret | ||
| // metadata: | ||
| // name: api-key | ||
| // stringData: | ||
| // client1: "k-123" | ||
| // client2: "k-456" | ||
| // | ||
| // +optional | ||
| SecretRef *gwv1.SecretObjectReference `json:"secretRef,omitempty"` | ||
ymesika marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // secretSelector selects multiple secrets containing API Keys. If the same key is defined in multiple secrets, the | ||
| // behavior is undefined. | ||
| // | ||
| // Each entry in the Secret represents one API Key. The key is an arbitrary identifier. | ||
| // The value is a string, representing the API Key. | ||
| // | ||
| // Example: | ||
| // | ||
| // apiVersion: v1 | ||
| // kind: Secret | ||
| // metadata: | ||
| // name: api-key | ||
| // stringData: | ||
| // client1: "k-123" | ||
| // client2: "k-456" | ||
| // | ||
| // +optional | ||
| SecretSelector *LabelSelector `json:"secretSelector,omitempty"` | ||
| } | ||
|
|
||
| // LabelSelector selects resources using label selectors. | ||
| type LabelSelector struct { | ||
| // Label selector to select the target resource. | ||
| // +required | ||
| MatchLabels map[string]string `json:"matchLabels"` | ||
| } | ||
|
|
||
| // +kubebuilder:validation:ExactlyOneOf=maxRequestSize;disable | ||
| type Buffer struct { | ||
| // MaxRequestSize sets the maximum size in bytes of a message body to buffer. | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.