Skip to content

Commit bb98142

Browse files
committed
P:puppet::server: Do not expose Puppetserver to the internet
Limit access to the Puppetserver endpoint to jQuery hosts, as a hardening measure. The provisioning script is adapted to manually add a firewall rule until the host is fully enrolled in Puppet. Refs #76.
1 parent e903ceb commit bb98142

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

bin/provision-instance.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ fi
2626
ssh root@"$INSTANCE" apt-get update
2727
ssh root@"$INSTANCE" apt-get -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef" upgrade -y
2828
ssh root@"$INSTANCE" apt-get -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-confdef" install -y puppet-agent
29+
INSTANCE_IP=$(ssh root@"$INSTANCE" facter networking.ip)
30+
ssh "$PUPPET_SERVER" sudo nft add rule inet filter input tcp dport 8140 ip saddr "$INSTANCE_IP" ct state new accept
2931
ssh root@"$INSTANCE" "$PUPPET" config --section agent set server "$PUPPET_SERVER"
3032
ssh root@"$INSTANCE" "$PUPPET" config --section agent set environment "$ENVIRONMENT"
3133
ssh root@"$INSTANCE" "$PUPPET" agent -t || true
@@ -39,3 +41,4 @@ fi
3941

4042
ssh "$PUPPET_SERVER" sudo puppetserver ca sign --certname "$INSTANCE"
4143
ssh root@"$INSTANCE" "$PUPPET" agent -t
44+
ssh "$PUPPET_SERVER" sudo run-puppet-agent

modules/jqlib/functions/resource_hosts.pp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
# @summary function to return a list of hosts running a specific resource
22
function jqlib::resource_hosts (
33
String[1] $resource_type,
4-
Optional[String[1]] $resource_title = undef,
4+
Optional[String[1]] $resource_title = undef,
5+
Boolean $all_environments = false,
56
) >> Array[Stdlib::Host] {
67
$title_query = $resource_title ? {
78
undef => '',
89
default => "and title = \"${jqlib::format_puppet_title($resource_title)}\"",
910
}
11+
$environment_query = $all_environments.bool2str('', "and environment = \"${::environment}\"")
1012

1113
$pql = @("PQL")
1214
resources[certname] {
1315
type = "${jqlib::format_puppet_title($resource_type)}"
1416
${title_query}
15-
and environment = "${::environment}"
17+
${environment_query}
1618
}
1719
| PQL
1820

modules/profile/manifests/puppet/server.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,13 @@
209209
interval => ['OnCalendar=*-*-* 12:00:00'],
210210
}
211211

212+
$clients = jqlib::resource_hosts('class', 'profile::puppet::agent', true)
213+
$client_ips = $puppetservers.map |Stdlib::Fqdn $fqdn| { dnsquery::lookup($fqdn, true) }.flatten
214+
212215
nftables::allow { 'puppetserver':
213216
proto => 'tcp',
214217
dport => 8140,
218+
saddr => $client_ips,
215219
}
216220

217221
notifier::run_command { 'puppet-public':

0 commit comments

Comments
 (0)