Jira (PUP-7394) Puppet::Util.replace_file cannot be used to create a read-only file (on non-Windows)

2 views
Skip to first unread message

Ethan Brown (JIRA)

unread,
Mar 23, 2017, 5:10:03 PM3/23/17
to puppe...@googlegroups.com
Ethan Brown created an issue
 
Puppet / Bug PUP-7394
Puppet::Util.replace_file cannot be used to create a read-only file (on non-Windows)
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2017/03/23 2:09 PM
Priority: Normal Normal
Reporter: Ethan Brown

Assuming a file does not yet exist, a call to FileUtils.replace_file like the following will fail:

Puppet::Util.replace_file('/tmp/foo', 0440) { |of| FileUtils.copy_stream(StringIO.new("\u1234"), of) }

With an error like:

Errno::EACCES: Permission denied @ rb_sysopen - /tmp/foo20170323-24678-rg0fn9
from /usr/local/opt/rbenv/versions/2.1.9/lib/ruby/2.1.0/fileutils.rb:494:in `initialize'

This is because the replace_file code will use permissions of an existing file should it exist, but will try to chmod a file *before* yielding it back in the block if it does not yet exist. Therefore it is impossible to create a new read-only file like you might normally with Ruby itself like:

File.open('/tmp/foo.txt', 'w+', 0440) { |fh| fh.write('hello world') }
# => 11

Also note that the code path on Windows is slightly different and does not exhibit the same problem.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Geoff Nichols (JIRA)

unread,
Mar 30, 2017, 1:08:02 PM3/30/17
to puppe...@googlegroups.com

Geoff Nichols (JIRA)

unread,
Mar 30, 2017, 1:10:02 PM3/30/17
to puppe...@googlegroups.com
Geoff Nichols updated an issue
Change By: Geoff Nichols
Sprint: Agent  Triage  Ready for Engineering

Geoff Nichols (JIRA)

unread,
Mar 30, 2017, 1:10:02 PM3/30/17
to puppe...@googlegroups.com

Ethan Brown (JIRA)

unread,
May 17, 2017, 1:13:04 PM5/17/17
to puppe...@googlegroups.com

Jorie Tappa (JIRA)

unread,
Dec 13, 2017, 5:16:02 PM12/13/17
to puppe...@googlegroups.com
Jorie Tappa assigned an issue to Jorie Tappa
Change By: Jorie Tappa
Assignee: Jorie Tappa
This message was sent by Atlassian JIRA (v7.0.2#70111-sha1:88534db)
Atlassian logo

Jorie Tappa (JIRA)

unread,
Jan 12, 2018, 5:19:03 PM1/12/18
to puppe...@googlegroups.com
Jorie Tappa updated an issue
Change By: Jorie Tappa
Fix Version/s: PUP 5.y
Fix Version/s: PUP 5.4.0

Jorie Tappa (JIRA)

unread,
Jan 16, 2018, 5:14:02 PM1/16/18
to puppe...@googlegroups.com
Jorie Tappa updated an issue
Change By: Jorie Tappa
Sub-team: Coremunity
Story Points: 3
Sprint: Platform Core KANBAN

Josh Cooper (JIRA)

unread,
Jan 17, 2018, 6:33:02 PM1/17/18
to puppe...@googlegroups.com

Melissa Stone (JIRA)

unread,
Jan 29, 2018, 5:09:03 PM1/29/18
to puppe...@googlegroups.com

Melissa Stone (JIRA)

unread,
Jan 30, 2018, 5:29:02 PM1/30/18
to puppe...@googlegroups.com
Melissa Stone commented on Bug PUP-7394
 
Re: Puppet::Util.replace_file cannot be used to create a read-only file (on non-Windows)

I manually verified this code change in both windows and non-windows, and it is behaving as expected

Kenn Hussey (JIRA)

unread,
Feb 5, 2018, 10:31:03 AM2/5/18
to puppe...@googlegroups.com
Kenn Hussey commented on Bug PUP-7394

Jorie Tappa please add release notes for this issue, if needed. Thanks!

This message was sent by Atlassian JIRA (v7.5.1#75006-sha1:7df2574)
Atlassian logo

Jorie Tappa (JIRA)

unread,
Feb 5, 2018, 2:46:02 PM2/5/18
to puppe...@googlegroups.com
Jorie Tappa updated an issue
Change By: Jorie Tappa
Release Notes Summary: When replacing an existing file, Puppet::Util.replace_file would set the temp file's permissions to be that of the existing file or the provided default permissions. This was done originally because the temp file was created with insecure file permissions, but using the existing file's mode meant that Puppet couldn't write to the temporary file if the file it was trying to replace was read-only. This is no longer necessary, because Puppet::FileSystem::Uniquefile creates temporary files with mode 0600.
Release Notes: Bug Fix

John Duarte (JIRA)

unread,
Oct 21, 2019, 10:50:05 AM10/21/19
to puppe...@googlegroups.com
John Duarte updated an issue
Change By: John Duarte
QA Risk Assessment: Needs Assessment No Action
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages