File tree Expand file tree Collapse file tree 5 files changed +57
-1
lines changed
templates/server/puppetserver/conf.d Expand file tree Collapse file tree 5 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 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:
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
Original file line number Diff line number Diff line change 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
340344class puppet::server (
341345 Variant[Boolean, Stdlib::Absolutepath] $autosign = $puppet::autosign,
342346 Array[String] $autosign_entries = $puppet::autosign_entries,
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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
582609end
Original file line number Diff line number Diff line change @@ -361,7 +361,17 @@ authorization: {
361361 name: "puppetlabs experimental"
362362 },
363363<%- end -%>
364- <%- unless @jolokia_metrics_allowlist.empty? -%>
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+ <%- elsif !@jolokia_metrics_allowlist.empty? -%>
365375 {
366376 match-request: {
367377 path: "/metrics/v2"
@@ -375,6 +385,9 @@ authorization: {
375385 sort-order: 500
376386 name: "jolokia metrics"
377387 },
388+ <%- end -%>
389+ <%- if @auth_extra -%>
390+ <%= @auth_extra %>
378391<%- end -%>
379392 {
380393 # Deny everything else. This ACL is not strictly
You can’t perform that action at this time.
0 commit comments