bake: derive git auth host from remote URL#3648
bake: derive git auth host from remote URL#3648crazy-max wants to merge 1 commit intodocker:masterfrom
Conversation
ac8f506 to
8573243
Compare
8573243 to
22217e5
Compare
This comment was marked as outdated.
This comment was marked as outdated.
tonistiigi
left a comment
There was a problem hiding this comment.
I don't think users should need to set the host in the env variable. We can just get the host from the remote URL and connect these automatically.
22217e5 to
eebe1e5
Compare
eebe1e5 to
ac54d55
Compare
bake/bake.go
Outdated
| } | ||
|
|
||
| func isRemoteContext(t build.Inputs, inp *Input) bool { | ||
| func remoteContextURL(t build.Inputs, inp *Input) string { |
There was a problem hiding this comment.
nit: bit cleaner to return string, bool from such functions.
bake/gitauth.go
Outdated
| return nil | ||
| } | ||
| secrets := make(buildflags.Secrets, 0, len(hosts)+1) | ||
| secrets = append(secrets, &buildflags.Secret{ |
There was a problem hiding this comment.
I still don't get it.
(assuming this isn't breaking existing users badly), this should be only set if the Bake command is using remote input, not based on if the target is using remote URL or not what seems to happen atm.
Additionally, there is no point in adding the main secret key and host key with the same value. Only host key should be set, and only for the host that was "bake remote URL", not any host that happened to be remote URL for a bake target.
There was a problem hiding this comment.
there is no point in adding the main secret key and host key with the same value.
Ah right, this should only emit host-scoped git auth secrets (no generic main key).
(assuming this isn't breaking existing users badly), this should be only set if the Bake command is using remote input, not based on if the target is using remote URL or not what seems to happen atm.
I kept target remote-context handling for backward compatibility for now. I'm a bit hesitant to switch to strict remote input only immediately, because the current behavior follows context resolution in
Lines 1294 to 1331 in 268f1c7
And changing that could break existing flows. If you prefer, I can still change it to strict remote input only behavior.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
ac54d55 to
f43adf9
Compare
This PR refactors Bake Git authentication secret handling by introducing a dedicated gitauth helper that centralizes how secrets are built from environment variables. The same helper is now used in both build option creation and remote bake file reads, so the behavior is consistent across those paths while preserving existing support for
BUILDX_BAKE_GIT_AUTH_TOKENandBUILDX_BAKE_GIT_AUTH_HEADER.It also adds automatic host-based Git auth secret derivation for remote Bake invocations. When a remote URL is in play, Bake now emits both base BuildKit secret IDs and host-scoped IDs (for example
GIT_AUTH_TOKEN.<host>/GIT_AUTH_HEADER.<host>) based on the resolved remote URL logic, enabling per-host auth routing automatically without introducing host-suffixed auth env vars.