Skip to content

Commit 809a156

Browse files
committed
(gh-26) Chown csr_attributes.yaml puppet:puppet on server
File.chown ignores nils, so if the puppet user/group do not exist, nothing is done, and the file remains root:root which is correct for the agent. This chown is only important on the node running openvox-server , as puppetserver may otherwise choke on first startup because the file can't be read during its ca bootstrap. (I think because puppetserver runs as the puppet user and is calling puppet ssl at some point.) Note that it is the openvox-server package that creates the puppet user/group at install.
1 parent f8d9cad commit 809a156

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22
# frozen_string_literal: true
33

44
require_relative '../lib/openvox_bootstrap/task'
5+
require 'etc'
56
require 'open3'
67
require 'yaml'
78

89
module OpenvoxBootstrap
910
class Configure < Task
11+
def puppet_uid
12+
Etc.getpwnam('puppet').uid
13+
rescue ArgumentError
14+
nil
15+
end
16+
17+
def puppet_gid
18+
Etc.getgrnam('puppet').gid
19+
rescue ArgumentError
20+
nil
21+
end
22+
1023
# Overwrite puppet.conf with the values in the puppet_conf hash.
1124
#
1225
# Does nothing if given an empty or nil puppet_conf.
@@ -42,6 +55,9 @@ def write_puppet_conf(puppet_conf, etc_puppet_path = '/etc/puppetlabs/puppet')
4255
# Does nothing if given an empty or nil csr_attributes.
4356
#
4457
# The file will be mode 640.
58+
# It will either be owned root:root (assuming task is run as root,
59+
# as expected), or puppet:puppet if the puppet user and group
60+
# exist (openvox-server package is installed).
4561
#
4662
# @param csr_attributes [Hash] A hash of custom_attributes
4763
# and extension_requests to write to the csr_attributes.yaml
@@ -55,6 +71,8 @@ def write_csr_attributes(csr_attributes, etc_puppet_path = '/etc/puppetlabs/pupp
5571
File.open(csr_attributes_path, 'w', perm: 0o640) do |f|
5672
f.write(csr_attributes_contents)
5773
end
74+
# nil uid/gid are ignored by FileUtils.chown...
75+
File.chown(puppet_uid, puppet_gid, csr_attributes_path)
5876

5977
{
6078
csr_attributes: {

0 commit comments

Comments
 (0)