Skip to content

Commit 1565695

Browse files
author
Frank Jogeleit
committed
SMTP TLS Config
Signed-off-by: Frank Jogeleit <[email protected]>
1 parent 2a76543 commit 1565695

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

charts/policy-reporter/values.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ emailReports:
233233
password: ""
234234
from: "" # displayed from email address
235235
encryption: "" # default is none, supports ssl/tls and starttls
236+
skipTLS: false
237+
certificate: ""
236238

237239
# basic summary report
238240
summary:

pkg/config/config.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,14 @@ type GCS struct {
221221

222222
// SMTP configuration
223223
type SMTP struct {
224-
Host string `mapstructure:"host"`
225-
Port int `mapstructure:"port"`
226-
Username string `mapstructure:"username"`
227-
Password string `mapstructure:"password"`
228-
From string `mapstructure:"from"`
229-
Encryption string `mapstructure:"encryption"`
224+
Host string `mapstructure:"host"`
225+
Port int `mapstructure:"port"`
226+
Username string `mapstructure:"username"`
227+
Password string `mapstructure:"password"`
228+
From string `mapstructure:"from"`
229+
Encryption string `mapstructure:"encryption"`
230+
SkipTLS bool `mapstructure:"skipTLS"`
231+
Certificate string `mapstructure:"certificate"`
230232
}
231233

232234
// EmailReport configuration

pkg/config/resolver.go

+24-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package config
22

33
import (
44
"context"
5+
"crypto/tls"
6+
"crypto/x509"
7+
"os"
58
"time"
69

710
goredis "github.com/go-redis/redis/v8"
@@ -405,14 +408,30 @@ func (r *Resolver) ViolationsReporter() *violations.Reporter {
405408
}
406409

407410
func (r *Resolver) SMTPServer() *mail.SMTPServer {
411+
smtp := r.config.EmailReports.SMTP
412+
408413
server := mail.NewSMTPClient()
409-
server.Host = r.config.EmailReports.SMTP.Host
410-
server.Port = r.config.EmailReports.SMTP.Port
411-
server.Username = r.config.EmailReports.SMTP.Username
412-
server.Password = r.config.EmailReports.SMTP.Password
414+
server.Host = smtp.Host
415+
server.Port = smtp.Port
416+
server.Username = smtp.Username
417+
server.Password = smtp.Password
413418
server.ConnectTimeout = 10 * time.Second
414419
server.SendTimeout = 10 * time.Second
415-
server.Encryption = email.EncryptionFromString(r.config.EmailReports.SMTP.Encryption)
420+
server.Encryption = email.EncryptionFromString(smtp.Encryption)
421+
server.TLSConfig = &tls.Config{InsecureSkipVerify: smtp.SkipTLS}
422+
423+
if smtp.Certificate != "" {
424+
caCert, err := os.ReadFile(smtp.Certificate)
425+
if err != nil {
426+
zap.L().Error("failed to read certificate for SMTP Client", zap.String("path", smtp.Certificate))
427+
return server
428+
}
429+
430+
caCertPool := x509.NewCertPool()
431+
caCertPool.AppendCertsFromPEM(caCert)
432+
433+
server.TLSConfig.RootCAs = caCertPool
434+
}
416435

417436
return server
418437
}

0 commit comments

Comments
 (0)