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

Add support for proxy connect headers #409

Merged
merged 1 commit into from Dec 14, 2022
Merged

Conversation

mem
Copy link
Contributor

@mem mem commented Nov 11, 2022

Some proxy configurations require additional headers to be able to use them (e.g. authorization token specific to the proxy).

Fixes: #402
Signed-off-by: Marcelo E. Magallon marcelo.magallon@grafana.com

@mem
Copy link
Contributor Author

mem commented Nov 11, 2022

Ok, this is weird. The files use ioutil, but they don't import it. I don't see the change that introduced the usage introducing the import, so it's not like the import was accidentally removed. I don't understand how this even compiles...

@roidelapluie
Copy link
Member

This is explicitly for secrets, so it would be a security breach to allow this to be marshalled back. We have to use our secrets, which I think would be better to duplicate the auth parameters as we have them now, with credentials and basic_auth.

@@ -48,6 +49,29 @@ func (s Secret) MarshalJSON() ([]byte, error) {
return json.Marshal(secretToken)
}

type Header map[string][]Secret
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 added mostly to be able to test the conversion to http.Header and the marshaling / unmarshaling.

@mem
Copy link
Contributor Author

mem commented Nov 21, 2022

This is explicitly for secrets, so it would be a security breach to allow this to be marshalled back. We have to use our secrets, which I think would be better to duplicate the auth parameters as we have them now, with credentials and basic_auth.

I see, you are right.

I have modified the implementation.

I didn't fully understand the comment about duplicating auth parameters...

While the use case is basically https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization, I haven't been able to trace why the Go implementation has a separate field for these headers. I imagine the reason is that some proxies pay attention to other headers that aren't about authentication / authorization, e.g. https://everything.curl.dev/usingcurl/proxies/headers and the Go client needs a way to differentiate between headers sent to the proxy and headers sent to the final destination over the tunnel that gets created using CONNECT.

@mem
Copy link
Contributor Author

mem commented Dec 1, 2022

@roidelapluie I would appreciate it if you can take another look. Thanks!

@mem mem force-pushed the mem/proxy_header branch 2 times, most recently from ddf4a4d to 7d6e36a Compare December 1, 2022 15:40
config/config.go Outdated Show resolved Hide resolved
config/config_test.go Outdated Show resolved Hide resolved
Copy link
Member

@roidelapluie roidelapluie left a comment

Choose a reason for hiding this comment

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

We also support JSON, json tests would be welcome

@mem mem force-pushed the mem/proxy_header branch 2 times, most recently from 9141262 to af85c28 Compare December 13, 2022 21:19
@mem
Copy link
Contributor Author

mem commented Dec 13, 2022

We also support JSON, json tests would be welcome

Done :-)

Some proxy configurations require additional headers to be able to use
them (e.g. authorization token specific to the proxy).

Fixes: #402
Co-authored-by: Julien Pivotto <roidelapluie@o11y.eu>
Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
@roidelapluie roidelapluie merged commit 296ec92 into main Dec 14, 2022
@roidelapluie roidelapluie deleted the mem/proxy_header branch December 14, 2022 08:50
@roidelapluie
Copy link
Member

Thanks!

Comment on lines +62 to +69
var s []string
if values != nil {
s = make([]string, 0, len(values))
for _, value := range values {
s = append(s, string(value))
}
}
header[name] = s

Choose a reason for hiding this comment

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

This code has a slightly odd smell to me. Why not simply use header.Add(name, string(value)) (https://pkg.go.dev/net/http#Header.Add)?

The test cases would need to be adjusted, since the bogus items like nil header names or empty value lists won't be added, as they would be illegal headers - and as such I don't see the point of including them as test cases anyway. Header.Add() will also canonicalize the header names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, yeah, I completely missed that. I'll follow up with another PR.

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.

Support ProxyConnectHeader
3 participants