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

basic_auth: add WWW-Authenticate header for 401 response #34214

Merged
merged 7 commits into from
May 29, 2024

Conversation

sdwbgn
Copy link
Contributor

@sdwbgn sdwbgn commented May 16, 2024

Commit Message: Adds valid WWW-Authenticate header for 401 response in Basic Auth filter
Additional Description:
Risk Level: Low
Testing: unit test, integration
Docs Changes: N/A
Release Notes: Set WWW-Authenticate header for 401 responses from the Basic Auth filter.
Platform Specific Features: N/A
Fixes #34015

Copy link

Hi @sdwbgn, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #34214 was opened by sdwbgn.

see: more, trace.

Copy link

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #34214 was opened by sdwbgn.

see: more, trace.

@sdwbgn
Copy link
Contributor Author

sdwbgn commented May 17, 2024

/retest

@sdwbgn sdwbgn marked this pull request as ready for review May 17, 2024 01:04
@sdwbgn sdwbgn requested a review from wbpcode as a code owner May 17, 2024 01:04
Comment on lines 103 to 109
decoder_callbacks_->sendLocalReply(
Http::Code::Unauthorized, body,
[uri = this->original_uri_](Http::ResponseHeaderMap& headers) {
std::string value = absl::StrCat("Basic realm=\"", uri, "\"");
headers.setCopy(Http::Headers::get().WWWAuthenticate, value);
},
absl::nullopt, response_code_details);
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the contribution. LGTM overall.

But I don't think we need to create and store the original_uri_ as a member of filter. You could simply capture this in the lambda and build the value in the lambda.

Tips: You can get request headers by the decoder_callbacks_->requestHeaders() in the lambda.

@wbpcode
Copy link
Member

wbpcode commented May 18, 2024

/wait

Signed-off-by: Vasilii Bulatov <sdwbgn@gmail.com>
Signed-off-by: Vasilii Bulatov <sdwbgn@gmail.com>
Signed-off-by: Vasilii Bulatov <sdwbgn@gmail.com>
Signed-off-by: Vasilii Bulatov <sdwbgn@gmail.com>
Signed-off-by: Vasilii Bulatov <sdwbgn@gmail.com>
Signed-off-by: Vasilii Bulatov <sdwbgn@gmail.com>
@sdwbgn
Copy link
Contributor Author

sdwbgn commented May 25, 2024

/retest

@sdwbgn sdwbgn requested a review from wbpcode May 25, 2024 20:00
Copy link
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM with one nit comment. :)

const auto request_headers = this->decoder_callbacks_->requestHeaders();
const std::string uri = Http::Utility::buildOriginalUri(*request_headers, MaximumUriLength);
const std::string value = absl::StrCat("Basic realm=\"", uri, "\"");
headers.setCopy(Http::Headers::get().WWWAuthenticate, value);
Copy link
Member

Choose a reason for hiding this comment

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

nit: setReferenceKey(...)

Signed-off-by: Vasilii Bulatov <sdwbgn@gmail.com>
@sdwbgn sdwbgn requested a review from wbpcode May 29, 2024 10:36
Copy link
Member

@wbpcode wbpcode 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.

@wbpcode wbpcode merged commit 1b70b9e into envoyproxy:main May 29, 2024
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Basic Auth Filter should include WWW-Authenticate header in its 401 response
2 participants