-
Notifications
You must be signed in to change notification settings - Fork 481
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
bake: git auth support for remote definitions #2363
Conversation
b04c3f0
to
35bbed2
Compare
23b8fd2
to
d7a8f4d
Compare
@tonistiigi While adding tests I discovered a strange behavior with git source in BuildKit when authenticated. It seems most of the requests send the authorization header but not the one when checking the default branch in https://github.com/moby/buildkit/blob/ad5a64c68f20435c52a51db73ef9246d6a3feba6/source/git/source.go#L732 even if header is set in See https://github.com/docker/buildx/actions/runs/8465151975/job/23191259148#step:7:635
So for now in this test I just check the very first request is authenticated but I think we need a fix on BuildKit side. Works fine though when testing directly:
Editseems to be a limitation with Edit2after testing with:
It seems we could use Test on gitlab:
Works with basic auth as well. Also we should make sure this is a server supporting Git's smart service by checking |
d7a8f4d
to
1009504
Compare
Will these always be for bake only, or could these be for "build" as well? (curious if the |
Only bake, this is used to build remote bake definitions. For build we already use secrets to build from a remote Git context. |
Ah! So.. naive question; if that doesn't require special env-vars; why does bake need them? |
1009504
to
a686f8d
Compare
Re-reading; you mention remote definitions (so equivalent to "remote dockerfile"); I know |
Because a remote definition is not a build context per-say. We can't set secrets directly as this will be used also in the underlying builds from the definition. What @tonistiigi suggested in #2360 (comment) with a builtin target name could work but UX wise this is not great. |
a686f8d
to
c7e9dab
Compare
Yes indeed I don't think we have that for the Dockerfile atm. For bake we have "builtin" ways to use either a local or remote context, as well as merging local and remote definitions: https://docs.docker.com/build/bake/remote-definition/ @dvdksn Talking about merging local and remote bake definitions, I don't think we have this documented atm #1838 Edit: nevermind https://docs.docker.com/build/bake/remote-definition/#remote-definition-with-the---file-flag |
c7e9dab
to
0da453d
Compare
} | ||
|
||
var gitAuthSecrets []*controllerapi.Secret | ||
if _, ok := os.LookupEnv("BUILDX_BAKE_GIT_AUTH_TOKEN"); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably out of scope, but unclear to me how the controller takes Env
keys as input. Doesn't the controller have its own env if it is running in another process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum good point, it seems to work when connecting to local controller. I don't think there is another process except when using --invoke
and setting envs through invoke config:
buildx/controller/pb/controller.proto
Line 199 in a7d59ae
repeated string Env = 3; |
bake/remote.go
Outdated
if err == nil { | ||
session = append(session, ssh) | ||
var sshSpecs []*controllerapi.SSH | ||
if v := os.Getenv("BUILDX_BAKE_GIT_SSH"); v != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ID of this needs to be set with MountSSHSock()
if not default. Setting it to other ID would not work otherwise. So probably it should just be the path.
020ac59
to
8cb85e5
Compare
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
8cb85e5
to
4d39259
Compare
fixes #2360
Adds support for Git auth when using remote bake definitions through
BUILDX_BAKE_GIT_AUTH_TOKEN
andBUILDX_BAKE_GIT_AUTH_HEADER
envs var that will setGIT_AUTH_TOKEN
andGIT_AUTH_HEADER
secrets respectively, matching https://github.com/moby/buildkit/blob/ad5a64c68f20435c52a51db73ef9246d6a3feba6/client/llb/source.go#L270-L271Also adds
BUILDX_BAKE_GIT_SSH
to be consistent so user can provide SSH sock paths.