Skip to content

Commit 7123a62

Browse files
authored
Merge pull request #85 from Sharpie/PE-31705-reenable-remote-metric-collection
(PE-31705) Re-enable remote metric collection
2 parents 3200657 + 838d67c commit 7123a62

File tree

4 files changed

+72
-14
lines changed

4 files changed

+72
-14
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ Table of Contents
2121
This module collects metrics provided by the status endpoints of Puppet Enterprise services.
2222
The metrics can be used to identify performance issues that may be addressed by performance tuning.
2323

24-
> In PE 2018.1.13 and newer and PE 2019.4 and newer, the `/metrics/v1` endpoints are disabled by default and access to the `/metrics/v2` endpoints are restricted to localhost ... in response to CVE-2020-7943.
25-
This module requires access those endpoints to collect additional metrics from PuppetDB, and those metrics will not be collected from remote PuppetDB hosts until these restricted are resolved.
26-
Refer to [Configuration for Distributed Metrics Collection](#Configuration-for-distributed-metrics-collection) for a workaround.
24+
25+
> For PE versions older than 2019.8.5, access to the `/metrics/v2` API endpoint is restricted to `localhost` as a mitigation for [CVE-2020-7943](https://puppet.com/security/cve/CVE-2020-7943/). This module requires access the `/metrics/v2` API to collect a complete set of performance metrics from PuppetDB. Refer to [Configuration for Distributed Metrics Collection](#Configuration-for-distributed-metrics-collection) for a workaround.
2726
2827

2928
## Setup

files/pe_metrics.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def coalesce(higher_precedence, lower_precedence, default = nil)
4242
USE_SSL = coalesce(options[:ssl], config['ssl'], true)
4343
EXCLUDES = config['excludes']
4444
ADDITIONAL_METRICS = config['additional_metrics']
45+
REMOTE_METRICS_ENABLED = config['remote_metrics_enabled']
4546

4647
# Metrics endpoints for our Puma services require a client certificate with SSL.
4748
# Metrics endpoints for our Trapper Keeper services do not require a client certificate.
@@ -114,12 +115,15 @@ def post_endpoint(url, use_ssl, post_data)
114115
endpoint_data = {}
115116
end
116117

117-
# PE-28451 Disables Metrics API v1 (/metrics/v1/beans/) and restricts v2 (/metrics/v2/read/) to localhost by default.
118-
119118
def retrieve_additional_metrics(host, port, use_ssl, metrics_type, metrics)
120119
if metrics_type == 'puppetdb'
121120
host = '127.0.0.1' if host == CERTNAME
122-
return [] unless ['127.0.0.1', 'localhost'].include?(host)
121+
unless REMOTE_METRICS_ENABLED || ['127.0.0.1', 'localhost'].include?(host)
122+
# Puppet services released between May, 2020 and Feb 2021 had
123+
# the /metrics API disabled due to:
124+
# https://puppet.com/security/cve/CVE-2020-7943/
125+
return []
126+
end
123127
end
124128

125129
host_url = generate_host_url(host, port, use_ssl)

manifests/pe_metric.pp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Boolean $ssl = true,
1111
Array[String] $excludes = puppet_metrics_collector::version_based_excludes($title),
1212
Array[Hash] $additional_metrics = [],
13+
Optional[Boolean] $remote_metrics_enabled = lookup('puppet_metrics_collector::pe_metric::remote_metrics_enabled', {'default_value' => undef}), # lint:ignore:140chars
1314
Optional[String] $override_metrics_command = undef,
1415
Optional[Enum['influxdb','graphite','splunk_hec']] $metrics_server_type = undef,
1516
Optional[String] $metrics_server_hostname = undef,
@@ -30,15 +31,28 @@
3031
force => true,
3132
}
3233

34+
$_remote_metrics_enabled = if $remote_metrics_enabled =~ Boolean {
35+
$remote_metrics_enabled
36+
} elsif fact('pe_server_version') =~ NotUndef {
37+
if versioncmp(fact('pe_server_version'), '2019.8.5') >= 0 {
38+
true
39+
} else {
40+
false
41+
}
42+
} else {
43+
false
44+
}
45+
3346
$config_hash = {
34-
'metrics_type' => $metrics_type,
35-
'pe_version' => $facts['pe_server_version'],
36-
'clientcert' => $::clientcert,
37-
'hosts' => $hosts.sort(),
38-
'metrics_port' => $metrics_port,
39-
'ssl' => $ssl,
40-
'excludes' => $excludes,
41-
'additional_metrics' => $additional_metrics,
47+
'metrics_type' => $metrics_type,
48+
'pe_version' => $facts['pe_server_version'],
49+
'clientcert' => $::clientcert,
50+
'hosts' => $hosts.sort(),
51+
'metrics_port' => $metrics_port,
52+
'ssl' => $ssl,
53+
'excludes' => $excludes,
54+
'additional_metrics' => $additional_metrics,
55+
'remote_metrics_enabled' => $_remote_metrics_enabled,
4256
}
4357

4458
file { "${puppet_metrics_collector::config_dir}/${metrics_type}.yaml" :

spec/defines/pe_metric_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'spec_helper'
2+
3+
describe 'puppet_metrics_collector::pe_metric' do
4+
let(:title) { 'test-service' }
5+
let(:params) {
6+
{metrics_port: 9000}
7+
}
8+
# This define has an undeclared dependency on the main
9+
# puppet_metrics_collector class.
10+
let(:pre_condition) { 'include puppet_metrics_collector' }
11+
12+
it 'compiles with minimal parameters set' do
13+
expect(subject).to compile
14+
end
15+
16+
describe 'remote metric collection' do
17+
it 'is disabled by default due to CVE-2020-7943' do
18+
expect(subject).to contain_file('/opt/puppetlabs/puppet-metrics-collector/config/test-service.yaml').with_content(/remote_metrics_enabled: false/)
19+
end
20+
21+
context 'when the PE version is 2019.8.5 or newer' do
22+
let(:facts) {
23+
{pe_server_version: '2019.8.5'}
24+
}
25+
26+
it 'is enabled by default' do
27+
expect(subject).to contain_file('/opt/puppetlabs/puppet-metrics-collector/config/test-service.yaml').with_content(/remote_metrics_enabled: true/)
28+
end
29+
end
30+
31+
context 'when the PE version is 2019.8.4 or older' do
32+
let(:facts) {
33+
{pe_server_version: '2019.8.4'}
34+
}
35+
36+
it 'is disabled by default' do
37+
expect(subject).to contain_file('/opt/puppetlabs/puppet-metrics-collector/config/test-service.yaml').with_content(/remote_metrics_enabled: false/)
38+
end
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)