feat(config): <PREFIX>_API_URL sets the cloud API address #46

Merged
mikluko merged 2 commits from config-api-url into main 2026-12-04 16:37:43 +00:00
Owner

Conformance item S: an optional <PREFIX>_API_URL for the cloud API address, read by config.Load into Config.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; localhost is refused, since a resolver could send it off the host. User info is refused without quoting the value. Agreed with Vultr (kpv-q1p).

Wiring APIURL into each provider's client is the provider's change.

🤖 Generated with Claude Code

Conformance item S: an optional `<PREFIX>_API_URL` for the cloud API address, read by `config.Load` into `Config.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; `localhost` is refused, since a resolver could send it off the host. User info is refused without quoting the value. Agreed with Vultr (kpv-q1p). Wiring `APIURL` into each provider's client is the provider's change. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(config): <PREFIX>_API_URL sets the cloud API address
All checks were successful
CI / verify (pull_request) Has been skipped
CI / changelog (pull_request) Successful in 0s
Vulnerabilities / govulncheck-1 (pull_request) Successful in 13s
Vulnerabilities / govulncheck (pull_request) Successful in 0s
CI / check (pull_request) Successful in 1m6s
CI / ci (pull_request) Successful in 0s
dc40e3ff00
Plain http is allowed only to a loopback IP literal, for a proxy sidecar
on 127.0.0.1; localhost is refused, since a resolver could send it off
the host. Agreed with Vultr (kpv-q1p).

Assisted-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Changes requested: checkAPIURL quotes a credential that it claims to refuse.

Must change: user info leaks in two error paths. I ran these against dc40e3f with a scratch test, since removed:

VULTR_API_URL Error
https://u:SECRETTOK%zz@api.vultr.com not a URL: parse "https://u:SECRETTOK%zz@api.vultr.com": invalid URL escape "%zz"
https://u:SECRET TOK@api.vultr.com not a URL: parse "https://u:SECRET TOK@api.vultr.com": net/url: invalid userinfo
https://u:SECRETTOK@/v2 "https://u:SECRETTOK@/v2" has no host, …
  • The first two come from url.Parse, whose *url.Error quotes the whole value. Wrap only its inner error (errors.As to *url.Error, then use .Err), or don't wrap it at all.
  • The third comes from the check order: host == "" runs before u.User != nil. Move the user info check first.
  • Before any user info check, quote nothing derived from v. Extend TestLoad_APIURLWithUserInfoIsNotQuoted to these three cases.

The same not a URL: %w sits at config.go:147 for API_SERVER_URL. It is older than this PR, but has the same leak.

What holds:

  • netip.ParseAddr followed by IsLoopback accepts only IP literals. It refuses localhost and 127.0.0.1.example.com, and IsLoopback also covers ::ffff:127.x.
  • A bare ? is caught through ForceQuery.
  • An unset value stays empty, so each provider keeps its own default.

Ran: go test ./config with the scratch test, removed afterwards.

Changes requested: `checkAPIURL` quotes a credential that it claims to refuse. **Must change: user info leaks in two error paths.** I ran these against dc40e3f with a scratch test, since removed: | `VULTR_API_URL` | Error | |---|---| | `https://u:SECRETTOK%zz@api.vultr.com` | `not a URL: parse "https://u:SECRETTOK%zz@api.vultr.com": invalid URL escape "%zz"` | | `https://u:SECRET TOK@api.vultr.com` | `not a URL: parse "https://u:SECRET TOK@api.vultr.com": net/url: invalid userinfo` | | `https://u:SECRETTOK@/v2` | `"https://u:SECRETTOK@/v2" has no host, …` | - The first two come from `url.Parse`, whose `*url.Error` quotes the whole value. Wrap only its inner error (`errors.As` to `*url.Error`, then use `.Err`), or don't wrap it at all. - The third comes from the check order: `host == ""` runs before `u.User != nil`. Move the user info check first. - Before any user info check, quote nothing derived from `v`. Extend `TestLoad_APIURLWithUserInfoIsNotQuoted` to these three cases. The same `not a URL: %w` sits at config.go:147 for `API_SERVER_URL`. It is older than this PR, but has the same leak. **What holds:** - `netip.ParseAddr` followed by `IsLoopback` accepts only IP literals. It refuses `localhost` and `127.0.0.1.example.com`, and `IsLoopback` also covers `::ffff:127.x`. - A bare `?` is caught through `ForceQuery`. - An unset value stays empty, so each provider keeps its own default. Ran: `go test ./config` with the scratch test, removed afterwards.
Author
Owner

Request changes at dc40e3f, from the provider-hetzner session. Code only. go test ./config passes.

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_APIURLWithUserInfoIsNotQuoted is meant to prevent. I ran these through config.Load in a scratch copy:

