All docsStellar ControlMission control · by Stellar Systems v1.1.0

Deployment

Nomad

Stellar Control on HashiCorp Nomad, in containers: the jobs of NATS and of Stellar Control, their variables, TLS, reverse proxy, secrets and scaling.

Nomad is the workload orchestrator of HashiCorp: it schedules containers and processes on a cluster of machines from declarative job files. Stellar Systems delivers, with the container image, the Nomad job files that run Stellar Control on it: NATS with JetStream, and the services of the core, their web editor and simulated targets, in containers of the image stellar-control (Docker driver), behind a Traefik that finds them with its Nomad provider.

Files#

FileContent
agent-containers.hclExample of a Nomad agent running Stellar Control in containers: Docker driver with volumes, a private host network for NATS, no raw_exec
jobs/containers/nats.nomad.hclJob nats in a container of the official image, with the resolver of the operator
jobs/containers/cell.nomad.hclJob stellar: one container per component (or the core in one), the simulated targets, routed by Traefik from the tags of its API service
policies/traefik.hclACL policy of the Nomad provider of Traefik: it reads the services and their tags

Deploy#

On a Nomad agent configured like agent-containers.hcl, with the operator, the account and the users of NATS made with nsc (see NATS and JetStream):

Shell
# NATS, on the private network of the clients
nomad job run \
    -var data_dir=/srv/stellar/nats/data \
    -var resolver_conf=/etc/stellar/nats/resolver.conf \
    -var resolver_dir=/srv/stellar/nats/accounts \
    -var host_network=private \
    jobs/containers/nats.nomad.hcl
curl -fsS http://172.17.0.1:8222/healthz          # NATS is up, on the private network

# The secrets of Stellar Control, readable by its job only
nomad var put nomad/jobs/stellar \
    services_creds=@admin.creds bootstrap_creds=@bootstrap.creds \
    signing_key=@stellar-account-signing.nk account=A…

# Stellar Control
nomad job run \
    -var image=<registry>/stellar-control -var tag=<version> \
    -var host=control.example.org \
    -var repository=/srv/stellar/config \
    -var nats_url=nats://172.17.0.1:4222 \
    jobs/containers/cell.nomad.hcl
nomad job status stellar                          # its groups and their allocations
nomad alloc logs <alloc> main                     # logs of a component

repository is a configuration repository (a Git working copy) on every client that may run the job; the containers mount it read only. Without NATS authentication (a trial), run the job with -var secrets=false and skip the variable.

Containers#

Stellar Control runs in containers of the image stellar-control, one per component (or the core in one, all_in_one=true) and one per simulated target:

  • Configuration. Before the reconciler starts, the prestart task publish-config runs stellar compile <repository> --publish <nats> with the CLI of the image: every restart of the reconciler group publishes the configuration repository as it is.
  • Order. Nomad does not order jobs: run Stellar Control once NATS answers. A component that cannot reach NATS retries its connection, and a failed allocation is rescheduled every 10 s.
  • Routes from tags. The service <job>-api carries the router of Traefik: its host, entry point, TLS and certificate resolver.
  • Ports of their own. Each API instance listens on 8080 in its container, published on a port chosen by Nomad; Traefik spreads the requests among them. Its health check is GET /v1/openapi.json. The editor is found by the API through its service <job>-editor.
  • Hardened containers. Read-only root file system, no capabilities, no-new-privileges, the user of the image (10001); the secrets are files of that user, mode 0400. The only host path is the configuration repository, mounted read only (read and write for the editor): the Docker plugin needs volumes { enabled = true }.
  • NATS off the public address. The components reach NATS at nats_url: its ports are published on the host network host_network of the clients, a private one on a host with a public address (agent-containers.hcl: the bridge of Docker).
  • Metrics. Each component serves /metrics and /healthz on port 9100 of its container, published as the service <job>-metrics. See Observability.

Variables of the jobs#

nats (jobs/containers/nats.nomad.hcl)

VariableDefaultMeaning
data_dir—JetStream storage on the client, kept across restarts
resolver_conf—Operator and resolver configuration (resolver.conf of nsc generate config)
resolver_dir—Directory of the accounts of a full resolver, as written in resolver_conf; an existing directory with a memory resolver
host_networkdefaultHost network of the clients where the ports are published (default: the address of the client)
port, monitoring_port4222, 8222Client and monitoring ports
tls_dirempty (no TLS)Directory of ca.pem, server.pem and server-key.pem
tls_verifyfalseRequire client certificates signed by the CA (mTLS)
leafnode_port0 (none)Port of the leaf nodes of the benches, with TLS
websocket_port0 (none)NATS WebSocket for leaf nodes and clients behind firewalls (443 in production), with TLS
encryptfalseJetStream encrypts its files, with the key of the Nomad variable nomad/jobs/nats (see Encryption at rest)
nats_version2.12.15Tag of the image nats

stellar (jobs/containers/cell.nomad.hcl)

