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 default TLS client cert and key paths for Prometheus input and receiver #1510

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
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")
DefaultTLSCertFilePath = filepath.Join("/etc", "amazon-cloudwatch-observability-agent-outbound-cert", "client.crt")
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that we already have amazon-cloudwatch-observability-agent-cert used in a couple of places. Is the outbound-cert new? Is it only for TA?

Copy link
Contributor Author

@musa-asad musa-asad Jan 24, 2025

Choose a reason for hiding this comment

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

The outbound-cert is only for when the agent behaves as a client in mTLS. Right now, it's only being used for when the agent acts as a client to the TA server, but it could be used against other servers too.

  • amazon-cloudwatch-observability-agent-client-cert -> client cert and key for fluent-bit
  • amazon-cloudwatch-observability-agent-server-cert -> server cert and key for agent (technically can be used in this place, but avoided due to separation of concerns)
  • amazon-cloudwatch-observability-agent-cert -> server cert and key for dcgm, neuron, and ta
  • amazon-cloudwatch-observability-agent-outbound-cert -> client cert and key for agent

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

const DEFAULT_TLS_RELOAD_INTERVAL_SECONDS = 10 * time.Second

Expand Down Expand Up @@ -150,7 +154,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-outbound-cert/client.crt"
defaultTLSKeyPath = "/etc/amazon-cloudwatch-observability-agent-outbound-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