Skip to content
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

HTTP basic auth support #2269

Merged
merged 7 commits into from
Jun 30, 2022
Merged

Conversation

svvac
Copy link
Contributor

@svvac svvac commented Dec 13, 2021

Proposed changes

Add support for HTTP Basic authentication to Policy objects and to Ingresses via annotations.

#200 #1872

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 master
  • I will ensure my PR is targeting the master branch and pulling from my branch from my own fork

@svvac
Copy link
Contributor Author

svvac commented Dec 13, 2021

First draft to get the discussion going regarding naming, etc.

Will add tests and docs.

@svvac svvac changed the title Http basic auth support HTTP basic auth support Dec 13, 2021
@codecov-commenter
Copy link

codecov-commenter commented Dec 13, 2021

Codecov Report

Merging #2269 (452190a) into main (22c1e90) will decrease coverage by 0.20%.
The diff coverage is 52.65%.

❗ Current head 452190a differs from pull request most recent head 6416a37. Consider uploading reports for the commit 6416a37 to get more accurate results

@@            Coverage Diff             @@
##             main    #2269      +/-   ##
==========================================
- Coverage   53.63%   53.43%   -0.21%     
==========================================
  Files          52       52              
  Lines       14842    14871      +29     
==========================================
- Hits         7961     7946      -15     
- Misses       6617     6657      +40     
- Partials      264      268       +4     
Impacted Files Coverage Δ
internal/configs/config_params.go 76.74% <ø> (ø)
internal/configs/version1/config.go 0.00% <ø> (ø)
internal/configs/version2/http.go 0.00% <ø> (ø)
internal/k8s/reference_checkers.go 84.00% <0.00%> (-4.03%) ⬇️
internal/k8s/validation.go 90.85% <0.00%> (-8.33%) ⬇️
internal/nginx/manager.go 0.00% <ø> (ø)
internal/configs/configurator.go 37.20% <16.66%> (-0.51%) ⬇️
pkg/apis/configuration/validation/policy.go 90.58% <36.00%> (-3.89%) ⬇️
internal/k8s/controller.go 11.30% <41.66%> (-0.07%) ⬇️
internal/configs/ingress.go 76.90% <82.75%> (+0.41%) ⬆️
... and 18 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@nginx-bot nginx-bot force-pushed the http-basic-auth-support branch 8 times, most recently from aef566b to b7b50f3 Compare December 16, 2021 14:25
Copy link
Contributor

@pleshakov pleshakov left a comment

Choose a reason for hiding this comment

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

Hi @svvac

Thanks for the pull request! This is a great addition to the Ingress Controller.

I left a few comments, questions and suggestions. As you mentioned, let's finalize the requirements first, this review doesn't include comments about missing tests, etc.

pkg/apis/configuration/validation/policy.go Show resolved Hide resolved
pkg/apis/configuration/validation/policy.go Outdated Show resolved Hide resolved
pkg/apis/configuration/v1/types.go Outdated Show resolved Hide resolved
@@ -28,6 +31,9 @@ const SecretTypeJWK api_v1.SecretType = "nginx.org/jwk"
// SecretTypeOIDC contains an OIDC client secret for use in oauth flows. #nosec G101
const SecretTypeOIDC api_v1.SecretType = "nginx.org/oidc"

// SecretTypeHtpasswd contains an htpasswd file for use in HTTP Basic authorization.. #nosec G101
const SecretTypeHtpasswd api_v1.SecretType = "nginx.org/htpasswd"
Copy link
Contributor

Choose a reason for hiding this comment

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

are we creating a new secret type nginx.org/htpasswd instead of using kubernetes.io/basic-auth standard type (https://kubernetes.io/docs/concepts/configuration/secret/#basic-authentication-secret), because that type is limited to one user/pass combination?

cc @brianehlert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's the idea. I considered using keys of the secret as usernames and their value as auth string, but this would add processing and the user wouldn't be able to use existing passwd databases with e.g. comments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My thought here is the experience of creating the htpasswd file and how that feels bespoke to a Kubernetes (yaml focused) operator.
I understand the choice though. The file is both native to NGINX configuration and not unusual in itself in the full context.
Documentation might help me here - walking through defining, generating, and using the htpasswd as part of the configuration.
We have tutorials or examples that could be used for that.

Copy link
Member

Choose a reason for hiding this comment

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

There's a gosec linting error, but it's a false positive. We need to skip the error similar to other places.

Suggested change
const SecretTypeHtpasswd api_v1.SecretType = "nginx.org/htpasswd"
const SecretTypeHtpasswd api_v1.SecretType = "nginx.org/htpasswd" // #nosec G101

internal/configs/annotations.go Show resolved Hide resolved
@svvac svvac force-pushed the http-basic-auth-support branch 2 times, most recently from ee70870 to 4d218b2 Compare December 17, 2021 10:19
@svvac
Copy link
Contributor Author

svvac commented Dec 17, 2021

I've made the requested changes and I'll start working on the tests.

@svvac svvac force-pushed the http-basic-auth-support branch 3 times, most recently from dede2c5 to d0442a5 Compare December 17, 2021 11:32
@nginx-bot nginx-bot force-pushed the http-basic-auth-support branch 8 times, most recently from 4a334bc to 932ae89 Compare December 22, 2021 23:05
Copy link
Member

@ciarams87 ciarams87 left a comment

Choose a reason for hiding this comment

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

Hi @svvac - apologies again for the delay. I'm pulling down your code here to run through the example myself, but this overall looks great! I've a couple of minor comments, and there are some merge conflicts that need to be addressed, but otherwise this is definitely nearly there!

Thank you so much for all the work so far, and for your patience.

@svvac
Copy link
Contributor Author

svvac commented Jun 20, 2022

@ciarams87 Good news then! I pushed a rebased version against main, including fixes regarding the issues you raised

Copy link
Member

@ciarams87 ciarams87 left a comment

Choose a reason for hiding this comment

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

🚀 LGTM!! Thanks again!!

@lucacome lucacome added this to the 2.3.0-k8s-ingress-controller milestone Jun 30, 2022
@lucacome lucacome merged commit f83076b into nginxinc:main Jun 30, 2022
@ciarams87 ciarams87 added enhancement Pull requests for new features/feature enhancements labels Jun 30, 2022
@hostalp
Copy link

hostalp commented Feb 23, 2023

Hello, could you consider changing the secet resource requirement so that it would be possible to use the same secret for both Kubernetes ingress controller as well as for this one?

Their secret looks like the following example: https://kubernetes.github.io/ingress-nginx/examples/auth/basic/#examine-secret
With the 2 most important differences being:

  • type: Opaque (this ingress controller requires type: nginx.org/htpasswd)
  • auth data being located in data.auth (this ingress controller requires them in data.htpasswd)

It would make things easier.

@brianehlert
Copy link
Collaborator

Hello, could you consider changing the secet resource requirement so that it would be possible to use the same secret for both Kubernetes ingress controller as well as for this one?

Their secret looks like the following example: https://kubernetes.github.io/ingress-nginx/examples/auth/basic/#examine-secret With the 2 most important differences being:

  • type: Opaque (this ingress controller requires type: nginx.org\htpasswd)
  • auth data being located in data.auth (this ingress controller requires them in data.htpasswd)

It would make things easier.

Since this PR was merged approximately 9 months ago. Would you consider adding this request to Issues as a proposal?

@hostalp
Copy link

hostalp commented Feb 23, 2023

Sure, I just didn't want to open a new issue not knowing if this proposal would be declined anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Pull requests for new features/feature enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants