Skip to content

Commit 52f5717

Browse files
committed
Add option to allow unauthenticated access to metrics, and for generic additions to auth
1 parent ce2f9fa commit 52f5717

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

manifests/init.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,15 @@
557557
# invokes when on static_file_content requests.
558558
# Defaults to undef
559559
#
560+
# $server_jolokia_allow_unauthenticated:: Whether to allow unauthenticated access to metrics
561+
# Defaults to false
562+
#
560563
# $server_jolokia_metrics_allowlist:: The allowlist of clients that
561564
# can query the jolokia /metrics/v2 endpoint
562565
#
566+
# $server_auth_extra:: Additional rules for auth.conf
567+
# Defaults to undef
568+
#
563569
# === Usage:
564570
#
565571
# * Simple usage:
@@ -762,6 +768,8 @@
762768
Optional[Stdlib::Absolutepath] $server_versioned_code_id = undef,
763769
Optional[Stdlib::Absolutepath] $server_versioned_code_content = undef,
764770
Array[String[1]] $server_jolokia_metrics_allowlist = [],
771+
Optional[Boolean] $server_jolokia_allow_unauthenticated = undef,
772+
Optional[String] $server_auth_extra = undef,
765773
Stdlib::Filemode $puppetconf_mode = $puppet::params::puppetconf_mode,
766774
) inherits puppet::params {
767775
contain puppet::config

manifests/server.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,12 @@
340340
# a static_file_content API request for the contents of a file resource that
341341
# has a source attribute with a puppet:/// URI value.
342342
#
343+
# $jolokia_allow_unauthenticated:: Should we disable authentication for the metrics
344+
#
343345
# $jolokia_metrics_allowlist:: The allowlist of clients that
344346
# can query the jolokia /metrics/v2 endpoint
347+
#
348+
# $auth_extra:: Additional rules for the auth.conf
345349
class puppet::server (
346350
Variant[Boolean, Stdlib::Absolutepath] $autosign = $puppet::autosign,
347351
Array[String] $autosign_entries = $puppet::autosign_entries,
@@ -465,6 +469,8 @@
465469
Optional[Stdlib::Absolutepath] $versioned_code_id = $puppet::server_versioned_code_id,
466470
Optional[Stdlib::Absolutepath] $versioned_code_content = $puppet::server_versioned_code_content,
467471
Array[String[1]] $jolokia_metrics_allowlist = $puppet::server_jolokia_metrics_allowlist,
472+
Optional[Boolean] $jolokia_allow_unauthenticated = $puppet::server_jolokia_allow_unauthenticated,
473+
Optional[String] $auth_extra = $puppet::server_auth_extra,
468474
) {
469475
$cadir = "${puppetserver_dir}/ca"
470476

manifests/server/puppetserver.pp

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

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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,17 @@ authorization: {
375375
name: "puppetlabs experimental"
376376
},
377377
<%- end -%>
378-
<%- unless @jolokia_metrics_allowlist.empty? -%>
378+
<%- if @jolokia_allow_unauthenticated -%>
379+
{
380+
match-request: {
381+
path: "/metrics/v2"
382+
type: path
383+
}
384+
allow-unauthenticated: true
385+
sort-order: 500
386+
name: "jolokia metrics"
387+
},
388+
<%- elsif !@jolokia_metrics_allowlist.empty? -%>
379389
{
380390
match-request: {
381391
path: "/metrics/v2"
@@ -389,6 +399,9 @@ authorization: {
389399
sort-order: 500
390400
name: "jolokia metrics"
391401
},
402+
<%- end -%>
403+
<%- if @auth_extra -%>
404+
<%= @auth_extra %>
392405
<%- end -%>
393406
{
394407
# Deny everything else. This ACL is not strictly

0 commit comments

Comments
 (0)