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 global TLS config #588

Merged
merged 6 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ mutualtlsclient: # takes priority over mutualtlsfilespath if not emtpy
certfile: "/etc/certs/client/client.crt" # client certification file
keyfile: "/etc/certs/client/client.key" # client key
cacertfile: "/etc/certs/client/ca.crt" # for server certification
tlsclient:
cacertfile: "/etc/certs/client/ca.crt" # CA certificate file for server certification on TLS connections, appended to the system CA pool if not empty
tlsserver:
deploy: false # if true, TLS server will be deployed instead of HTTP
certfile: "/etc/certs/server/server.crt" # server certification file
Expand Down Expand Up @@ -696,6 +698,7 @@ care of lower/uppercases**) : `yaml: a.b --> envvar: A_B` :
- **MUTUALTLSCLIENT_CERTFILE**: client certification file for mutual TLS client certification, takes priority over MUTUALTLSFILESPATH if not empty
- **MUTUALTLSCLIENT_KEYFILE**: client key file for mutual TLS client certification, takes priority over MUTUALTLSFILESPATH if not empty
- **MUTUALTLSCLIENT_CACERTFILE**: CA certification file for server certification for mutual TLS authentication, takes priority over MUTUALTLSFILESPATH if not empty
- **TLSCLIENT_CACERTFILE**: CA certificate file for server certification on TLS connections, appended to the system CA pool if not empty
- **TLSSERVER_DEPLOY**: if _true_ TLS server will be deployed instead of HTTP
- **TLSSERVER_CERTFILE**: server certification file for TLS Server (default: "/etc/certs/server/server.crt")
- **TLSSERVER_KEYFILE**: server key file for TLS Server (default: "/etc/certs/server/server.key")
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func getConfig() *types.Configuration {
v.SetDefault("MutualTLSClient.CertFile", "")
v.SetDefault("MutualTLSClient.KeyFile", "")
v.SetDefault("MutualTLSClient.CaCertFile", "")
v.SetDefault("TLSClient.CaCertFile", "")

v.SetDefault("TLSServer.Deploy", false)
v.SetDefault("TLSServer.CertFile", "/etc/certs/server/server.crt")
Expand Down
2 changes: 2 additions & 0 deletions config_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ mutualtlsclient: # takes priority over mutualtlsfilespath if not emtpy
certfile: "/etc/certs/client/client.crt" # client certification file
keyfile: "/etc/certs/client/client.key" # client key
cacertfile: "/etc/certs/client/ca.crt" # for server certification
tlsclient:
cacertfile: "/etc/certs/client/ca.crt" # CA certificate file for server certification on TLS connections, appended to the system CA pool if not empty
tlsserver:
deploy: false # if true, TLS server will be deployed instead of HTTP
certfile: "/etc/certs/server/server.crt" # server certification file
Expand Down
31 changes: 24 additions & 7 deletions outputs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@

customTransport := http.DefaultTransport.(*http.Transport).Clone()

if customTransport.TLSClientConfig == nil {
customTransport.TLSClientConfig = &tls.Config{}

Check failure on line 197 in outputs/client.go

View workflow job for this annotation

GitHub Actions / lint

G402: TLS MinVersion too low. (gosec)
}

customTransport.TLSClientConfig.MinVersion = tls.VersionTLS12

if customTransport.TLSClientConfig.RootCAs == nil {
pool, err := x509.SystemCertPool()
if err != nil {
pool = x509.NewCertPool()
}
customTransport.TLSClientConfig.RootCAs = pool
}

if c.Config.TLSClient.CaCertFile != "" {
caCert, err := ioutil.ReadFile(c.Config.TLSClient.CaCertFile)
if err != nil {
log.Printf("[ERROR] : %v - %v\n", c.OutputType, err.Error())
}
customTransport.TLSClientConfig.RootCAs.AppendCertsFromPEM(caCert)
}

if c.MutualTLSEnabled {
// Load client cert
var MutualTLSClientCertPath, MutualTLSClientKeyPath, MutualTLSClientCaCertPath string
Expand Down Expand Up @@ -221,13 +243,8 @@
if err != nil {
log.Printf("[ERROR] : %v - %v\n", c.OutputType, err.Error())
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
customTransport.TLSClientConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: caCertPool,
MinVersion: tls.VersionTLS12,
}
customTransport.TLSClientConfig.RootCAs.AppendCertsFromPEM(caCert)
customTransport.TLSClientConfig.Certificates = []tls.Certificate{cert}
} else {
// With MutualTLS enabled, the check cert flag is ignored
if !c.CheckCert {
Expand Down
6 changes: 6 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (f FalcoPayload) Check() bool {
type Configuration struct {
MutualTLSFilesPath string
MutualTLSClient MutualTLSClient
TLSClient TLSClient
TLSServer TLSServer
Debug bool
ListenAddress string
Expand Down Expand Up @@ -115,6 +116,11 @@ type MutualTLSClient struct {
CaCertFile string
}

// MutualTLSClient represents parameters for global TLS client options
type TLSClient struct {
CaCertFile string
}

// TLSServer represents parameters for TLS Server
type TLSServer struct {
Deploy bool
Expand Down
Loading