Mirexa

Wiki Operations

Authentication and tokens

How Mirexa authenticates clients with offline-signed Ed25519 tokens — issuing them, trusting keys, the grant ceiling, expiry, renewal, key revocation in a cluster, and control-plane admin authentication.

Mirexa authenticates a client by a session token: a short claim — tenant, expiry and a permission bitmap — signed with an Ed25519 key. Tokens are minted offline by mirexa-cli token; a node holds only the issuers' public keys and verifies each token itself, with no token service and no network call. Authentication is on by default (since 2026-10-31): a single node with no keys configured makes its own issuer and admin token on first start, so it serves nothing unauthenticated and still needs no setup.

The model

sequenceDiagram
  participant Op as Operator (holds private key)
  participant C as Client
  participant N as Node (holds public keys)
  Op->>Op: mirexa-cli token issue -perms ... -validity 30m
  Op->>C: token (112 characters)
  C->>N: INIT frame = the token
  N->>N: signature, revoked key, expiry, validity window, defined bits
  N->>N: grant = token permissions ∩ security.max_permissions
  N-->>C: INIT_ACK with the grant
  • A token is the handshake. Its 84 bytes (tenant 2, reserved 2, expiry 8, permissions 8, signature 64) are the INIT frame's payload; the 112-character string is their base64. The client sends it verbatim.
  • The signature covers everything else, under a domain-separation prefix (mirexa-cst-v1), so no field can be edited without the key.
  • The node's grant can only be narrower than the token. It is the token's permissions intersected with security.max_permissions, and it is returned to the client in INIT_ACK so the client knows what it actually holds.
  • Permissions are checked per request. A frame the session's grant does not cover is refused with Unauthorized (0x0003). See permissions for each bit and the frames it guards.

What is checked, in order

Check Applies with auth off? Refusal message (to the client)
Not yet expired yes session token has expired; issue a fresh one
Expiry no more than one hour ahead yes session token expires further out than 1h0m0s; it cannot have been legitimately issued
Signature from a trusted key no (anything is accepted) session token signature is not from a trusted issuer; check security.auth.trusted_keys, or that a token was supplied at all
Signing key not revoked by the cluster cluster only session token is signed by a key this cluster has revoked; issue one under a trusted key
No undefined permission bits yes session token requests a permission this server does not define

A refused handshake gets an ERROR frame with code Unauthorized and one of these messages before the connection closes, so a client learns why. The outcome is counted in mirexa_init_handshakes_total{result} (expired, validity_exceeded, invalid_signature, undefined_permission, revoked, timeout, …).[1]

A single node issues its own tokens

security.auth.enabled is true by default. A node with it on and security.auth.trusted_keys empty, not clustered, provisions its own issuer at startup:[2]

File Mode What it is
<data_dir>/auth/ 0700 the directory
<data_dir>/auth/issuer.key 0600 an Ed25519 private key, generated on first start, in the format mirexa-cli token keygen writes
<data_dir>/auth/issuer.pub its public half, trusted under the name local
<data_dir>/auth/admin.token 0600 a token carrying every permission (READ_TICKS, READ_CANDLES, WRITE_TICKS, WRITE_CANDLES, ADMIN_STREAM, LIST_STREAMS, ADMIN_CLUSTER), valid for one hour, the most a node accepts

The startup log says auth: no trusted_keys configured, so this node issues its own tokens, with the two paths as admin_token and issuer_key. While the node runs it re-mints the admin token every 20 minutes, so the file always holds one with at least 40 minutes left. The key is reused on every later start, so a token minted before a restart still verifies after it.

Point a client at the file rather than copying the token out of it: mirexa-cli with -token-file <data_dir>/auth/admin.token, the Go SDK with an Options.TokenSource that reads it, the Python SDK with token_file=. Each re-reads the file on every reconnect, and the two SDKs also renew over the open connection at two-thirds of a token's life, so a long-running client keeps working (Renewal).

The admin token can do anything. Mint narrower ones from the same key for everything else:

bash
mirexa-cli token issue -key <data_dir>/auth/issuer.key -perms READ_CANDLES -validity 30m

Configuring any trusted_keys turns this off: nothing is generated, and a key generated earlier is no longer trusted. A cluster cannot use it — each node would generate a different issuer, and a token from one would be refused by the node it is redirected to — so a node with cluster.enabled: true, auth on and no trusted keys is refused at config load; list the same public key on every node.[3]

Turning it off

