Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server_jolokia_metrics_whitelist parameter #826

Merged
merged 1 commit into from
Apr 5, 2022
Merged
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
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,9 @@
# invokes when on static_file_content requests.
# Defaults to undef
#
# $server_jolokia_metrics_whitelist:: The whitelist of clients that
# can query the jolokia /metrics/v2 endpoint
#
# === Usage:
#
# * Simple usage:
Expand Down Expand Up @@ -732,6 +735,7 @@
Optional[Integer[1]] $server_max_open_files = $puppet::params::server_max_open_files,
Optional[Stdlib::Absolutepath] $server_versioned_code_id = undef,
Optional[Stdlib::Absolutepath] $server_versioned_code_content = undef,
Array[String[1]] $server_jolokia_metrics_whitelist = [],
) inherits puppet::params {
contain puppet::config

Expand Down
4 changes: 4 additions & 0 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@
# $versioned_code_content:: Contains the path to an executable script that Puppet Server invokes when an agent makes
# a static_file_content API request for the contents of a file resource that
# has a source attribute with a puppet:/// URI value.
#
# $jolokia_metrics_whitelist:: The whitelist of clients that
# can query the jolokia /metrics/v2 endpoint
class puppet::server(
Variant[Boolean, Stdlib::Absolutepath] $autosign = $puppet::autosign,
Array[String] $autosign_entries = $puppet::autosign_entries,
Expand Down Expand Up @@ -449,6 +452,7 @@
Optional[Integer[1]] $max_open_files = $puppet::server_max_open_files,
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_whitelist = $puppet::server_jolokia_metrics_whitelist,
) {
# For Puppetserver, certain configuration parameters are version specific. We
# assume a particular version here.
Expand Down
1 change: 1 addition & 0 deletions manifests/server/puppetserver.pp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
$versioned_code_id = $puppet::server::versioned_code_id,
$versioned_code_content = $puppet::server::versioned_code_content,
$disable_fips = $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8',
$jolokia_metrics_whitelist = $puppet::server::jolokia_metrics_whitelist,
) {
include puppet::server

Expand Down
17 changes: 17 additions & 0 deletions spec/classes/puppet_server_puppetserver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,23 @@
}
end
end

describe 'jolokia_metrics_whitelist' 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_metrics_whitelist: ['localhost', 'host.example.com']) }

it { expect(rule['match-request']['path']).to eq('/metrics/v2') }
it { expect(rule['allow']).to eq(['localhost', 'host.example.com']) }
end
end
end
end
end
15 changes: 15 additions & 0 deletions templates/server/puppetserver/conf.d/auth.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ authorization: {
sort-order: 500
name: "puppetlabs experimental"
},
<%- end -%>
<%- unless @jolokia_metrics_whitelist.empty? -%>
{
match-request: {
path: "/metrics/v2"
type: path
}
allow: [
<%- @jolokia_metrics_whitelist.each do |client| -%>
"<%= client %>",
<%- end -%>
]
sort-order: 500
name: "jolokia metrics"
},
<%- end -%>
{
# Deny everything else. This ACL is not strictly
Expand Down