Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider mounting with guests user/group ids on filesystem #20

Open
dustymabe opened this issue Apr 13, 2016 · 8 comments
Open

consider mounting with guests user/group ids on filesystem #20

dustymabe opened this issue Apr 13, 2016 · 8 comments

Comments

@dustymabe
Copy link
Owner

The vbox synced folder plugin detects the user's uid and gid and then sets those options when mounting the filesystem. We should consider doing something similar.

@hferentschik
Copy link
Contributor

Does that also imply that the matching user and group are creates on the VM? So for example, on my machine I have uid=501(hardy) gid=20(staff). What will the plugin do?

@dustymabe
Copy link
Owner Author

I don't believe so - it means that the folders will get mounted as the user that you are connecting to the vagrant box as. This is usually the 'vagrant' user, but could be something different depending on how you set up the box.

Here is the code from the vbox plugin that does this now:
https://github.com/mitchellh/vagrant/blob/a26742fc27c609d6eebe9a6d14584809ed1f88ea/plugins/providers/virtualbox/synced_folder.rb#L45-L48
and
https://github.com/mitchellh/vagrant/blob/a26742fc27c609d6eebe9a6d14584809ed1f88ea/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb#L11-L33

@hferentschik
Copy link
Contributor

it means that the folders will get mounted as the user that you are connecting to the vagrant box as. This is usually the 'vagrant' user

Ahh, ok. It is the vagrant user. Then it makes sense. +1 for this feature.

@hferentschik
Copy link
Contributor

Any ETA on this one?

@dustymabe
Copy link
Owner Author

Hey Hardy.. I don't have one right now. I had started to work on it, but other things got pushed to the foreground so I haven't revisited.

@nicobrevin
Copy link

@dustymabe do you have any code worth sharing? I might be able to finish it off for you. I was wondering where the best place would be for the uidmap and gidmap files, and the best way to get them on to the host, especially in the case that you're sharing your project dir with type sshfs

@dustymabe
Copy link
Owner Author

@nicobrevin I don't have anything on this right now.

@nicobrevin
Copy link

I've got this "working" with the following patch:

diff --git a/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb b/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb
index 4f2a23d..0a0382e 100644
--- a/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb
+++ b/lib/vagrant-sshfs/cap/guest/linux/sshfs_forward_mount.rb
@@ -198,7 +198,13 @@ module VagrantPlugins
 
           # The remote sshfs command that will run (in slave mode)
           sshfs_opts+= ' -o slave '
-          sshfs_cmd = "sudo -E sshfs :#{hostpath} #{expanded_guest_path}" 
+          # by supplying uid and gid options, we make sure the vagrant user can
+          # edit the files owned by the connecting user - with the side effect
+          # that some files will appear to be owned by you without actually
+          # being owned, resulting in permission denied errors.  idmap=file
+          # would fix this, but be more complex
+          sshfs_opts+= ' -o uid=\$(id -u) -o gid=\$(id -g)'
+          sshfs_cmd = "sudo -E sshfs :#{hostpath} #{expanded_guest_path}"
           sshfs_cmd+= sshfs_opts + ' ' + sshfs_opts_append + ' '
 
           # The ssh command to connect to guest and then launch sshfs

This works, although it makes every file and dir appear to be owned by the vagrant user, so mostly just a cosmetic fix - i.e. same permissions apply with or without this change. I suppose the better fix would by to supply an idmap=file and map only the vagrant user to your workstation user ... anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants