Expand description
Node identity: load or generate a persistent ed25519 SecretKey.
The key is stored as 32 raw bytes at <data_dir>/node.secret. On Unix the
temp file is opened with mode 0600 from creation (no umask-window where
the key material is world-readable) and atomically renamed into place.
On Unix, permissions are validated on every load to block key-replacement
attacks: data_dir must be a directory with no group or world permission
bits (e.g. 0o700), and node.secret must be a regular file with no group
or world permission bits (e.g. 0o600). Setuid/setgid/sticky bits are not
inspected. A world- or group-writable data_dir would let any local
process replace node.secret between load and use. On first run the
directory is created with 0o700 via DirBuilder::mode (no umask window).
Non-Unix platforms skip these checks — POSIX mode bits do not map
meaningfully to NTFS ACLs.
New keys are built via SecretKey::generate, which draws from
the auto-seeded thread-local CSPRNG backed by OS entropy.
Structs§
- Loaded
Key - A node key from
load_or_create, and whether that call created it. - Staged
Node Key - A freshly-generated node key written to a temp file in
data_dir, not yet committed tonode.secret.
Functions§
- ensure_
data_ dir - Validate (or create+validate)
data_dirwith0o700semantics: if it exists, the permission policy is enforced; if it’sNotFound, it’s created securely and then validated. Other stat errors propagate. - fresh_
secret_ key - A newly generated node secret key, drawn from the OS RNG. The caller owns persisting it; nothing here touches disk.
- install_
staged - Install the staged temp file
tmpattarget, archiving any existingtargetfirst. Shared commit primitive for the staged-key types (StagedNodeKeyanddecdn_incentive’sStagedKeystore) so their archive → rename → fail-safe-rollback logic stays in one place. - key_
path - Location of the persistent node key within
data_dir. - load
- Load the node’s
SecretKeyfrom disk without generating one when it is absent — the read-only counterpart ofload_or_generate, used bydecdn whoamito report the existing identity without minting a new key. - load_
or_ create - Load the node’s
SecretKeyfrom disk, generating and persisting one if absent, and report which of the two happened. - load_
or_ generate - Load the node’s
SecretKeyfrom disk, generating and persisting one if absent. - move_
aside - Rename
pathto<filename>.bak.<unix_ts>so an in-place key rotation preserves the prior key material rather than destroying it. Required byappendix-operator-key-rotation.md§1 step 9 (“Archive the old iroh keystore offline. Retain it for at leastMAX_EVIDENCE_AGE_US”) and the §5 rollback path (“Repoint config at old keystore”). The operator can later move the.bakfile offline; deleting it is up to them. - stage_
node_ key - Generate a fresh node key and write it to a temp file in
data_dir(mode0o600on Unix) without touchingnode.secret. Validates or securely createsdata_dirwith the same0o700semantics asload_or_create.