Skip to content

Trust and keys ​

kernable assumes that any party may lie, and makes every claim checkable.

  • TLS keeps strangers off the network: over TCP, every process presents a certificate from your CA.
  • The signature proves which key sent a command, a query or a result.
  • The grant, signed by a root key, says what that key may do at all.
  • The middleware decides what the person behind the request may do, from the request context.
  • The hash chain with signed checkpoints proves afterwards that nothing stored was changed: kernable verify.

Processes and people ​

kernable authenticates processes, by their keys, not the people using your application. Who the person is, your API says in the request context (senderIdentity, senderTenant, …), signed with the API's key. The middleware decides on it: may this customer see this cart?

So two limits apply to every request, and both must allow it:

  • The key's grant limits what the process may do at all, whoever it claims to act for. A compromised API can impersonate its users, but only within its own grant: it cannot run commands it may not submit, or read events it may not listen to.
  • The middleware limits what each person may do. It builds its knowledge from events (who owns which cart, who is blocked) and fails closed while it is away.

Signing in the people themselves (passwords, sessions, tokens) happens in your API. Part 6 of the shop tutorial shows the pattern; the kit is a complete version of it as source you copy: accounts with passwords, second factors, passkeys and single sign-on, sessions, tenants, groups, and the middleware that decides on them.

Keys and grants ​

Every process has an Ed25519 key (kernable keys new). Its key ID is the public key in hex, so a signature can be checked without a registry. A signature proves who sent a message, not that the sender may do it: anyone can create a key.

So the kernel trusts root keys only (kernable start --root root.pub). A root key signs grants: a grant says what one key may do, per action and type.

sh
kernable grant root.key app.pub 'submit=shop.*' 'listen=shop.*'   # writes app.grant
ActionCovers
submitcommands the key may submit
runcommands it may run as a worker; it writes events of their domains only
subscribeevents it may read with a subscription
listenevents it may read as a listener (read model, reactor)
queryqueries it may ask
answerqueries it may answer as a read model
checkcommands and queries it may check as a middleware
privilegedprivileged request context switches it may set (bypass_authorization)
vault_readevents and commands whose vault values it gets as a listener or middleware
vault_eraseevents that erase a subject it may write as a worker
data_readdomains whose files it may read (shop.*)
data_writedomains whose files it may put and delete
cachedomains whose cache it may use
manageservices whose membership it may apply (service names, or *); with * also kernable promote
replicate*: following the kernel as its standby; the key gets every record, file and vault value
read*: following the kernel as a reader, a read-only copy; the key gets every record, file and vault value, as a standby's does, but can never follow as a standby
export*: exporting the whole kernel; the vault values stay sealed with its vault key
backup*: following the kernel as its backup follower; the key gets every record and file, the vault values sealed
reserved_order*: registering listeners and middlewares at negative orders, which run before every other listener; for kernable's kits (tenancy, accounts, authorization)
copycopies at a relay by name (shop.eu, or *): the copy's pusher hands that copy's key to the key, sealed to it; whoever has it reads everything the copy holds
grantthe actions (by name, never * or grant) it may grant other keys: a delegate; not part of the action *

A type is a qualified type (shop.PlaceOrder), a whole domain (shop.*) or everything (*). A bare type ('shop.*') means every action on it.

The process sends its grant with every call, in the gRPC metadata entry kernable-grant; the SDKs read <name>.grant next to the key file. The kernel checks the chain: the grant is signed by a root key, it names the key that signed the request, and neither key is revoked. It keeps the newest grant per key. The kernel's settings hold no keys of services and no permissions, so a new service needs a grant, not a change to the kernel. The root key issues only grants and revocations, so it can stay offline (The root key).

Delegated grants ​

A root key can let another key, a delegate, grant a few actions in its place, so the root key stays offline while, for example, a tool that adds standbys and readers works:

sh
kernable keys new keys/mover
kernable grant keys/root.key keys/mover.pub grant=replicate,read     # writes keys/mover.grant
kernable grant keys/mover.key keys/reader-1.pub --delegated 'read=*'   # signed by the mover

--delegated puts keys/mover.grant (beside the signing key) into the new grant. The kernel takes such a grant only

  • for actions the delegate's grant names (never *, grant or succeeds): anything else it signs is refused;
  • one step from a root: a key a delegate granted cannot grant on;
  • while the delegate's newest grant still names the action.

To end it, revoke the delegate (or the root that signed its grant): every grant it signed goes with it, and the streams of those keys end. To narrow it, issue the delegate a newer grant with fewer actions and push it to every running kernel; it takes effect at once, like a revocation:

