Data Lake Authentication Token Profile¶
This page defines the Ed25519 session JWT returned as __token and accepted by both the trading server and Data Lake when its audience permits. Platform sessions are also bound to a server-side SessionGuard record by the JWT sid claim. New session tokens use profile version 2. Data Lake verifiers may temporarily accept the old Data Lake-only version 1 profile for already-issued tokens; the trading server accepts only version 2.
Token and transport¶
A successful session-creation response can contain:
{
"__token": "<Ed25519 ion-session+jwt>"
}
__token is the platform JWT session credential. HTTP returns it in the existing Authorization response header; no JWT session cookie is set by the server. Guest-session restoration uses a separate __Host-ion_guest HttpOnly cookie; that cookie is not the JWT and does not extend the JWT expiration. Data Lake clients send the same compact JWT as raw x-data-token only when its audience allows Data Lake access. There is no refresh endpoint: obtain a new token by signing in again after expiry.
The token is emitted for AuthUser, AuthManager (including admin sessions),
SSOAuthUser, ExchangeSSOCode, AuthCustomer, AuthCustomerByCode, and
registration flows that automatically create a session
(CustomerRegistration and CustomerRegistrationByAffiliate). Guest flows also
issue __token: GuestSession issues a guest account token, and
GuestRegistration issues an account token by default or a customer token when
auth_type is customer. A public registration that does not establish a
session returns no token. Affiliate sessions do not receive the Data Lake
audience. Affiliate API JWTs are server-only and checked against the current
credential record. WebSocket authentication accepts __token only and does not
issue tokens.
Session creation requires an active v2 lease and successful signing; failure prevents issuing the session token. Guest-session restoration uses a separate 30-day inactivity cookie and mints a guest JWT with the configured ordinary session lifetime; cookie activity does not automatically renew that JWT. Guest tokens use auth_kind: "guest", a canonical UUIDv4 guest_id, customer_id, and aud: ["ion-server"], so they authenticate only to the platform and are never accepted by Data Lake.
JOSE format¶
The session token is a standard compact JWT with three Base64URL components. The JOSE header is:
{
"alg": "EdDSA",
"typ": "ion-session+jwt",
"kid": "<lowercase SHA-256 of the raw 32-byte signing public key>"
}
EdDSA uses the server license private key. The key remains inside STCore; the host exposes only a constrained session-token signing operation and the corresponding public verification key. The public key is derived from the license private key carried by the capsule. The capsule public_key is the crossed peer key used to verify license-service replies and must not be used for session JWT validation. kid is SHA-256 of the raw 32-byte server signing public key.
Resolve the signing public key¶
A verifier maps lic_uuid to a trusted license-service host from its own
configuration and requests:
GET /v1/license/license/public-key?lic_uuid={lic_uuid}
The public route returns the trading-server license identity Ed25519 public
key used to verify Data Lake tokens. It does not return the license service's
peer-signing key, a private key, or the encrypted license capsule. Connect over
HTTPS to a trusted host configured by the verifier. Do not fetch a URL from JWT
jku, another JWT header, or a caller-provided value.
The response contains lic_uuid, kid, alg, public_key, status, active,
and expires_at. The verifier must check that the returned UID matches the
requested UID, alg is EdDSA, and the SHA-256 hash of the raw 32-byte key
matches the JWT kid. This kid hash differs from the runtime-license
key_fingerprint, which hashes the DER SubjectPublicKeyInfo encoding.
The service also returns the key for inactive licenses so historical tokens can
still be identified or cryptographically checked. active is true only for
trial, active, or development licenses that have not expired according to the
license-service database clock; expired and blocked licenses return false. A
verifier must deny new authorization when active is false. expires_at
describes the license, not the JWT: it does not add an exp claim or an
independent token expiration. The route does not specify a cache duration. Check active for each new authorization, or use an explicitly bounded cache policy that accounts for license-status changes. This license lookup is separate from platform session state; Data Lake does not introspect platform session revocations.
Payload¶
Account, customer, staff, and guest session JWTs carry the claims below. Guest sessions are an exception to the Data Lake audience: they use aud: ["ion-server"] and are rejected by Data Lake. Affiliate sessions use the server-only profile described below and are also rejected by Data Lake:
| Claim | Type | Meaning |
|---|---|---|
ver |
integer | Session-token profile version; 2. |
sid |
string | Mandatory canonical UUIDv4 identifier for the platform session. The trading server requires a matching active SessionGuard cache record. Data Lake does not use sid for revocation checks. |
iss |
string | ion-server:{lic_uuid} for the issuing licensed trading server. |
aud |
array of strings | ["ion-server", "datalake"] for account/customer/staff sessions; ["ion-server"] for guest, affiliate, and manager API tokens. Exact values and order are required. |
lic_uuid |
string | License UUID that identifies the signing authority. |
subject_type |
string | Principal kind: account, manager, dealer, admin, customer, crm_manager, crm_admin, or server-only affiliate. |
sub |
string | Stable principal string {subject_type}:{id}. For an account, {id} is the trading login. |
type |
integer | Session type code: 0 account, 1 manager, 2 dealer, 3 admin, 9 customer, 10 CRM manager, 11 CRM admin, 12 affiliate. Affiliate audience is server-only. |
id |
integer | Original identity ID, when present in the primary session identity. |
login |
integer | Trading login, when present in the primary session identity. |
customer_id |
integer | Customer ID, when present in the primary session identity. |
impersonated_by |
integer | Manager ID, when the customer session is an impersonation session. |
name |
string | Optional display name copied from the authenticated identity, up to 32,768 bytes. |
iat |
integer | Actual session issue time as Unix seconds. |
exp |
integer | Mandatory for account/customer/staff and affiliate-login sessions; expires according to the configured session_ttl_hours value (default 24; range 1–8760). Customer impersonation expires at the earlier of the original four-hour deadline and the configured lifetime. Manager API tokens use the expires_days lifetime selected at creation (1–365 days), independent of session_ttl_hours. Affiliate API credentials use their configured expiry; an affiliate API credential with no configured expiry omits this claim and remains subject to a live credential-record check. |
authorization |
object | Freshly resolved identity scope described below. |
affiliate_id |
integer | Affiliate identifier for server-only affiliate sessions, when present. |
brand |
string | Affiliate brand for server-only affiliate sessions, when present. |
auth_kind |
string | guest for guest account sessions; affiliate_api for affiliate API credentials; or manager_api for manager TCP Server API tokens. Guest and manager tokens use aud: ["ion-server"] and are excluded from Data Lake. Manager API tokens expire according to their configured expires_days (1–365). |
guest_id |
string | Canonical UUIDv4 guest identity identifier when auth_kind is guest. |
token_id |
integer | Affiliate API credential record identifier. |
scopes |
integer | Affiliate API scope bitmask. |
Guest account sessions use SessionGuard.kind: "guest" and are checked against their server-side SessionGuard record by the trading server. Their JWT has an account profile (type: 0) plus auth_kind: "guest", guest_id, and customer_id; aud is exactly ["ion-server"], so Data Lake must reject it. The guest cookie has a 30-day rolling inactivity lifetime, which is separate from the JWT exp; activity through the cookie does not automatically renew the JWT.
The identity claims id, login, customer_id, and impersonated_by are
included only when the corresponding field exists in the session identity.
The issuer copies only the listed identity claims and freshly resolved authorization data into the session JWT.
The verifier rejects expired sessions. Affiliate sessions use aud: ["ion-server"], subject_type: "affiliate", and type: 12; affiliate API credentials additionally carry auth_kind: "affiliate_api", token_id, scopes, and optional exp. Manager API JWTs retain the relevant manager subject_type and type, use aud: ["ion-server"], and carry auth_kind: "manager_api". Both API token profiles are server-only and never eligible for Data Lake access.
Authorization object¶
Account, customer, and staff tokens contain one authorization shape according to their principal. Affiliate session tokens use an empty authorization object.
Account (subject_type: "account")
| Claim | Type | Meaning |
|---|---|---|
brand |
string | Account's resolved brand. |
group |
string | Account's current trading group. |
login |
integer | Account login. |
Customer (subject_type: "customer")
| Claim | Type | Meaning |
|---|---|---|
brand |
string | Customer's resolved brand. |
customer_id |
integer | Customer ID. |
Staff (manager, dealer, admin, crm_manager, crm_admin)
| Claim | Type | Meaning |
|---|---|---|
brand |
string | Manager's assigned brand. |
groups |
string | Current accessible groups selector. |
desks |
string | Current accessible CRM desks selector. |
admin |
integer | Current admin flag. |
super_admin |
integer | Current cross-brand admin flag. |
permissions |
object | Integer permission flags listed below. |
The permissions object contains access_backoffice, access_crm,
see_accounts, see_accounts_balance, see_trades, reports,
see_customers, see_all_customers, see_customer_contacts, see_clients,
see_leads, see_desks_clients, see_desks_leads, see_clients_contacts,
and see_leads_contacts.
The issuer resolves these resource and permission values from current in-memory server managers when it creates the token. Account and customer issuance also requires the entity to remain enabled and its brand to pass the current API admission check.
Decoded example¶
The example shows decoded header and payload values for an impersonated customer. In the compact token, the header and payload are Base64URL encoded and the encoded input is signed; the payload below is illustrative and signature bytes are not shown.
{
"header": {
"alg": "EdDSA",
"typ": "ion-session+jwt",
"kid": "<64 lowercase hexadecimal characters>"
},
"payload": {
"ver": 2,
"iss": "ion-server:11111111-2222-4333-8444-555555555555",
"aud": ["ion-server", "datalake"],
"lic_uuid": "11111111-2222-4333-8444-555555555555",
"subject_type": "customer",
"sub": "customer:1042",
"type": 9,
"id": 1042,
"customer_id": 1042,
"impersonated_by": 1001,
"iat": 1792430400,
"exp": 1792434000,
"authorization": {
"brand": "ALFA",
"customer_id": 1042
}
}
}
For every version 2 normal account, customer, staff, and affiliate-login session, exp is mandatory. Its interval from iat is session_ttl_hours × 3600 seconds. The default is 24 hours. Valid configured intervals span 3,600 through 31,536,000 seconds. Impersonation may have a shorter interval because its earlier original expiry is preserved.
Verification requirements¶
A Data Lake verifier must:
- Require exactly three compact-JWT components, a canonical Ed25519 JOSE header with exactly
alg,typ, andkid, and pinalgtoEdDSA,typtoion-session+jwt, and profileverto2. - Resolve
lic_uuidthrough the trusted license-service host configured by the verifier using the public-key route above. Require the returned UID to match, compare the raw-keykid, and requireactive: truefor new authorization. Do not use the license-service peer/public key embedded in the license capsule; that key serves the opposite verification direction. - Verify the Ed25519 signature before trusting any claim, then require
aud = [ion-server, datalake],iss = ion-server:{lic_uuid}, and the version 2subject_type/typepair. Reject affiliate tokens for Data Lake. - Apply the
authorizationbrand, group, desk, and permission scope to every Data Lake request. A valid signature attests the licensed server's issued claims; it does not authorize every tenant or resource automatically. - Enforce the mandatory
expclaim and reject expired account, customer, or staff session tokens. The allowed maximum interval fromiatis 365 days as a verifier sanity limit; the server configuration permits at most one year. The only expiry-free server token is an affiliate API credential with no configured expiry; its current record must be checked on every request.
The Data Lake verifier checks license active status on each authorization unless a bounded cache is configured. It validates the JWT signature, license status, authorization claims, and exp; it does not look up sid or introspect the trading server session store. Consequently, platform logout/revocation and owner-state changes do not invalidate Data Lake authorization before the signed JWT expires. Data Lake continues to rely on the signed authorization snapshot until exp (or license deactivation).
Main Server REST gateway integration¶
The REST gateway supports an opt-in authentication profile for individual
service routes. A route enables it with auth: "datalake" and must
declare a non-empty licenseAccess.subjects allowlist. The supported subject
names are account, manager, dealer, admin, customer, crm_manager,
and crm_admin. This allowlist is required even when a route intends to permit
all subject types.
In a versioned Moleculer service, add route metadata to each action. For
example, a customer route may allow customer tokens, while a staff reporting
route may require the reports permission:
actions: {
customerSummary: {
route: {
path: "customer/summary",
method: "GET",
auth: "datalake",
licenseAccess: { subjects: ["customer"] }
}
},
staffReport: {
route: {
path: "staff/report",
method: "GET",
auth: "datalake",
licenseAccess: {
subjects: ["manager", "admin"],
permissions: ["reports"]
}
}
}
}
licenseAccess.permissions is optional. When supplied, it must be an array of
known permission names and every listed permission must equal 1 in the signed
token's staff authorization scope. Customer and account token profiles do not
contain staff permissions, so a route requiring a permission should allow only
staff subject types. The recognized names are access_backoffice,
access_crm, see_accounts, see_accounts_balance, see_trades, reports,
see_customers, see_all_customers, see_customer_contacts, see_clients,
see_leads, see_desks_clients, see_desks_leads, see_clients_contacts,
and see_leads_contacts. The gateway checks these route-level conditions; it
does not apply generic row filters or automatically authorize access to every
resource in the claims. The downstream action must enforce the relevant
brand, group, desks, login, customer_id, and permission scope for the
requested resource.
The client sends the compact Data Lake JWT as the raw x-data-token header
value, without a Bearer prefix. The gateway does not use Authorization as
a fallback for this profile; legacy RS256 routes retain their existing
Authorization handling. CORS allows the x-data-token request header:
GET /v1/data/customer/summary?customer_id=1042 HTTP/1.1
Host: api.example.test
x-data-token: <compact EdDSA Data Lake JWT>
For an authenticated request, the gateway passes request data and trusted
authentication context to the configured service action. For example, the
forwarded data includes the requested customer_id, request metadata such as
__ip, and gateway-created fields similar to:
{
"customer_id": 1042,
"__ip": "203.0.113.10",
"__auth_profile": "datalake",
"__token": "<the raw compact Data Lake JWT>",
"__access": {
"ver": 2,
"iss": "ion-server:11111111-2222-4333-8444-555555555555",
"aud": ["ion-server", "datalake"],
"lic_uuid": "11111111-2222-4333-8444-555555555555",
"subject_type": "customer",
"sub": "customer:1042",
"type": 9,
"id": 1042,
"customer_id": 1042,
"iat": 1792430400,
"authorization": {
"brand": "ALFA",
"customer_id": 1042
}
}
}
The gateway removes caller-supplied __* fields before attaching its trusted
context. It does not translate this profile into legacy roles, elevate admin
flags, or create an RS256 session token. __access is internal forwarded
context and is removed from the HTTP response. When gateway response caching is
enabled for such a route, its cache namespace includes the license UID, subject,
and hash of the presented token in addition to the route's configured cache
keys.
The Data Lake gateway resolves the public key through the configured broker action
(license.license.public_key by default). Its additive gateway settings are:
| Setting | Default | Meaning |
|---|---|---|
datalake.licenseAction |
license.license.public_key |
Broker action used to look up the trusted license key and state. |
datalake.timeoutMs |
3000 |
Lookup timeout in milliseconds. |
datalake.cacheTtlMs |
0 |
Public-key and active-state cache duration in milliseconds; zero disables the verifier cache. A positive TTL can delay recognition of status changes by up to that TTL; token and license expiration are still checked against the current verifier clock. |
datalake.maxCacheEntries |
256 |
Maximum verifier cache/in-flight lookup entries. |
Verification failures use these HTTP error types: 401 INVALID_DATALAKE_TOKEN
for malformed tokens, wrong profile, key ID mismatch, or invalid signature;
403 DATALAKE_ACCESS_DENIED for route policy mismatch or an inactive/expired
license or impersonation token; and 503 LICENSE_KEY_UNAVAILABLE when the
trusted license lookup cannot provide a usable key. The existing gateway error
envelope includes code, type, message, and data; for example:
{
"code": 401,
"type": "INVALID_DATALAKE_TOKEN",
"message": "Invalid datalake token",
"data": {}
}
This profile is opt-in and does not alter legacy RS256 authentication. It does
not harden /api/sessions, /api/session, upload routes, or middleware order.
The gateway repository currently has no Data Lake business routes enabled by
this profile, so downstream services must opt in route by route and implement
resource-level authorization. The same signed compact token is accepted by the trading server and Data Lake, but their session-state checks differ. The trading server requires a matching active sid record and checks the current owner state; Data Lake does not introspect sid and relies on signature, license status, signed authorization, and exp. A platform logout or session revocation therefore does not revoke Data Lake access before expiry.
Platform session binding and revocation¶
Every newly issued platform session JWT carries a UUIDv4 sid. SessionGuardManager is cache-first: at startup it initializes or migrates bases/session_guard.db, loads retained session metadata and active payloads into memory, then accepts requests. Its in-memory maps and indexes serve authorization, metadata reads, and mutations; those paths do not fall back to SQL. SQLite is owned by a background Boost.Asio strand.
Session creation and revocation update the cache and enqueue ordered persistence work. Ordinary interactive session issuance and revocation acknowledge queue admission; they do not wait for SQLite to commit. Manager and affiliate API credential issuance, payload updates, and revocations wait for the persistence commit before reporting success. This makes an acknowledged API credential mutation durable across an unclean process exit. Revocation takes effect immediately for subsequent platform authorization checks. If the manager is unavailable, cannot accept a mutation, or cannot commit a durable API credential mutation, it fails closed. If a background write fails, it marks itself unavailable and denies guarded platform authorization and metadata operations until restart.
On shutdown, the manager drains accepted persistence work. If the manager remains healthy and the queue is empty, it writes the clean-shutdown marker before closing SQLite. A clean restart preserves flushed sessions. Startup marks the store dirty before publishing the cache. With the current session-store format, an unclean restart revokes ordinary interactive sessions while retaining valid manager and affiliate API credentials whose issuance or latest credential update was acknowledged after commit. Already revoked or expired API credentials are never restored. On the first upgrade from an older session-store format, an unclean store is handled conservatively: all active records are revoked because older versions could acknowledge API revocations before they reached disk. A clean upgrade preserves valid API credentials. The store format is now version 5; older server builds that do not support it cannot reopen the upgraded store, so plan rollback with a compatible backup or forward fix. Revoked and expired metadata remains available for session management, while inactive payloads are cleared from the cache. HTTP, TCP, WebSocket, and Moleculer user-session calls use the same guard. Trusted in-process SYSTEM and FIX access without a user sid remains a separate exception.
A normal user, customer, affiliate, or staff session can end itself with SessionLogout or POST /session/logout. Staff can inspect sessions using MngGetSessions; ordinary staff can manage their own sessions, while super admins can select other owners and list all owners. MngRevokeSession revokes one session and MngRevokeSessionsByOwner revokes all sessions belonging to one owner. Account disablement, trading-group changes, or deletion; staff enable/admin-role changes or deletion; and customer disablement, brand changes, or deletion revoke affected platform sessions. See the TCP session-management methods and REST logout endpoint.
The Data Lake verifier deliberately does not call the platform session store. It continues to accept a valid signed authorization snapshot until exp, even after platform logout, session revocation, or an owner change. Purging an inactive SessionGuard record after its 30-day history-retention period does not change this Data Lake behavior or extend the token's expiry. License deactivation is checked separately by the Data Lake verifier according to its license status/cache policy. A previously issued v2 token without sid is rejected by the platform and requires the user to sign in again; its Data Lake use remains governed by the Data Lake verifier's accepted profile and expiry.
Manager API tokens are time-limited, server-only JWTs. By default they use the target manager's normal permissions and do not require a command list. A caller may instead supply a non-empty explicit command allowlist, which narrows the available commands. Both modes remain subject to the manager's current permissions and policy fingerprint; any role, permission, brand, group, or desk change invalidates affected tokens and commits the revocation before acknowledging the change. Promotion cannot expand an existing token, which must be reissued after access changes. On TCP, these tokens provide the owner's manager permissions, including session-management and SSO-code commands, unless an explicit command allowlist narrows access. They have no Data Lake audience and cannot authenticate WebSocket connections or uploads. TCP network access remains subject to the server's firewall and other network controls.
Backup and restore behavior¶
The platform session authority database, bases/session_guard.db, is intentionally excluded from trading backup participants and is never restored from a trading backup. For an actual restore, the server first creates the pre-restore safety snapshot, then revokes all platform sessions and manager API grants in the SessionGuard cache and queues persistence with reason platform_restore before mutating restored data. The restore aborts if the manager cannot accept that change; when API grants are affected, it waits for their revocation commit. If background persistence fails, SessionGuard becomes unavailable and the next startup applies the recovery rules above. A dry run does not revoke sessions. A clean server restart preserves flushed active sessions.
After an actual restore begins, all platform sessions and manager API credentials require fresh login or token reissue, even if later restore work fails. An offline recovery that copies an old complete bases/ directory can reintroduce an old session_guard.db; if the same JWT signing key remains trusted, that can revive old authority. Exclude or purge session_guard.db from that recovery and require fresh authentication.
Issuance failures and compatibility¶
Session-token issuance requires an active v2 license lease and successful signing. On failure authentication cannot return a session token. The constrained signing API was introduced in STCORE ABI 12, but the current session profile requires STCORE ABI 14 so the runtime enforces and copies the required sid. The session_ttl_hours field crosses ICoreApi, which remains CORE API ABI 12. Deploy matching STCORE ABI 14 server/runtime builds with CORE API ABI 12; do not mix older signing runtimes with the ABI 14 server. The trading server rejects legacy HS256 tokens and old profile-v1 Data Lake JWTs. The Data Lake verifier may retain v1 verification temporarily for already-issued tokens; remove it after migration.
STCore SDK compatibility¶
STCore ABI 12 introduced constrained session-token signing and public-key trust retrieval; the current session/configuration contract requires STCORE ABI 14:
int stcore_license_gate_session_token_trust(
StLicenseGateHandle* handle, StLicenseTokenWriter writer, void* context) noexcept;
int stcore_license_gate_issue_session_token(
StLicenseGateHandle* handle, const char* claims, size_t claims_size,
StLicenseTokenWriter writer, void* context) noexcept;
typedef void (*StLicenseTokenWriter)(
const char* token,
size_t token_size,
void* context) noexcept;
For the current contract, the server and STCore runtime must both implement STCORE ABI 14 (CORE API ABI 12). The host obtains only the public trust key and license UID for local signature checks; the signing private key is never exported from STCore. Signing requires an active v2 lease. The signing callback accepts a constrained session identity and freshly resolved authorization scope; it does not sign arbitrary JWT payloads.
The claims input is a non-empty JSON byte sequence of at most 65,536 bytes.
It has this internal input shape (the identity object is an input to the
signer, not a nested claim in the resulting wire JWT):
{
"identity": { "type": 0, "login": 100001, "name": "Example Trader" },
"authorization": { "brand": "ALFA", "group": "Standard", "login": 100001 }
}
The callback runs synchronously. Its output pointer refers to STCore-owned memory and is valid only until the callback returns; copy the bytes inside the callback if they must be retained. Return status 0 means output was written, -2 means no active v2 lease, and -1 means invalid arguments, invalid claims, or signing failure. The host checks the resulting token locally before returning it to the client.
Legacy Data Lake token profile during migration¶
Older Data Lake-only tokens use header typ: ion-datalake+jwt, ver: 1, string audience datalake, and mandatory session_sha256. The Data Lake verifier retains support for this profile while older clients or live issued tokens require it. The trading server rejects this profile. Do not issue new v1 tokens.
Marketplace publisher identity¶
Marketplace publisher authentication accepts either a verified v1 token with
typ: ion-datalake+jwt, ver: 1, and the string audience datalake, or a
verified v2 session token with typ: ion-session+jwt, ver: 2, and the exact
audience array ["ion-server", "datalake"]. V2 tokens are accepted only for
their own non-guest account or customer identity and only when their audience
permits Data Lake access. Guest sessions have a server-only audience and cannot
publish as a Marketplace owner. Impersonation sessions and manager identities,
including manager API tokens, cannot publish as a Marketplace owner.
Publisher ownership is keyed by the license UID and token subject, so signing in again after migrating from v1 to v2 preserves the same publisher identity. This Marketplace compatibility does not change token issuance, claims, or the trading server's rejection of v1 tokens.