Skip to content

Commit 13597fe

Browse files
committed
f configure chown csr_attributes.yaml on server
1 parent cde4aed commit 13597fe

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-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: 24 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.
@@ -55,6 +68,17 @@ def write_csr_attributes(csr_attributes, etc_puppet_path = '/etc/puppetlabs/pupp
5568
File.open(csr_attributes_path, 'w', perm: 0o640) do |f|
5669
f.write(csr_attributes_contents)
5770
end
71+
# File.chown ignores nils, so if the puppet user/group do not
72+
# exist, nothing is done, and the file remains root:root
73+
# which is correct for the agent.
74+
#
75+
# This chown is only important on the node running openvox-server
76+
# (this package creates the puppet user), as puppetserver may
77+
# otherwise choke on first startup because the file
78+
# can't be read during its ca bootstrap. (I think because
79+
# puppetserver runs as the puppet user and is calling puppet ssl
80+
# at some point.)
81+
File.chown(puppet_uid, puppet_gid, csr_attributes_path)
5882

5983
{
6084
csr_attributes: {

0 commit comments

Comments
 (0)