Skip to content

Commit e3ca85b

Browse files
committed
feat(agent): validate TLS certificates before enabling TLS for integrations
1 parent d5c7a3e commit e3ca85b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

agent/modules/configuration.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func ChangeIntegrationStatus(logTyp string, proto string, isEnabled bool, tlsOpt
8484
// Handle TLS configuration if specified
8585
if len(tlsOptions) > 0 && isEnabled {
8686
if tlsOptions[0] {
87+
if !utils.CheckIfPathExist(config.IntegrationCertPath) || !utils.CheckIfPathExist(config.IntegrationKeyPath) {
88+
return "", fmt.Errorf("TLS certificates not found. Please load certificates first")
89+
}
8790
// Enable TLS
8891
integration.TCP.TLSEnabled = true
8992
mod := GetModule(logTyp)
@@ -249,6 +252,7 @@ func EnableTLSForIntegration(logTyp string, proto string) (string, error) {
249252
if integration.TCP.Port == "" {
250253
return "", fmt.Errorf("TCP port not configured for %s", logTyp)
251254
}
255+
252256
port = integration.TCP.Port
253257
integration.TCP.TLSEnabled = true
254258

agent/modules/syslog.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"crypto/tls"
77
"errors"
8+
"fmt"
89
"io"
910
"net"
1011
"os"
@@ -96,6 +97,12 @@ func (m *SyslogModule) GetPort(proto string) string {
9697
func (m *SyslogModule) EnablePort(proto string, enableTLS bool) error {
9798
switch proto {
9899
case "tcp":
100+
if enableTLS {
101+
if !utils.CheckIfPathExist(config.IntegrationCertPath) || !utils.CheckIfPathExist(config.IntegrationKeyPath) {
102+
return fmt.Errorf("TLS certificates not found. Please load certificates first")
103+
}
104+
}
105+
99106
// Update TLS configuration before enabling
100107
m.TCPListener.TLSEnabled = enableTLS
101108
go m.enableTCP()

0 commit comments

Comments
 (0)