Skip to content

Commit

Permalink
do not mount secrets that are optional and missing from solve opts
Browse files Browse the repository at this point in the history
Signed-off-by: coryb <[email protected]>
(cherry picked from commit b5afdec)
  • Loading branch information
coryb authored and tonistiigi committed Feb 13, 2023
1 parent 04e63cb commit 4fe7d93
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 16 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,9 @@ func testSecretMounts(t *testing.T, sb integration.Sandbox) {
}, nil)
require.NoError(t, err)

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

def, err = st.Marshal(sb.Context())
require.NoError(t, err)
Expand Down Expand Up @@ -1176,6 +1176,20 @@ func testSecretMounts(t *testing.T, sb integration.Sandbox) {
})},
}, nil)
require.NoError(t, err)

// test empty cert still creates secret file
st = llb.Image("busybox:latest").
Run(llb.Shlex(`test -f /run/secrets/mysecret5`), llb.AddSecret("/run/secrets/mysecret5", llb.SecretID("mysecret")))

def, err = st.Marshal(sb.Context())
require.NoError(t, err)

_, err = c.Solve(sb.Context(), def, SolveOpt{
Session: []session.Attachable{secretsprovider.FromMap(map[string][]byte{
"mysecret": []byte(""),
})},
}, nil)
require.NoError(t, err)
}

func testSecretEnv(t *testing.T, sb integration.Sandbox) {
Expand Down
6 changes: 3 additions & 3 deletions solver/llbsolver/mounts/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ func (mm *MountManager) getSecretMountable(ctx context.Context, m *pb.Mount, g s
err = mm.sm.Any(ctx, g, func(ctx context.Context, _ string, caller session.Caller) error {
dt, err = secrets.GetSecret(ctx, caller, id)
if err != nil {
if errors.Is(err, secrets.ErrNotFound) && m.SecretOpt.Optional {
return nil
}
return err
}
return nil
})
if err != nil {
if errors.Is(err, secrets.ErrNotFound) && m.SecretOpt.Optional {
return nil, nil
}
return nil, err
}
return &secretMount{mount: m, data: dt, idmap: mm.cm.IdentityMapping()}, nil
Expand Down

0 comments on commit 4fe7d93

Please sign in to comment.