With security.auth.enabled: false, the node accepts any token, including the unsigned request a client sends when it has no token at all. The permission bitmap is then whatever the client asks for: authorization is effectively decorative. A tokenless SDK client asks for read and write on candles and ticks, ADMIN_STREAM and LIST_STREAMS (permissions). A node with auth on refuses every tokenless client. Every startup logs the posture ("auth":false or the trusted issuer names), so a node accepting unsigned tokens says so.

One control works either way: security.max_permissions clamps every grant, with auth on or off. Setting it to [READ_CANDLES, READ_TICKS] makes a node read-only to every client, whatever its token says.[4]

Setting up

The node's own issuer (above) is enough for one node. Make a keypair of your own to keep the private key off the node, or for a cluster, whose nodes must all trust the same key.

1. Make a signing keypair

bash
mirexa-cli token keygen -name ops -dir ./keys

The directory must exist. This writes ops.key (private, mode 0600) and ops.pub, and prints the configuration snippet with the public key. keygen refuses to overwrite an existing key, because every token issued from it would stop verifying. issue refuses a private key file readable by group or others.

The private key mints any permission for any tenant. Keep it on the machine that issues tokens, never on a node, a dashboard host or in an image. (A node's own issuer.key is the one exception, and the reason to mint a key of your own once a node is shared.)

2. Trust the public key on every node

yaml
security:
  auth:
    enabled: true
    trusted_keys:
      - name: ops
        public_key: "RLklkcBhC7oZgzdpVSkbQKhBmkS9UE44KCaYurPJwRw="

public_key is the base64 string itself, not a path to ops.pub. Validation at load refuses malformed base64, a key that is not 32 bytes, duplicate names, and, in a cluster, enabled: true with no keys — each a startup failure naming the entry, not a node that silently refuses everyone. name appears in logs; it carries no authority.

trusted_keys is a list so keys can rotate without downtime: add the new key, reissue tokens, then remove the old one.

3. Issue tokens

bash
mirexa-cli token issue -key ./keys/ops.key -perms READ_CANDLES,WRITE_CANDLES -validity 30m > token.txt
Flag Default Meaning
-key (required) private key file
-perms (none) comma-separated names: READ_TICKS, READ_CANDLES, WRITE_TICKS, WRITE_CANDLES, ADMIN_STREAM, LIST_STREAMS, ADMIN_CLUSTER
-tenant 0 tenant id (signed, but not yet used for isolation)
-validity 30m lifetime; more than 1h is refused

The token goes to stdout alone; the human-readable summary goes to stderr. mirexa-cli token inspect -pub ./keys/ops.pub <token> decodes one and checks its signature. See the mirexa-cli token reference.

4. Present the token

  • Go SDK: Options.Token, or Options.TokenSource — a function called on every connect and reconnect, typically reading a file that something refreshes.
  • mirexa-cli: -token-file <file> (re-read on every reconnect), -token <token>, or the MIREXA_TOKEN environment variable.
  • Python SDK: token_file=, token_source= or token=; see the Python SDK reference.
  • Dashboard: dashboard.upstream_token_file, re-read on every reconnect.

Expiry, mid-session

Tokens live at most one hour, and a session does not outlive its token:

  • A request on an expired session is refused on its next frame with Unauthorized.
  • A subscriber sends nothing after subscribing, so the node arms a timer and closes the connection at expiry. The SDK's resuming subscriber reconnects (with a fresh token from its TokenSource) and resumes from the last candle it received.[5]
  • security.auth.subscriber_grace (default 0) delays only that timer: an established subscription keeps receiving for the grace period past expiry, so a disconnect does not land in the same instant an orchestrator is rewriting the token file. It never admits an expired token at a handshake and never extends a writer.[6]

Renewal over the open connection

A client can hand the node a fresh token on its existing connection (a REAUTH frame) instead of reconnecting. The node checks it by exactly the handshake's rules, requires the same tenant, and replaces the session's grant and expiry. A refused renewal leaves the session as it was. If the new grant is narrower, subscriptions it no longer permits are ended.

A Go SDK client with a TokenSource renews by itself once two-thirds of the token's life has passed (Options.DisableRenewal turns this off), so its subscriptions are not cut at each expiry. A node that does not support renewal, or a failed renewal, falls back to the reconnect path.[7]

Revocation

There is no per-token revocation. A leaked token is valid until it expires — at most an hour — which is why validity should be as short as practical.

What can be revoked is an issuer key, and only in a cluster: the control API's RevokeKey records the revocation in the replicated control-plane log. Each node hands its applied set of revoked keys to its data plane every 250 ms; from then on that key's handshakes and renewals are refused, its established sessions are refused at their next frame, and its subscribers are cut. The bound is one sync interval after the node applies the entry.[8] ListRevokedKeys shows the set. On a single node, removing the key from trusted_keys and restarting is the equivalent.

mirexa-cli token still prints "no revocation: a token is valid until it expires" after keygen and issue. That is true of individual tokens; a cluster can additionally revoke a whole issuer key as described above.

Control-plane admin authentication

The gRPC control listener has its own switch, control.admin_auth, independent of security.auth.enabled. With it on, every call on the listener needs a token carrying ADMIN_CLUSTER, signed by one of the same security.auth.trusted_keys, sent as gRPC metadata authorization: Bearer <token>:

bash
mirexa-cli token issue -key ./keys/ops.key -perms ADMIN_CLUSTER -validity 15m
  • The token is admitted by the same rule as a data-plane handshake: signature, the cluster's revoked keys, expiry, the one-hour validity window, defined bits, and security.max_permissions. ADMIN_CLUSTER must be in the resulting grant.[9]
  • No, malformed, unsigned, revoked, expired or over-long credential → UNAUTHENTICATED. A valid token without ADMIN_CLUSTER → PERMISSION_DENIED, naming the permissions it does carry; one that carries it on a node whose max_permissions does not name it → PERMISSION_DENIED, naming max_permissions.
  • Turning it on with no trusted keys stops the node at startup.
  • A node with a routable control.addr must have admin_auth on, or it refuses to start — clustered or not. A single node's listener serves DeleteStream, UpdateStreamMetadata and AcceptGap, so it is held to the same rule.
  • A clustered node that registers and heartbeats through peers whose control planes require admin auth reads its credential from cluster.admin_token_file, re-read before every request so it can be rotated in place.
  • mirexa-cli passes the admin token with -token (or MIREXA_TOKEN) on its control commands.

A revoked key's admin token is refused within one revocation sync, exactly as its data-plane sessions are: the admin check reads the data server's own revoked set.

Defaults and recommendations

Setting Default Recommendation
security.auth.enabled true keep it; with no trusted_keys a single node issues its own tokens
security.auth.trusted_keys none a key you minted, its private half off the node; required in a cluster
security.max_permissions none set it to what the node's clients need
security.auth.subscriber_grace 0 a few seconds if a token refresher rewrites files on a timer
control.admin_auth false true for any control listener off loopback
token -validity 30 m (max 1 h) as short as your refresher allows
TLS off on wherever tokens cross a network: a token is a bearer credential, replayable by anyone who sees the handshake until it expires

References

Source

Tests

Further reading

External


  1. admitToken, Handshaker.admit and recordFailure in /internal/network/handshaker.go; tokenRefusal in /internal/network/server.go. ↩︎

  2. provisionLocalIssuer and localIssuer.start in /cmd/server/local_issuer.go; TestServerBinary_ANodeWithNoAuthConfigIssuesItsOwnAdminToken, TestLocalIssuer_ARestartKeepsTheIssuer, TestLocalIssuer_RemintsBeforeTheTokenLapses. ↩︎

  3. authConflicts in /internal/config/validate.go; TestAuthConfig_EnabledWithNoKeysIsRefusedInACluster. ↩︎

  4. TestServer_GrantCeilingAppliesWithAuthDisabled. ↩︎

  5. TestServer_ExpiredSubscriberIsDisconnected, TestAuth_SubscriberSurvivesTokenExpiryWithoutLoss. ↩︎

  6. TestSubscriberGrace_DelaysTheCutWithoutGrantingAnything, TestSubscriberGrace_DoesNotAdmitAnExpiredToken. ↩︎

  7. TestReauth_ARenewedSubscriptionOutlivesItsFirstToken, TestReauth_AClientWithATokenSourceRenewsBeforeItsTokenExpires. ↩︎

  8. startRevocationSync in /cmd/server/revocation.go; TestServerBinary_AKeyRevokedThroughTheControlPlaneIsRefusedOnEveryNode. ↩︎

  9. AdminAuth.Verify in /internal/control/admin_auth.go admits through network.Server.Admission in /internal/network/revocation.go; TestAdminAuth_RefusesAKeyTheClusterRevoked, TestAdminAuth_TheGrantCeilingApplies. ↩︎