Skip to content

Commit

Permalink
Reverted mounting host working directory
Browse files Browse the repository at this point in the history
Because of this bug cirruslabs/tart#567
  • Loading branch information
fkorotkov committed Feb 27, 2024
1 parent 3a71e8f commit 56173b6
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ func (parallels *Parallels) Run(ctx context.Context, config *runconfig.RunConfig
return fmt.Errorf("%w: failed to retrieve VM %q IP-address: %v", ErrFailed, vm.name, err)
}

return remoteagent.WaitForAgent(ctx, parallels.logger, ip,
parallels.sshUser, parallels.sshPassword, parallels.agentOS, "amd64",
config, vm.ClonedFromSuspended(), nil, nil, "")
return remoteagent.WaitForAgent(ctx, parallels.logger, ip, parallels.sshUser, parallels.sshPassword, parallels.agentOS, "amd64", config, vm.ClonedFromSuspended(), nil, nil)
}

func (parallels *Parallels) WorkingDirectory(projectDir string, dirtyMode bool) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ func WithDisplay(display string) Option {
}
}

func WithMountTemporaryWorkingDirectoryFromHost() Option {
return func(tart *Tart) {
tart.mountTemporaryWorkingDirectoryFromHost = true
}
}

func WithVolumes(volumes []*api.Isolation_Tart_Volume) Option {
return func(tart *Tart) {
tart.volumes = volumes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ type Tart struct {
softnet bool
display string
volumes []*api.Isolation_Tart_Volume

mountTemporaryWorkingDirectoryFromHost bool
}

func New(
Expand Down Expand Up @@ -113,23 +111,6 @@ func (tart *Tart) Run(ctx context.Context, config *runconfig.RunConfig) (err err
}

// Start the VM (asynchronously)
var preCreatedWorkingDir string

if tart.mountTemporaryWorkingDirectoryFromHost {
tmpDir, err := os.MkdirTemp("", "")
if err != nil {
return fmt.Errorf("%w: failed to create temporary directory: %v",
ErrFailed, err)
}
defer func() {
_ = os.RemoveAll(tmpDir)
}()

config.ProjectDir = tmpDir
config.DirtyMode = true
preCreatedWorkingDir = tart.WorkingDirectory(config.ProjectDir, config.DirtyMode)
}

var directoryMounts []directoryMount
if config.DirtyMode {
directoryMounts = append(directoryMounts, directoryMount{
Expand Down Expand Up @@ -205,9 +186,7 @@ func (tart *Tart) Run(ctx context.Context, config *runconfig.RunConfig) (err err

prepareInstanceSpan.End()

err = remoteagent.WaitForAgent(ctx, tart.logger, ip,
tart.sshUser, tart.sshPassword, "darwin", "arm64",
config, true, initializeHooks, terminateHooks, preCreatedWorkingDir)
err = remoteagent.WaitForAgent(ctx, tart.logger, ip, tart.sshUser, tart.sshPassword, "darwin", "arm64", config, true, initializeHooks, terminateHooks)
if err != nil {
addTartListBreadcrumb(ctx)
addDHCPDLeasesBreadcrumb(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ func (vetu *Vetu) Run(ctx context.Context, config *runconfig.RunConfig) error {

prepareInstanceSpan.End()

err = remoteagent.WaitForAgent(ctx, vetu.logger, ip,
vetu.sshUser, vetu.sshPassword, "linux", runtime.GOARCH,
config, true, vetu.initializeHooks(config), nil, "")
err = remoteagent.WaitForAgent(ctx, vetu.logger, ip, vetu.sshUser, vetu.sshPassword, "linux", runtime.GOARCH, config, true, vetu.initializeHooks(config), nil)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ func newTart(iso *api.Isolation_Tart_, security *security.Security, logger logge
opts = append(opts, tart.WithDisplay(iso.Tart.Display))
}

if iso.Tart.MountTemporaryWorkingDirectoryFromHost {
opts = append(opts, tart.WithMountTemporaryWorkingDirectoryFromHost())
}

if iso.Tart.DiskSize != 0 {
opts = append(opts, tart.WithDiskSize(iso.Tart.DiskSize))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,7 @@ func (hooks WaitForAgentHooks) Run(ctx context.Context, cli *ssh.Client) error {
return nil
}

func WaitForAgent(
ctx context.Context,
logger logger.Lightweight,
ip string,
sshUser string,
sshPassword string,
agentOS string,
agentArchitecture string,
config *runconfig.RunConfig,
synchronizeTime bool,
initializeHooks WaitForAgentHooks,
terminateHooks WaitForAgentHooks,
preCreatedWorkingDir string,
) error {
func WaitForAgent(ctx context.Context, logger logger.Lightweight, ip string, sshUser string, sshPassword string, agentOS string, agentArchitecture string, config *runconfig.RunConfig, synchronizeTime bool, initializeHooks WaitForAgentHooks, terminateHooks WaitForAgentHooks) error {
ctx, span := tracer.Start(ctx, "upload-and-wait-for-agent")
defer span.End()

Expand Down Expand Up @@ -160,10 +147,6 @@ func WaitForAgent(
strconv.FormatInt(config.TaskID, 10),
}

if preCreatedWorkingDir != "" {
command = append(command, "-pre-created-working-dir", "\""+preCreatedWorkingDir+"\"")
}

// Start the agent and wait for it to terminate
logger.Debugf("running agent on %s with arguments: %v...", addr, command)

Expand Down
43 changes: 0 additions & 43 deletions internal/worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,49 +236,6 @@ func TestWorkerIsolationTart(t *testing.T) {
workerTestHelper(t, lis, isolation, nil, worker.WithUpstream(upstream))
}

func TestWorkerIsolationTartMountTemporaryWorkingDirectoryFromHost(t *testing.T) {
// Support Tart isolation testing configured via environment variables
image, vmOk := os.LookupEnv("CIRRUS_INTERNAL_TART_VM")
user, userOk := os.LookupEnv("CIRRUS_INTERNAL_TART_SSH_USER")
password, passwordOk := os.LookupEnv("CIRRUS_INTERNAL_TART_SSH_PASSWORD")
if !vmOk || !userOk || !passwordOk {
t.Skip("no Tart credentials configured")
}

t.Logf("Using Tart VM %s for testing...", image)

lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatal(err)
}

isolation := &api.Isolation{
Type: &api.Isolation_Tart_{
Tart: &api.Isolation_Tart{
Image: image,
User: user,
Password: password,
Cpu: 5,
Memory: 1024 * 5,
MountTemporaryWorkingDirectoryFromHost: true,
},
},
}

listenerPort := lis.Addr().(*net.TCPAddr).Port
rpcEndpoint := fmt.Sprintf("http://127.0.0.1:%d", listenerPort)
upstream, err := upstream.New("test", registrationToken,
upstream.WithRPCEndpoint(rpcEndpoint),
upstream.WithAgentEndpoint(endpoint.NewLocal(rpcEndpoint, rpcEndpoint)),
)
require.NoError(t, err)

workerTestHelper(t, lis, isolation, []string{
"pwd",
"test \"$(pwd)\" = \"/Volumes/My Shared Files/working-dir\"",
}, worker.WithUpstream(upstream))
}

func TestWorkerSecurity(t *testing.T) {
//nolint:gosec // this is a test, so it's fine to bind on 0.0.0.0
lis, err := net.Listen("tcp", "0.0.0.0:0")
Expand Down

0 comments on commit 56173b6

Please sign in to comment.