sh
kernable grant keys/root.key keys/mover.pub grant=replicate          # read taken away
kernable push-grant http://127.0.0.1:7233 keys/mover.grant

The kernel stores the newer grant, passes it to its standby and readers, drops the grants the delegate signed for the actions taken away, and ends the sessions that relied on them. A kernel that is not running gets it when it next starts only if something presents it, so push it again then, or revoke the delegate instead.

A newer grant replaces an older one this way for any key: Changing what a key may do.

What is signed ​

MessageSigned byProves
commandclientwho asked for exactly this, in which context
result (events, snapshot)workerwhich worker decided, based on which version
query, subscriptionclientwho asked; valid 60 s around its timestamp
stream openingworker, listenerpossession of the key (challenge)
checkpointkernelthe state of the whole log at a position
grantroot keywhat a key may do
revoke requestroot keythat a root key ended a key; valid 60 s around its timestamp
membershipa key granted managewhat a service consists of; valid 60 s around its timestamp
file and cache requestclientwho reads, writes or deletes which file or value; valid 60 s around its timestamp

Replays are harmless or refused: a command runs once per command ID, whoever sends it again; a result is bound to its command and the version it was decided on; queries, subscriptions, file and cache requests, revocations and memberships are valid only for 60 s around their timestamp, and mutual TLS keeps others from capturing them.

Acknowledgements, query answers and middleware verdicts are not signed: they travel on a stream whose key was proven, and are not stored. The exact byte layouts and test vectors are in Signatures.

The hash chain ​

Every claim is signed, every event is chained to the one before, and kernable verify checks it all.
CommandEventSignatureRejection / mismatch

Every stored event's hash covers its content, its worker's signature, its request context and the previous event's hash. The kernel signs a checkpoint of the chain regularly. kernable verify recomputes the chain and checks every signature: a changed, removed or reordered event shows, and so does a command without its client's signature. Events after the last checkpoint are protected by the chain only.

Revoking and changing keys ​

A key that leaked is revoked from the time it may have been used, and kernable verify lists everything it signed since as suspect (Revoking a stolen key). Keys change without a restart: a new key needs only its grant, a listener moves to a new key whose grant succeeds the old one (Changing a key), and the kernel reads its own key file again on SIGHUP.

If something is compromised ​

CompromisedWhat an attacker can doWhat limits it, and what you do
a client's keysend what its grant allows, as that client, in the name of any person it claimsnarrow grants per service; the middleware still decides per person; revoke the key from the suspected time, and kernable verify lists everything it signed since as suspect
a worker's keyconnect as a worker for its command types and decide those commands wronglyit can only answer commands that clients signed, and write events of its own domains; revoke it, and verify flags its results
a listener's keyread the events, and vault values, its grant allowsnarrow listen and vault_read grants; revoke it
the kernel's keysign checkpointsstored events still carry the client's and worker's signatures, which it cannot forge; replace the key file and reload it (SIGHUP), and verify with every kernel key you had
a root keyissue any grantkeep root keys offline; with several roots (--root repeated), revoke the compromised one and its grants lose their effect
the store filechange, remove or reorder eventskernable verify shows every such change up to the last signed checkpoint; only events after it could be cut off unnoticed, so keep the checkpoint interval short
the vault key, with the vault fileread personal and secret valueskeep both apart from the store and its backups; kernable vault rekey re-encrypts with a new key
the UI's addressread events, payloads and connectionsit listens on loopback only, has no login, and never decrypts the vault; reach it through an SSH tunnel

Transport ​

Over TCP, the kernel requires mutual TLS: every process presents a certificate from your CA (Mutual TLS with your own PKI). Signatures make a message trustworthy; TLS keeps it private and keeps strangers out.

Privileged switches ​

The request context is business data and the client decides it, except for privileged switches such as bypass_authorization, which only keys granted privileged for that switch may set. Even then, the middleware decides what a bypass means; the kernel does not skip the chain.

Keys per service, and changing a key ​

The steps, from the tutorial's single key to production, and for replacing a key: routinely, or because it leaked.

SituationWhat to doKernel restart?
a new service, or more rightsissue a grantno
fewer rightschange the key, revoke the old oneno
a key leakedrevoke itno
the instance key (the kernel's own, and its vault's)a new instance key, the vault rekeyedyes
the root keystart with both rootsyes, twice

One key per service ​

