diff --git a/manifests/init.pp b/manifests/init.pp index 48a157cf..2617fde2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -549,9 +549,15 @@ # invokes when on static_file_content requests. # Defaults to undef # +# $server_jolokia_allow_unauthenticated:: Whether to allow unauthenticated access to metrics +# Defaults to false +# # $server_jolokia_metrics_allowlist:: The allowlist of clients that # can query the jolokia /metrics/v2 endpoint # +# $server_auth_extra:: Additional rules for auth.conf +# Defaults to undef +# # === Usage: # # * Simple usage: @@ -752,6 +758,8 @@ Optional[Stdlib::Absolutepath] $server_versioned_code_id = undef, Optional[Stdlib::Absolutepath] $server_versioned_code_content = undef, Array[String[1]] $server_jolokia_metrics_allowlist = [], + Optional[Boolean] $server_jolokia_allow_unauthenticated = false, + Optional[String] $server_auth_extra = undef, Stdlib::Filemode $puppetconf_mode = $puppet::params::puppetconf_mode, ) inherits puppet::params { contain puppet::config diff --git a/manifests/server.pp b/manifests/server.pp index 551a8c38..8ee5f995 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -335,8 +335,12 @@ # a static_file_content API request for the contents of a file resource that # has a source attribute with a puppet:/// URI value. # +# $jolokia_allow_unauthenticated:: Should we disable authentication for the metrics +# # $jolokia_metrics_allowlist:: The allowlist of clients that # can query the jolokia /metrics/v2 endpoint +# +# $auth_extra:: Additional rules for the auth.conf class puppet::server ( Variant[Boolean, Stdlib::Absolutepath] $autosign = $puppet::autosign, Array[String] $autosign_entries = $puppet::autosign_entries, @@ -458,6 +462,8 @@ Optional[Stdlib::Absolutepath] $versioned_code_id = $puppet::server_versioned_code_id, Optional[Stdlib::Absolutepath] $versioned_code_content = $puppet::server_versioned_code_content, Array[String[1]] $jolokia_metrics_allowlist = $puppet::server_jolokia_metrics_allowlist, + Optional[Boolean] $jolokia_allow_unauthenticated = $puppet::server_jolokia_allow_unauthenticated, + Optional[String] $auth_extra = $puppet::server_auth_extra, ) { $cadir = "${puppetserver_dir}/ca" diff --git a/manifests/server/puppetserver.pp b/manifests/server/puppetserver.pp index d2b6d2a1..25b00f29 100644 --- a/manifests/server/puppetserver.pp +++ b/manifests/server/puppetserver.pp @@ -144,6 +144,8 @@ Optional[Stdlib::Absolutepath] $versioned_code_content = $puppet::server::versioned_code_content, Boolean $disable_fips = $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8', Array[String[1]] $jolokia_metrics_allowlist = $puppet::server::jolokia_metrics_allowlist, + Optional[Boolean] $jolokia_allow_unauthenticated = $puppet::server::jolokia_allow_unauthenticated, + Optional[String] $auth_extra = $puppet::server::auth_extra, ) { include puppet::server diff --git a/spec/classes/puppet_server_puppetserver_spec.rb b/spec/classes/puppet_server_puppetserver_spec.rb index a3e59ff7..65034394 100644 --- a/spec/classes/puppet_server_puppetserver_spec.rb +++ b/spec/classes/puppet_server_puppetserver_spec.rb @@ -577,6 +577,33 @@ it { expect(rule['allow']).to eq(['localhost', 'host.example.com']) } end end + + describe 'jolokia_allow_unauthenticated' do + let(:content) { catalogue.resource('file', auth_conf).send(:parameters)[:content] } + let(:rules) { Hocon.parse(content)['authorization']['rules'] } + let(:rule) { rules.find {|rule| rule['name'] == 'jolokia metrics' } } + + context 'by default' do + it { expect(rule).to be_nil } + end + + context 'when set' do + let(:params) { super().merge(server_jolokia_allow_unauthenticated: true) } + + it { expect(rule['match-request']['path']).to eq('/metrics/v2') } + it { expect(rule['allow-unauthenticated']).to eq(true) } + end + end + + describe 'auth_extra' do + let(:content) { catalogue.resource('file', auth_conf).send(:parameters)[:content] } + + context 'when set' do + let(:params) { super().merge(server_auth_extra: "# test-content-string" ) } + + it { should contain_file(auth_conf).with_content(%r{^# test-content-string$}) } + end + end end end end diff --git a/templates/server/puppetserver/conf.d/auth.conf.erb b/templates/server/puppetserver/conf.d/auth.conf.erb index 49603119..e2a561dd 100644 --- a/templates/server/puppetserver/conf.d/auth.conf.erb +++ b/templates/server/puppetserver/conf.d/auth.conf.erb @@ -361,6 +361,17 @@ authorization: { name: "puppetlabs experimental" }, <%- end -%> +<%- if @jolokia_allow_unauthenticated -%> + { + match-request: { + path: "/metrics/v2" + type: path + } + allow-unauthenticated: true + sort-order: 500 + name: "jolokia metrics" + }, +<%- else -%> <%- unless @jolokia_metrics_allowlist.empty? -%> { match-request: { @@ -375,6 +386,10 @@ authorization: { sort-order: 500 name: "jolokia metrics" }, +<%- end -%> +<%- end -%> +<%- if @auth_extra -%> +<%= @auth_extra %> <%- end -%> { # Deny everything else. This ACL is not strictly