-
Notifications
You must be signed in to change notification settings - Fork 148
Generate CRD for AuthenticationFilter with BasicAuth #4349
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: feat/authentication-filter-basic-auth
Are you sure you want to change the base?
Generate CRD for AuthenticationFilter with BasicAuth #4349
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feat/authentication-filter-basic-auth #4349 +/- ##
========================================================================
Coverage ? 86.11%
========================================================================
Files ? 132
Lines ? 14343
Branches ? 35
========================================================================
Hits ? 12351
Misses ? 1787
Partials ? 205 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
the target should be |
|
The linter seemed to have problems with the comments the AuthenticationFilterSpec and BasicAuth structs: a127e6b |
@shaun-nx I think I wrote about this on another PR, but the linter (fieldalignment) does not have a problem with comments. The linter automatically reorganizes fields within a struct to optimize it for the compiler. There is a bug that causes comments to be removed when it does this, so you have to manually add the comments back in. |
Thanks Saylor. We managed to fix it too. @tataruty pointed out the same thing. Will probably be one of those things that I need to see a few times before I remember haha. |
|
|
||
| const ( | ||
| AuthSchemeBasic AuthScheme = "Basic" | ||
| AuthSchemeBearer AuthScheme = "Bearer" |
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.
should we mention in comment that bearer is for JWT auth?
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.
Good catch! Since we're just implementing Basic Auth now, I'll remove Bearer as an option.
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.
Following a response to a comment in my RL doc, we typically have our fields as pointers. What makes a field optional is the // +optional tag for kubebuilder not if it is a pointer or not.
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.
From what I remember, we only use pointers on our Optional fields.
Are you saying all fields should be pointers?
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.
hmm, as i checked the other apis we have, it seems like i was mistaken, yea we only use pointers on our optional fields, so you can disregard my comment
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.
You have a lot of fields defined here that should be optional but aren't.
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.
Scratch my last comment, I misread. However, BasicAuth in the top level spec should be 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.
Thanks for calling that one out. I had planned on having it as a required field and making it optional only after JWT auth was added as well, but that might break the API. I'll update that to be optional
sjberman
left a comment
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.
See #4266 for an example of API structure and other things that should be implemented as part of this.
| // | ||
| // +optional | ||
| // +kubebuilder:default=401 | ||
| // +kubebuilder:validation:XValidation:message="statusCode must be 401 or 403",rule="self in [401, 403]" |
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.
You don't need CEL for this, you can use an enum.
// +kubebuilder:validation:Enum=401;403
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.
Ah, that's a good point. I'll change that.
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.
Please ensure that all fields have comments associated with them that describe what the field is.
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.
When through them all. From what I can see they should all have descriptive comments.
Some of the type fields were missing the same comment separation as well so I added them were I saw they were missing here
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.
constants should have comments as well
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.
Should be updated now.
| // AuthFailureBodyPolicy controls the failure response body behavior. | ||
| // +kubebuilder:validation:Enum=Unauthorized;Forbidden;Empty |
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.
| // AuthFailureBodyPolicy controls the failure response body behavior. | |
| // +kubebuilder:validation:Enum=Unauthorized;Forbidden;Empty | |
| // AuthFailureBodyPolicy controls the failure response body behavior. | |
| // | |
| // +kubebuilder:validation:Enum=Unauthorized;Forbidden;Empty |
We like the separation between descriptive and functional comments. Be sure to apply to all other fields in the same way.
| // AuthFailureResponse customizes 401/403 failures. | ||
| // | ||
|
|
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.
comment malformed
| // Status defines the state of the AuthenticationFilter, following the same | ||
| // pattern as SnippetsFilter: per-controller conditions with an Accepted condition. | ||
| // | ||
| // +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.
| // Status defines the state of the AuthenticationFilter, following the same | |
| // pattern as SnippetsFilter: per-controller conditions with an Accepted condition. | |
| // | |
| // +optional | |
| // Status defines the state of the AuthenticationFilter. |
No need to reference another filter in here, can just keep this isolated. It also shouldn't be marked as optional.
| } | ||
|
|
||
| // AuthenticationFilterSpec defines the desired configuration. | ||
| // +kubebuilder:validation:XValidation:message="for type=Basic, spec.basic must be set",rule="self.type == 'Basic' ? self.basic != null : true" |
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.
Since Basic is optional, no need for this validation.
| // Basic configures HTTP Basic Authentication. | ||
| // | ||
| // +optional | ||
| Basic *BasicAuth `json:"basic"` |
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.
| Basic *BasicAuth `json:"basic"` | |
| Basic *BasicAuth `json:"basic,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.
Unless this isn't needed due to being a nested struct?
|
|
||
| // BasicAuth configures HTTP Basic Authentication. | ||
| type BasicAuth struct { | ||
| // OnFailure customizes the 401 response for failed authentication. |
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.
| // OnFailure customizes the 401 response for failed authentication. | |
| // OnFailure customizes the response for failed authentication. |
| type AuthScheme string | ||
|
|
||
| const ( | ||
| AuthSchemeBasic AuthScheme = "Basic" // For Basic Auth. |
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.
Comment should be above the field and follow the usual format.
| AuthFailureBodyPolicyEmpty AuthFailureBodyPolicy = "Empty" | ||
| ) | ||
|
|
||
| // AuthFailureResponse customizes 401/403 failures. |
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.
| // AuthFailureResponse customizes 401/403 failures. | |
| // AuthFailureResponse customizes auth response failures. |
| // Allowed: 401, 403. | ||
| // Default: 401. |
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.
Need a more descriptive comment on what the StatusCode field actually is.
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 the 401 default provided by nginx? If not, then we'll need to set the default with the kubebuilder tag in the spec.
| // Configures WWW-Authenticate header in error page location. | ||
| // | ||
| // +optional | ||
| // +kubebuilder:default=Basic |
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 infer from the filter type, then we don't need to set a default in here. Otherwise, it's impossible to omit.
| // Default: Unauthorized. | ||
| // | ||
| // +optional | ||
| // +kubebuilder:default=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.
Is this an nginx default or our own default?
Proposed changes
This change adds a new GoLang API type to
apis/v1alpha1for theAuthenticationFilterThis change only adds the types required for Basic Auth to work, and does not include types specific to JWT Auth. These will be added in future work.
Closes #4309
Example manifest for basic auth
Example output from
kubectl describe authenticationfilters.gateway.nginx.org basic-authValidation
Performed manual checks on x-Kubernetes-Validations for CRD:
for type=Basic, spec.basic must be setFile used:
Result:
when spec.basic is set, type must be 'Basic'Files used:
typeis not definedtypeis set toBlahResults:
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.