Skip to content

Commit 5c81edb

Browse files
committed
webhook: Make service user configureable
1 parent a0bbea9 commit 5c81edb

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,14 @@ class { 'r10k::webhook':
585585

586586
### Ignore deploying some environments
587587

588-
Webhook Go does not support this yet, but will in the future.
588+
Since [2.10.0](https://github.com/voxpupuli/webhook-go/releases/tag/v2.10.0) the webhook has support for ignoring certain branches.
589+
This is not yet configureable via the puppet module.
590+
591+
### configuring the webservice/deploy user
592+
593+
For historic reasons, webhook-go runs as root and executes r10k with the same user.
594+
Via `r10k::webhook::service_user` you can change the user.
595+
With the 15.0.0 release the default will switch from root to puppet.
589596

590597
## Reference
591598

REFERENCE.md

+9
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ install and configure the webhook-go package as local webhook receiver to trigge
525525

526526
The following parameters are available in the `r10k::webhook` class:
527527

528+
* [`service_user`](#-r10k--webhook--service_user)
528529
* [`install_method`](#-r10k--webhook--install_method)
529530
* [`ensure`](#-r10k--webhook--ensure)
530531
* [`version`](#-r10k--webhook--version)
@@ -539,6 +540,14 @@ The following parameters are available in the `r10k::webhook` class:
539540
* [`r10k`](#-r10k--webhook--r10k)
540541
* [`config`](#-r10k--webhook--config)
541542

543+
##### <a name="-r10k--webhook--service_user"></a>`service_user`
544+
545+
Data type: `Optional`
546+
547+
the user that should run the service
548+
549+
Default value: `undef`
550+
542551
##### <a name="-r10k--webhook--install_method"></a>`install_method`
543552

544553
Data type: `Enum['package', 'repo', 'none']`

manifests/webhook.pp

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# @summary install and configure the webhook-go package as local webhook receiver to trigger r10k runs
22
#
3+
# @param service_user the user that should run the service
34
# @param install_method
45
# how the package should be installed
56
# @param ensure
@@ -16,6 +17,7 @@
1617
# @param config
1718
#
1819
class r10k::webhook (
20+
Optional $service_user = undef,
1921
Enum['package', 'repo', 'none'] $install_method = 'package',
2022
Boolean $ensure = false,
2123
String[1] $version = '2.10.0',

manifests/webhook/config.pp

+3
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
ensure => $r10k::webhook::config_ensure,
88
path => $r10k::webhook::config_path,
99
content => stdlib::to_yaml($r10k::webhook::config),
10+
owner => 'root',
11+
group => 'root',
12+
mode => '0644',
1013
}
1114
}

manifests/webhook/service.pp

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
#
33
#
44
class r10k::webhook::service () {
5-
service { 'webhook-go':
5+
service { 'webhook-go.service':
66
ensure => $r10k::webhook::service_ensure,
77
enable => $r10k::webhook::service_enabled,
88
}
9+
if $r10k::webhook::service_user {
10+
systemd::dropin_file { 'user.conf':
11+
unit => 'webhook-go.service',
12+
content => "[Service]\nUser=${r10k::webhook::service_user}\n",
13+
}
14+
}
915
}

spec/acceptance/r10k_webhook_spec.rb

+40
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,44 @@ class { 'r10k': }
3535
its(:stdout) { is_expected.to match(%r{webhook-go}) }
3636
end
3737
end
38+
39+
context 'with service_user = puppet' do
40+
it_behaves_like 'an idempotent resource' do
41+
let(:manifest) do
42+
<<-PUPPET
43+
user { 'puppet':
44+
ensure => 'present',
45+
}
46+
-> group { 'puppet':
47+
ensure => 'present',
48+
}
49+
-> class { 'r10k': }
50+
-> class { 'r10k::webhook':
51+
service_user => 'puppet',
52+
}
53+
PUPPET
54+
end
55+
end
56+
57+
describe package('webhook-go') do
58+
it { is_expected.to be_installed }
59+
end
60+
61+
describe file('/etc/voxpupuli/webhook.yml') do
62+
it 'exists' do
63+
expect(subject).to exist
64+
expect(subject).to be_owned_by 'root'
65+
expect(subject).to be_grouped_into 'root'
66+
end
67+
end
68+
69+
describe service('webhook-go') do
70+
it { is_expected.to be_enabled }
71+
it { is_expected.to be_running }
72+
end
73+
74+
describe command('systemctl cat webhook-go') do
75+
its(:stdout) { is_expected.to match(%r{User=puppet}) }
76+
end
77+
end
3878
end

spec/classes/webhook_spec.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
it { is_expected.to contain_class('r10k::webhook::service') }
1919
it { is_expected.to contain_class('r10k::webhook::config') }
2020
it { is_expected.to contain_package('webhook-go').with_ensure('present') }
21-
it { is_expected.to contain_service('webhook-go').with_ensure('running') }
21+
it { is_expected.to contain_service('webhook-go.service').with_ensure('running') }
2222
end
2323
end
2424

@@ -106,7 +106,8 @@
106106
it { is_expected.to contain_class('r10k::webhook::service') }
107107
it { is_expected.to contain_class('r10k::webhook::config') }
108108
it { is_expected.to contain_package('webhook-go').with_ensure('present') }
109-
it { is_expected.to contain_service('webhook-go').with_ensure('running') }
109+
it { is_expected.to contain_service('webhook-go.service').with_ensure('running') }
110+
it { is_expected.not_to contain_systemd__dropin_file('user.conf') }
110111
it { is_expected.to contain_file('webhook.yml').with_content(content) }
111112

112113
if os_facts[:os]['family'] == 'RedHat'
@@ -126,6 +127,18 @@
126127

127128
it { is_expected.to compile.with_all_deps }
128129
end
130+
131+
context 'with service_user = puppet' do
132+
let :params do
133+
super().merge({ service_user: 'puppet' })
134+
end
135+
136+
if %w[archlinux-rolling-x86_64 archlinux-6-x86_64 gentoo-2-x86_64].include?(os)
137+
it { is_expected.not_to compile }
138+
else
139+
it { is_expected.to contain_systemd__dropin_file('user.conf').with_content("[Service]\nUser=puppet\n") }
140+
end
141+
end
129142
end
130143
end
131144
end

0 commit comments

Comments
 (0)