Skip to content

Commit 01086a1

Browse files
committed
f configure chown csr_attributes.yaml on server
1 parent cde4aed commit 01086a1

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

spec/tasks/configure_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,33 @@
5959
end
6060
end
6161

62+
def check_returned_id(uid_or_gid)
63+
case uid_or_gid
64+
when Integer
65+
uid_or_gid > 0
66+
when nil
67+
true # If the user does not exist, it returns nil.
68+
else
69+
false # Should not return anything else.
70+
end
71+
end
72+
73+
describe '#puppet_uid' do
74+
it 'returns the UID of the puppet user' do
75+
expect(task.puppet_uid).to satisfy do |uid|
76+
check_returned_id(uid)
77+
end
78+
end
79+
end
80+
81+
describe '#puppet_gid' do
82+
it 'returns the GID of the puppet group' do
83+
expect(task.puppet_gid).to satisfy do |gid|
84+
check_returned_id(gid)
85+
end
86+
end
87+
end
88+
6289
describe '#write_csr_attributes' do
6390
let(:csr_attributes) do
6491
{

tasks/configure.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77

88
module OpenvoxBootstrap
99
class Configure < Task
10+
def puppet_uid
11+
Etc.getpwnam('puppet').uid
12+
rescue ArgumentError
13+
nil
14+
end
15+
16+
def puppet_gid
17+
Etc.getgrnam('puppet').gid
18+
rescue ArgumentError
19+
nil
20+
end
21+
1022
# Overwrite puppet.conf with the values in the puppet_conf hash.
1123
#
1224
# Does nothing if given an empty or nil puppet_conf.
@@ -55,6 +67,15 @@ def write_csr_attributes(csr_attributes, etc_puppet_path = '/etc/puppetlabs/pupp
5567
File.open(csr_attributes_path, 'w', perm: 0o640) do |f|
5668
f.write(csr_attributes_contents)
5769
end
70+
# File.chown ignores nils, so if the puppet user/group don't
71+
# exist, nothing is done, and the file remains root:root
72+
# which is fine for the agent. This chown is only important
73+
# on the node running openvox-server, as puppetserver may
74+
# otherwise choke on first startup because the file
75+
# can't be read during its ca bootstrap. (I think because
76+
# puppetserver runs as the puppet user and is calling puppet ssl
77+
# at some point.)
78+
File.chown(puppet_uid, puppet_gid, csr_attributes_path)
5879

5980
{
6081
csr_attributes: {

0 commit comments

Comments
 (0)