Skip to content

Commit b7641d8

Browse files
committed
Add option to allow unauthenticated access to metrics, and for generic additions to auth
1 parent b234dda commit b7641d8

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

manifests/init.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,15 @@
549549
# invokes when on static_file_content requests.
550550
# Defaults to undef
551551
#
552+
# $server_jolokia_allow_unauthenticated:: Whether to allow unauthenticated access to metrics
553+
# Defaults to false
554+
#
552555
# $server_jolokia_metrics_allowlist:: The allowlist of clients that
553556
# can query the jolokia /metrics/v2 endpoint
554557
#
558+
# $server_auth_extra:: Additional rules for auth.conf
559+
# Defaults to undef
560+
#
555561
# === Usage:
556562
#
557563
# * Simple usage:
@@ -752,6 +758,8 @@
752758
Optional[Stdlib::Absolutepath] $server_versioned_code_id = undef,
753759
Optional[Stdlib::Absolutepath] $server_versioned_code_content = undef,
754760
Array[String[1]] $server_jolokia_metrics_allowlist = [],
761+
Optional[Boolean] $server_jolokia_allow_unauthenticated = undef,
762+
Optional[String] $server_auth_extra = undef,
755763
Stdlib::Filemode $puppetconf_mode = $puppet::params::puppetconf_mode,
756764
) inherits puppet::params {
757765
contain puppet::config

manifests/server.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,12 @@
335335
# a static_file_content API request for the contents of a file resource that
336336
# has a source attribute with a puppet:/// URI value.
337337
#
338+
# $jolokia_allow_unauthenticated:: Should we disable authentication for the metrics
339+
#
338340
# $jolokia_metrics_allowlist:: The allowlist of clients that
339341
# can query the jolokia /metrics/v2 endpoint
342+
#
343+
# $auth_extra:: Additional rules for the auth.conf
340344
class puppet::server (
341345
Variant[Boolean, Stdlib::Absolutepath] $autosign = $puppet::autosign,
342346
Array[String] $autosign_entries = $puppet::autosign_entries,
@@ -458,6 +462,8 @@
458462
Optional[Stdlib::Absolutepath] $versioned_code_id = $puppet::server_versioned_code_id,
459463
Optional[Stdlib::Absolutepath] $versioned_code_content = $puppet::server_versioned_code_content,
460464
Array[String[1]] $jolokia_metrics_allowlist = $puppet::server_jolokia_metrics_allowlist,
465+
Optional[Boolean] $jolokia_allow_unauthenticated = $puppet::server_jolokia_allow_unauthenticated,
466+
Optional[String] $auth_extra = $puppet::server_auth_extra,
461467
) {
462468
$cadir = "${puppetserver_dir}/ca"
463469

manifests/server/puppetserver.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@
144144
Optional[Stdlib::Absolutepath] $versioned_code_content = $puppet::server::versioned_code_content,
145145
Boolean $disable_fips = $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8',
146146
Array[String[1]] $jolokia_metrics_allowlist = $puppet::server::jolokia_metrics_allowlist,
147+
Optional[Boolean] $jolokia_allow_unauthenticated = $puppet::server::jolokia_allow_unauthenticated,
148+
Optional[String] $auth_extra = $puppet::server::auth_extra,
147149
) {
148150
include puppet::server
149151

spec/classes/puppet_server_puppetserver_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,33 @@
577577
it { expect(rule['allow']).to eq(['localhost', 'host.example.com']) }
578578
end
579579
end
580+
581+
describe 'jolokia_allow_unauthenticated' do
582+
let(:content) { catalogue.resource('file', auth_conf).send(:parameters)[:content] }
583+
let(:rules) { Hocon.parse(content)['authorization']['rules'] }
584+
let(:rule) { rules.find {|rule| rule['name'] == 'jolokia metrics' } }
585+
586+
context 'by default' do
587+
it { expect(rule).to be_nil }
588+
end
589+
590+
context 'when set' do
591+
let(:params) { super().merge(server_jolokia_allow_unauthenticated: true) }
592+
593+
it { expect(rule['match-request']['path']).to eq('/metrics/v2') }
594+
it { expect(rule['allow-unauthenticated']).to eq(true) }
595+
end
596+
end
597+
598+
describe 'auth_extra' do
599+
let(:content) { catalogue.resource('file', auth_conf).send(:parameters)[:content] }
600+
601+
context 'when set' do
602+
let(:params) { super().merge(server_auth_extra: "# test-content-string" ) }
603+
604+
it { should contain_file(auth_conf).with_content(%r{^# test-content-string$}) }
605+
end
606+
end
580607
end
581608
end
582609
end

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,17 @@ authorization: {
361361
name: "puppetlabs experimental"
362362
},
363363
<%- end -%>
364+
<%- if @jolokia_allow_unauthenticated -%>
365+
{
366+
match-request: {
367+
path: "/metrics/v2"
368+
type: path
369+
}
370+
allow-unauthenticated: true
371+
sort-order: 500
372+
name: "jolokia metrics"
373+
},
374+
<%- else -%>
364375
<%- unless @jolokia_metrics_allowlist.empty? -%>
365376
{
366377
match-request: {
@@ -375,6 +386,10 @@ authorization: {
375386
sort-order: 500
376387
name: "jolokia metrics"
377388
},
389+
<%- end -%>
390+
<%- end -%>
391+
<%- if @auth_extra -%>
392+
<%= @auth_extra %>
378393
<%- end -%>
379394
{
380395
# Deny everything else. This ACL is not strictly

0 commit comments

Comments
 (0)