diff --git a/setup/config/config_jetstream.go b/setup/config/config_jetstream.go index b8abed25c..a048e4d09 100644 --- a/setup/config/config_jetstream.go +++ b/setup/config/config_jetstream.go @@ -21,6 +21,9 @@ type JetStream struct { NoLog bool `yaml:"-"` // Disables TLS validation. This should NOT be used in production DisableTLSValidation bool `yaml:"disable_tls_validation"` + // A credentials file to be used for authentication, example: + // https://docs.nats.io/using-nats/developer/connecting/creds + Credentials Path `yaml:"credentials_path"` } func (c *JetStream) Prefixed(name string) string { @@ -38,6 +41,7 @@ func (c *JetStream) Defaults(opts DefaultOpts) { c.StoragePath = Path("./") c.NoLog = true c.DisableTLSValidation = true + c.Credentials = Path("") } } diff --git a/setup/jetstream/nats.go b/setup/jetstream/nats.go index c6b88e00f..09048cc94 100644 --- a/setup/jetstream/nats.go +++ b/setup/jetstream/nats.go @@ -103,6 +103,9 @@ func setupNATS(process *process.ProcessContext, cfg *config.JetStream, nc *natsc InsecureSkipVerify: true, })) } + if string(cfg.Credentials) != "" { + opts = append(opts, natsclient.UserCredentials(string(cfg.Credentials))) + } nc, err = natsclient.Connect(strings.Join(cfg.Addresses, ","), opts...) if err != nil { logrus.WithError(err).Panic("Unable to connect to NATS")