Skip to content

Commit

Permalink
Add owner, group and mode parameters for file
Browse files Browse the repository at this point in the history
This allows a user to set the owner, group and mode for the file that gets
created. By default this sets it in a more secure fashion but not making it
world readable.

Signed-off-by: Lance Albertson <lance@osuosl.org>
  • Loading branch information
ramereth committed Sep 28, 2020
1 parent ec90954 commit d8d2e91
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This file is used to list changes made in each version of the htpasswd cookbook.
- Support for 'plaintext' type [\#32](https://github.com/sous-chefs/htpasswd/pull/32)
- Adoption by Sous-Chefs [\#40](https://github.com/sous-chefs/htpasswd/pull/40)
- Add delete and overwrite test-kitchen suites
- Add owner, group and mode parameters for file

### Changed

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ This cookbook requires Chef Infra >= 14.
- :password: Password for the user
- :type: Password algorithm to use. Valid options are: "md5", "bcrypt", "sha1", "plaintext", or "crypt". Default is
"md5"
- :owner: User which owns the file. Default is `root`.
- :group: Group which owns the file. Default is `root`.
- :mode: File mode for the file. Default is `0640`.

### Example

Expand Down
8 changes: 8 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ module Cookbook
module Helpers
private

def fix_perms(new_resource)
file new_resource.name do
owner new_resource.owner
group new_resource.group
mode new_resource.mode
end
end

def htpasswd_user_exists?(new_resource)
!user_entry(new_resource).nil?
end
Expand Down
6 changes: 6 additions & 0 deletions resources/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
property :type, String,
equal_to: %w(md5 bcrypt sha1 plaintext crypt),
default: 'md5'
property :owner, String, default: 'root'
property :group, String, default: 'root'
property :mode, String, default: '0640'

action :add do
unless htpasswd_user_set?(@new_resource)
Expand All @@ -20,12 +23,14 @@
end
end
end
fix_perms(new_resource)
end

action :overwrite do
converge_by("Overwrite file #{@new_resource.name} with user #{@new_resource.user}") do
htpasswd_create(@new_resource)
end
fix_perms(new_resource)
end

action :delete do
Expand All @@ -34,4 +39,5 @@
htpasswd_delete(@new_resource)
end
end
fix_perms(new_resource)
end

0 comments on commit d8d2e91

Please sign in to comment.