Skip to content

Commit 8db2baa

Browse files
authored
Merge pull request #43 from AkihiroSuda/dev-sshfs
Fix "Mounted filesystems not accessible by root"
2 parents a2a292b + 4fc6979 commit 8db2baa

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

pkg/cidata/user-data.TEMPLATE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ write_files:
9292
dnf install -y shadow-utils
9393
{{- end}}
9494
fi
95+
# Modify /etc/fuse.conf to allow "-o allow_root"
96+
{{- if .Mounts }}
97+
if ! grep -q "^user_allow_other" /etc/fuse.conf ; then
98+
echo "user_allow_other" >> /etc/fuse.conf
99+
fi
100+
{{- end}}
95101
owner: root:root
96102
path: /var/lib/cloud/scripts/per-boot/10-install-packages.boot.sh
97103
permissions: '0755'

pkg/hostagent/mount.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func (a *HostAgent) setupMount(ctx context.Context, m limayaml.Mount) (*mount, e
4848
Port: a.y.SSH.LocalPort,
4949
RemotePath: expanded,
5050
Readonly: !m.Writable,
51+
// NOTE: allow_root requires "user_allow_other" in /etc/fuse.conf
52+
SSHFSAdditionalArgs: []string{"-o", "allow_root"},
5153
}
5254
if err := rsf.Prepare(); err != nil {
5355
return nil, errors.Wrapf(err, "failed to prepare reverse sshfs for %q", expanded)

pkg/hostagent/requirements.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package hostagent
22

33
import (
44
"context"
5-
"github.com/AkihiroSuda/lima/pkg/limayaml"
65
"time"
76

7+
"github.com/AkihiroSuda/lima/pkg/limayaml"
88
"github.com/AkihiroSuda/sshocker/pkg/ssh"
99
"github.com/hashicorp/go-multierror"
1010
"github.com/pkg/errors"
@@ -83,6 +83,18 @@ Also see "/var/log/cloud-init-output.log" in the guest.
8383
A possible workaround is to run "apt-get install sshfs" in the guest.
8484
`,
8585
})
86+
req = append(req, requirement{
87+
description: "/etc/fuse.conf to contain \"user_allow_other\"",
88+
script: `#!/bin/bash
89+
set -eux -o pipefail
90+
if ! timeout 30s bash -c "until grep -q ^user_allow_other /etc/fuse.conf; do sleep 3; done"; then
91+
echo >&2 "/etc/fuse.conf is not updated to contain \"user_allow_other\""
92+
exit 1
93+
fi
94+
`,
95+
debugHint: `Append "user_allow_other" to /etc/fuse.conf in the guest`,
96+
})
97+
8698
}
8799
req = append(req, requirement{
88100
description: "the guest agent to be running",

0 commit comments

Comments
 (0)