Skip to content

[extensions/azureauth] Retrieve scope from Host/URL.Host instead of Header for client authentication #40033

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ms-hujia
Copy link
Contributor

Description

For client request, there won't be a Host entry in Header. The scope should be retrieved from Host or URL.Host.

Link to tracking issue

Fixes #40032.

Testing

Updated the existing test case.

Documentation

N/A.

@ms-hujia ms-hujia requested a review from a team as a code owner May 13, 2025 08:20
@ms-hujia ms-hujia requested a review from songy23 May 13, 2025 08:20
@github-actions github-actions bot requested a review from constanca-m May 13, 2025 08:21

host := req.Header.Get("Host")
host := req.Host
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not correct. This host is meant to be a Host header. If you look at the README file, the request is meant to have headers, of which one of them is Host (see azure documentation).

This host will then be used to define the scope of the authentication request.

Copy link
Contributor

Choose a reason for hiding this comment

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

For example, set the Host of your request to management.azure.com. Will your use case work now? Which azure service are you using? The host might change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not correct. This host is meant to be a Host header. If you look at the README file, the request is meant to have headers, of which one of them is Host (see azure documentation).

This host will then be used to define the scope of the authentication request.

No, it won't be added. I can give you a minimum example to reproduce the issue if you don't have a chance to verify this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example, set the Host of your request to management.azure.com. Will your use case work now? Which azure service are you using? The host might change.

Not all exporters give user the opportunity to override the HTTP header.

Copy link
Contributor

Choose a reason for hiding this comment

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

can give you a minimum example to reproduce the issue if you don't have a chance to verify this.

I would that, if you could.

I'm very busy this week, so I am trying not to respond slow to this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries, take your time since I've already unblocked myself.

Copy link
Contributor

@constanca-m constanca-m May 14, 2025

Choose a reason for hiding this comment

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

@ms-hujia Can you share with me the config.yaml you are using for the collector? So I can have a reference and test it Sorry, I see you have put the comment in the issue

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for your example @ms-hujia. I think I understand the issue now.

I am not sure how to resolve this in an idiomatic way. I believe requests for authentication on azure should be in sync with what the user expects - so based on azure documentation, the host should be on the header.

But it is true that if you use azureauth, then you cannot set the headers of the request - there is headers_setter extension, but since you can only use 1 authenticator, you could not use it at the same time as azureauth.

I believe the best way would be to use a new component that could set the header Host, and then use azureauth right after. So, what headers_transform extension could possible do (this is not an approved component, it is just something we use internally at the company I work at, Elastic, to handle this exact same issue).

If we set the host the way this PR shows, then we are expecting the request to be hosted on azure, and I am not sure if that is always right. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Golang's HTTP client implementation, the Host entry will be added to the HTTP header server received, even if it's not set in the Header field of http.Request. This is done in the base http.RoundTripper. Generally, user don't need to pass those basic HTTP headers explicitly, e.g., another example is Content-Length.

Going back to the issue itself, the issue happens due to the Host entry is checked before base http.RoundTripper add it to request.

@constanca-m
Copy link
Contributor

@ms-hujia Could you add a changelog please? So we can start working on getting this merged :)

@ms-hujia
Copy link
Contributor Author

@ms-hujia Could you add a changelog please? So we can start working on getting this merged :)

I've added the changelog and rebased my branch.

@mx-psi mx-psi requested a review from constanca-m May 22, 2025 11:40
Copy link
Contributor

github-actions bot commented Jun 7, 2025

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[extension/azureauth] Client authentication failed with "missing \"host\" header"
3 participants