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 tlsfirst option to pass through to NATS connection #189

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions cmd/jetstream-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func run() error {
cert := flag.String("tlscert", "", "NATS TLS public certificate")
key := flag.String("tlskey", "", "NATS TLS private key")
ca := flag.String("tlsca", "", "NATS TLS certificate authority chain")
tlsfirst := flag.Bool("tlsfirst", false, "If true, then NATS connections will be initiated with a TLS negotiation, rather than using a plain text / STARTTLS approach")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not call it STARTTLS, as it has some differences. It's more of implicit TLS vs explicit TLS.

Let's maybe write something along te lines "If enabled, forces explicit TLS without waiting for Server INFO".

server := flag.String("s", "", "NATS Server URL")
crdConnect := flag.Bool("crd-connect", false, "If true, then NATS connections will be made from CRD config, not global config")
cleanupPeriod := flag.Duration("cleanup-period", 30*time.Second, "Period to run object cleanup")
Expand Down Expand Up @@ -111,6 +112,7 @@ func run() error {
NATSCA: *ca,
NATSCertificate: *cert,
NATSKey: *key,
NATSTLSFirst: *tlsfirst,
KubeIface: kc,
JetstreamIface: jc,
Namespace: *namespace,
Expand Down
5 changes: 5 additions & 0 deletions controllers/jetstream/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type Options struct {
NATSCertificate string
NATSKey string

NATSTLSFirst bool

Namespace string
CRDConnect bool
CleanupPeriod time.Duration
Expand Down Expand Up @@ -180,6 +182,9 @@ func (c *Controller) Run() error {
opts := make([]nats.Option, 0)
// Always attempt to have a connection to NATS.
opts = append(opts, nats.MaxReconnects(-1))
if c.opts.NATSTLSFirst {
opts = append(opts, nats.TLSHandshakeFirst())
}
natsCtxDefaults := &natsContextDefaults{Name: c.opts.NATSClientName}
if !c.opts.CRDConnect {
// Use JWT/NKEYS based credentials if present.
Expand Down