@@ -74,14 +74,14 @@ This portion also contains:
7474
7575### Golang API
7676
77- Below is the Golang API for the ` AuthenticationFilter ` API:
77+ Below is the Golang API for the ` AuthenticationFilter ` API.
78+ This is currently designed for Basic Auth.
7879
7980``` go
8081package v1alpha1
8182
8283import (
8384 metav1 " k8s.io/apimachinery/pkg/apis/meta/v1"
84- " github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
8585)
8686
8787// +genclient
@@ -91,278 +91,76 @@ import (
9191// +kubebuilder:resource:categories=nginx-gateway-fabric,shortName=authfilter;authenticationfilter
9292// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
9393
94- // AuthenticationFilter configures request authentication (Basic or JWT) and is
95- // referenced by HTTPRoute filters via ExtensionRef.
94+ // AuthenticationFilter configures request authentication and is
95+ // referenced by HTTPRoute and GRPCRoute filters using ExtensionRef.
9696type AuthenticationFilter struct {
97- metav1.TypeMeta ` json:",inline"`
98- metav1.ObjectMeta ` json:"metadata,omitempty "`
97+ metav1.TypeMeta ` json:",inline"`
98+ metav1.ObjectMeta ` json:"metadata"`
9999
100- // Spec defines the desired state of the AuthenticationFilter.
101- Spec AuthenticationFilterSpec ` json:"spec"`
100+ // Spec defines the desired state of the AuthenticationFilter.
101+ Spec AuthenticationFilterSpec ` json:"spec"`
102102
103- // Status defines the state of the AuthenticationFilter, following the same
104- // pattern as SnippetsFilter: per-controller conditions with an Accepted condition.
105- //
106- // +optional
107- Status AuthenticationFilterStatus ` json:"status,omitempty"`
103+ // Status defines the state of the AuthenticationFilter.
104+ Status AuthenticationFilterStatus ` json:"status,omitempty"`
108105}
109106
110107// +kubebuilder:object:root=true
111108
112109// AuthenticationFilterList contains a list of AuthenticationFilter resources.
113110type AuthenticationFilterList struct {
114111 metav1.TypeMeta ` json:",inline"`
115- metav1.ListMeta ` json:"metadata,omitempty "`
112+ metav1.ListMeta ` json:"metadata"`
116113 Items []AuthenticationFilter ` json:"items"`
117114}
118115
119116// AuthenticationFilterSpec defines the desired configuration.
120- // Exactly one of Basic or JWT must be set according to Type.
121- // +kubebuilder:validation:XValidation:message="for type=Basic, spec.basic must be set and spec.jwt must be empty; for type=JWT, spec.jwt must be set and spec.basic must be empty",rule="self.type == 'Basic' ? self.basic != null && self.jwt == null : self.type == 'JWT' ? self.jwt != null && self.basic == null : false"
122- // +kubebuilder:validation:XValidation:message="type 'Basic' requires spec.basic to be set. All other spec types must be unset",rule="self.type == 'Basic' ? self.type != null && self.jwt == null : true"
123- // +kubebuilder:validation:XValidation:message="type 'JWT' requires spec.jwt to be set. All other spec types must be unset",rule="self.type == 'JWT' ? self.type != null && self.basic == null : true"
124- // +kubebuilder:validation:XValidation:message="when spec.basic is set, type must be 'Basic'",rule="self.basic != null ? self.type == 'Basic' : true"
125- // +kubebuilder:validation:XValidation:message="when spec.jwt is set, type must be 'JWT'",rule="self.jwt != null ? self.type == 'JWT' : true"
117+ // +kubebuilder:validation:XValidation:message="for type=Basic, spec.basic must be set",rule="!(!has(self.basic) && self.type == 'Basic')"
118+ //
119+ // nolint:lll
126120type AuthenticationFilterSpec struct {
127- // Type selects the authentication mechanism.
128- Type AuthType ` json:"type"`
129-
130- // Basic configures HTTP Basic Authentication.
131- // Required when Type == Basic.
132- //
133- // +optional
134- Basic *BasicAuth ` json:"basic,omitempty"`
121+ // Basic configures HTTP Basic Authentication.
122+ //
123+ // +optional
124+ Basic *BasicAuth ` json:"basic,omitempty"`
135125
136- // JWT configures JSON Web Token authentication (NGINX Plus).
137- // Required when Type == JWT.
138- //
139- // +optional
140- JWT *JWTAuth ` json:"jwt,omitempty"`
126+ // Type selects the authentication mechanism.
127+ Type AuthType ` json:"type"`
141128}
142129
143130// AuthType defines the authentication mechanism.
144- // +kubebuilder:validation:Enum=Basic;JWT
131+ //
132+ // +kubebuilder:validation:Enum=Basic;
145133type AuthType string
146134
147135const (
148- AuthTypeBasic AuthType = " Basic"
149- AuthTypeJWT AuthType = " JWT "
136+ // AuthTypeBasic is the HTTP Basic Authentication mechanism.
137+ AuthTypeBasic AuthType = " Basic "
150138)
151139
152140// BasicAuth configures HTTP Basic Authentication.
153141type BasicAuth struct {
154- // SecretRef allows referencing a Secret in the same namespace
155- SecretRef LocalObjectReference ` json:"secretRef"`
156-
157- // Realm used by NGINX `auth_basic` directive.
158- // https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html#auth_basic
159- // Also configures "realm="<realm_value>" in WWW-Authenticate header in error page location.
160- Realm string ` json:"realm"`
161-
162- // OnFailure customizes the 401 response for failed authentication.
163- //
164- // +optional
165- OnFailure *AuthFailureResponse ` json:"onFailure,omitempty"`
166- }
167-
168- // JWTKeyMode selects where JWT keys come from.
169- // +kubebuilder:validation:Enum=File;Remote
170- type JWTKeyMode string
171-
172- const (
173- JWTKeyModeFile JWTKeyMode = " File"
174- JWTKeyModeRemote JWTKeyMode = " Remote"
175- )
176-
177- // JWTAuth configures JWT-based authentication (NGINX Plus).
178- // +kubebuilder:validation:XValidation:message="mode 'File' requires file set and remote unset",rule="self.mode == 'File' ? self.file != null && self.remote == null : true"
179- // +kubebuilder:validation:XValidation:message="mode 'Remote' requires remote set and file unset",rule="self.mode == 'Remote' ? self.remote != null && self.file == null : true"
180- // +kubebuilder:validation:XValidation:message="when file is set, mode must be 'File'",rule="self.file != null ? self.mode == 'File' : true"
181- // +kubebuilder:validation:XValidation:message="when remote is set, mode must be 'Remote'",rule="self.remote != null ? self.mode == 'Remote' : true"
182- type JWTAuth struct {
183- // Realm used by NGINX `auth_jwt` directive
184- // https://nginx.org/en/docs/http/ngx_http_auth_jwt_module.html#auth_jwt
185- // Configures "realm="<realm_value>" in WWW-Authenticate header in error page location.
186- Realm string ` json:"realm"`
187-
188- // Mode selects how JWT keys are provided: local file or remote JWKS.
189- Mode JWTKeyMode ` json:"mode"`
190-
191- // File specifies local JWKS configuration.
192- // Required when Mode == File.
193- //
194- // +optional
195- File *JWTFileKeySource ` json:"file,omitempty"`
196-
197- // Remote specifies remote JWKS configuration.
198- // Required when Mode == Remote.
199- //
200- // +optional
201- Remote *RemoteKeySource ` json:"remote,omitempty"`
202-
203- // Leeway is the acceptable clock skew for exp/nbf checks.
204- // Configures `auth_jwt_leeway` directive.
205- // https://nginx.org/en/docs/http/ngx_http_auth_jwt_module.html#auth_jwt_leeway
206- // Example: "auth_jwt_leeway 60s".
207- //
208- // +optional
209- Leeway *v1alpha1.Duration ` json:"leeway,omitempty"`
210-
211- // Type sets token type: signed | encrypted | nested.
212- // Default: signed.
213- // Configures `auth_jwt_type` directive.
214- // https://nginx.org/en/docs/http/ngx_http_auth_jwt_module.html#auth_jwt_type
215- // Example: "auth_jwt_type signed;".
216- //
217- // +optional
218- // +kubebuilder:default=signed
219- Type *JWTType ` json:"type,omitempty"`
220-
221- // KeyCache is the cache duration for keys.
222- // Configures auth_jwt_key_cache directive.
223- // https://nginx.org/en/docs/http/ngx_http_auth_jwt_module.html#auth_jwt_key_cache
224- // Example: "auth_jwt_key_cache 10m".
225- //
226- // +optional
227- KeyCache *v1alpha1.Duration ` json:"keyCache,omitempty"`
142+ // SecretRef allows referencing a Secret in the same namespace.
143+ SecretRef LocalObjectReference ` json:"secretRef"`
228144
229- // OnFailure customizes the 401 response for failed authentication.
230- //
231- // +optional
232- OnFailure *AuthFailureResponse ` json:"onFailure,omitempty"`
233- }
234-
235- // JWTFileKeySource specifies local JWKS key configuration.
236- type JWTFileKeySource struct {
237- // SecretRef references a Secret containing the JWKS.
238- SecretRef LocalObjectReference ` json:"secretRef"`
239-
240- // KeyCache is the cache duration for keys.
241- // Configures `auth_jwt_key_cache` directive.
242- // https://nginx.org/en/docs/http/ngx_http_auth_jwt_module.html#auth_jwt_key_cache
243- // Example: "auth_jwt_key_cache 10m;".
244- //
245- // +optional
246- KeyCache *v1alpha1.Duration ` json:"keyCache,omitempty"`
145+ // Realm used by NGINX `auth_basic` directive.
146+ // https://nginx.org/en/docs/http/ngx_http_auth_basic_module.html#auth_basic
147+ // Also configures "realm="<realm_value>" in WWW-Authenticate header in error page location.
148+ Realm string ` json:"realm"`
247149}
248150
249- // LocalObjectReference specifies a local Kubernetes object
250- // with a required `key` field to extract data.
151+ // LocalObjectReference specifies a local Kubernetes object.
251152type LocalObjectReference struct {
252- Name string : ` json:"name"`
253- }
254-
255-
256- // RemoteKeySource specifies remote JWKS configuration.
257- type RemoteKeySource struct {
258- // URL is the JWKS endpoint, e.g. "https://issuer.example.com/.well-known/jwks.json".
259- URL string ` json:"url"`
260-
261- // Cache configures NGINX proxy_cache for JWKS fetches made via auth_jwt_key_request.
262- // When set, NGF will render proxy_cache_path in http{} and attach proxy_cache to the internal JWKS location.
263- //
264- // +optional
265- Cache *JWKSCache ` json:"cache,omitempty"`
266- }
267-
268- // JWKSCache controls NGINX `proxy_cache_path` and `proxy_cache` settings used for JWKS responses.
269- type JWKSCache struct {
270- // Levels specifies the directory hierarchy for cached files.
271- // Used in `proxy_cache_path` directive.
272- // https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path
273- // Example: "levels=1:2".
274- //
275- // +optional
276- Levels *string ` json:"levels,omitempty"`
277-
278- // KeysZoneName is the name of the cache keys zone.
279- // If omitted, the controller SHOULD derive a unique, stable name per filter instance.
280- //
281- // +optional
282- KeysZoneName *string ` json:"keysZoneName,omitempty"`
283-
284- // KeysZoneSize is the size of the cache keys zone (e.g. "10m").
285- // This is required to avoid unbounded allocations.
286- KeysZoneSize string ` json:"keysZoneSize"`
287-
288- // MaxSize limits the total size of the cache (e.g. "50m").
289- //
290- // +optional
291- MaxSize *string ` json:"maxSize,omitempty"`
292-
293- // Inactive defines the inactivity timeout before cached items are evicted (e.g. "10m").
294- //
295- // +optional
296- Inactive *string ` json:"inactive,omitempty"`
297-
298- // UseTempPath controls whether a temporary file is used for cache writes.
299- // Maps to use_temp_path=(on|off). Default: false (off).
300- //
301- // +optional
302- UseTempPath *bool ` json:"useTempPath,omitempty"`
303- }
304-
305- // JWTType represents NGINX auth_jwt_type.
306- // +kubebuilder:validation:Enum=signed;encrypted;nested
307- type JWTType string
308-
309- const (
310- JWTTypeSigned JWTType = " signed"
311- JWTTypeEncrypted JWTType = " encrypted"
312- JWTTypeNested JWTType = " nested"
313- )
314-
315- // AuthScheme enumerates supported WWW-Authenticate schemes.
316- // +kubebuilder:validation:Enum=Basic;Bearer
317- type AuthScheme string
318-
319- const (
320- AuthSchemeBasic AuthScheme = " Basic"
321- AuthSchemeBearer AuthScheme = " Bearer"
322- )
323-
324- // AuthFailureBodyPolicy controls the failure response body behavior.
325- // +kubebuilder:validation:Enum=Unauthorized;Forbidden;Empty
326- type AuthFailureBodyPolicy string
327-
328- const (
329- AuthFailureBodyPolicyUnauthorized AuthFailureBodyPolicy = " Unauthorized"
330- AuthFailureBodyPolicyForbidden AuthFailureBodyPolicy = " Forbidden"
331- AuthFailureBodyPolicyEmpty AuthFailureBodyPolicy = " Empty"
332- )
333-
334- // AuthFailureResponse customizes 401/403 failures.
335- type AuthFailureResponse struct {
336- // Allowed: 401, 403.
337- // Default: 401.
338- //
339- // +optional
340- // +kubebuilder:default=401
341- // +kubebuilder:validation:XValidation:message="statusCode must be 401 or 403",rule="self == null || self in [401, 403]"
342- StatusCode *int32 ` json:"statusCode,omitempty"`
343-
344- // Challenge scheme. If omitted, inferred from filter Type (Basic|Bearer).
345- // Configures WWW-Authenticate header in error page location.
346- //
347- // +optional
348- // +kubebuilder:default=Basic
349- Scheme *AuthScheme ` json:"scheme,omitempty"`
350-
351- // Controls whether a default canned body is sent or an empty body.
352- // Default: Unauthorized.
353- //
354- // +optional
355- // +kubebuilder:default=Unauthorized
356- BodyPolicy *AuthFailureBodyPolicy ` json:"bodyPolicy,omitempty"`
153+ // Name is the referenced object.
154+ Name string ` json:"name"`
357155}
358156
359157// AuthenticationFilterStatus defines the state of AuthenticationFilter.
360158type AuthenticationFilterStatus struct {
361- // Controllers is a list of Gateway API controllers that processed the AuthenticationFilter
362- // and the status of the AuthenticationFilter with respect to each controller.
363- //
364- // +kubebuilder:validation:MaxItems=16
365- Controllers []ControllerStatus ` json:"controllers,omitempty"`
159+ // Controllers is a list of Gateway API controllers that processed the AuthenticationFilter
160+ // and the status of the AuthenticationFilter with respect to each controller.
161+ //
162+ // +kubebuilder:validation:MaxItems=16
163+ Controllers []ControllerStatus ` json:"controllers,omitempty"`
366164}
367165
368166// AuthenticationFilterConditionType is a type of condition associated with AuthenticationFilter.
@@ -372,22 +170,22 @@ type AuthenticationFilterConditionType string
372170type AuthenticationFilterConditionReason string
373171
374172const (
375- // AuthenticationFilterConditionTypeAccepted indicates that the AuthenticationFilter is accepted.
376- //
377- // Possible reasons for this condition to be True:
378- // * Accepted
379- //
380- // Possible reasons for this condition to be False:
381- // * Invalid
382- AuthenticationFilterConditionTypeAccepted AuthenticationFilterConditionType = " Accepted"
383-
384- // AuthenticationFilterConditionReasonAccepted is used with the Accepted condition type when
385- // the condition is true.
386- AuthenticationFilterConditionReasonAccepted AuthenticationFilterConditionReason = " Accepted"
387-
388- // AuthenticationFilterConditionReasonInvalid is used with the Accepted condition type when
389- // the filter is invalid.
390- AuthenticationFilterConditionReasonInvalid AuthenticationFilterConditionReason = " Invalid"
173+ // AuthenticationFilterConditionTypeAccepted indicates that the AuthenticationFilter is accepted.
174+ //
175+ // Possible reasons for this condition to be True:
176+ // * Accepted
177+ //
178+ // Possible reasons for this condition to be False:
179+ // * Invalid.
180+ AuthenticationFilterConditionTypeAccepted AuthenticationFilterConditionType = " Accepted"
181+
182+ // AuthenticationFilterConditionReasonAccepted is used with the Accepted condition type when
183+ // the condition is true.
184+ AuthenticationFilterConditionReasonAccepted AuthenticationFilterConditionReason = " Accepted"
185+
186+ // AuthenticationFilterConditionReasonInvalid is used with the Accepted condition type when
187+ // the filter is invalid.
188+ AuthenticationFilterConditionReasonInvalid AuthenticationFilterConditionReason = " Invalid"
391189)
392190```
393191
0 commit comments