This release changes how the client decides to use TLS and which servers it takes from the cluster. Read Breaking below before upgrading.
Breaking:
- A
tls://orwss://URL is always connected to with TLS. WithTlsMode.Prefer, atls://URL used to be opportunistic, so a server that did not offer TLS got a plaintext connection. It now fails (#1300) - A
tls://orwss://URL among the configured servers requires TLS for every server, configured or discovered, in the defaultTlsMode.Auto. A list that mixesnats://withtls://orwss://no longer connects to a server without TLS. SetTlsMode.Preferto keep each URL as written (#1300) - With TLS after INFO, servers are discovered only from INFO received inside TLS. The
connect_urlsin the plaintext INFO sent before the TLS upgrade are no longer used. nats-server 2.12 and later sends an INFO inside TLS after the first PONG, so discovery works as before. Against nats-server before 2.12, other cluster members are not discovered until a later INFO brings them, which happens when cluster membership changes. List all servers in the URL to keep failover. Plaintext, handshake-first TLS and WebSocket connections are unchanged (#1300) - Discovered servers are dialled with the transport and TLS of the connection they were learned on. A
connect_urlsentry can no longer pick the scheme, so a server cannot move the client to plaintext or to another transport. A server learned over TLS keeps TLS when it is reported again over a plaintext connection (#1300) connect_urlsentries must behostorhost:port. Entries with a scheme, user info, a path, whitespace or control characters are skipped with a warning. An entry with user info (x@host:port) used to make the client log in to that server asx; configure such a server directly with its credentials instead (#1300)- When TLS is required, a socket from
SocketConnectionFactoryorOnSocketAvailableAsyncmust support it. It must implementINatsTlsUpgradeableSocketConnection, so the client can upgrade it, or the newINatsTlsSocketConnection, to declare that it already provides TLS. Any other socket connection fails the attempt instead of carrying credentials in plaintext. TLS is required by atls://orwss://URL, certificate or CA options, orTlsMode.RequireorTlsMode.Implicit(#1300) - A
ws://URL is refused when TLS is required, and awss://URL withTlsMode.Disablefails on connect. These configuration errors failConnectAsynceven withRetryOnInitialConnect. Usewss://for TLS over WebSocket (#1300) - The server must send INFO first. Anything received before it fails the connection attempt, and the client retries as per its reconnect options (#1300)
New:
INatsTlsSocketConnectionfor custom socket connections that set up TLS themselves (#1300)NatsJSOrderedConsumerOpts.NamePrefixnames the consumers an ordered consumer creates{NamePrefix}_1,{NamePrefix}_2and so on, instead of random names, as other clients allow (#1293)
Fixed:
- A failed handshake-first TLS handshake closes the socket and fails the attempt. Previously the client could go on with the socket in plaintext (#1300)
- INFO still buffered from a closed connection no longer changes the server info or the discovered servers after a reconnect (#1300)
- An INFO without
connect_urlsno longer clears the discovered servers, and a malformed entry no longer stops the reconnect loop (#1300) - Errors for a required TLS name what made it required (the URL scheme, a
tls://orwss://URL in the list, certificate options, or the mode) instead of always "TlsMode is set to Require" (#1300) NatsSvcServer.StopAsyncdrains endpoints instead of disposing them, so requests already on the wire when the service stops are handled instead of dropped, asRemoveEndpointAsyncalready did for a single endpoint (#1282)
Thanks to @Ivandemidov00 for the service drain fix, and to @jnmoyne for asking for the ordered consumer name prefix.