Security
On this page
- Threat model
- What a signature binds
- In practice
- What the node checks, in order
- The module policy limits the blast radius
- Protocol implementations
- Rollback is a deploy
- The deadman rollback and a stolen key
- The rollout policy and a compromised node
- Signing is informed consent
- The HTTP endpoint
- Brakes
- Audit
- The store directory
- Key management
- Deployment checklist
- Reporting a vulnerability
Hot loading gives whoever can trigger it arbitrary code execution on production. Hotcode is built around that: the node is default-deny and holds no secret, and every decision about running code is made by signatures from people, never by network position.
The question this guide answers is: who can make a node load code, and what stops everyone else?
In short: a node loads code only for the holders of the private keys it trusts, for one specific
patch, once, for one environment, within 15 minutes. The node holds no secret, so a compromised
server cannot create a deploy. The HTTP endpoint authenticates every request, reads included,
over a single-use challenge before it reads the body, and answers every failure with the same
401. Persisted patches are stored as signed envelopes and re-verified at boot. Every attempt is
audited. Not protected: the Erlang distribution cookie (it already grants full access), a
compromised signer's machine, and a malicious patch its signers approved.
Threat model
What an attacker may be:
| attacker | can they deploy? |
|---|---|
| anyone who can reach the deploy port | no. They get an identical 401 for every failure and learn nothing, not even the module list |
| someone who steals the node's disk, memory or config | no. It holds only public keys |
| a compromised node in the cluster | no. Each node verifies the signed patch itself and never trusts the one that forwarded it |
| a network attacker who captures a request | no. Requests are signed over a challenge only that node issued, single-use |
a hostile node an operator lists in a fleet push (--targets) |
no. It can hand the operator's signed requests (a deploy of an envelope the signers signed, a rollback, a status read) on to another node; that node refuses them when it sets public_urls (see The HTTP endpoint) |
| someone who captures a signed patch | not without the audience, inside 15 minutes, once, and only on top of the exact code it was built against |
one stolen signing key, with threshold: 2 |
no. A second distinct key is required |
one stolen signing key, with threshold: 1 |
yes, within the module policy. This is why you should use threshold: 2 for anything that matters |
What is out of scope, and why:
- The Erlang distribution cookie. Anyone holding it can already
:erpcanything on the node. No deploy check can matter to them. Keep distribution off untrusted networks, use TLS distribution, and prefer the HTTP transport for deploys. - A compromised signer's machine. If the signer's key can be used, it can be used. Use a second signer, and keep keys off CI unless CI is the deliberate signer.
- A malicious patch its signers approved. A signature means "run exactly this". Read what you sign.
- Write access to
store_dir. See below.
What a signature binds
A deploy is a signed statement plus the patch it describes. The statement binds:
| field | defeats |
|---|---|
bundle_sha256 |
swapping the patch under a valid signature |
audience |
replaying a staging patch against production |
issued_at, expires_at (15 min by default) |
using an old or intercepted envelope later |
seq, which must equal issued_at, strictly increasing and persisted |
replay of an old envelope, and a dishonest signer pushing the counter sky-high to block all later deploys |
base: the MD5 of every module the patch replaces, which must cover all of them |
applying a patch built for a different release, or on code its signers never looked at |
force |
overriding the analyzer's safety blocks without the signers saying so |
restart_apps |
restarting an application in place without the signers saying so |
accept_major |
a semver-major bump, a downgrade or a non-semver version of an application (usually a dependency) without the signers saying so |
requires |
applying a release before the one it depends on |
auto_rollback (optional) |
an automatic cluster-wide undo of this release that its signers did not authorize (below) |
rollout (optional) |
nodes spreading this release among themselves without the signers saying so, or faster, wider or with fewer canaries than they said (below) |
The signed bytes are the statement exactly as written, prefixed with hotcode-v1-deploy\n.
HTTP requests use a different prefix (hotcode-v1-req\n), so a signature can never be reused
across the two.
In practice
A node that trusts two people and needs both for every deploy and rollback:
# config/runtime.exs
config :hotcode,
trusted_keys: [
%{name: "alice", public: "QwsIC7hunlG7..."}, # PUBLIC keys only
%{name: "bob", public: "8mH2x0Zr1d9..."}
],
threshold: 2,
audience: "prod",
allowed_prefixes: ["MyApp", "MyAppWeb", "Jason"], # a patch may touch these, nothing else
store_dir: "/var/lib/my_app/hotcode"
mix hotcode.build https://prod:4747 --out patch.hcp --key alice.key
mix hotcode.sign patch.hcp --key alice.key # prints what it authorizes, asks first
mix hotcode.sign patch.hcp --key bob.key # bob sees the same list, refuses a mismatch
mix hotcode.push patch.hcp https://prod:4747 --key alice.key
examples/pulse runs with threshold: 2 (alice and bob). Its v10 goes exactly this way, and
shows the push with one signature refused (insufficient_signatures), then a push with both
signatures refused because nobody signed for the application restart it needs, then the
patch built again with --restart-app and accepted.
What bob sees before signing (and what a forged envelope cannot hide):
type: deploy
audience: prod
version: 8f2c1d0
expires: 2026-12-02 18:45:00Z
app version: jason 1.4.4
ACCEPTS: breaking version changes of jason <- only if alice passed --accept-major jason
replaces: MyApp.Billing
signatures: 1 so far
What each refusal looks like to the caller:
Hotcode.Loader.deploy_binary(envelope_with_one_signature)
#=> {:error, {:insufficient_signatures, %{required: 2, valid: 1}}}
Hotcode.Loader.deploy_binary(envelope_for_staging)
#=> {:error, {:wrong_audience, "staging"}}
Hotcode.Loader.deploy_binary(envelope_touching_erlang_ssl)
#=> {:error, {:policy_denied, [:ssl]}}
What the node checks, in order
- The node is not locked (kill switch) and not in failure lockout.
- At least
thresholddistinct trusted keys signed. One person signing twice counts once; a key whose fingerprint merely collides is useless, because verification uses the trusted public key looked up by fingerprint. The list of signatures comes from the sender: more than 64 entries is a malformed envelope, refused before any signature is checked, and only the first entry naming each trusted key is verified, so checking an envelope costs at most one Ed25519 verification per trusted key. - The statement is a deploy for this
audience, inside its time window, withseqstrictly above the last accepted value. - The patch's SHA-256 equals the signed
bundle_sha256. - The patch unpacks and its manifest matches its beams.
- Module policy: every module touched must match
allowed_prefixes, and none may be part of Hotcode, Erlang/OTP or the Elixir standard library. - The
basecovers every touched module and equals what the node runs right now.
Nothing allocates atoms or decodes untrusted terms before step 4, archives are inflated in capped steps before anything else, and every field of a signed statement is type-checked once, so a malformed envelope cannot crash the verifier.
A plan needs one signature, not the threshold (POST /plan, hotcode push --dry-run), so
that the second signer can see what the first one built. Analyzing it reads the beams' exports
and attributes, which creates every atom their atom tables name, and the atom table of a VM never
shrinks: one key could otherwise fill it with plan after plan. Below the threshold, the node first
counts the atoms the beams name that it does not have yet, reading the atom tables by hand
without creating any, and refuses ({:too_many_atoms, count, limit}, counted toward the failure
lockout) a plan that would create more than 20 000 of them, or more than 100 000 for all such
plans together since the node started (config :hotcode, plan_new_atoms: [per_plan:, per_boot:]).
Atoms that already exist cost nothing, so planning the same patch again is free. A plan signed by
the threshold, a preflight and a deploy are not limited: their signers can deploy the code anyway.
The module policy limits the blast radius
The policy does not isolate anything: code you are allowed to deploy can still do anything your
application can. What it prevents is a stolen key being used to replace :crypto, :ssl, :code, or Hotcode's own
checks. Keep allowed_prefixes as narrow as your deploys need.
Protocol implementations
With allowed_prefixes: ["MyApp"], defimpl String.Chars, for: MyApp.Money cannot be hot
deployed. Two things stand in the way, and only the first is about names:
- The implementation compiles to
String.Chars.MyApp.Money, which does not start withMyApp. - Protocols are consolidated (every release does it). The consolidated
String.Charsdispatches on a list of types fixed when it was built. LoadingString.Chars.MyApp.Moneyalone changes nothing:String.Chars.impl_for(%MyApp.Money{})staysnilandto_string/1raisesProtocol.UndefinedError. It starts working only whenString.Charsitself is replaced by a re-consolidated build, andString.Charsis part of Elixir.
So the build leaves both out and says so (warning: ... is NOT shipped, finding
:protocol_impl_not_shipped), and a signed patch that carries either is refused
({:policy_denied, [String.Chars, String.Chars.MyApp.Money]}). Ship such implementations
with a release. A protocol under your own prefix, and its consolidated module, ship like any
other module, and so do implementations of a dependency's protocol when that dependency's
prefix is allowed ("Jason" covers Jason.Encoder and Jason.Encoder.MyApp.Money).
Why there is no exception. An exception would let a signed patch replace a
standard-library module. That is only acceptable if what gets loaded is provably "the
protocol the node runs now, plus implementations for allowed types, and nothing else". The
invariant to keep: for every value whose type is outside allowed_prefixes, dispatch
through the new protocol is identical to the old one. Holding it needs:
- checking each added implementation from its beam (
__impl__: [protocol: P, for: T], module name exactlyP.T,Tunderallowed_prefixesand not a core type such asInteger,ListorAny). This part is easy, and the implementation's code then only runs for values of allowed types. - proving that the shipped
String.Charsdiffers from the running one only in its list of implementations. The node cannot take the patch's word for it: a crafted beam can claim any__protocol__(:impls). The only sound check is for the node to rebuild the protocol itself,Protocol.consolidate(String.Chars, running_impls ++ added)(it sorts the list, so the result is deterministic), and load that or require the shipped beam to be identical.Protocol.consolidate/2needs the protocol's debug info, andmix releasestrips it by default (strip_beams: true): on such a node the rebuild is impossible. The fallback, recompiling the patch's own copy of the protocol and checking that with the old list it compiles to what runs, is not sound: that copy comes from the signer, and the BEAM compiler optimizes across the functions of a module, so "compiles to the running code with the old list" does not bound what it compiles to with the new one. - replacing a module every process in the VM calls (
String.Charsbehind every interpolation,Inspectbehind every log line and crash report,EnumerablebehindEnum). The next deploy or rollback purges the old version, which kills any process still running it, kernel and Hotcode processes included, and Hotcode's own rollback and audit paths go throughString.Chars.
What it would widen. With the exception, a stolen signing key (with threshold: 1, or
enough stolen keys) could, beyond what it can do today, replace a standard-library module
(with a node-built copy, at best) and run its code in any process that formats, inspects or
enumerates a value of an allowed type: the logger, crash reports, other applications'
processes, Hotcode's own error handling. Today its code runs where MyApp is called. That is
a wider blast radius than the policy promises, it would only work on releases built with
strip_beams: false (or keep: ["Dbgi"]), and a mistake in the rebuild breaks the whole VM
rather than one application. Hotcode therefore keeps the rule: an implementation of a
standard-library protocol needs a release.
Rollback is a deploy
Undoing code carries the same risk as installing it (an attacker could roll back a security fix), so a rollback is a signed statement that names the version it undoes and needs the same threshold, audience, expiry and replay protection as a deploy.
The deadman rollback and a stolen key
A release built with --auto-rollback-after carries "auto_rollback" inside its signed
statement, and a cluster in convergence: [mode: :auto] undoes that release by itself if a
reachable node cannot follow it in time (Deadman rollback). No
separate signature authorizes that undo: the signatures on the deploy do. That is deliberate. The
policy cannot be added, removed or changed without breaking the signatures, so the people who
authorize a release also authorize, in the same act and on the same screen (AUTO-ROLLBACK: in
mix hotcode.sign), how it may be taken back.
An attacker with ONE valid signer key, on nodes with threshold: 2:
- cannot add a policy to a release: a statement with the field is a different statement, and needs two signatures like any deploy. Grafting the field onto an envelope someone else signed breaks those signatures;
- cannot strip or lengthen the policy of a release that has one, for the same reason;
- cannot trigger an undo: the deadman is driven by the nodes' own view of the cluster, not
by any message an attacker can sign; and
Hotcode.Loader.auto_rollback/2undoes only the entry on top of the stack that already carries a policy, and only on a node whose own configuration saysmode: :auto; - can do exactly what one key could do before: sign half of a statement, which is useless alone.
What the signers of a deploy can now do that they could not before: with the threshold of
signatures they could already deploy any code, and (with the same threshold) sign a rollback of
it. With auto_rollback they can also pre-authorize ONE conditional undo of THAT release, carried
out later without anyone signing again, on the nodes that run it, only while it is on top, only in
mode: :auto, and only when the cluster has split around it. A release that degrades the
cluster on purpose and then disappears is no worse than what they can already do by deploying
and signing a rollback. What is new is timing: the undo happens when the conditions hold, not
when a person decides. Operators who do not want that keep the default mode (:report) or
:converge: the field is then inert, and the node refuses the undo (:auto_rollback_disabled).
In mode: :spread the deadman does not run; the field acts only for a release whose statement
also carries a rollout policy, when its spread halts (see below), and the node refuses the undo
of any other release (:no_rollout_policy).
Inside the cluster the coordinator calls the other nodes over distribution, so the Erlang
cookie is the trust boundary, as for a roll. A cookie holder can already :erpc anything; the
deadman adds nothing they could not do, and each node still checks its own stack and policy
before undoing anything.
Partitions: do nothing, and alert. An automatic undo needs a strict majority of every node
the table knows to be reachable (expected_nodes counts), every lagging node reachable and
answering that it gave up, no unreachable node last seen on the release, and the roll lock on
every node involved. Two halves of a partition each see half or less, or see the other half as
down: neither acts, and both report. This is the same rule as converging forward: a partition
must never make two halves undo each other.
The rollout policy and a compromised node
A release built with --rollout-* flags carries "rollout" in its signed statement, and nodes in
convergence: [mode: :spread] pass it to each other (Rolling out to a large
cluster). Each node decides from a table its peers fill (their version,
their role, their metadata): that table is NOT trusted for what a node loads.
What a node that forges its entry in the table, or serves forged bytes, can do:
-
make other nodes try a pull from it. Each of them verifies what it receives with its own loader, as any deploy: threshold signatures from its own trusted keys, its own audience, the expiry, its replay counter, the base of what it runs,
requires, the module policy, the analyzer. On top of that the bytes must carry a rollout policy, and must be the release the puller expected. A patch signed by an unknown key, for another audience, expired, or built for other code is refused, and the refusal is audited (test/cluster_spread_test.exsforges both of the first two); -
accelerate a release the signers approved for this audience: by claiming to be a spreader before the canaries passed, it lets pending nodes pull a release that is genuinely signed, with a policy, and verified by each of them. It cannot change the policy itself (it is signed);
-
stop a spread: by claiming a halt or failures, or by reporting a policy for the release that differs from what the other nodes report (the nodes halt the release,
{:policy_conflict, nodes}). Nodes then do nothing more; withauto_rollbackin the release, the undo still needs a majority, the roll lock on every node involved, and each node's own check that the release is on top and carries the policy. -
push to a node that asked for a push: the node accepts only the release it would pull right now, verifies the bytes like any deploy (the policy and the expected
{version, seq}included), and a refused push does not even make it:failed(tested with a patch signed by an unknown key, an unsigned one, one for another audience, and one that is not the release named).
What it cannot do: make any node load code the signers did not sign for that node; bypass
the kill switch or the failure lockout of another node; resume a halted release (a node clears
its halt only for a resume it verified itself: threshold, audience, expiry, bound to the release,
and its seq above the last resume that node applied, a number kept across a restart of the
spread process); keep a release halted past a resume by claiming a later one (once a node has
verified a resume, only failures and halts said under that resume count).
What it can do to the policy. A node that runs the release decides with the policy of its own
stack entry, which its loader verified; a promote it needs (require_promote), its fanout, its
soak and its halt threshold come from there. A pending node, which has not verified the release
yet, reads the policy from the rows of the nodes that report it, and halts the release when they
disagree. So a forged row can widen what a pending node reads (its cap, max_unavailable_pct,
the group order) only while no honest node reports the release, that is before the first
honest canary runs it; and even then every pull is verified as above, and the first honest node
that runs it makes the disagreement visible and halts the spread.
A signed resume carries the same weight as a deploy: the signers decide that a halted release
goes on. It cannot resurrect a release whose undo started (both take the roll lock on every
reachable node, and a resume after the undo is refused as :undone). It reopens the replay window
by exactly one statement on exactly the nodes that rolled that statement back themselves after
their own health gate in a spread: such a node may accept THAT statement once more, because a
resume it verified itself (threshold, audience, expiry, bound to the release, not replayed) asked
for it. The replay counter is never lowered; any other statement, an older one, or a release
undone by a signed rollback, a roll or an automatic undo is refused as before. The arming is in
memory, so a restart clears it.
A stolen signing key with threshold: 2 cannot add or change a policy, for the same reason as
auto_rollback. The signers of a release with a policy authorize, in the same act and on the
same screen (ROLLOUT: in mix hotcode.sign), that the nodes take it from each other within
those limits. A signed promote (--require-promote, mix hotcode.promote) needs the threshold of
signatures, names the release by version and statement seq, and expires like a deploy.
Inside the cluster the Erlang cookie is still the trust boundary: a cookie holder can already
:erpc anything, and nothing above changes that. What the spread adds is a way for honest nodes
to move a signed release; it does not add a way for a dishonest one to load code.
Signing is informed consent
A multi-party signing scheme fails when the second signer signs without looking. Hotcode guards against that in two places:
mix hotcode.signprints what the signature authorizes (type, audience, version, issue and expiry time, whether it overrides safety checks, applications that may be restarted, breaking version changes accepted, releases it requires, an automatic rollback policy, the version of every application whose modules change, every module replaced or removed) and asks first.Hotcode.Envelope.sign/2refuses to sign unless the statement really describes the code in the envelope. Otherwise a malicious first signer could hand the second an envelope whose statement is for different code than the one inspected, then swap the evil patch back in.
--yes skips the question for automation. It still refuses an inconsistent envelope.
The HTTP endpoint
Every request, including GET /manifest, is authenticated before the server reads a byte of
its body:
- The client asks
GET /challenge(the only unauthenticated route). The reply is a stateless token: random bytes, an expiry and an HMAC under a secret generated at node boot. Issuing one stores nothing, so flooding it can neither exhaust memory nor evict an operator's challenge. - The client signs
method,path(with its query), the body's length and SHA-256, the challenge and the authority it sent the request to (host:portas written in its URL) with its private key. - The server checks a trusted key, a live challenge, the authority (when
public_urlsis set, see below) and the signature using the claimed length and hash, consumes the challenge, and only then reads the body, which must match what was signed.
Consequences: without a trusted key nothing is ever buffered; a captured request cannot be
replayed (the challenge is used up), and a captured challenge is worthless on any other node
(its secret differs); no clocks are involved; and every failure produces an identical 401.
A request aimed at one node, relayed to another. The client cannot tell which node issued
the challenge it signs: a hostile node listed as a fleet target can fetch a challenge from
another node, hand it to the operator's client as its own, and forward the signed request there.
That is what the authority in the signature is for. Set public_urls on every node to the URLs
operators and CI use to reach it:
config :hotcode, public_urls: ["https://node-a.internal:4747", "https://10.0.0.5:4747"]
A node with public_urls refuses a request signed for any other address, so the relayed request
is refused (401). A node without it accepts any address, and the relay works against it: the
hostile target can then read that node's /manifest and /status, and pass on the operator's
/deploy (only of an envelope the signers signed, which that node verifies like any other) and
/rollback (a signed rollback) to it. It still cannot deploy anything the signers did not sign.
The client never follows a redirect (a 3xx answer is an error), so a target cannot send the
signed headers or the patch elsewhere, and on OTP 27 and later it reads at most 8 MB of an answer
(64 MB for /manifest); an answer without a length, ended by closing the connection, and any
answer on OTP 26 (whose :httpc has no such limit), is bounded by the request's timeout only. It prints a warning when a target is plain http:// off loopback.
Plain HTTP is refused off loopback. The client always verifies TLS certificates (trust a
private CA with --cacert ca.pem or HOTCODE_CACERT, or cacertfile: in Hotcode.Client.new/2).
A locked node (the kill switch) answers 423 to an authenticated request; anyone else gets the
same 401 as for every other failure, and learns nothing about the lock.
A tunnel or reverse proxy in front of the node changes none of this: the signature covers the
method, the path, the authority, the body's hash and a challenge only the node can issue, so a
proxy can read a request but cannot alter or replay it. With a proxy, list the URL operators use
(the proxy's) in public_urls: the node checks the authority the client signed, not the Host
header it receives. What a proxy does change is who sees the traffic in clear: with TLS ending
at the proxy (a Cloudflare tunnel, a load balancer), the proxy's operator sees the patch. Keep
the proxy-to-node hop on the same host (loopback) or on TLS. Setups:
Reaching the node.
Brakes
- Kill switch.
Hotcode.lock/0refuses every deploy untilHotcode.unlock/0(config :hotcode, locked: truestarts locked). It is held in memory. - Failure lockout. Five rejected envelopes in a minute lock deploys for five minutes.
Rejections that reach this point already carry a valid request signature (or came over
distribution), so only key or cookie holders can trigger it. Anonymous traffic never counts,
so strangers cannot lock operators out. What counts: every refusal of the verification of a
deploy, a plan (which needs one signature), a preflight, a signed promote or a signed resume
(signatures, audience, expiry, replay, hash, archive, manifest, beams, module policy), not
operational refusals (a base that moved,
requires, a hook's veto, lingering old code). During a lockout deploys, plans, promotes and resumes are refused; a signed rollback still works. - Self-lock. If an undo cannot be completed or a crash cannot be recovered from, the node locks itself until an operator has inspected it.
Audit
Every attempt, accepted or refused, goes to three places: Logger (at :notice), telemetry
([:hotcode, :audit]) and an append-only JSON-lines audit.log in store_dir; that includes
signed promotes and resumes, and their refusals. Unauthenticated request noise (a 401) goes to
telemetry and to Logger at :debug only, so nobody can flood the file or the log. Alert on
rejected, lockout, node_locked, deploy_crashed, persist_failed and
app_restore_degraded.
The store directory
Persisted patches are untrusted input:
- only the raw signed envelope is stored; what loads, what it replaces and in which order are derived from the verified statement, never from other fields in the file;
- each envelope is re-verified against the trusted keys at boot, with sequence numbers required to strictly increase across files;
- files are never decoded as Erlang terms in production;
- rolled-back patches are recorded in a revoked set, so one cannot return at the next boot;
- the replay counter and revoked set are written atomically.
Someone who can write to the directory therefore cannot run code or choose what runs. They
can delete patches (the node boots the release's own code) and delete the seq or
revoked files (reopening the replay window for a still-valid envelope). Protect the
directory: owned by the service user, mode 0700.
Pulled envelopes are verified like any other. With convergence: [mode: :converge] a node
that is behind reads the signed envelopes it lacks from a peer's store over Erlang distribution
and deploys them through its own Hotcode.Loader.deploy_binary/2: threshold, audience, expiry,
replay counter, base, requires and module policy are checked by the receiving node against its
own keys and configuration, so a peer (or someone who wrote to the peer's store) can at most
offer bytes the node refuses, and each refusal counts toward its failure lockout. Nothing new is
trusted: the Erlang cookie remains the trust boundary inside the cluster, as it is for rolls
(whoever holds it can already call the loader directly). An expired envelope is refused, so
convergence never stretches what the signers authorized past their deadline.
Key management
- One key per person, generated on their own machine. Never share a private key; never put one on a server.
- Prefer an encrypted disk or a hardware-backed store for the key file.
gen_keycreates it with mode0600and never overwrites. - Rotation and revocation are config changes: replace the entry in
trusted_keysand restart (orApplication.put_env/3at runtime; keys are read on every verification). A key removed fromtrusted_keysstops counting immediately, including for stored patches at the next boot. - Use
threshold: 2for production, and give the two keys to people who do not share a machine.
Deployment checklist
- [ ]
trusted_keys,audienceand a narrowallowed_prefixesset - [ ]
threshold: 2in production - [ ] the HTTP endpoint behind TLS (or loopback behind your own proxy), not plain HTTP
- [ ]
public_urlsset on every node to the URLs operators and CI use to reach it - [ ]
store_dirset, owned by the service user, mode0700, on durable storage - [ ] the distribution cookie secret, distribution not exposed, ideally TLS distribution
- [ ] alerting on audit events
rejected,lockout,node_locked,deploy_crashed - [ ]
allow_app_restartempty unless you have tested in-place restarts against your real application tree - [ ]
unsafe_allow_unsignednot set (the node logs an error at boot if it is) - [ ] a documented procedure for revoking a key and for the runbook
Reporting a vulnerability
See the security policy.