Skip to content

Tunnel interface overwrites existing files when creating Unix sockets #1140

Open

Description

@shizuku198411

Description

When a Host-to-Workshop tunnel is configured with a Unix socket endpoint, Workshop may overwrite an existing file at the specified path during launch.

This can cause unintended data loss, as the existing file is replaced with a Unix socket without any warning or error.

Steps to Reproduce

  1. Configure the tunnel in .workshop/dev.yaml:

    name: dev
    base: [email protected]
    
    sdks:
      - name: system
        plugs:
          probe:
            interface: tunnel
            endpoint: $HOME/workshop-tunnel-test/target.sock
    
      - name: project-socket-probe
  2. Define .workshop/socket-probe/sdk.yaml:

    name: socket-probe
    
    slots:
      probe:
        interface: tunnel
        endpoint: "@workshop-socket-probe"
  3. Create an existing regular file and launch Workshop:

    echo "SENTINEL" > target.sock
    stat -c '%F %n' target.sock
    # regular file target.sock
    
    workshop launch --verbose
    
    stat -c '%F %n' target.sock
    # socket target.sock    <- overwrited

Expected Behavior

Workshop should reject tunnel creation if the Unix socket endpoint path already exists, regardless of the existing file type, rather than overwriting it.

Proposed Fix

Validate the endpoint path using os.Lstat() before configuring the LXD proxy device.

  • Allow creation if the path does not exist.
  • Reject creation if the path already exists, including regular files, directories, symbolic links, and Unix sockets.
  • Return a clear error without modifying the existing file.

Verification

With the proposed fix, Workshop aborts launch with:

ERROR cannot create socket ".../target.sock": path already exists

The original file remains unchanged.

I have also verified that this fix does not affect the normal Workshop lifecycle. The start, stop, and refresh operations all continue to work as expected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions