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

Use constant value for unix socket so valid host is set in request URL #250

Merged
merged 4 commits into from Jan 18, 2024

Conversation

jakubbujny
Copy link
Contributor

Description

When unix socket is used, usually it's in form like VAULT_ADDR="unix:///var/run/vault.sock"
Currently library correctly detects usage of unix socket based on unix:// prefix. However later /var/run/vault.sock is used as Host parameter in HTTP requests over unix socket. It's incorrect as golang URL library expects valid URL in such case so it will try to escape slashes and construct URL in form like: http://%2Fvar%2Frun%2Fvault%2Fvault.sock/v1/secret/data/... what will cause error as host is incorrect.

I propose to use instead "fake" host which is still valid URL as http://unix.socket/v1/secret/data is correct from HTTP perspective - later dial function with unix socket will be used anyway (

vault-client-go/client.go

Lines 97 to 104 in b335dfa

if strings.HasPrefix(configuration.Address, "unix://") {
// Adjust the dial context for unix domain socket addresses in the
// internal HTTP transport, if exists.
if httpTransport, ok := c.client.Transport.(*http.Transport); ok {
httpTransport.DialContext = func(context.Context, string, string) (net.Conn, error) {
return net.Dial("unix", strings.TrimPrefix(configuration.Address, "unix://"))
}
} else {
) so host part of the URL will be ignored.

How has this been tested?

Ran go test ./... and tested code locally.

@jakubbujny jakubbujny requested a review from a team as a code owner January 17, 2024 13:26
@hashicorp-cla
Copy link

hashicorp-cla commented Jan 17, 2024

CLA assistant check
All committers have signed the CLA.

generate/templates/client.handlebars Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
jakubbujny and others added 2 commits January 18, 2024 19:38
Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com>
Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com>
Copy link
Collaborator

@averche averche left a comment

Choose a reason for hiding this comment

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

Thanks again for contributing!

@averche averche merged commit cfdcbed into hashicorp:main Jan 18, 2024
4 checks passed
@jakubbujny
Copy link
Contributor Author

thanks for the suggestions @averche ! I committed them :)

@jakubbujny
Copy link
Contributor Author

@averche is there any chance to release new version of library with that change?

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.

None yet

3 participants