1

When I put in top.sls this:

/var/www:
  file.directory:
    - user: {{ pillar['user'] }}
    - group: www-data
    - mode: 755
    - makedirs: True

It creates "/var/www" dir with permissions which are defined and that is ok. So basically chown is: user:www-data

But when I try to mount that folder to my Mac then problem show up. owner and group are-> 501:dialout

Here is code which I use:

/var/www:
{% if pillar['sshfs_www'] %}
    file.directory:
    - mode: 755
    - follow_symlinks: False
    - group: www-data
    - makedirs: True

    mount:
    - user: {{ pillar['user'] }}
    - mounted
    - device: sshfs#{{ pillar['sshfs_www'] }}
    - fstype: fuse
    - opts: nonempty,allow_other,auto
{% else %}
    file.directory:
    - mode: 755
    - group: www-data
    - makedirs: True
{% endif %}

Not only that user and group are not set as I set, I get error: Failed to change user to myuser

How can I mount with my user and group?

Thank you

tarleb
  • 19,863
  • 4
  • 51
  • 80
iWizard
  • 6,816
  • 19
  • 67
  • 103

2 Answers2

1

I hope this will help other users to solve their problem with permissions when mounting with salt:

So here how I solved that.

First I manually setup id for user and group:

{{ pillar['user'] }}:
  user.present:    
    - shell: /bin/bash
    - home: /home/{{ pillar['user'] }}
    - require_in:
    - uid: 4000
    - gid: 4000
    - file: /home/{{ pillar['user'] }}/.ssh/id_rsa
    - file: /home/{{ pillar['user'] }}/.ssh/authorized_keys

www-data:
  group.present:
    - gid: 4000
    - system: True
    - members:
      - {{ pillar['user'] }}

After that in part where is mount, I defined uid and gid with this part: uid=4000,gid=4000

/var/www:
{% if pillar['sshfs_www'] %}
    mount:
    - user: {{ pillar['user'] }}
    - mounted
    - device: sshfs#{{ pillar['sshfs_www'] }}
    - fstype: fuse
    - opts: nonempty,allow_other,auto,uid=4000,gid=4000
{% else %}
    file.directory:
    - mode: 755
    - group: www-data
    - makedirs: True
{% endif %}
iWizard
  • 6,816
  • 19
  • 67
  • 103
0

Citing Sven from a serverfail answer:

You can't. That's a limitation of SSHFS/Fuse: Everything is mapped to the permission of the user you use to connect with SSH by default.

However, it appears you can work around this a bit with idmap files, see the options -o idmap, -o uidfile, -o gidfile and -o nomap in the man page.

Community
  • 1
  • 1
tarleb
  • 19,863
  • 4
  • 51
  • 80