add config option to enable or disable TLS for nats
This commit is contained in:
committed by
Michael Barz
parent
ff8b16f9da
commit
45b92fc56f
@@ -41,23 +41,26 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
|
||||
evtsCfg := cfg.Events
|
||||
|
||||
var rootCAPool *x509.CertPool
|
||||
if evtsCfg.TLSRootCACertificate != "" {
|
||||
rootCrtFile, err := os.Open(evtsCfg.TLSRootCACertificate)
|
||||
if err != nil {
|
||||
return err
|
||||
var tlsConf *tls.Config
|
||||
if evtsCfg.EnableTLS {
|
||||
var rootCAPool *x509.CertPool
|
||||
if evtsCfg.TLSRootCACertificate != "" {
|
||||
rootCrtFile, err := os.Open(evtsCfg.TLSRootCACertificate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rootCAPool, err = ociscrypto.NewCertPoolFromPEM(rootCrtFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
evtsCfg.TLSInsecure = false
|
||||
}
|
||||
|
||||
rootCAPool, err = ociscrypto.NewCertPoolFromPEM(rootCrtFile)
|
||||
if err != nil {
|
||||
return err
|
||||
tlsConf = &tls.Config{
|
||||
InsecureSkipVerify: evtsCfg.TLSInsecure, //nolint:gosec
|
||||
RootCAs: rootCAPool,
|
||||
}
|
||||
evtsCfg.TLSInsecure = false
|
||||
}
|
||||
|
||||
tlsConf := &tls.Config{
|
||||
InsecureSkipVerify: evtsCfg.TLSInsecure, //nolint:gosec
|
||||
RootCAs: rootCAPool,
|
||||
}
|
||||
client, err := server.NewNatsStream(
|
||||
natsjs.TLSConfig(tlsConf),
|
||||
|
||||
@@ -28,6 +28,7 @@ type Events struct {
|
||||
ConsumerGroup string `yaml:"group" env:"AUDIT_EVENTS_GROUP" desc:"The consumergroup of the service. One group will only get one copy of an event."`
|
||||
TLSInsecure bool `yaml:"tls_insecure" env:"OCIS_INSECURE;AUDIT_EVENTS_TLS_INSECURE" desc:"Whether to verify the server TLS certificates."`
|
||||
TLSRootCACertificate string `yaml:"tls_root_ca_certificate" env:"AUDIT_EVENTS_TLS_ROOT_CA_CERTIFICATE" desc:"The root CA certificate used to validate the server's TLS certificate. If provided AUDIT_EVENTS_TLS_INSECURE will be seen as false."`
|
||||
EnableTLS bool `yaml:"enable_tls" env:"OCIS_EVENTS_ENABLE_TLS;AUDIT_EVENTS_ENABLE_TLS" desc:"Enable TLS for the connection to the events broker."`
|
||||
}
|
||||
|
||||
// Auditlog holds audit log information
|
||||
|
||||
@@ -25,6 +25,7 @@ func DefaultConfig() *config.Config {
|
||||
Endpoint: "127.0.0.1:9233",
|
||||
Cluster: "ocis-cluster",
|
||||
ConsumerGroup: "audit",
|
||||
EnableTLS: false,
|
||||
},
|
||||
Auditlog: config.Auditlog{
|
||||
LogToConsole: true,
|
||||
|
||||
Reference in New Issue
Block a user