Skip to content

Commit eefe206

Browse files
authored
Merge pull request moby#3561 from coryb/issue-3521
do not mount secrets that are optional and missing from solve opts
2 parents 30ab7d8 + b5afdec commit eefe206

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

client/client_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,9 @@ func testSecretMounts(t *testing.T, sb integration.Sandbox) {
11391139
}, nil)
11401140
require.NoError(t, err)
11411141

1142-
// test optional
1142+
// test optional, mount should not exist when secret not present in SolveOpt
11431143
st = llb.Image("busybox:latest").
1144-
Run(llb.Shlex(`echo secret2`), llb.AddSecret("/run/secrets/mysecret2", llb.SecretOptional))
1144+
Run(llb.Shlex(`test ! -f /run/secrets/mysecret2`), llb.AddSecret("/run/secrets/mysecret2", llb.SecretOptional))
11451145

11461146
def, err = st.Marshal(sb.Context())
11471147
require.NoError(t, err)
@@ -1178,6 +1178,20 @@ func testSecretMounts(t *testing.T, sb integration.Sandbox) {
11781178
})},
11791179
}, nil)
11801180
require.NoError(t, err)
1181+
1182+
// test empty cert still creates secret file
1183+
st = llb.Image("busybox:latest").
1184+
Run(llb.Shlex(`test -f /run/secrets/mysecret5`), llb.AddSecret("/run/secrets/mysecret5", llb.SecretID("mysecret")))
1185+
1186+
def, err = st.Marshal(sb.Context())
1187+
require.NoError(t, err)
1188+
1189+
_, err = c.Solve(sb.Context(), def, SolveOpt{
1190+
Session: []session.Attachable{secretsprovider.FromMap(map[string][]byte{
1191+
"mysecret": []byte(""),
1192+
})},
1193+
}, nil)
1194+
require.NoError(t, err)
11811195
}
11821196

11831197
func testSecretEnv(t *testing.T, sb integration.Sandbox) {

solver/llbsolver/mounts/mount.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,14 @@ func (mm *MountManager) getSecretMountable(ctx context.Context, m *pb.Mount, g s
251251
err = mm.sm.Any(ctx, g, func(ctx context.Context, _ string, caller session.Caller) error {
252252
dt, err = secrets.GetSecret(ctx, caller, id)
253253
if err != nil {
254-
if errors.Is(err, secrets.ErrNotFound) && m.SecretOpt.Optional {
255-
return nil
256-
}
257254
return err
258255
}
259256
return nil
260257
})
261258
if err != nil {
259+
if errors.Is(err, secrets.ErrNotFound) && m.SecretOpt.Optional {
260+
return nil, nil
261+
}
262262
return nil, err
263263
}
264264
return &secretMount{mount: m, data: dt, idmap: mm.cm.IdentityMapping()}, nil

0 commit comments

Comments
 (0)