@@ -111,8 +111,6 @@ type AuthenticationFilterList struct {
111111// +kubebuilder:validation:XValidation:message="when spec.jwt is set, type must be 'JWT'",rule="self.jwt != null ? self.type == 'JWT' : true"
112112type AuthenticationFilterSpec struct {
113113 // Type selects the authentication mechanism.
114- //
115- // +kubebuilder:validation:Enum=Basic;JWT
116114 Type AuthType ` json:"type"`
117115
118116 // Basic configures HTTP Basic Authentication.
@@ -127,6 +125,7 @@ type AuthenticationFilterSpec struct {
127125}
128126
129127// AuthType defines the authentication mechanism.
128+ // +kubebuilder:validation:Enum=Basic;JWT
130129type AuthType string
131130
132131const (
@@ -170,10 +169,7 @@ type JWTAuth struct {
170169 // Mode selects how JWT keys are provided: local file or remote JWKS.
171170 // Default: File.
172171 //
173- // +optional
174- // +kubebuilder:default=File
175- // +kubebuilder:validation:Enum=File;Remote
176- // +kubebuilder:validation:XValidation:message="mode must be one of [File, Remote]",rule="self in ['File','Remote']"
172+ // +kubebuilder:default=File"
177173 Mode JWTKeyMode ` json:"mode,omitempty"`
178174
179175 // File specifies local JWKS configuration (Secret or ConfigMap, mount path, file name).
@@ -203,7 +199,6 @@ type JWTAuth struct {
203199 //
204200 // +optional
205201 // +kubebuilder:default=signed
206- // +kubebuilder:validation:Enum=signed;encrypted;nested
207202 Type *JWTTokenType ` json:"type,omitempty"`
208203
209204 // KeyCache is the cache duration for keys.
@@ -240,7 +235,7 @@ type JWTAuth struct {
240235 Require *JWTRequiredClaims ` json:"require,omitempty"`
241236
242237 // TokenSource defines where the client presents the token.
243- // Defaults to Authorization header only .
238+ // Defaults to reading from Authorization header.
244239 //
245240 // +optional
246241 TokenSource *JWTTokenSource ` json:"tokenSource,omitempty"`
@@ -252,6 +247,7 @@ type JWTAuth struct {
252247}
253248
254249// JWTKeyMode selects where JWT keys come from.
250+ // +kubebuilder:validation:Enum=File;Remote
255251type JWTKeyMode string
256252
257253const (
@@ -262,28 +258,12 @@ const (
262258// JWTFileKeySource specifies local JWKS key configuration.
263259// +kubebuilder:validation:XValidation:message="exactly one of configMapRef or secretRef must be set",rule="(self.configMapRef == null) != (self.secretRef == null)"
264260type JWTFileKeySource struct {
265- // ConfigMapRef references a ConfigMap containing the JWKS.
266- // Exactly one of ConfigMapRef or SecretRef must be set.
267- //
268- // +optional
269- ConfigMapRef *NamespacedObjectReference ` json:"configMapRef,omitempty"`
270-
271261 // SecretRef references a Secret containing the JWKS (with optional key).
272262 // Exactly one of ConfigMapRef or SecretRef must be set.
273263 //
274264 // +optional
275265 SecretRef *NamespacedSecretKeyReference ` json:"secretRef,omitempty"`
276266
277- // MountPath is the path where NGF will mount the data into the NGINX container.
278- // Used in `auth_jwt_key_file` directive.
279- // Example: "/etc/nginx/keys".
280- MountPath string ` json:"mountPath"`
281-
282- // FileName is the file name of the JWKS within the mount path.
283- // Used in `auth_jwt_key_file` directive.
284- // Example: "jwks.json".
285- FileName string ` json:"fileName"`
286-
287267 // KeyCache is the cache duration for keys.
288268 // Configures `auth_jwt_key_cache` directive
289269 // Example: "auth_jwt_key_cache 10m;".
@@ -345,6 +325,7 @@ type JWKSCache struct {
345325}
346326
347327// JWTTokenType represents NGINX auth_jwt_type.
328+ // +kubebuilder:validation:Enum=signed;encrypted;nested
348329type JWTTokenType string
349330
350331const (
@@ -366,39 +347,34 @@ type JWTRequiredClaims struct {
366347 Aud *string ` json:"aud,omitempty"`
367348}
368349
369- // JWTTokenSource specifies where tokens may be read from.
370- type JWTTokenSource struct {
371- // Read token from Authorization header. Default: true.
372- //
373- // +optional
374- // +kubebuilder:default=true
375- Header *bool ` json:"header,omitempty"`
350+ // JWTTokenSourceMode selects where the JWT token is read from.
351+ type JWTTokenSourceMode string
376352
377- // Read token from a cookie. Default: false.
378- //
379- // +optional
380- // +kubebuilder:default=false
381- Cookie *bool ` json:"cookie,omitempty"`
382-
383- // CookieName when Cookie is true. Example: "access_token".
384- //
385- // +optional
386- // +kubebuilder:default=access_token
387- CookieName *string ` json:"cookieName,omitempty"`
353+ const (
354+ // Read from Authorization header (Bearer). Default.
355+ JWTTokenSourceModeHeader JWTTokenSourceMode = " Header"
356+ // Read from a cookie named tokenName.
357+ JWTTokenSourceModeCookie JWTTokenSourceMode = " Cookie"
358+ // Read from a query arg named tokenName.
359+ JWTTokenSourceModeQueryArg JWTTokenSourceMode = " QueryArg"
360+ )
388361
389- // Read token from query string. Default: false.
390- //
391- // +optional
392- // +kubebuilder:default=false
393- Query *bool ` json:"query,omitempty"`
362+ // JWTTokenSource specifies where tokens may be read from and the name when required.
363+ type JWTTokenSource struct {
364+ // Mode selects the token source.
365+ // +kubebuilder:validation:Enum=Header;Cookie;QueryArg
366+ // +kubebuilder:default=Header
367+ Type JWTTokenSourceMode ` json:"mode"`
394368
395- // QueryParam when Query is true. Example: "access_token".
369+ // TokenName is the cookie or query parameter name when Mode=Cookie or Mode=QueryArg.
370+ // Ignored when Mode=Header.
396371 //
397372 // +optional
398- // +kubebuilder:default=access_token
399- QueryParam * string ` json:"queryParam ,omitempty"`
373+ // +kubebuilder:default=access_token
374+ TokenName string ` json:"tokenName ,omitempty"`
400375}
401376
377+
402378// JWTPropagation controls identity header propagation and header stripping.
403379type JWTPropagation struct {
404380 // AddIdentityHeaders defines headers to add on success with values
@@ -420,6 +396,7 @@ type HeaderValue struct {
420396}
421397
422398// AuthScheme enumerates supported WWW-Authenticate schemes.
399+ // +kubebuilder:validation:Enum=Basic;Bearer
423400type AuthScheme string
424401
425402const (
@@ -428,6 +405,7 @@ const (
428405)
429406
430407// AuthFailureBodyPolicy controls the failure response body behavior.
408+ // +kubebuilder:validation:Enum=Unauthorized;Forbidden;Empty
431409type AuthFailureBodyPolicy string
432410
433411const (
@@ -451,26 +429,16 @@ type AuthFailureResponse struct {
451429 //
452430 // +optional
453431 // +kubebuilder:default=Basic
454- // +kubebuilder:validation:Enum=Basic;Bearer
455432 Scheme *AuthScheme ` json:"scheme,omitempty"`
456433
457434 // Controls whether a default canned body is sent or an empty body.
458435 // Default: Unauthorized.
459436 //
460437 // +optional
461438 // +kubebuilder:default=Unauthorized
462- // +kubebuilder:validation:Enum=Unauthorized;Forbidden;Empty
463439 BodyPolicy *AuthFailureBodyPolicy ` json:"bodyPolicy,omitempty"`
464440}
465441
466- // NamespacedObjectReference references an object by name with an optional namespace.
467- // If namespace is omitted, it defaults to the AuthenticationFilter's namespace.
468- type NamespacedObjectReference struct {
469- // +optional
470- Namespace *string ` json:"namespace,omitempty"`
471- Name string ` json:"name"`
472- }
473-
474442// NamespacedSecretKeyReference references a Secret and optional key, with an optional namespace.
475443// If namespace differs from the filter's, a ReferenceGrant in the target namespace is required.
476444type NamespacedSecretKeyReference struct {
@@ -647,14 +615,9 @@ spec:
647615 # Key verification mode: Local file or Remote JWKs
648616 mode : File # Defaults to File.
649617 file :
650- # In File mode, exactly one of configMapRef or secretRef must be defined.
651- configMapRef :
652- name : jwt-keys
653618 secretRef :
654619 name : jwt-keys-secure
655620 key : jwks.json
656- mountPath : /etc/nginx/keys
657- fileName : jwks.json
658621 keyCache : 10m # Optional cache time for keys (auth_jwt_key_cache)
659622 # Acceptable clock skew for exp/nbf
660623 leeway : 60s # Configures auth_jwt_leeway
@@ -942,13 +905,16 @@ spec:
942905 - "api"
943906 - "cli"
944907
945- # Where client presents the token (defaults to Authorization header)
908+ # Where client presents the token
909+ # By defaults to reading from Authorization header (Bearer)
946910 tokenSource:
947- header: true
948- cookie: false
949- cookieName: access_token
950- query: false
951- queryParam: access_token
911+ type: Header
912+ # Alternative: read from a cookie named tokenName
913+ # type: Cookie
914+ # tokenName: access_token
915+ # Alternative: read from a query arg named tokenName
916+ # type: QueryArg
917+ # tokenName: access_token
952918
953919 # Identity propagation to backend and header stripping
954920 propagation:
@@ -1058,9 +1024,6 @@ Users that attach an `AuthenticaitonFilter` to a HTTPRoute/GRPCRoute should be a
10581024
10591025Any exmaple configurations and deployments for the `AuthenticationFilter` should enable HTTPS at the Gateway level by default.
10601026
1061- The `mountPath` for local JWKS should be mounted to a fixed location (e.g. /etc/nginx/keys).
1062- The `fileName` for a local JWKS should be sanatized to a pattern of [A-Za-z0-9._-].
1063-
10641027# ## Namespace isolataion and cross-namespace references
10651028Both Auth and Local JWKS should only have access to Secrets and ConfigMaps in the same namespace by default.
10661029
@@ -1141,8 +1104,6 @@ spec:
11411104 configMapRef:
11421105 namespace: keys-ns
11431106 name: jwt-keys
1144- mountPath: /etc/nginx/keys
1145- fileName: jwks.json
11461107` ` `
11471108
11481109# ## Remote JWKS
0 commit comments