Skip to content

Commit e5253a6

Browse files
alexjfisherekohl
authored andcommitted
Add server_jolokia_metrics_whitelist parameter
When set, allows listed clients access to the V2 (jolokia) metrics endpoint. See https://puppet.com/docs/puppet/7/server/metrics-api/v2/metrics_api.html
1 parent b6dd984 commit e5253a6

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

manifests/init.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@
538538
# invokes when on static_file_content requests.
539539
# Defaults to undef
540540
#
541+
# $server_jolokia_metrics_whitelist:: The whitelist of clients that
542+
# can query the jolokia /metrics/v2 endpoint
543+
#
541544
# === Usage:
542545
#
543546
# * Simple usage:
@@ -733,6 +736,7 @@
733736
Optional[Integer[1]] $server_max_open_files = $puppet::params::server_max_open_files,
734737
Optional[Stdlib::Absolutepath] $server_versioned_code_id = undef,
735738
Optional[Stdlib::Absolutepath] $server_versioned_code_content = undef,
739+
Array[String[1]] $server_jolokia_metrics_whitelist = [],
736740
) inherits puppet::params {
737741
contain puppet::config
738742

manifests/server.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@
331331
# $versioned_code_content:: Contains the path to an executable script that Puppet Server invokes when an agent makes
332332
# a static_file_content API request for the contents of a file resource that
333333
# has a source attribute with a puppet:/// URI value.
334+
#
335+
# $jolokia_metrics_whitelist:: The whitelist of clients that
336+
# can query the jolokia /metrics/v2 endpoint
334337
class puppet::server(
335338
Variant[Boolean, Stdlib::Absolutepath] $autosign = $puppet::autosign,
336339
Array[String] $autosign_entries = $puppet::autosign_entries,
@@ -449,6 +452,7 @@
449452
Optional[Integer[1]] $max_open_files = $puppet::server_max_open_files,
450453
Optional[Stdlib::Absolutepath] $versioned_code_id = $puppet::server_versioned_code_id,
451454
Optional[Stdlib::Absolutepath] $versioned_code_content = $puppet::server_versioned_code_content,
455+
Array[String[1]] $jolokia_metrics_whitelist = $puppet::server_jolokia_metrics_whitelist,
452456
) {
453457
# For Puppetserver, certain configuration parameters are version specific. We
454458
# assume a particular version here.

manifests/server/puppetserver.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
$versioned_code_id = $puppet::server::versioned_code_id,
145145
$versioned_code_content = $puppet::server::versioned_code_content,
146146
$disable_fips = $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8',
147+
$jolokia_metrics_whitelist = $puppet::server::jolokia_metrics_whitelist,
147148
) {
148149
include puppet::server
149150

spec/classes/puppet_server_puppetserver_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,23 @@
572572
}
573573
end
574574
end
575+
576+
describe 'jolokia_metrics_whitelist' do
577+
let(:content) { catalogue.resource('file', auth_conf).send(:parameters)[:content] }
578+
let(:rules) { Hocon.parse(content)['authorization']['rules'] }
579+
let(:rule) { rules.find {|rule| rule['name'] == 'jolokia metrics' } }
580+
581+
context 'by default' do
582+
it { expect(rule).to be_nil }
583+
end
584+
585+
context 'when set' do
586+
let(:params) { super().merge(server_jolokia_metrics_whitelist: ['localhost', 'host.example.com']) }
587+
588+
it { expect(rule['match-request']['path']).to eq('/metrics/v2') }
589+
it { expect(rule['allow']).to eq(['localhost', 'host.example.com']) }
590+
end
591+
end
575592
end
576593
end
577594
end

templates/server/puppetserver/conf.d/auth.conf.erb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,21 @@ authorization: {
356356
sort-order: 500
357357
name: "puppetlabs experimental"
358358
},
359+
<%- end -%>
360+
<%- unless @jolokia_metrics_whitelist.empty? -%>
361+
{
362+
match-request: {
363+
path: "/metrics/v2"
364+
type: path
365+
}
366+
allow: [
367+
<%- @jolokia_metrics_whitelist.each do |client| -%>
368+
"<%= client %>",
369+
<%- end -%>
370+
]
371+
sort-order: 500
372+
name: "jolokia metrics"
373+
},
359374
<%- end -%>
360375
{
361376
# Deny everything else. This ACL is not strictly

0 commit comments

Comments
 (0)