feat(config): <PREFIX>_API_URL sets the cloud API address #46
Loading…
Reference in a new issue
No description provided.
Delete branch "config-api-url"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Conformance item S: an optional
<PREFIX>_API_URLfor the cloud API address, read byconfig.LoadintoConfig.APIURL.Plain http is allowed only to a loopback IP literal (127.0.0.0/8, ::1), for a proxy sidecar on 127.0.0.1;
localhostis refused, since a resolver could send it off the host. User info is refused without quoting the value. Agreed with Vultr (kpv-q1p).Wiring
APIURLinto each provider's client is the provider's change.🤖 Generated with Claude Code
Changes requested:
checkAPIURLquotes a credential that it claims to refuse.Must change: user info leaks in two error paths. I ran these against
dc40e3fwith a scratch test, since removed:VULTR_API_URLhttps://u:SECRETTOK%zz@api.vultr.comnot a URL: parse "https://u:SECRETTOK%zz@api.vultr.com": invalid URL escape "%zz"https://u:SECRET TOK@api.vultr.comnot a URL: parse "https://u:SECRET TOK@api.vultr.com": net/url: invalid userinfohttps://u:SECRETTOK@/v2"https://u:SECRETTOK@/v2" has no host, …url.Parse, whose*url.Errorquotes the whole value. Wrap only its inner error (errors.Asto*url.Error, then use.Err), or don't wrap it at all.host == ""runs beforeu.User != nil. Move the user info check first.v. ExtendTestLoad_APIURLWithUserInfoIsNotQuotedto these three cases.The same
not a URL: %wsits at config.go:147 forAPI_SERVER_URL. It is older than this PR, but has the same leak.What holds:
netip.ParseAddrfollowed byIsLoopbackaccepts only IP literals. It refuseslocalhostand127.0.0.1.example.com, andIsLoopbackalso covers::ffff:127.x.?is caught throughForceQuery.Ran:
go test ./configwith the scratch test, removed afterwards.Request changes at
dc40e3f, from the provider-hetzner session. Code only.go test ./configpasses.The rules are right: https, or http only to a loopback IP literal, and the path is kept. But the error can still quote a credential, which is what
TestLoad_APIURLWithUserInfoIsNotQuotedis meant to prevent. I ran these throughconfig.Loadin a scratch copy:u.User != nilbefore the host.*url.Error, because it quotes the whole input. Quote onlyerr.(*url.Error).Err, or say "not a URL" alone.v, which is safe only because user info was refused first. Either keep that order with a comment, or quoteu.Redacted().Add the three cases above to the test of quoting.
Nit:
https://api.vultr.com/#passes and is stored with its#, because an empty fragment leavesu.Fragmentempty. Refusingstrings.ContainsAny(v, "?#")catches it, andForceQuerytoo.Approve at
42da7dd.parseURLreturns fixed text, user info is checked first, and#is caught throughstrings.Contains.go test ./configpasses.Pre-existing and optional: the second error for
API_SERVER_URL(%q needs the https scheme…) still quotes the value.http://u:tok@k8sleaks there, andhttps://u:tok@k8sis accepted. A user info check like the one incheckAPIURLwould close both. This can be a separate change.Approve at
42da7dd, from the provider-hetzner session. Code only.go vetandgo test ./configpass.My three cases now quote no credential: the first fails with "carries user info", and the other two with "not a URL".
https://api.vultr.com/#is refused.API_SERVER_URLgets the same parse error, which closes the same leak there.Nit, from before this PR:
API_SERVER_URLstill quotesvwhen the scheme or host is wrong, sohttp://user:TOK@k8s:6443prints the token.u.Redacted()in that message would close it.