Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@shaun-nx
Copy link
Contributor

@shaun-nx shaun-nx commented Nov 6, 2025

Proposed changes

Status set to Implementable after merging #4136

This document proposes a solution for enabling Authentication use cases through NGINX Gateway Fabric.

Closes #4052

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

NONE

@shaun-nx shaun-nx requested review from a team as code owners November 6, 2025 18:19
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Nov 6, 2025
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.10%. Comparing base (a2e2ec1) to head (c937366).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4235      +/-   ##
==========================================
+ Coverage   86.08%   86.10%   +0.01%     
==========================================
  Files         131      131              
  Lines       14162    14162              
  Branches       35       35              
==========================================
+ Hits        12192    12194       +2     
+ Misses       1766     1765       -1     
+ Partials      204      203       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


## Introduction

This document focus expliclty on Authentiaction (AuthN) and not Authorization (AuthZ). Authentiaction (AuthN) defines the verification of identiy. It asks the question, "Who are you?". This is different from Authorization (AuthZ), which preceeds Authentication. It asks the question, "What are you allowed to do".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This document focus expliclty on Authentiaction (AuthN) and not Authorization (AuthZ). Authentiaction (AuthN) defines the verification of identiy. It asks the question, "Who are you?". This is different from Authorization (AuthZ), which preceeds Authentication. It asks the question, "What are you allowed to do".
This document focuses expliclty on Authentication (AuthN) and not Authorization (AuthZ). Authentication (AuthN) defines the verification of identiy. It asks the question, "Who are you?". This is different from Authorization (AuthZ), which preceeds Authentication. It asks the question, "What are you allowed to do".

// +optional
Basic *BasicAuth `json:"basic,omitempty"`

// JWT configures JSON Web Token authentication (NGINX Plus).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is JWT a plus feature only?

Comment on lines +125 to +128
const (
AuthTypeBasic AuthType = "Basic"
AuthTypeJWT AuthType = "JWT"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should specify the nginx modules these constants associate with

// BasicAuth configures HTTP Basic Authentication.
type BasicAuth struct {
// Secret is the name of the Secret containing htpasswd data.
// The Secret must be in the same namespace as this filter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it have to be in the same namespace? we can always resolve the secret in different namespace, unless there is another limitation assumed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we follow the ReferenceGrant pattern for accessing Secrets in another namespace?

Comment on lines +134 to +150
Secret string `json:"secret"`

// Key is the key within the Secret that contains the htpasswd data.
// Default: "htpasswd".
//
// +optional
Key *string `json:"key,omitempty"`

// Realm used by NGINX auth_basic; helps with logging and WWW-Authenticate.
//
// +optional
Realm *string `json:"realm,omitempty"`

// OnFailure customizes the 401 response for failed authentication.
//
// +optional
OnFailure *AuthFailureResponse `json:"onFailure,omitempty"`
Copy link
Contributor

@salonichf5 salonichf5 Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nginx directives should be specified for the cases that apply.

// Default: File.
//
// +optional
// +kubebuilder:validation:Enum=File;Remote
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as below for specifying defaults and enum

Path string `json:"path"`

// Levels specifies the directory hierarchy for cached files.
// Example: "1:2".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like 1: is for most frequently used?

type JWTTokenSource struct {
// Read token from Authorization header. Default: true.
//
// +optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set defaults using kubebuilder: default

Comment on lines +563 to +572
# Internal location for custom 401 response
location @basic_auth_failure {
add_header WWW-Authenticate 'Basic realm="Restricted"' always;
add_header Content-Type "text/plain; charset=utf-8" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Cache-Control "no-store" always;
add_header Pragma "no-cache" always;
return 401 'Unauthorized';
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Internal location for custom 401 response
location @basic_auth_failure {
add_header WWW-Authenticate 'Basic realm="Restricted"' always;
add_header Content-Type "text/plain; charset=utf-8" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Cache-Control "no-store" always;
add_header Pragma "no-cache" always;
return 401 'Unauthorized';
}
}
# Internal location for custom 401 response
location @basic_auth_failure {
internal;
add_header WWW-Authenticate 'Basic realm="Restricted"' always;
add_header Content-Type "text/plain; charset=utf-8" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Cache-Control "no-store" always;
add_header Pragma "no-cache" always;
return 401 'Unauthorized';
}
}

Comment on lines +1021 to +1026
### Auth failure behaviour

3xx response codes should not be allowed and AuthenticationFilter.onFailure must not support redirect targets. This is to prevent to prevent open-redirect abuse.

401 and 403 should be the only allowable auth failure codes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not see this as a rule at API level, we will allow this at API spec level?

@github-project-automation github-project-automation bot moved this from 🆕 New to 🏗 In Progress in NGINX Gateway Fabric Nov 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

Status: 🏗 In Progress

Development

Successfully merging this pull request may close these issues.

Design for Authentication Filter

4 participants