The tutorial uses one key for everything (--dev writes app.key with a grant for everything). In production, give every service its own key and grant it only what it needs.

  1. Create the keys. Each call writes <name>.key (secret) and <name>.pub (the key ID):

    sh
    for k in root api confirmations shop-worker read-models deploy; do kernable keys new keys/$k; done

    Keep keys/root.key offline; the kernel needs only keys/root.pub.

  2. Grant each key what it needs:

    sh
    kernable grant keys/root.key keys/api.pub \
      submit=shop.Register,shop.Place,shop.AddItem,shop.Submit 'query=shop.*'
    kernable grant keys/root.key keys/confirmations.pub \
      submit=shop.Confirm listen=shop.OrderSubmitted query=shop.GetOrder,shop.GetCustomer
    kernable grant keys/root.key keys/shop-worker.pub 'run=shop.*'
    kernable grant keys/root.key keys/read-models.pub 'listen=shop.*' 'answer=shop.*' 'vault_read=shop.*'
    kernable grant keys/root.key keys/deploy.pub manage=shop   # applies the shop's membership

    Each call prints the permissions and wrote keys/<name>.grant. A permission is <action>=<type>,<type>, or a bare type for every action; a type is shop.Place, shop.* or *. The actions are in the table above; manage takes service names. Kernels that follow another get keys of their own: a standby replicate=*, a reader read=*, a backup follower backup=*. A reader's key never follows as a standby, and a standby's never as a reader.

  3. Start the kernel with the root's public key: kernable start --root keys/root.pub ....

  4. Give each service its .key and .grant file. The SDKs read the .grant file next to the key file, or the file in the grant option or KERNABLE_GRANT, and send it with every call. The key file comes from the key option or KERNABLE_KEY (default app.key).

A process that runs an app (kernable.app(...).run()) applies its service's membership on every start, so its key also needs manage=<service> (Deploy and upgrade). Without that, a single deploy key applies it.

A key without a grant, or whose grant does not cover a type, gets PERMISSION_DENIED. A grant takes effect when a process first presents it.

Changing what a key may do ​

Issue a new grant for the key and restart the service with it. A grant cannot be withdrawn, only replaced by a newer one (by its issue time): once the kernel has seen it, it refuses the older one, also after a restart. Open streams follow the newer grant at once: workers, listeners and subscriptions whose key may no longer do what it registered for are disconnected, and one that asked for every event type gets only the types the new grant allows. Rights a key used before stay used; to take rights away from a key that may be stolen, change the key and revoke the old one.

Changing a key ​

Signatures in the log stay verifiable after a change: a key ID is the public key itself.

A client or worker key: create the new key, grant it what the old one had, and restart the process with the new key and grant. Revoke the old key if it may have leaked.

A listener's key is part of its registration. Grant the new key with --succeeds <old key>, and the listener keeps its position, order and middleware registration:

sh
kernable keys new keys/read-models-2
kernable grant keys/root.key keys/read-models-2.pub --succeeds keys/read-models.pub \
  'listen=shop.*' 'answer=shop.*' 'vault_read=shop.*'

Then restart the listener with the new key and grant. Without succeeds, another key is refused, so no service can take over another's listener.

Revoking a stolen key ​

When a key leaks, revoke it from the moment it may have been used. The root key signs the revocation, and the running kernel takes it at once:

sh
kernable revoke http://127.0.0.1:7233 keys/root.key keys/api.pub 2026-10-27T09:00:00Z   # UTC

It answers revoked <key ID>. kernable revoke connects over mutual TLS when KERNABLE_TLS_CA, KERNABLE_TLS_CERT and KERNABLE_TLS_KEY are set, like the SDKs. The revoke request is valid for 60 s around its creation. The kernel then:

  • stores the revocation, signed with its own key; it is never undone and holds after a restart;
  • refuses the key everywhere, also with a grant, and disconnects its sessions;
  • rejects commands of the key that still wait in the queue and were accepted after that time (key_revoked).

kernable verify then lists everything the key signed from that time on:

text
$ kernable verify sqlite:data/shop.db keys/instance.pub
2311 events, 1903 commands, 41 checkpoints, 0 events after the last checkpoint
SUSPECT command c-8f2a: signed by revoked key 1f0a…
OK, 1 suspect

It exits with 2 when there are suspects, 1 when the log was tampered with. Review what the suspects did, and undo it with new commands where needed: the log itself is never rewritten.

The instance key ​

Each kernel has one key of its own, the file --instance-key names (written by kernable keys new). Its ID, the .pub beside it, names the kernel everywhere:

  • it signs the kernel's checkpoints and stored revocations;
  • a standby, a kernel of a pair, a partition or a reader follows with it: its grant, <name>.grant beside it, allows replicate or read;
  • the writer's pusher pushes its copy to a relay with it, and a relay lets it in by that ID;
  • the vault's key is derived from it, so the vault belongs to it.

