Skip to content

Add default TLS client cert and key paths for Prometheus input and receiver #1510

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion plugins/inputs/prometheus/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func Test_loadConfigFromFileWithTargetAllocator(t *testing.T) {
assert.NoError(t, err)
assert.True(t, taManager.enabled)
assert.Equal(t, taManager.config.TargetAllocator.CollectorID, "collector-1")
assert.Equal(t, taManager.config.TargetAllocator.TLSSetting.CAFile, DEFAULT_TLS_CA_FILE_PATH)
assert.Equal(t, taManager.config.TargetAllocator.TLSSetting.CAFile, DefaultTLSCaFilePath)

}

Expand Down
10 changes: 8 additions & 2 deletions plugins/inputs/prometheus/target_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import (
"github.com/aws/amazon-cloudwatch-agent/cfg/envconfig"
)

var DEFAULT_TLS_CA_FILE_PATH = filepath.Join("/etc", "amazon-cloudwatch-observability-agent-cert", "tls-ca.crt")
var (
DefaultTLSCaFilePath = filepath.Join("/etc", "amazon-cloudwatch-observability-agent-cert", "tls-ca.crt")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this also have to be amazon-cloudwatch-observability-agent-ta-client-cert ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the helm changes have:

apiVersion: v1
kind: Secret
metadata:
  labels:
      {{- include "amazon-cloudwatch-observability.labels" . | nindent 4}}
  name: "amazon-cloudwatch-observability-agent-ta-client-cert"
  namespace: {{ .Release.Namespace }}
data:
  ca.crt: {{ $ca.Cert | b64enc }}
  tls.crt: {{ $agentTAClientCert.Cert | b64enc }}
  tls.key: {{ $agentTAClientCert.Key | b64enc }}
---

https://github.com/aws-observability/helm-charts/pull/163/files

Copy link
Contributor Author

@musa-asad musa-asad Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't since it's grabbing the server CA, not the client CA.

It needs to use the server CA to verify the client cert.

DefaultTLSCertFilePath = filepath.Join("/etc", "amazon-cloudwatch-observability-agent-ta-client-cert", "client.crt")
DefaultTLSKeyFilePath = filepath.Join("/etc", "amazon-cloudwatch-observability-agent-ta-client-cert", "client.key")
)

const DEFAULT_TLS_RELOAD_INTERVAL_SECONDS = 10 * time.Second

Expand Down Expand Up @@ -149,7 +153,9 @@ func (tam *TargetAllocatorManager) loadConfig(filename string) error {
return nil // no target allocator return
}
//has target allocator
tam.config.TargetAllocator.TLSSetting.CAFile = DEFAULT_TLS_CA_FILE_PATH
tam.config.TargetAllocator.TLSSetting.CAFile = DefaultTLSCaFilePath
tam.config.TargetAllocator.TLSSetting.CertFile = DefaultTLSCertFilePath
tam.config.TargetAllocator.TLSSetting.KeyFile = DefaultTLSKeyFilePath
tam.config.TargetAllocator.TLSSetting.ReloadInterval = DEFAULT_TLS_RELOAD_INTERVAL_SECONDS
return nil
}
Expand Down
10 changes: 7 additions & 3 deletions translator/translate/otel/receiver/prometheus/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (

const (
otelConfigParsingError = "has invalid keys: global"
defaultTlsCaPath = "/etc/amazon-cloudwatch-observability-agent-cert/tls-ca.crt"
defaultTLSCaPath = "/etc/amazon-cloudwatch-observability-agent-cert/tls-ca.crt"
defaultTLSCertPath = "/etc/amazon-cloudwatch-observability-agent-ta-client-cert/client.crt"
defaultTLSKeyPath = "/etc/amazon-cloudwatch-observability-agent-ta-client-cert/client.key"
)

var (
Expand Down Expand Up @@ -92,9 +94,11 @@ func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) {
cfg.PrometheusConfig.TracingConfig = promCfg.TracingConfig
} else {
// given prometheus config is in otel format so check if target allocator is being used
// then add the default cert for TargetAllocator
// then add the default ca, cert, and key for TargetAllocator
if cfg.TargetAllocator != nil && len(cfg.TargetAllocator.CollectorID) > 0 {
cfg.TargetAllocator.TLSSetting.Config.CAFile = defaultTlsCaPath
cfg.TargetAllocator.TLSSetting.Config.CAFile = defaultTLSCaPath
cfg.TargetAllocator.TLSSetting.Config.CertFile = defaultTLSCertPath
cfg.TargetAllocator.TLSSetting.Config.KeyFile = defaultTLSKeyPath
cfg.TargetAllocator.TLSSetting.ReloadInterval = 10 * time.Second
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func TestTranslator(t *testing.T) {
ClientConfig: confighttp.ClientConfig{
TLSSetting: configtls.ClientConfig{
Config: configtls.Config{
CAFile: defaultTlsCaPath,
CAFile: defaultTLSCaPath,
CertFile: defaultTLSCertPath,
KeyFile: defaultTLSKeyPath,
ReloadInterval: 10 * time.Second,
},
},
Expand Down
Loading