Skip to content

Commit

Permalink
Add option to allow unauthenticated access to metrics, and for generi…
Browse files Browse the repository at this point in the history
…c additions to auth
  • Loading branch information
fraenki committed Dec 12, 2023
1 parent b234dda commit 8f10bf0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,

Check warning on line 761 in manifests/init.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Optional parameter defaults to something other than undef (check: optional_default)
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 @@ -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,
Expand Down Expand Up @@ -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"

Expand Down
2 changes: 2 additions & 0 deletions manifests/server/puppetserver.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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

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: 15 additions & 0 deletions templates/server/puppetserver/conf.d/auth.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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
Expand Down

0 comments on commit 8f10bf0

Please sign in to comment.