Skip to content

Commit 47683ec

Browse files
authored
Add default TLS client cert and key paths for Prometheus input and receiver (#1510)
1 parent b145032 commit 47683ec

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

plugins/inputs/prometheus/metrics_receiver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func Test_loadConfigFromFileWithTargetAllocator(t *testing.T) {
132132
assert.NoError(t, err)
133133
assert.True(t, taManager.enabled)
134134
assert.Equal(t, taManager.config.TargetAllocator.CollectorID, "collector-1")
135-
assert.Equal(t, taManager.config.TargetAllocator.TLSSetting.CAFile, DEFAULT_TLS_CA_FILE_PATH)
135+
assert.Equal(t, taManager.config.TargetAllocator.TLSSetting.CAFile, DefaultTLSCaFilePath)
136136

137137
}
138138

plugins/inputs/prometheus/target_allocator.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import (
3030
"github.com/aws/amazon-cloudwatch-agent/cfg/envconfig"
3131
)
3232

33-
var DEFAULT_TLS_CA_FILE_PATH = filepath.Join("/etc", "amazon-cloudwatch-observability-agent-cert", "tls-ca.crt")
33+
var (
34+
DefaultTLSCaFilePath = filepath.Join("/etc", "amazon-cloudwatch-observability-agent-cert", "tls-ca.crt")
35+
DefaultTLSCertFilePath = filepath.Join("/etc", "amazon-cloudwatch-observability-agent-ta-client-cert", "client.crt")
36+
DefaultTLSKeyFilePath = filepath.Join("/etc", "amazon-cloudwatch-observability-agent-ta-client-cert", "client.key")
37+
)
3438

3539
const DEFAULT_TLS_RELOAD_INTERVAL_SECONDS = 10 * time.Second
3640

@@ -149,7 +153,9 @@ func (tam *TargetAllocatorManager) loadConfig(filename string) error {
149153
return nil // no target allocator return
150154
}
151155
//has target allocator
152-
tam.config.TargetAllocator.TLSSetting.CAFile = DEFAULT_TLS_CA_FILE_PATH
156+
tam.config.TargetAllocator.TLSSetting.CAFile = DefaultTLSCaFilePath
157+
tam.config.TargetAllocator.TLSSetting.CertFile = DefaultTLSCertFilePath
158+
tam.config.TargetAllocator.TLSSetting.KeyFile = DefaultTLSKeyFilePath
153159
tam.config.TargetAllocator.TLSSetting.ReloadInterval = DEFAULT_TLS_RELOAD_INTERVAL_SECONDS
154160
return nil
155161
}

translator/translate/otel/receiver/prometheus/translator.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121

2222
const (
2323
otelConfigParsingError = "has invalid keys: global"
24-
defaultTlsCaPath = "/etc/amazon-cloudwatch-observability-agent-cert/tls-ca.crt"
24+
defaultTLSCaPath = "/etc/amazon-cloudwatch-observability-agent-cert/tls-ca.crt"
25+
defaultTLSCertPath = "/etc/amazon-cloudwatch-observability-agent-ta-client-cert/client.crt"
26+
defaultTLSKeyPath = "/etc/amazon-cloudwatch-observability-agent-ta-client-cert/client.key"
2527
)
2628

2729
var (
@@ -92,9 +94,11 @@ func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) {
9294
cfg.PrometheusConfig.TracingConfig = promCfg.TracingConfig
9395
} else {
9496
// given prometheus config is in otel format so check if target allocator is being used
95-
// then add the default cert for TargetAllocator
97+
// then add the default ca, cert, and key for TargetAllocator
9698
if cfg.TargetAllocator != nil && len(cfg.TargetAllocator.CollectorID) > 0 {
97-
cfg.TargetAllocator.TLSSetting.Config.CAFile = defaultTlsCaPath
99+
cfg.TargetAllocator.TLSSetting.Config.CAFile = defaultTLSCaPath
100+
cfg.TargetAllocator.TLSSetting.Config.CertFile = defaultTLSCertPath
101+
cfg.TargetAllocator.TLSSetting.Config.KeyFile = defaultTLSKeyPath
98102
cfg.TargetAllocator.TLSSetting.ReloadInterval = 10 * time.Second
99103
}
100104
}

translator/translate/otel/receiver/prometheus/translator_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ func TestTranslator(t *testing.T) {
8080
ClientConfig: confighttp.ClientConfig{
8181
TLSSetting: configtls.ClientConfig{
8282
Config: configtls.Config{
83-
CAFile: defaultTlsCaPath,
83+
CAFile: defaultTLSCaPath,
84+
CertFile: defaultTLSCertPath,
85+
KeyFile: defaultTLSKeyPath,
8486
ReloadInterval: 10 * time.Second,
8587
},
8688
},

0 commit comments

Comments
 (0)