VariableDefaultMeaning
image, tagstellar-control, latestImage of the components; an immutable tag in production (latest is pulled at every start)
host—Host name of Stellar Control, routed by Traefik
repository—Configuration repository on the clients
configarchive of 7 days, JSON logsGlobal configuration of the components, in YAML; the job sets NATS, the API and the metrics through the environment
nats_url, nats_cathe address of the client, port 4222; emptyNATS server, reached from the containers; its CA
secretstrueCredentials, signing key and account from the Nomad variable secrets_path (items services_creds, bootstrap_creds, signing_key, account, and forge_token optionally)
secrets_pathnomad/jobs/stellarThat variable, readable by the job only (nomad/jobs/<job>)
all_in_onefalseThe core in one container (stellar-control, group mcs)
counts1 per group (0 for the editor)Instances of each group at deployment
memory{default = 128, mcs = 384, editor = 256, simulators = 64}Memory of the containers in MB, by group
storage0JetStream storage of the deployment in bytes (archive.max_bytes), see Storage of a deployment; 0: bounded by age only
editor_repository, editor_pathempty, .Web editor: its Git remote as seen from its container (/srv/stellar/config, the configuration repository, mounted read and write for it)
editor_forgeempty (that of config)Forge of the editor: direct publishes a proposed draft at once
simulatorstwo example targetsSimulated targets, one container each (simulation, target, gateway, driver); the defaults are the targets sim-1 and psu-sim-1 of the example configuration
auth_issuer, auth_audience, auth_organization, auth_client_id, auth_cli_client_id, auth_roles_prefixempty, stellar: for the prefixOpenID Connect provider of the users (see Identity and Roles); empty issuer: declared identities, no sign-in
traefik_entrypointwebsecureEntry point of Traefik
traefik_certresolveremptyCertificate resolver; empty, the default certificate of Traefik
traefik_wildcardemptyWildcard domain of the certificate (*.example.org)
rootlessfalseA Nomad client not run as root with a rootless engine (Podman, a development machine): the components run as root in their containers, without capabilities, to read their secrets

Scaling#

Every group scales from 0 to its maximum with nomad job scale stellar <group> <n>; the initial counts come from the counts variable.

GroupInstancesHow they share the work
api0 to 3All active; Traefik spreads the requests among them
executor0 to 3All active: runs spread by identifier, targets held by leases
scheduler0 to 3All active: each run submitted once
reconciler0 to 3One leader, the others stand by
compute, alarms, transfers0 to 3One active, the others take over within leader_ttl
mcs0 to 1The core in one container, with all_in_one=true
editor0 to 1Drafts are working copies in its allocation
simulators0 to 1One container per simulated target

At 0, a component stops: api at 0 closes the web application and the CLI. See Running the Services.

With all_in_one=true, stellar-control runs in the group mcs beside the simulators: about a quarter of the memory of the separate services.

TLS#

A deployment uses the certificates of its own CA: tls_dir (ca.pem, server.pem, server-key.pem) and tls_verify (mTLS) for the nats job, nats_ca for Stellar Control, and leafnode_port, websocket_port for the benches and the edges on other networks. Clients then use tls://<host>:4222 and the CA (STELLAR_NATS_CA), or wss://<host>:<websocket_port> through the WebSocket.

Reverse proxy#

Traefik serves the API, the web application and their WebSockets over HTTPS. Its Nomad provider finds the API by the tags of its service, with a token of the policy policies/traefik.hcl:

YAML
providers:
  nomad:
    endpoint:
      address: http://172.17.0.1:4646      # the API of Nomad, on the private network
      token: <a token of the policy traefik>
    namespaces: [default]
    exposedByDefault: false

In production it listens on 80 and 443 and gets its certificates from an ACME certificate resolver (traefik_certresolver). The CLI checks the certificate against the system roots, or with STELLAR_API_CA when it is not signed by a public CA:

Shell
STELLAR_API_CA=/etc/stellar/tls/ca.pem \
  stellar send sim-1 'tcu[TCU1].ping' --api https://control.example.org

Secrets#

No secret is written in a job or in a repository: each lives in a Nomad variable (encrypted at rest by Nomad, readable by the tasks of its job only) or with the operator of NATS.

SecretWhereRead byRotation
Operator key of NATSWith nsc, offlineWhoever makes the accountsA new operator: every account signed again
Signing key of the account, credentials of the services and bootstrap credentialsnomad/jobs/stellar (secrets_path)The job stellar (secrets=true)New values in the variable, then the job run again
Forge token of the editorforge_token in the same variableThe editorSet it again: the editor restarts with it
JetStream keynomad/jobs/nats (jetstream_key, with encrypt=true)NATSSee Encryption at rest
TLS keysFiles of tls_dir on the Nomad clients, or ACMENATS, TraefikA new certificate in place and a restart; ACME renews by itself

Keep the data directory of JetStream, the configuration repository and the data directory of Nomad on encrypted disks. See TLS, Encryption and Secrets.

↑↓ to moveEnter to open