Configuration
leafnodes
Configuration Block
leafnodes
Configuration BlockThe leaf node configuration block is used to configure incoming as well as outgoing leaf node connections. Most properties are for the configuration of incoming connections. The properties remotes
and reconnect
are for outgoing connections.
Property | Description |
---|---|
| Interface where the server will listen for incoming leafnode connections. |
| Port where the server will listen for incoming leafnode connections (default is 7422). |
| Combines |
| TLS configuration block (same as other nats-server |
| Hostport |
| if |
| Authorization block. See Authorization Block section below. |
| List of |
| Interval in seconds at which reconnect attempts to a remote server are made. |
| Configures compression of leafnode connections similar to cluster routes. Defaults to |
TLS Block
As of NATS v2.10.0
The tls
block for leafnodes
configuration has an additional field enabling a TLS-first handshake between the remote and the accepting server.
Property | Description |
---|---|
| If |
Accepting side
Since Leafnodes can connect to a variety of servers, the ability to indicate if the TLS handshake should be done first is configured in 2 places. The accepting side is in the tls
block of the leafnodes
block.
With the above configuration, an older server, or a server that does not have the remote configuration also configured with handshake_first: true
, will fail to create a leafnode connection because the accepting-side server will initiate the TLS handshake while the soliciting side will wait for the INFO protocol to be received.
Remote side
To indicate that a leafnode connection should perform the TLS handshake first, it needs to be configured in the remote configuration:
If the remote is configured as such but the server it is connecting to does not have handshake_first: true
configured, the connection will fail since the solicit side is performing a TLS handshake but will receive an INFO protocol in clear.
Authorization Block
A leaf node can authenticate against any user account on the hub (the incoming side of the connection), including those defined in the accounts themselves. This authorization block is therefore optional if appropriate account users already exist.
Whether configuring users in the account or in this dedicated authorization block is more convenient will depend on your deployment style.
Property | Description |
---|---|
| Username for the leaf node connection. |
| Password for the user entry. |
| Account this leaf node connection should be bound to. |
| Maximum number of seconds to wait for leaf node authentication. |
| List of credentials and account to bind to leaf node connections. See User Block section below. |
Users Block
Property | Description |
---|---|
| Username for the leaf node connection. |
| Password for the user entry. |
| Account this leaf node connection should be bound to. |
Here are some examples of using basic user/password authentication for leaf nodes (note while this is using accounts it is not using JWTs)
Singleton mode:
With above configuration, if a soliciting server creates a Leafnode connection with url: nats://leaf:secret@host:port
, then the accepting server will bind the leafnode connection to the account "TheAccount". This account needs to exist otherwise the connection will be rejected.
Multi-users mode:
With the above, if a server connects using leaf1:secret@host:port
, then the accepting server will bind the connection to account account1
. If using leaf2
user, then the accepting server will bind to connection to account2
.
If username/password (either singleton or multi-users) is defined, then the connecting server MUST provide the proper credentials otherwise the connection will be rejected.
If no username/password is provided, it is still possible to provide the account the connection should be associated with:
With the above, a connection without credentials will be bound to the account "TheAccount".
If other form of credentials are used (jwt, nkey or other), then the server will attempt to authenticate and if successful associate to the account for that specific user. If the user authentication fails (wrong password, no such user, etc..) the connection will be also rejected.
LeafNode remotes
Entry Block
remotes
Entry BlockProperty | Description |
---|---|
| Leafnode URL (URL protocol should be |
| Leafnode URL array. Supports multiple URLs for discovery, e.g., urls: [ "nats-leaf://host1:7422", "nats-leaf://host2:7422" ] |
| IF true, always try connecting in sequence on the URLs in the list. Default behavior if to shuffle the URLs and start connection attempts with a random URL |
| Account name or JWT public key identifying the local account to bind to this remote server. Any traffic locally on this account will be forwarded to the remote server. |
| List of subjects which will not be imported over this leaf node connection. Subscriptions to those subjects will not be propagated to the hub. |
| List of subjects which will not be exported over this leaf node connection. Subscriptions to those subjects will not be propagated into the leaf node. |
| Credential file for connecting to the leafnode server. |
| Nkey used for connecting to the leafnode server. |
| A TLS configuration block. Leafnode client will use specified TLS certificates when connecting/authenticating. |
| If connecting with Websocket protocol, this boolean ( |
| If connecting with Websocket protocol, this boolean indicates to the remote server that it wishes not to mask outbound WebSocket frames. The default is |
| Configures compression of leafnode connections similar to cluster routes. Defaults to |
| Default is false. If set to true the roles of leaf node and hub will be reversed. This allows the hub to initiate a leaf node connection to the leaf. |
| Default |
Signature Handler
As of NATS Server v.2.9.0, for users embedding the NATS Server, it is possible to replace the use of the credentials file by a signature callback which will sign the nonce
and provide the JWT in the CONNECT
protocol. The RemoteLeafOpts
has a new field:
The callback definition is:
And example of how to use it can be found here
Connecting using WebSocket protocol
Since NATS 2.2.0, Leaf nodes support outbound WebSocket connections by specifying ws
as the scheme component of the remote server URLs:
Note that if a URL has the ws
scheme, all URLs the list must be ws
. You cannot mix and match. Therefore this would be considered an invalid configuration:
Note that the decision to make a TLS connection is not based on wss://
(as opposed to ws://
) but instead in the presence of a TLS configuration in the leafnodes{}
or the specific remote configuration block.
To configure Websocket in the remote server, check the Websocket section.
tls
Configuration Block
tls
Configuration BlockProperty | Description |
---|---|
| TLS certificate file. |
| TLS certificate key file. |
| TLS certificate authority file. |
| Skip certificate verification. |
| If |
| If |
| When set, only the specified TLS cipher suites will be allowed. Values must match golang version used to build the server. |
| List of TLS cypher curves to use in order. |
| TLS handshake timeout in fractional seconds. |
Last updated