Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,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:
Expand Down Expand Up @@ -762,6 +768,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 = undef,
Optional[String] $server_auth_extra = undef,
Stdlib::Filemode $puppetconf_mode = $puppet::params::puppetconf_mode,
) inherits puppet::params {
contain puppet::config
Expand Down
6 changes: 6 additions & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,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,
Expand Down Expand Up @@ -465,6 +469,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"

Expand Down
2 changes: 2 additions & 0 deletions manifests/server/puppetserver.pp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
Optional[Stdlib::Absolutepath] $versioned_code_content = $puppet::server::versioned_code_content,
Boolean $disable_fips = $facts['os']['family'] == 'RedHat',
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

Expand Down
27 changes: 27 additions & 0 deletions spec/classes/puppet_server_puppetserver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 14 additions & 1 deletion templates/server/puppetserver/conf.d/auth.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,17 @@ authorization: {
name: "puppetlabs experimental"
},
<%- end -%>
<%- unless @jolokia_metrics_allowlist.empty? -%>
<%- if @jolokia_allow_unauthenticated -%>
{
match-request: {
path: "/metrics/v2"
type: path
}
allow-unauthenticated: true
sort-order: 500
name: "jolokia metrics"
},
<%- elsif !@jolokia_metrics_allowlist.empty? -%>
{
match-request: {
path: "/metrics/v2"
Expand All @@ -389,6 +399,9 @@ authorization: {
sort-order: 500
name: "jolokia metrics"
},
<%- end -%>
<%- if @auth_extra -%>
<%= @auth_extra %>
<%- end -%>
{
# Deny everything else. This ACL is not strictly
Expand Down
Loading