Skip to content
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

set GIT_AUTH_TOKEN secret if Git context used #284

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Jan 10, 2025

@crazy-max crazy-max requested a review from tonistiigi January 10, 2025 10:36
@crazy-max crazy-max marked this pull request as ready for review January 10, 2025 10:36
// request: https://github.com/docker/buildx/pull/2905
const gitAuthToken = getGitAuthToken(inputs);
if (gitAuthToken && !Bake.hasGitAuthTokenSecret(definition) && inputs.source.startsWith(Context.gitContext())) {
args.push('--set', `*.secrets=${Build.resolveSecretString(`GIT_AUTH_TOKEN=${gitAuthToken}`)}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, this does not overwrite existing secrets, right?

How does this looks as a raw value? The actual secret value should not be argument for --set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, this does not overwrite existing secrets, right?

Yes it doesn't, !Bake.hasGitAuthTokenSecret(definition) checks if GIT_AUTH_TOKEN is set first.

How does this looks as a raw value? The actual secret value should not be argument for --set.

It creates a temp file setting the secret value: https://github.com/docker/bake-action/actions/runs/12707842078/job/35423580416#step:4:231

image

And is removed when job is completed: https://github.com/docker/bake-action/actions/runs/12707842078/job/35423580416#step:6:35

image

This is the same behavior in build-push-action repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it doesn't, !Bake.hasGitAuthTokenSecret(definition) checks if GIT_AUTH_TOKEN is set first.

I meant that if user has own secrets (not git) defined in HCL then this doesn't overwrite it. I don't remember how the merge logic was in this case.

It creates a temp file setting the secret value:

Temp file shouldn't be needed as buildx can just read the value from env, but this doesn't need to be part of this PR.

Copy link
Member Author

@crazy-max crazy-max Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that if user has own secrets (not git) defined in HCL then this doesn't overwrite it. I don't remember how the merge logic was in this case.

Yes we check and skip if defined either through override or within the bake definition because we solve the definition first and look at existing secrets from there: https://github.com/docker/actions-toolkit/blob/54bdcf6c08a9b43d37df4156506648c978b372fe/src/buildx/bake.ts#L411-L423

image

Temp file shouldn't be needed as buildx can just read the value from env, but this doesn't need to be part of this PR.

Yes we could improve that agree, env was not a thing before. Will open a follow-up.

@crazy-max crazy-max merged commit 5a1b7c9 into docker:master Jan 14, 2025
40 checks passed
@crazy-max crazy-max deleted the fix-git-auth-token branch January 14, 2025 12:52
crazy-max added a commit to crazy-max/docker-bake-action that referenced this pull request Jan 14, 2025
This reverts commit 5a1b7c9, reversing
changes made to ded8f8f.

Signed-off-by: CrazyMax <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants