-
Notifications
You must be signed in to change notification settings - Fork 141
Enhancement Proposal: Authentication Filter #4235
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
|
||
| ## 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". |
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.
| 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). |
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.
is JWT a plus feature only?
| const ( | ||
| AuthTypeBasic AuthType = "Basic" | ||
| AuthTypeJWT AuthType = "JWT" | ||
| ) |
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.
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. |
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.
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?
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.
Can we follow the ReferenceGrant pattern for accessing Secrets in another namespace?
| 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"` |
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.
directives should be specified for the cases that apply.
| Path string `json:"path"` | ||
|
|
||
| // Levels specifies the directory hierarchy for cached files. | ||
| // Example: "1:2". |
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.
like 1: is for most frequently used?
| type JWTTokenSource struct { | ||
| // Read token from Authorization header. Default: true. | ||
| // | ||
| // +optional |
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.
set defaults using kubebuilder: default
| const ( | ||
| // AuthenticationFilterConditionTypeAccepted indicates that the AuthenticationFilter is accepted. | ||
| // | ||
| // Possible reasons for this condition to be True: | ||
| // * Accepted | ||
| // | ||
| // Possible reasons for this condition to be False: | ||
| // * Invalid | ||
| AuthenticationFilterConditionTypeAccepted AuthenticationFilterConditionType = "Accepted" | ||
|
|
||
| // AuthenticationFilterConditionReasonAccepted is used with the Accepted condition type when | ||
| // the condition is true. | ||
| AuthenticationFilterConditionReasonAccepted AuthenticationFilterConditionReason = "Accepted" | ||
|
|
||
| // AuthenticationFilterConditionReasonInvalid is used with the Accepted condition type when | ||
| // the filter is invalid. | ||
| AuthenticationFilterConditionReasonInvalid AuthenticationFilterConditionReason = "Invalid" | ||
| ) |
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.
If we’re aiming to follow community guidelines, should we also add a condition for resolved refs? Since we usually have a Secret referenced for auth, we should probably tell the user when that reference was successfully resolved. I’m not sure if we currently do that for Secrets – I’ve only seen this done for backendRefs and inferencePools. Not certain what the right behavior is here, but I wanted to call it out.
| # 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'; | ||
| } | ||
| } |
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.
| # 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'; | |
| } | |
| } |
| ### 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. | ||
|
|
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.
did not see this as a rule at API level, we will allow this at API spec level?
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.
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.