update gateway exec mount tests to verity ssh and secret mounts

Signed-off-by: Cory Bennett <cbennett@netflix.com>
v0.8
Cory Bennett 2020-09-17 00:13:06 +00:00
parent 3cc8aa0649
commit 5fcf6dd426
2 changed files with 59 additions and 12 deletions

View File

@ -14,11 +14,15 @@ import (
"github.com/moby/buildkit/frontend/gateway/client"
gatewayapi "github.com/moby/buildkit/frontend/gateway/pb"
"github.com/moby/buildkit/identity"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/secrets/secretsprovider"
"github.com/moby/buildkit/session/sshforward/sshprovider"
"github.com/moby/buildkit/solver/errdefs"
"github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/testutil/integration"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/ssh/agent"
)
func TestClientGatewayIntegration(t *testing.T) {
@ -566,6 +570,17 @@ func testClientGatewayContainerMounts(t *testing.T, sb integration.Sandbox) {
err = ioutil.WriteFile(filepath.Join(tmpdir, "local-file"), []byte("local"), 0644)
require.NoError(t, err)
a := agent.NewKeyring()
sockPath, clean, err := makeSSHAgentSock(a)
require.NoError(t, err)
defer clean()
ssh, err := sshprovider.NewSSHAgentProvider([]sshprovider.AgentConfig{{
ID: t.Name(),
Paths: []string{sockPath},
}})
require.NoError(t, err)
product := "buildkit_test"
b := func(ctx context.Context, c client.Client) (*client.Result, error) {
@ -593,6 +608,18 @@ func testClientGatewayContainerMounts(t *testing.T, sb integration.Sandbox) {
}, {
Dest: "/tmpfs",
MountType: pb.MountType_TMPFS,
}, {
Dest: "/run/secrets/mysecret",
MountType: pb.MountType_SECRET,
SecretOpt: &pb.SecretOpt{
ID: "/run/secrets/mysecret",
},
}, {
Dest: sockPath,
MountType: pb.MountType_SSH,
SSHOpt: &pb.SSHOpt{
ID: t.Name(),
},
}}
for mountpoint, st := range mounts {
@ -620,8 +647,9 @@ func testClientGatewayContainerMounts(t *testing.T, sb integration.Sandbox) {
}
pid1, err := ctr.Start(ctx, client.StartRequest{
Args: []string{"sleep", "10"},
Cwd: "/",
Args: []string{"sleep", "10"},
Cwd: "/",
Stderr: os.Stderr,
})
require.NoError(t, err)
defer pid1.Wait()
@ -666,6 +694,25 @@ func testClientGatewayContainerMounts(t *testing.T, sb integration.Sandbox) {
err = pid.Wait()
require.NoError(t, err)
secretOutput := bytes.NewBuffer([]byte{})
pid, err = ctr.Start(ctx, client.StartRequest{
Args: []string{"cat", "/run/secrets/mysecret"},
Cwd: "/",
Stdout: &nopCloser{secretOutput},
})
require.NoError(t, err)
err = pid.Wait()
require.NoError(t, err)
require.Equal(t, "foo-secret", secretOutput.String())
pid, err = ctr.Start(ctx, client.StartRequest{
Args: []string{"test", "-S", sockPath},
Cwd: "/",
})
require.NoError(t, err)
err = pid.Wait()
require.NoError(t, err)
return &client.Result{}, ctr.Release(ctx)
}
@ -673,7 +720,14 @@ func testClientGatewayContainerMounts(t *testing.T, sb integration.Sandbox) {
LocalDirs: map[string]string{
"mylocal": tmpdir,
},
Session: []session.Attachable{
ssh,
secretsprovider.FromMap(map[string][]byte{
"/run/secrets/mysecret": []byte("foo-secret"),
}),
},
}, product, b, nil)
require.Error(t, err)
require.Contains(t, err.Error(), context.Canceled.Error())
checkAllReleasable(t, c, sb, true)

View File

@ -645,16 +645,6 @@ func (c *grpcClient) NewContainer(ctx context.Context, req client.NewContainerRe
id := identity.NewID()
var mounts []*opspb.Mount
for _, m := range req.Mounts {
if m.CacheOpt != nil {
mounts = append(mounts, &opspb.Mount{
Dest: m.Dest,
Selector: m.Selector,
Readonly: m.Readonly,
MountType: opspb.MountType_CACHE,
CacheOpt: m.CacheOpt,
})
continue
}
var resultID string
if m.Ref != nil {
ref, ok := m.Ref.(*reference)
@ -669,6 +659,9 @@ func (c *grpcClient) NewContainer(ctx context.Context, req client.NewContainerRe
Readonly: m.Readonly,
MountType: m.MountType,
ResultID: resultID,
CacheOpt: m.CacheOpt,
SecretOpt: m.SecretOpt,
SSHOpt: m.SSHOpt,
})
}