Keep it as carefully as the vault: whoever has it reads the vault. To hand the vault key alone to a restore or an export, without the instance key, derive it: kernable keys vault keys/instance.key vault.key.

Replacing it ​

Replace an instance key when it may have leaked, when the machine changes hands, or when its vault key has encrypted many values (each value gets a random nonce, and one key is safe for 2^32 of them; the kernel warns at startup past 2^31, the UI's verdict warns too, Explore → Data → Vault shows the count, and it refuses new values at 2^32). A new key is a new instance: give it what the old one had, move the vault to it, and start the kernel with it.

sh
kernable keys new keys/instance-2
kernable grant keys/root.key keys/instance-2.pub 'replicate=*'      # what the old key had
# with the kernel stopped:
kernable keys vault keys/instance.key old-vault.key
kernable keys vault keys/instance-2.key new-vault.key
kernable vault rekey sqlite:data/vault.db old-vault.key new-vault.key && shred -u new-vault.key
kernable start --instance-key keys/instance-2.key …

Its followers check its checkpoints with --primary-kernel-key: give them the new key ID beside the old one. If the old key leaked, revoke it. Keep every old public key, as kernable verify needs every key the kernel ever signed with (kernable verify <store> keys/instance-old.pub keys/instance-2.pub), and the old vault key (old-vault.key) as long as backups made before are kept: they are sealed with it. A continuous backup begins a new generation with the new vault key, and kernable backup list names each generation's key.

SIGHUP (Unix) reads the file again, which unwraps a wrapped key anew; a different key in the file is refused and logged, and the kernel keeps its own.

Keys that are not on the disk in clear ​

With --key-command, the instance key file holds a wrapped key, and a program you name unwraps it when the kernel starts (and on SIGHUP). The kernel runs it with the key file's path as its last argument and reads the key from its output: 64 hex characters, as a key file holds them. Nothing in the kernel depends on a provider; any tool that decrypts a file works.

With age and an identity on a hardware key or in a protected place:

sh
age -e -r age1… -o instance.key.age instance.key && shred -u instance.key
kernable start --instance-key instance.key.age --key-command "age -d -i /etc/kernable/age.identity" …

With systemd-creds, bound to the machine's TPM:

sh
systemd-creds encrypt --with-key=tpm2 instance.key instance.key.cred && shred -u instance.key
kernable start --instance-key instance.key.cred --key-command "systemd-creds decrypt" …

With a cloud KMS, a small script that takes the path, for example /usr/local/bin/kms-unwrap:

sh
#!/bin/sh
aws kms decrypt --ciphertext-blob "fileb://$1" --query Plaintext --output text | base64 -d

The command runs once per key file and has 30 s for it; the kernel keeps the unwrapped key in memory until SIGHUP, when it runs the command again. A key the command cannot unwrap stops the kernel at start, with the command's message; on SIGHUP the previous key stays. A key bound to one machine (the TPM) needs wrapping again for the standby on another one. TLS keys (--tls-key) are read as files.

The root key ​

The root key (with kernable Cloud: the project root key) is the one anchor of a project: it signs grants, revocations and the approvals of a partition's writer, and through a grant with copy=<copy> it decides who is handed a copy key. Whoever holds it can make a kernel of their own trusted. Keep it accordingly:

  • Offline. On a machine of its own, or a laptop that does nothing else, never on an instance, in CI or in a secrets manager instances read. Nothing running needs it: kernels and nodes take only its .pub.

  • Encrypted at rest, opened only to sign, for example with age and a passphrase or a hardware-backed identity:

    sh
    age -p -o root.key.age root.key && shred -u root.key          # once
    age -d root.key.age > /dev/shm/root.key                       # to sign, then:
    kernable grant /dev/shm/root.key reader-1.pub 'read=*' 'copy=shop.eu'
    shred -u /dev/shm/root.key
  • Backed up, encrypted, in two places only you reach (a safe, a second encrypted volume). A lost root key is replaced as below; until then nothing new can be granted.

  • Few people. Whoever signs with it should be whoever decides who may join. Every grant and approval is in the project's audit log with kernable Cloud.

Issue grants on a separate machine and copy the .grant files. To replace the root key, start the kernel with both roots (--root keys/root.pub --root keys/root-2.pub), issue new grants with the new root and restart the services with them. Then restart the kernel without the old --root: grants signed by it are refused from then on. If the old root leaked, revoke it first, signed with the new root (kernable revoke <addr> keys/root-2.key keys/root.pub <since>): the kernel drops the grants the old root signed at once and refuses them from then on.