Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions __tests__/.fixtures/bake-03-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
"ref": "user/app",
"type": "registry"
}
],
"secret": [
{
"env": "GITHUB_TOKEN",
"id": "GITHUB_TOKEN"
},
{
"id": "aws",
"src": "__tests__/.fixtures/secret.txt"
},
{
"id": "GITHUB_REPOSITORY"
}
]
}
}
Expand Down
5 changes: 5 additions & 0 deletions __tests__/.fixtures/bake-03.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ target "default" {
"./release-out",
"type=registry,ref=user/app"
]
secret = [
"id=GITHUB_TOKEN,env=GITHUB_TOKEN",
"id=aws,src=__tests__/.fixtures/secret.txt",
"id=GITHUB_REPOSITORY"
]
}
41 changes: 41 additions & 0 deletions __tests__/buildx/bake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,44 @@ describe('hasDockerExporter', () => {
expect(Bake.hasDockerExporter(def, load)).toEqual(expected);
});
});

describe('hasGitAuthTokenSecret', () => {
// prettier-ignore
test.each([
[
{
"target": {
"reg": {
"secret": [
{
"id": "A_SECRET",
"env": "A_SECRET"
}
]
},
}
} as unknown as BakeDefinition,
false
],
[
{
"target": {
"reg": {
"secret": [
{
"id": "A_SECRET",
"env": "A_SECRET"
},
{
"id": "GIT_AUTH_TOKEN"
}
]
},
}
} as unknown as BakeDefinition,
true
],
])('given %o returns %p', async (def: BakeDefinition, expected: boolean) => {
expect(Bake.hasGitAuthTokenSecret(def)).toEqual(expected);
});
});
15 changes: 15 additions & 0 deletions src/buildx/bake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ export class Bake {
secretEntry.src = value;
break;
case 'env':
secretEntry.env = value;

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This change is an oversight and fixes an issue when parsing secrets to be aligned with buildx logic: https://github.com/docker/buildx/blob/16edf5d4aa76ef9978c06889d66249aeab5729fe/util/buildflags/secrets.go#L106

Also add tests to make sure we cover everything.

break;
}
}
Expand Down Expand Up @@ -406,4 +407,18 @@ export class Bake {
}
return exporters;
}

public static hasGitAuthTokenSecret(def: BakeDefinition): boolean {
for (const key in def.target) {
const target = def.target[key];
if (target.secret) {
for (const secret of target.secret) {
if (Bake.parseSecretEntry(secret).id === 'GIT_AUTH_TOKEN') {
return true;
}
}
}
}
return false;
}
}