saltstack / saltstack/salt

file module assumes it can do operations as salt user (root) then modify perms

Open
#45,067 17 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description of Issue/Question

file.managed is unable to write to a nfs mount

Setup

Create an nfs share, mount it on the minion.

file-on-nfs:
  file.managed:
    - name: /path/to/nfs/share/file-i-want-to-manage
    - source: salt://blah/files/file-i-want-to-manage.jinja
    - template: jinja
    - user: username
    - group: groupname
    - mode: 644
Steps to Reproduce Issue
  1. Create nfs share on one VM (or just use one you have)
  2. Mount nfs share on a second VM
  3. Check you can write manually with touch /path/to/nfs/share/test
  4. Try and manage file with salt
Errors
[INFO    ] Running state [/path/to/nfs/share/file-i-want-to-manage] at time 15:20:15.286419
[INFO    ] Executing state file.managed for [/path/to/nfs/share/file-i-want-to-manage]
[DEBUG   ] In saltenv 'base', looking at rel_path 'blah/files/file-i-want-to-manage.jinja' to resolve 'salt://blah/files/file-i-want-to-manage.jinja'
[DEBUG   ] In saltenv 'base', ** considering ** path /path/to/nfs/share/file-i-want-to-manage' to resolve 'salt://blah/files/file-i-want-to-manage.jinja'
[DEBUG   ] Fetching file from saltenv 'base', ** attempting ** 'salt://blah/files/file-i-want-to-manage.jinja'
[DEBUG   ] No dest file found
[INFO    ] Fetching file from saltenv 'base', ** done ** 'blah/files/file-i-want-to-manage.jinja'
[DEBUG   ] Jinja search path: ['/var/cache/salt/minion/files/base']
[DEBUG   ] Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/salt/states/file.py", line 2485, in managed
    **kwargs)
  File "/usr/lib/python2.7/site-packages/salt/modules/file.py", line 5051, in manage_file
    __opts__['cachedir'])
  File "/usr/lib/python2.7/site-packages/salt/utils/files.py", line 87, in copyfile
    tgt = mkstemp(prefix=bname, dir=dname)
  File "/usr/lib/python2.7/site-packages/salt/utils/files.py", line 51, in mkstemp
    return salt.utils.mkstemp(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/salt/utils/__init__.py", line 3491, in mkstemp
    fd_, fpath = tempfile.mkstemp(*args, **kwargs)
  File "/usr/lib64/python2.7/tempfile.py", line 304, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags)
  File "/usr/lib64/python2.7/tempfile.py", line 239, in _mkstemp_inner
    fd = _os.open(file, flags, 0600)
OSError: [Errno 13] Permission denied: '/path/to/nfs/share/file-i-want-to-manageiAn_w1'

[ERROR   ] Unable to manage file: [Errno 13] Permission denied: /path/to/nfs/share/file-i-want-to-manageAn_w1'
[INFO    ] Completed state [/path/to/nfs/share/file-i-want-to-manage] at time 15:20:15.327657 duration_in_ms=41.237

nfs mount details: 192.168.10.13:/nfs/blah on /path/to/nfs/share type nfs4 (rw,noatime,vers=4.1,rsize=32768,wsize=32768,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.10.14,lookupcache=pos,local_lock=none,addr=192.168.10.13)

To confirm, I am able to read/write/delete files on the nfs share with the user specified manually, it is only Salt unable to write.

Versions Report
Salt Version:
           Salt: 2017.7.0-n/a-5d719a2
 
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.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.5 (default, Aug  4 2017, 00:39:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: centos 7.4.1708 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-693.5.2.el7.x86_64
         system: Linux
        version: CentOS Linux 7.4.1708 Core

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 in salt/states/file.py and salt/modules/file.py, following the traceback into salt/utils/files.py and salt/utils/init.py. Reproduce file.managed against the described NFS mount, compare Salt's temporary-file handling with the successful manual operation, and verify that the managed file can be written with the requested user, group, and mode.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python
Domain
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.