sending project content fails with non-local users
- Dominant language
- Go
- Stars
- 127
- Forks
- 81
- PR merge metrics
- No merged PRs in 30d
Description
Working on my shiny new Canonical-provided laptop, I noticed that `spread` was suddenly failing to send project contents to remote instances, failing with errors such as:
```
------
2025-04-16 08:36:44 Discarding lxd:ubuntu-24.10, cannot send project content:
-----
/bin/tar: src/main.rs: Cannot change ownership to uid 1994182092, gid 1595792306: Invalid argument
/bin/tar: src: Cannot change ownership to uid 1994182092, gid 1595792306: Invalid argument
/bin/tar: flake.lock: Cannot change ownership to uid 1994182092, gid 1595792306: Invalid argument
/bin/tar: ubuntu.yaml: Cannot change ownership to uid 1994182092, gid 1595792306: Invalid argument
...
```
The build used means I login to the laptop with my Google ID, rather than a local user in the `/etc/passwd` as usual.
I was able to make `spread` work in this context with a pretty small patch that runs tar with the `--no-same-owner` flag, but it's unclear to me whether this is a workable fix gloablly - either way this issue is likely to affect a lot of Canonical folk in the near future:
```diff
diff --git i/spread/client.go w/spread/client.go
index 3c4e25f..ba5e954 100644
--- i/spread/client.go
+++ w/spread/client.go
@@ -597,7 +597,7 @@ func (c *Client) Send(from, to string, include, exclude []string) error {
var stdout safeBuffer
session.Stdout = &stdout
- rcmd := fmt.Sprintf(`%s/bin/bash -c "mkdir -p '%s' && cd '%s' && /bin/tar -xz 2>&1"`, c.sudo(), to, to)
+ rcmd := fmt.Sprintf(`%s/bin/bash -c "mkdir -p '%s' && cd '%s' && /bin/tar --no-same-owner -xz 2>&1"`, c.sudo(), to, to)
err = c.runCommand(session, rcmd, &stdout, nil)
if err != nil {
return outputErr(stdout.Bytes(), err)
@@ -627,7 +627,7 @@ func (c *Client) SendTar(tar io.Reader, unpackDir string) error {
var stdout safeBuffer
session.Stdin = tar
session.Stdout = &stdout
- cmd := fmt.Sprintf(`%s/bin/bash -c "mkdir -p '%s' && cd '%s' && /bin/tar xz 2>&1"`, c.sudo(), unpackDir, unpackDir)
+ cmd := fmt.Sprintf(`%s/bin/bash -c "mkdir -p '%s' && cd '%s' && /bin/tar --no-same-owner -xz 2>&1"`, c.sudo(), unpackDir, unpackDir)
err = c.runCommand(session, cmd, &stdout, nil)
if err != nil {
return outputErr(stdout.Bytes(), err)
```
Thanks!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.