"https://user:SECRETTOK@/v2"               -> VULTR_API_URL: "https://user:SECRETTOK@/v2" has no host, as in https://api.example.com
"https://user:SECRET TOK@api.vultr.com"    -> VULTR_API_URL: not a URL: parse "https://user:SECRET TOK@api.vultr.com": net/url: invalid userinfo
"https://user:SECRET%zzTOK@api.vultr.com"  -> VULTR_API_URL: not a URL: parse "https://user:SECRET%zzTOK@api.vultr.com": invalid URL escape "%zz"
  1. Check u.User != nil before the host.
  2. Don't wrap the *url.Error, because it quotes the whole input. Quote only err.(*url.Error).Err, or say "not a URL" alone.
  3. The other messages quote v, which is safe only because user info was refused first. Either keep that order with a comment, or quote u.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 leaves u.Fragment empty. Refusing strings.ContainsAny(v, "?#") catches it, and ForceQuery too.

Request changes at dc40e3f, from the provider-hetzner session. Code only. `go test ./config` passes. 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_APIURLWithUserInfoIsNotQuoted` is meant to prevent. I ran these through `config.Load` in a scratch copy: ``` "https://user:SECRETTOK@/v2" -> VULTR_API_URL: "https://user:SECRETTOK@/v2" has no host, as in https://api.example.com "https://user:SECRET TOK@api.vultr.com" -> VULTR_API_URL: not a URL: parse "https://user:SECRET TOK@api.vultr.com": net/url: invalid userinfo "https://user:SECRET%zzTOK@api.vultr.com" -> VULTR_API_URL: not a URL: parse "https://user:SECRET%zzTOK@api.vultr.com": invalid URL escape "%zz" ``` 1. Check `u.User != nil` before the host. 2. Don't wrap the `*url.Error`, because it quotes the whole input. Quote only `err.(*url.Error).Err`, or say "not a URL" alone. 3. The other messages quote `v`, which is safe only because user info was refused first. Either keep that order with a comment, or quote `u.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 leaves `u.Fragment` empty. Refusing `strings.ContainsAny(v, "?#")` catches it, and `ForceQuery` too.
fix(config): a URL error quotes no part of the value
Some checks failed
Vulnerabilities / govulncheck-1 (pull_request) Successful in 11s
CI / verify (push) Has been skipped
CI / changelog (push) Has been skipped
Vulnerabilities / govulncheck (push) Successful in 0s
CI / verify (pull_request) Has been skipped
CI / changelog (pull_request) Successful in 0s
Vulnerabilities / govulncheck (pull_request) Successful in 0s
Vulnerabilities / govulncheck-1 (push) Successful in 20s
CI / ci (push) Has been cancelled
CI / check (push) Has been cancelled
CI / check (pull_request) Successful in 1m17s
CI / ci (pull_request) Successful in 0s
42da7dd915
url.Parse's error quotes the whole input, user info included; user info
is now checked before the host, whose error quotes the value. A bare
"#" is refused like a fragment.

Assisted-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Approve at 42da7dd. parseURL returns fixed text, user info is checked first, and # is caught through strings.Contains. go test ./config passes.

Pre-existing and optional: the second error for API_SERVER_URL (%q needs the https scheme…) still quotes the value. http://u:tok@k8s leaks there, and https://u:tok@k8s is accepted. A user info check like the one in checkAPIURL would close both. This can be a separate change.

Approve at 42da7dd. `parseURL` returns fixed text, user info is checked first, and `#` is caught through `strings.Contains`. `go test ./config` passes. Pre-existing and optional: the second error for `API_SERVER_URL` (`%q needs the https scheme…`) still quotes the value. `http://u:tok@k8s` leaks there, and `https://u:tok@k8s` is accepted. A user info check like the one in `checkAPIURL` would close both. This can be a separate change.
mikluko deleted branch config-api-url 2026-12-04 16:37:43 +00:00
Author
Owner

Approve at 42da7dd, from the provider-hetzner session. Code only. go vet and go test ./config pass.

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_URL gets the same parse error, which closes the same leak there.

Nit, from before this PR: API_SERVER_URL still quotes v when the scheme or host is wrong, so http://user:TOK@k8s:6443 prints the token. u.Redacted() in that message would close it.

Approve at 42da7dd, from the provider-hetzner session. Code only. `go vet` and `go test ./config` pass. 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_URL` gets the same parse error, which closes the same leak there. Nit, from before this PR: `API_SERVER_URL` still quotes `v` when the scheme or host is wrong, so `http://user:TOK@k8s:6443` prints the token. `u.Redacted()` in that message would close it.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
karpenter/kit!46
No description provided.