Skip to content

Commit 630acc2

Browse files
committed
Extract client_cert profile
1 parent 98ae5fc commit 630acc2

File tree

5 files changed

+94
-27
lines changed

5 files changed

+94
-27
lines changed

manifests/profile/client_cert.pp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2022 The Regents of the University of Michigan.
2+
# All Rights Reserved. Licensed according to the terms of the Revised
3+
# BSD License. See LICENSE.txt for details.
4+
5+
# nebula::profile::client_cert
6+
#
7+
# Put a copy of the certificate this host uses to talk to the
8+
# puppetserver where apache can see it. This way, the host will be able
9+
# to verify its authenticity with anyone that trusts our puppet CA.
10+
#
11+
# @example Including the profile
12+
# include nebula::profile::client_cert
13+
#
14+
# @example Adding the certificate to an apache vhost
15+
# ssl_proxy_machine_cert => $nebula::profile::client_cert::path,
16+
class nebula::profile::client_cert {
17+
$certname = $trusted['certname'];
18+
$path = "/etc/ssl/private/${certname}.pem";
19+
20+
concat { $path:
21+
ensure => 'present',
22+
mode => '0600',
23+
owner => 'root',
24+
}
25+
26+
concat::fragment { "${path} cert":
27+
target => $path,
28+
source => "/etc/puppetlabs/puppet/ssl/certs/${certname}.pem",
29+
order => 1
30+
}
31+
32+
concat::fragment { "${path} key":
33+
target => $path,
34+
source => "/etc/puppetlabs/puppet/ssl/private_keys/${certname}.pem",
35+
order => 2
36+
}
37+
}

manifests/profile/hathitrust/apache/babel.pp

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018 The Regents of the University of Michigan.
1+
# Copyright (c) 2018, 2022 The Regents of the University of Michigan.
22
# All Rights Reserved. Licensed according to the terms of the Revised
33
# BSD License. See LICENSE.txt for details.
44

@@ -25,6 +25,8 @@
2525
Array[String] $cache_paths = [ ],
2626
) {
2727

28+
include nebula::profile::client_cert
29+
2830
### MONITORING
2931

3032
$monitor_location = '/monitor'
@@ -58,29 +60,6 @@
5860
hour => '1',
5961
}
6062

61-
### client cert
62-
63-
$certname = $trusted['certname'];
64-
$client_cert = "/etc/ssl/private/${certname}.pem";
65-
66-
concat { $client_cert:
67-
ensure => 'present',
68-
mode => '0600',
69-
owner => 'root',
70-
}
71-
72-
concat::fragment { 'client cert':
73-
target => $client_cert,
74-
source => "/etc/puppetlabs/puppet/ssl/certs/${certname}.pem",
75-
order => 1
76-
}
77-
78-
concat::fragment { 'client key':
79-
target => $client_cert,
80-
source => "/etc/puppetlabs/puppet/ssl/private_keys/${certname}.pem",
81-
order => 2
82-
}
83-
8463
## VHOST DEFINITION
8564

8665
$servername = "${prefix}babel.${domain}"
@@ -353,7 +332,7 @@
353332
ssl_proxyengine => true,
354333
ssl_proxy_check_peer_name => 'on',
355334
ssl_proxy_check_peer_expire => 'on',
356-
ssl_proxy_machine_cert => $client_cert,
335+
ssl_proxy_machine_cert => $nebula::profile::client_cert::path,
357336

358337
custom_fragment => "
359338
<Proxy \"fcgi://${imgsrv_address}\" enablereuse=off max=10>

manifests/role/mgetit_log.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018 The Regents of the University of Michigan.
1+
# Copyright (c) 2018, 2022 The Regents of the University of Michigan.
22
# All Rights Reserved. Licensed according to the terms of the Revised
33
# BSD License. See LICENSE.txt for details.
44

@@ -12,4 +12,5 @@
1212
include nebula::profile::named_instances
1313
include nebula::profile::nodejs
1414
include nebula::profile::php73
15+
include nebula::profile::client_cert
1516
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright (c) 2022 The Regents of the University of Michigan.
4+
# All Rights Reserved. Licensed according to the terms of the Revised
5+
# BSD License. See LICENSE.txt for details.
6+
require 'spec_helper'
7+
8+
describe 'nebula::profile::client_cert' do
9+
on_supported_os.each do |os, os_facts|
10+
context "on #{os}" do
11+
let(:facts) { os_facts }
12+
13+
it { is_expected.to compile }
14+
15+
context 'on a host called default.invalid' do
16+
let(:node) { 'default.invalid' }
17+
let(:cert_path) { '/etc/ssl/private/default.invalid.pem' }
18+
let(:puppet_ssl) { '/etc/puppetlabs/puppet/ssl' }
19+
20+
it { is_expected.to compile }
21+
it { is_expected.to contain_concat(cert_path) }
22+
it { is_expected.to contain_concat__fragment("#{cert_path} cert").with_target(cert_path) }
23+
it { is_expected.to contain_concat__fragment("#{cert_path} cert").with_source("#{puppet_ssl}/certs/default.invalid.pem") }
24+
it { is_expected.to contain_concat__fragment("#{cert_path} key").with_target(cert_path) }
25+
it { is_expected.to contain_concat__fragment("#{cert_path} key").with_source("#{puppet_ssl}/private_keys/default.invalid.pem") }
26+
end
27+
28+
context 'on a host called abc' do
29+
let(:node) { 'abc' }
30+
let(:cert_path) { '/etc/ssl/private/abc.pem' }
31+
let(:puppet_ssl) { '/etc/puppetlabs/puppet/ssl' }
32+
33+
it { is_expected.to compile }
34+
it { is_expected.to contain_concat(cert_path) }
35+
it { is_expected.to contain_concat__fragment("#{cert_path} cert").with_target(cert_path) }
36+
it { is_expected.to contain_concat__fragment("#{cert_path} cert").with_source("#{puppet_ssl}/certs/abc.pem") }
37+
it { is_expected.to contain_concat__fragment("#{cert_path} key").with_target(cert_path) }
38+
it { is_expected.to contain_concat__fragment("#{cert_path} key").with_source("#{puppet_ssl}/private_keys/abc.pem") }
39+
end
40+
end
41+
end
42+
end

spec/classes/profile/hathitrust/apache/babel_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Copyright (c) 2018 The Regents of the University of Michigan.
3+
# Copyright (c) 2018, 2022 The Regents of the University of Michigan.
44
# All Rights Reserved. Licensed according to the terms of the Revised
55
# BSD License. See LICENSE.txt for details.
66
require 'spec_helper'
@@ -42,6 +42,14 @@
4242
end
4343

4444
end
45+
46+
context 'with certname set to myhostname.tld' do
47+
let(:node) { 'myhostname.tld' }
48+
49+
it { is_expected.to compile }
50+
it { is_expected.to contain_apache__vhost('babel.hathitrust.org ssl').with_ssl_proxy_machine_cert('/etc/ssl/private/myhostname.tld.pem') }
51+
it { is_expected.to contain_class('Nebula::Profile::Client_cert') }
52+
end
4553
end
4654
end
4755
end

0 commit comments

Comments
 (0)