Issue Details (XML | Word | Printable)

Key: CHEF-216
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Adam Jacob
Reporter: Sean Cribbs
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Chef

Allow execute/script resources to set umask

Created: 13/Apr/09 04:14 PM   Updated: 19/Feb/10 05:56 PM   Resolved: 26/Apr/09 07:17 PM
Component/s: Resources
Affects Version/s: 0.5.6
Fix Version/s: 0.6.0


 Description  « Hide

It would be nice to set a umask on an execute or script resource so all affected files would be set with appropriate permissions.

-----------------
bigfleet: I'm working with a Rails app that needs both to be generated from a template and to have that RAILS_ROOT be chmod -R g+w (or the equivalent)
bigfleet: should I be doing that with a directory resource?
seancribbs: bigfleet: yep
bigfleet: Or execute?
seancribbs: bigfleet: make the directory first
bigfleet: OK, I do that
seancribbs: the rails generator shouldn't care
bigfleet: Right, OK, but the files that Rails generates, (e.g. public)
bigfleet: are not g+w
bigfleet: not out of the gate anyway
bigfleet: Just run the recipe again maybe?
seancribbs: you can run the generator as another user
bigfleet: I am doing that too
seancribbs: sounds good
seancribbs: bigfleet: set the umask when you run the command?
bigfleet: seancribbs: it would help if I knew how to do that, lol
seancribbs: bigfleet: not sure if Chef has that, checking
seancribbs: if not, you can run "umask 002 && command"
jtimberman: chef doesn't have a umask attribute for execute/script resources that I'm aware of.
seancribbs: yeah, go with the latter
bigfleet: Sweet, that's very cool
jtimberman: And open a ticket to add that feature?
seancribbs: jtimberman: we should definitely add that, yeah
seancribbs: jtimberman: i'll add ticket



Sort Order: Ascending order - Click to sort in descending order
Nuo Yan added a comment - 26/Apr/09 07:17 PM - edited

Fixed. Now the umask value can be set when executing command. String or Oct number can be used as parameter(i.e. '777' or 0777).

Example:

execute "create-mastodon" do
umask '777'
command "echo wewt > /mastodon_rocks_umask"
end

Code files modified:

chef/lib/chef/mixin/command.rb
chef/lib/chef/resource/execute.rb
chef/lib/chef/provider/execute.rb

Details:

  • Added args[:umask] condition in popen4 method in command.rb to handle umask argument.
  • Added @umask instance variable and umask() method in execute.rb resource
  • Added value assignment to command_args[:umask] in execute.rb provider

Test files modified:

features/execute_commands.feature
features/steps/files.rb
features/data/cookbooks/execute_commands/recipes/umask.rb

Details:

  • Added Scenario: Execute a command with umask value 777 to execute_commands.feature.
  • Added corresponding step definition in files.rb verifying that making copy of the file with umask value 777 should not succeed. And it will delete the temp file created by the recipe at the end to clean up.
  • Added umask.rb recipe to set umask to 777 and create text file at the hard drive root (/mastodon_rocks_umask).

Note: Currently absolute path is used in the recipe because both of the relative path and the tmpdir refer to locations in the OS tmp folder which cannot be used to test umask.


Nuo Yan added a comment - 26/Apr/09 07:22 PM

Please pull from nuoyan/chef/CHEF-216


Adam Jacob added a comment - 28/Apr/09 10:42 PM

Thanks for the ticket, Sean, and the fix, Nuo.

Pushed to opscode/master.