Skip to content

Commit 151b8d3

Browse files
authored
feat(build/docker): support env as secret source (#6632)
Used in buildkit mode, allow users to specify secrets provided via env vars to Skaffold (and hence docker/buildkit) in addition to file sources ("src"). I am setting "src" and "env" as mutually exclusive here in skaffold, however docker currently does not enforce this (but "env" takes precedence regardless of the order if both specified). If we receive issues about this, we can relax it in a backwards-compatible way. Signed-off-by: Ahmet Alp Balkan <[email protected]>
1 parent a07019e commit 151b8d3

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

docs/content/en/schemas/v2beta24.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,11 @@
14541454
"id"
14551455
],
14561456
"properties": {
1457+
"env": {
1458+
"type": "string",
1459+
"description": "environment variable name containing the secret value.",
1460+
"x-intellij-html-description": "environment variable name containing the secret value."
1461+
},
14571462
"id": {
14581463
"type": "string",
14591464
"description": "id of the secret.",
@@ -1467,7 +1472,8 @@
14671472
},
14681473
"preferredOrder": [
14691474
"id",
1470-
"src"
1475+
"src",
1476+
"env"
14711477
],
14721478
"additionalProperties": false,
14731479
"type": "object",

pkg/skaffold/docker/image.go

+3
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,9 @@ func ToCLIBuildArgs(a *latestV1.DockerArtifact, evaluatedArgs map[string]*string
642642
if secret.Source != "" {
643643
secretString += ",src=" + secret.Source
644644
}
645+
if secret.Env != "" {
646+
secretString += ",env=" + secret.Env
647+
}
645648
args = append(args, "--secret", secretString)
646649
}
647650

pkg/skaffold/docker/image_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,23 @@ func TestGetBuildArgs(t *testing.T) {
353353
want: []string{"--secret", "id=mysecret"},
354354
},
355355
{
356-
description: "secret with source",
356+
description: "secret with file source",
357357
artifact: &latestV1.DockerArtifact{
358358
Secrets: []*latestV1.DockerSecret{
359359
{ID: "mysecret", Source: "foo.src"},
360360
},
361361
},
362362
want: []string{"--secret", "id=mysecret,src=foo.src"},
363363
},
364+
{
365+
description: "secret with env source",
366+
artifact: &latestV1.DockerArtifact{
367+
Secrets: []*latestV1.DockerSecret{
368+
{ID: "mysecret", Env: "FOO"},
369+
},
370+
},
371+
want: []string{"--secret", "id=mysecret,env=FOO"},
372+
},
364373
{
365374
description: "multiple secrets",
366375
artifact: &latestV1.DockerArtifact{

pkg/skaffold/schema/latest/v1/config.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,10 @@ type DockerSecret struct {
13151315
ID string `yaml:"id,omitempty" yamltags:"required"`
13161316

13171317
// Source is the path to the secret on the host machine.
1318-
Source string `yaml:"src,omitempty"`
1318+
Source string `yaml:"src,omitempty" yamltags:"oneOf=secretSource"`
1319+
1320+
// Env is the environment variable name containing the secret value.
1321+
Env string `yaml:"env,omitempty" yamltags:"oneOf=secretSource"`
13191322
}
13201323

13211324
// BazelArtifact describes an artifact built with [Bazel](https://bazel.build/).

0 commit comments

Comments
 (0)