hashicorp / vault-client-go

HashiCorp Vault Go Client Library generated from OpenAPI spec.
Mozilla Public License 2.0
84 stars 17 forks source link

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

Closed jakubbujny closed 10 months ago

jakubbujny commented 10 months ago

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 ( https://github.com/hashicorp/vault-client-go/blob/b335dfa06f347b1ad9c1a51503cef9b79c3e7725/client.go#L97-L104 ) so host part of the URL will be ignored.

How has this been tested?

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

hashicorp-cla commented 10 months ago

CLA assistant check
All committers have signed the CLA.

jakubbujny commented 10 months ago

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

jakubbujny commented 10 months ago

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