saltstack / saltstack/salt

Impossible to run Salt SSH as unprivileged user

Open
#55,825 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description of Issue

It is impossible to run Salt SSH as unprivileged user.
Instructions at https://docs.saltstack.com/en/latest/topics/ssh/#running-salt-ssh-as-non-root-user say it should be possible by specifying writable cachedir and pki_dir, but it is not. Following these instructions result in

PermissionError: [Errno 13] Permission denied: '/var/cache/salt'
Setup

As described in docs I've created following Saltfile:

salt-ssh:
  pki_dir: /tmp/pki
  cachedir: /tmp/cache
  ssh_log_file: /tmp/salt-ssh.log
  roster_file: /tmp/roster
Steps to Reproduce Issue
  1. Create Saltfile pointing to writable dirs (like above)
  2. Run salt-ssh -c . \* test.ping in directory with this Saltfile as unprivileged user.
  3. Receive
[ERROR   ] Unable to render roster file: Traceback (most recent call last):
  File "/tmp/lib/python3.7/site-packages/salt/utils/templates.py", line 169, in render_tmpl
    output = render_str(tmplstr, context, tmplpath)
  File "/tmp/lib/python3.7/site-packages/salt/utils/templates.py", line 309, in render_jinja_tmpl
    loader = salt.utils.jinja.SaltCacheLoader(opts, saltenv, pillar_rend=context.get('_pillar_rend', False))
  File "/tmp/lib/python3.7/site-packages/salt/utils/jinja.py", line 89, in __init__
    self.file_client()
  File "/tmp/lib/python3.7/site-packages/salt/utils/jinja.py", line 102, in file_client
    cached_client = salt.fileclient.get_file_client(self.opts, self.pillar_rend)
  File "/tmp/lib/python3.7/site-packages/salt/fileclient.py", line 63, in get_file_client
    }.get(client, RemoteClient)(opts)
  File "/tmp/lib/python3.7/site-packages/salt/fileclient.py", line 1392, in __init__
    self.channel = salt.fileserver.FSChan(opts)
  File "/tmp/lib/python3.7/site-packages/salt/fileserver/__init__.py", line 886, in __init__
    self.fs.update()
  File "/tmp/lib/python3.7/site-packages/salt/fileserver/__init__.py", line 503, in update
    self.servers[fstr]()
  File "/tmp/lib/python3.7/site-packages/salt/fileserver/roots.py", line 195, in update
    os.makedirs(mtime_map_path_dir)
  File "/usr/lib/python3.7/os.py", line 211, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.7/os.py", line 211, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/lib/python3.7/os.py", line 221, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/var/cache/salt'

So if these steps are not enough to run salt-ssh as unprivileged user I thinks docs should be updated accordingly to mention extra required settings and not be so confusing. Alternatively salt-ssh behaviour should be updated to respect settings from Saltfile.

Versions Report

Salt Version:
Salt: 2019.2.2

Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.10.3
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.6.2
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: Not Installed
pycryptodome: Not Installed
pygit2: Not Installed
Python: 3.7.3 (default, Oct 7 2019, 12:56:13)
python-gnupg: Not Installed
PyYAML: 3.13
PyZMQ: Not Installed
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.3
ZMQ: Not Installed

System Versions:
dist: Ubuntu 19.04 disco
locale: UTF-8
machine: x86_64
release: 5.0.0-38-generic
system: Linux
version: Ubuntu 19.04 disco

(Latest version from PyPi)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Salt SSH configuration loading path and the traceback locations in salt/fileserver/roots.py and salt/fileserver/init.py; compare the Saltfile settings with the paths used during roster rendering. Reproduce the command with the writable pki_dir and cachedir from the issue, then determine whether the expected fix is honoring those settings or clarifying the documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.