Jira (PUP-8983) validate_cmd creates tmp file with inconsistent permissions

6 views
Skip to first unread message

john (JIRA)

unread,
Jul 5, 2018, 12:56:02 PM7/5/18
to puppe...@googlegroups.com
john created an issue
 
Puppet / Bug PUP-8983
validate_cmd creates tmp file with inconsistent permissions
Issue Type: Bug Bug
Assignee: Unassigned
Components: Types and Providers
Created: 2018/07/05 9:55 AM
Priority: Normal Normal
Reporter: john

Puppet Version: 5.5.0
Puppet Server Version: NA
OS Name/Version: Linux & Mc OSX confirmed

When the validate_cmd runs it creates a temporary file however the permissions it assigns to this temporary file are not related to the permissions defined on the file type object. 

Desired Behaviour:

The temporary file used when running the validate command should have the exact same permissions as the file resources it is trying to create.  e.g. 

with a file type of

file {'/tmp/test':
   owner => 'foo',
   group => 'bar',
   mode  => '0555',
   validate_cmd => 'test -x %'
}

the tmpe file created should have `foo:bar 0555` permissions

Actual Behavior:

I have observed the following behaviour.

  • tmp files are always created with permissions `0600`
  • if the file being managed does not exist the tmp file is owned by root
  • if the file being managed the tmp file uses has the same owner as the file being managed on disk

 
the following runs a loop to detect the how the tmp file is created.  the tests use the folloing manifest file

file {'/tmp/test/test':
  ensure => file,
  owner => 'jbond',
  group => 'jbond',
  content => 'foobar',
  validate_cmd => '/bin/false ',
}

output when `/tmp/test/test` doesn't exist

root@dev:~# ls -la /tmp/test/
total 8
drwxr-xr-x  2 root root 4096 Jul  5 16:40 .
drwxrwxrwt 11 root root 4096 Jul  5 16:41 ..
root@dev01.l:~# while true ; do ls -l /tmp/test/ | grep test ; done
-rw------- 1 root root 6 Jul  5 16:41 test20180705-24634-jluwct

output when file exists with correct permissions

root@dev01.l:~# ls -la /tmp/test/test
-rw-r--r-- 1 jbond jbond 0 Jul  5 16:42 /tmp/test/test
root@dev:~# while true ; do ls -l /tmp/test/ | grep test | egrep -v 'test$'; done
-rw------- 1 jbond jbond 6 Jul  5 16:43 test20180705-5929-sdmjsa
 

output when file exists with correct incorrect permissions

root@dev~# chown nsd:nsd /tmp/test/test
root@dev:~# ls -la !$
ls -la /tmp/test/test
-rw-r--r-- 1 nsd nsd 0 Jul  5 16:42 /tmp/test/test
root@dev:~# while true ; do ls -l /tmp/test/ | grep test | egrep -v 'test$'; done
-rw------- 1 nsd nsd 6 Jul  5 16:43 test20180705-22012-13alhap

This causes problems when the validate command drops previlages or needs to run as a specific user.  An example of this is  using `/usr/lib/quagga/bgpd` to validate quagga files.  The command by default drops privileges to the quagga user before reading the config file.  if the file is owned by anything other then quagga then the validate command fails.  

 

  • note the bgpd command does take a user parameter so you can run the tests as the root user.  however bgpd still drops privileges to the root user and when it does so it does so without `CAP_DAV_OVERRIDE`.  meaning that even the root user can only validate files owned by root

 

 

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

john (JIRA)

unread,
Jul 5, 2018, 3:01:02 PM7/5/18
to puppe...@googlegroups.com
john commented on Bug PUP-8983
 
Re: validate_cmd creates tmp file with inconsistent permissions

re-ran the tests specifying a mode on the file type on the results are the same, i.e. the mode of the temp file is not set to the `should` state

file {'/tmp/test/test':
  ensure => file,
  owner => 'jbond',
  group => 'jbond',
  mode => '0555',
  content => 'foobar',
  validate_cmd => '/bin/false ',
}

root@dev:~# while true ; do ls -l /tmp/test/ | grep test ; done
-rw------- 1 root root 6 Jul  5 18:53 test20180705-18902-1r3rv8u
root@dev:~# touch /tmp/test/test
root@dev:~# chown jbond:jbond !$
chown jbond:jbond /tmp/test/test
root@dev:~# while true ; do ls -l /tmp/test/ | grep test | egrep -v 'test$' ; done
-rw------- 1 root  root  0 Jul  5 18:57 test20180705-27813-1ru0o33
-rw------- 1 jbond jbond 6 Jul  5 18:57 test20180705-27813-1ru0o33
root@dev:~# chown nsd:nsd /tmp/test/test
root@dev:~# while true ; do ls -l /tmp/test/ | grep test | egrep -v 'test$' ; done
-rw------- 1 nsd nsd 6 Jul  5 18:58 test20180705-25855-128546l

john (JIRA)

unread,
Jul 5, 2018, 5:01:07 PM7/5/18
to puppe...@googlegroups.com
john commented on Bug PUP-8983

have attempted a fix[1] for this.  It is not a complete fix as the mode is not maintained.  Further the uid/gid of the file on disk still takes preference over the `should` values.

 

 

[1]https://github.com/puppetlabs/puppet/pull/6908

Josh Cooper (JIRA)

unread,
Jul 12, 2018, 4:35:02 PM7/12/18
to puppe...@googlegroups.com

Melissa Stone (JIRA)

unread,
Apr 3, 2019, 6:47:03 PM4/3/19
to puppe...@googlegroups.com

Melissa Stone (JIRA)

unread,
Apr 3, 2019, 6:48:02 PM4/3/19
to puppe...@googlegroups.com
Melissa Stone updated an issue
Change By: Melissa Stone
Sprint: Platform Core KANBAN
Component/s: Community

Josh Cooper (JIRA)

unread,
Apr 30, 2019, 6:19:03 PM4/30/19
to puppe...@googlegroups.com
Josh Cooper assigned an issue to Jacob Helwig
Change By: Josh Cooper
Assignee: Melissa Stone Jacob Helwig

Josh Cooper (JIRA)

unread,
May 1, 2019, 2:35:02 PM5/1/19
to puppe...@googlegroups.com

Josh Cooper (JIRA)

unread,
May 1, 2019, 2:56:54 PM5/1/19
to puppe...@googlegroups.com

Jacob Helwig (JIRA)

unread,
May 1, 2019, 4:26:02 PM5/1/19
to puppe...@googlegroups.com
Jacob Helwig updated an issue
 
Change By: Jacob Helwig
Release Notes Summary: If there is a `validate_cmd` for a File resource, the command will be run with the temporary after the temporary file has had the final permissions set (on POSIX platforms).
Release Notes: Bug Fix

Heston Hoffman (JIRA)

unread,
Jun 11, 2019, 8:19:03 PM6/11/19
to puppe...@googlegroups.com

Mark Nejedlo (JIRA)

unread,
Sep 27, 2019, 9:53:02 AM9/27/19
to puppe...@googlegroups.com
Mark Nejedlo commented on Bug PUP-8983
 
Re: validate_cmd creates tmp file with inconsistent permissions

Please backport this change to puppet-agent 5.5.x

Josh Cooper (JIRA)

unread,
Sep 30, 2019, 3:41:05 PM9/30/19
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages