Categorygithub.com/choria-io/go-network-broker
modulepackage
1.3.2
Repository: https://github.com/choria-io/go-network-broker.git
Documentation: pkg.go.dev

# README

Choria Network Broker

This is a NATS compatible Network Broker for use by the Choria Orchestration System.

Please review the official documentation at choria.io for installation and usage.

Motivation

Running a middleware broker for Choria is quite the undertaking, while NATS is really easy to operate it does have a plethora of settings and using the wrong ones can adversely affect your network.

The Choria Network Broker is a managed NATS broker that integrates into the choria broker command. It ships as part of the normal Choria package and exist within the single binary.

It sets up the NATS server in ways thats suitable for use by Choria with sane defaults enabled.

Features:

  • Works by default without any broker specific configuration in your Choria broker
  • Secure by default - only accepts TLS connections with certificates signed by the known CA
  • Support NATS Accounts technology for large scale multi tenancy
  • Supports Clustering using a simple comma separated list of peers - TLS by default
  • Support Gateways enabling communication between NATS clusters - an alternative to Choria Federation
  • Support Leafnodes enabling joining older or unauthenticated clients to a secure multi tenant network
  • Exports statistics using the popular Prometheus format via the normal Choria statistics port

Configuration

The broker is configured using the Choria daemon configuration, below a reference of the settings it supports.

Choria core settings that affect the broker:

SettingDescription
plugin.choria.broker_networkEnables the network broker when running choria broker run
loglevelThe logging level to use
plugin.choria.stats_portThe port Choria listens on for metrics, when >0 the broker enables statistics
plugin.choria.stats_addressThe network address to listen on for metrics requests

It also uses the build.maxBrokerClients build time configuration in Choria to configure it's maximum connection limit, this defaults to 50 000.

Basic Broker Settings

SettingDescriptionDefault
plugin.choria.network.listen_addressThe network address to listen on::
plugin.choria.network.client_portThe port to listen on for network clients4222
plugin.choria.network.write_deadlineThe time to allow for writes to network clients to complete before considering them slow5s
plugin.choria.network.client_hostsList of hosts - ip addresses or cidrs - that are allowed to use clientsall
plugin.choria.network.client_tls_force_requiredForce TLS on for client connections regardless of build settingsfalse
plugin.choria.network.tls_timeoutSets the timeout for establishing TLS connections2

Cluster Settings

Network Clusters are suitable for creating a cluster of up to 5 nodes on a local LAN. These form a full Mesh and provides scalability and HA.

They are based on NATS technology and you can read more about them at NATS.io

SettingDescriptionDefault
plugin.choria.network.peer_portThe port to listen on for broker cluster peers5222
plugin.choria.network.peer_userUsername to connect to cluster peers withunset
plugin.choria.network.peer_passwordPassword to use when connecting to cluster peersunset
plugin.choria.network.peersComma separated List of cluster peers to connect tounset

Gateway Settings

Gateways allow you to combine multiple Clusters into a single large cluster. This allow you to span your collective across multiple data centers without the need for the much harder to configure federation brokers.

By default if the broker is compiled with TLS the Gateway will use the same TLS settings for the connection - you can customize it on a per remote basis.

They are based on NATS technology and you can read more about them at NATS.io

SettingDescriptionDefault
plugin.choria.network.gateway_portThe port to listen to for Gateway connections, disabled when 00
plugin.choria.network.gateway_nameUnique name for the cluster listening on the portCHORIA
plugin.choria.network.gateway_remotesA comma sep list of remote names to activate""
plugin.choria.network.gateway_remote.C1.urlsA comma sep list of host:port combinations to connect to for the remote C1 cluster
plugin.choria.network.gateway_remote.C1.tls.certPath to a custom certificate for this remote only
plugin.choria.network.gateway_remote.C1.tls.keyPath to a custom private key for this remote only
plugin.choria.network.gateway_remote.C1.tls.caPath to a custom ca for this remote only
plugin.choria.network.gateway_remote.C1.tls.disableDisables the TLS configuration that would have inherited from the Choria Security systemfalse
plugin.choria.network.gateway_remote.C1.tls.verifyDisables full TLS verify for this remote onlytrue

Leafnode Settings

Leafnodes exist to take unauthenticated or unsecured connections and forge them into a specific Account (see below). They allow older Choria agents and clients to take part of a multi tenant or account secured network.

By default if the broker is compiled with TLS the leafnode will use the same TLS settings for the connection - you can customize it on a per remote basis.

They are based on NATS technology and you can read more about them at NATS.io

SettingDescriptionDefault
plugin.choria.network.leafnode_portThe port to listen to for Gateway connections, disabled when 00
plugin.choria.network.leafnode_remotesA comma sep list of remote names to activate""
plugin.choria.network.leafnode_remote.C1.urlA host:port combination to connect to for the remote C1 leafnode
plugin.choria.network.leafnode_remote.C1.accountThe local account name to use when connecting to the remote
plugin.choria.network.leafnode_remote.C1.credentialThe local credential file to use when connecting to the remote
plugin.choria.network.leafnode_remote.C1.tls.certPath to a custom certificate for this remote only
plugin.choria.network.leafnode_remote.C1.tls.keyPath to a custom private key for this remote only
plugin.choria.network.leafnode_remote.C1.tls.caPath to a custom ca for this remote only
plugin.choria.network.leafnode_remote.C1.tls.disableDisables the TLS configuration that would have inherited from the Choria Security systemfalse
plugin.choria.network.leafnode_remote.C1.tls.verifyDisables full TLS verify for this remote onlytrue

Accounts

Accounts are based on NATS technology, you can read more about them at NATS.io

SettingDescriptionDefault
plugin.choria.network.operator_accountThe operator account that is managing this cluster
plugin.choria.network.system_accountThe system account to use, when set enables server events

Statistics

When Statistics are enabled in Choria by setting plugin.choria.stats_port to nonzero the Choria Broker expose the following Prometheus statistics:

StatisticDescription
choria_network_connectionsCurrent connections on the network broker
choria_network_total_connectionsTotal connections received since start
choria_network_routesCurrent active routes to other brokers
choria_network_remotesCurrent active connections to other brokers
choria_network_leafnode_remotesCurrent active connections to leaf nodes
choria_network_in_msgsMessages received by the network broker
choria_network_out_msgsMessages sent by the network broker
choria_network_in_bytesTotal size of messages received by the network broker
choria_network_out_bytesTotal size of messages sent by the network broker
choria_network_slow_consumersTotal number of clients who were considered slow consumers
choria_network_subscriptionsNumber of active subscriptions to subjects on this broker

# Functions

NewServer creates a new instance of the Server struct with a fully configured NATS embedded.

# Structs

IPAuth implements gnatsd server.Authentication interface and allows IP limits to be configured, connections that do not match the configured IP or CIDRs are not allowed to publish to the network targets used by clients to request actions on nodes.
Logger is nats server.Logger compatible logging wrapper for logrus.
Server represents the Choria network broker server.

# Interfaces

BuildInfoProvider provider build time flag information, example go-choria/build.
ChoriaFramework provider access to choria.