Skip to content

Commit 9c05082

Browse files
Szymon Szypulskidamacus
Szymon Szypulski
authored andcommitted
Add option to set haproxy.cfg chmod (sous-chefs#266)
Currently, default chmod is used (0644). Since haproxy.cfg can contain sensitive data, it is a good idea to give an operator option to pick what suits him. By default, it still will be 0644, with an option to change it using resource attribute. In addition, I have added sensitive true to haproxy.cfg template.
1 parent e663f32 commit 9c05082

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Installs and configures haproxy.
2121

2222
```ruby
2323
haproxy_install 'package' do
24-
24+
conf_file_mode '0640'
2525
end
2626
```
2727

resources/install.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
property :install_type, String, name_property: true, equal_to: %w(package source)
22
property :conf_template_source, String, default: 'haproxy.cfg.erb'
33
property :conf_cookbook, String, default: 'haproxy'
4+
property :conf_file_mode, String, default: '0644'
45
property :bin_prefix, String, default: '/usr'
56
property :config_dir, String, default: '/etc/haproxy'
67
property :config_file, String, default: lazy { ::File.join(config_dir, 'haproxy.cfg') }
@@ -111,7 +112,8 @@
111112
template new_resource.config_file do
112113
owner new_resource.haproxy_user
113114
group new_resource.haproxy_group
114-
mode '0644'
115+
mode new_resource.conf_file_mode
116+
sensitive true
115117
source lazy { node.run_state['haproxy']['conf_template_source'][config_file] }
116118
cookbook lazy { node.run_state['haproxy']['conf_cookbook'][config_file] }
117119
unless new_resource.install_only

test/integration/package/package_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
it { should exist }
88
end
99

10+
describe file '/etc/haproxy/haproxy.cfg' do
11+
its(:mode) { should cmp '0644' }
12+
end
13+
1014
describe service 'haproxy' do
1115
it { should be_installed }
1216
it { should be_enabled }

test/integration/source/source_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
it { should exist }
44
end
55

6+
describe file '/etc/haproxy/haproxy.cfg' do
7+
its(:mode) { should cmp '0644' }
8+
end
9+
610
describe service 'haproxy' do
711
it { should be_installed }
812
it { should be_enabled }

0 commit comments

Comments
 (0)