Skip to content

Commit a91d6f2

Browse files
committed
feat: Add support for vault agent
1 parent 6889893 commit a91d6f2

File tree

7 files changed

+27
-10
lines changed

7 files changed

+27
-10
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ Please see [The official documentation](https://www.vaultproject.io/docs/configu
5454

5555
* `service_provider`: Customise the name of the system service provider; this also controls the init configuration files that are installed.
5656

57-
* `service_options`: Extra argument to pass to `vault server`, as per: `vault server --help`
57+
* `service_type`: Choose between `server` or `agent` for which mode you want the Vault binary to run as.
58+
59+
* `service_options`: Extra argument to pass to `vault`, e.g., `vault server --help` or `vault agent --help`
5860

5961
* `num_procs`: Sets the `GOMAXPROCS` environment variable, to determine how many CPUs Vault can use. The official Vault Terraform install.sh script sets this to the output of ``nprocs``, with the comment, "Make sure to use all our CPUs, because Vault can block a scheduler thread". Default: number of CPUs on the system, retrieved from the ``processorcount`` fact.
6062

manifests/init.pp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@
4747
# Customise the name of the system service provider; this
4848
# also controls the init configuration files that are installed.
4949
#
50+
# * `service_type`
51+
# Choose between `server` or `agent` for which mode you want the
52+
# Vault binary to run as.
53+
#
5054
# * `service_options`
51-
# Extra argument to pass to `vault server`, as per:
52-
# `vault server --help`
55+
# Extra argument to pass to `vault`, e.g.,
56+
# `vault server --help` or `vault agent --help`
5357

5458
# * `manage_service`
5559
# Instruct puppet to manage service or not
@@ -88,6 +92,7 @@
8892
$service_enable = $::vault::params::service_enable,
8993
$service_ensure = $::vault::params::service_ensure,
9094
$service_provider = $::vault::params::service_provider,
95+
$service_type = $::vault::params::service_type,
9196
$manage_service = $::vault::params::manage_service,
9297
$manage_service_file = $::vault::params::manage_service_file,
9398
Hash $storage = $::vault::params::storage,

manifests/params.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656

5757
$service_provider = $facts['service_provider']
5858

59+
$service_type = 'server'
60+
5961
case $facts['architecture'] {
6062
/(x86_64|amd64)/: { $arch = 'amd64' }
6163
'i386': { $arch = '386' }

spec/classes/vault_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@
747747
{
748748
bin_dir: '/opt/bin',
749749
config_dir: '/opt/etc/vault',
750+
service_type: 'agent',
750751
service_options: '-log-level=info',
751752
user: 'root',
752753
group: 'admin'
@@ -769,6 +770,12 @@
769770
}
770771
it { is_expected.to contain_user('root') }
771772
it { is_expected.to contain_group('admin') }
773+
context 'contains /etc/init/vault.conf' do
774+
it {
775+
is_expected.to contain_file('/etc/init/vault.conf').
776+
with_content(%r{exec start-stop-daemon -u \$USER -g \$GROUP -p \$PID_FILE -x \$VAULT -S -- agent -config=\$CONFIG $})
777+
}
778+
end
772779
end
773780
context 'install through repo with default service management' do
774781
let(:params) do
@@ -859,6 +866,7 @@
859866
{
860867
bin_dir: '/opt/bin',
861868
config_dir: '/opt/etc/vault',
869+
service_type: 'agent',
862870
service_options: '-log-level=info',
863871
user: 'root',
864872
group: 'admin',
@@ -876,7 +884,7 @@
876884
with_content(%r{^User=root$}).
877885
with_content(%r{^Group=admin$}).
878886
with_content(%r{Environment=GOMAXPROCS=8}).
879-
with_content(%r{^ExecStart=/opt/bin/vault server -config=/opt/etc/vault/config.json -log-level=info$})
887+
with_content(%r{^ExecStart=/opt/bin/vault agent -config=/opt/etc/vault/config.json -log-level=info$})
880888
}
881889
end
882890
context 'with mlock disabled' do

templates/vault.initd.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
#
3-
# vault - this script manages the vault server
3+
# vault - this script manages the vault <%= scope['vault::service_type'] %>
44
#
55
# chkconfig: 3 85 15
66
# processname: vault
@@ -18,7 +18,7 @@
1818
# Required-Stop: $local_fs $network
1919
# Default-Start: 3 4 5
2020
# Default-Stop: 0 1 2 6
21-
# Short-Description: Manage the vault server
21+
# Short-Description: Manage the vault <%= scope['vault::service_type'] %>
2222
### END INIT INFO
2323

2424
# Source function library.
@@ -51,7 +51,7 @@ start() {
5151
touch $logfile $pidfile
5252
chown <%= scope['vault::user'] %> $logfile $pidfile
5353
export GOMAXPROCS=${GOMAXPROCS:-<%= scope['vault::num_procs'] %>}
54-
daemon --user <%= scope['vault::user'] %> "{ $exec server -config=$conffile $OPTIONS &>> $logfile & }; echo \$! >| $pidfile"
54+
daemon --user <%= scope['vault::user'] %> "{ $exec <%= scope['vault::service_type'] %> -config=$conffile $OPTIONS &>> $logfile & }; echo \$! >| $pidfile"
5555

5656
RETVAL=$?
5757
if [ $RETVAL -eq 0 ]; then

templates/vault.systemd.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CapabilityBoundingSet=CAP_SYSLOG CAP_IPC_LOCK
3030
<% end -%>
3131
NoNewPrivileges=yes
3232
Environment=GOMAXPROCS=<%= scope['vault::num_procs'] %>
33-
ExecStart=<%= scope['vault::bin_dir'] %>/vault server -config=<%= scope['vault::config_dir'] %>/config.json <%= scope['vault::service_options'] %>
33+
ExecStart=<%= scope['vault::bin_dir'] %>/vault <%= scope['vault::service_type'] %> -config=<%= scope['vault::config_dir'] %>/config.json <%= scope['vault::service_options'] %>
3434
KillSignal=SIGINT
3535
TimeoutStopSec=30s
3636
Restart=on-failure

templates/vault.upstart.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# this file has been put in place by the jsok/vault Puppet module (https://forge.puppetlabs.com/jsok/vault)
44
# any changes will be overwritten if Puppet is run again
55
###########################################################################################################
6-
description "vault server"
6+
description "vault <%= scope['vault::service_type'] %>"
77
start on (local-filesystems and net-device-up IFACE!=lo)
88
stop on runlevel [06]
99

@@ -18,7 +18,7 @@ script
1818
export GOMAXPROCS=${GOMAXPROCS:-<%= scope['vault::num_procs'] %>}
1919
[ -e /etc/default/$UPSTART_JOB ] && . /etc/default/$UPSTART_JOB
2020
exec >> $LOG_FILE 2>&1
21-
exec start-stop-daemon -u $USER -g $GROUP -p $PID_FILE -x $VAULT -S -- server -config=$CONFIG <%= scope['vault::service_options'] %>
21+
exec start-stop-daemon -u $USER -g $GROUP -p $PID_FILE -x $VAULT -S -- <%= scope['vault::service_type'] %> -config=$CONFIG <%= scope['vault::service_options'] %>
2222
end script
2323

2424
respawn

0 commit comments

Comments
 (0)