Repository navigation
Keep secrets out of logs and memory, and the key out of the volume - #166
Merged
Merged
Conversation
RikusVanRensburg
force-pushed
the
fix/RVR/config-secrets
branch
2 times, most recently
from
November 12, 2026 20:07
fefb3ea to
30b4071
Compare
…e config files Secret<T> prints as Secret(<redacted>) in Debug, wipes its value on drop, and reads and writes as the value it holds, so no file changes. It covers client secrets, private keys, certificates with their keys and the password hash in the file structs, and the places that build them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… plaintext - KOPPEL_KEY_FILE, a systemd credential (koppel-key) and a Docker secret (koppel-key) can hold the key. Any secret of 32 bytes or more; HKDF-SHA256 gives the AES key and key id. - The box reads every key it finds and seals with one. koppel-secrets.<anything>.key files are older keys. At start, secret files sealed with another key are written again. - Plaintext buffers of a decrypted file are wiped after use. - Property tests for the secret container and the PKCS#12 reader. - docs: threat model and key sources in security.md, decisions in decisions.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
RikusVanRensburg
force-pushed
the
fix/RVR/config-secrets
branch
from
November 12, 2026 20:11
30b4071 to
e642af3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #156
What changed and why
State.current_jsonis gone, "unchanged" is a typedPartialEqcompare plus a SHA-256 of the bytes.Secret<T>(koppel-config/src/redact.rs):DebugprintsSecret(<redacted>), the value is zeroized on drop, serde is transparent so no file changes, it derefs to the value, and there is noDisplay. Used for client secrets (ClientConnection,SkakelClientRecord,LegacyClient), private keys, PKCS#12 certificates, 0.1.0's signing key and the UI password hash.secret_hash(SHA-256 of a random secret) stays a plain string. A test fills every secret with a sentinel and checks{:?}and{:#?}of every file struct show none. Cost:.as_deref()on an optional secret gives&String, and the code that builds these structs needs.into(). That touchedkoppel-web(auth/mod.rs,api/client.rs,roles/skakel/{client,links,store}.rs) and onekoppel-usbtest helper, only as type conversions.ConfigFileload and write, and the buffers inSecretBox::protect,unprotectandreseal. Not wiped, and documented: serde_json's intermediate values, ring's key schedule, TLS keys, swap, core dumps.KOPPEL_KEY_FILE, a systemd credentialkoppel-key($CREDENTIALS_DIRECTORY) and a Docker secretkoppel-key(/run/secrets), tried in that order.KOPPEL_KEY_FILEthat names nothing is an error. The file is any secret of 32 to 4096 bytes (openssl rand -base64 32), a trailing newline ignored; HKDF-SHA256 gives the AES key and the key id. Windows keeps DPAPI and warns if the variable is set. No new dependency beyondzeroize(already in the tree).koppel-secrets.keyis then only read, never made); otherwisekoppel-secrets.keyseals.koppel-secrets.<anything>.keyare older keys, only read, in Koppel's format or a plain secret.SecretBox::resealruns at start fromkoppel/src/main.rsover the three secret files andui-session.key, so a rotation or a move out of the volume is one restart. The start log says which source seals.docs/security.md(key beside the files by default, no passphrase and why, memory limits, logs, the 0.1.x key ring staying, retrievable client secrets), with the procedures to move the key out and to rotate.docs/decisions.md: password hash stays PBKDF2-SHA256 (reasons: OWASP figure met, Argon2id needs a new dependency and a second format next to the 0.1.x one that carries over, the hash sits behind a rate limit in an encrypted file); client secrets stay retrievable (the signing key in the same file already allows forged tokens); no proptest or cargo-fuzz (property loops on a fixed generator instead).Not done, and why
migrate.rs). The brief keeps that file to the agent moving the upgrade code (The 0.1.x upgrade code leaves the daemon, and certificates are stored as DER #144), and deleting it stops a rollback to 0.1.x. Documented in the threat model; say if you want the deletion.LoadCredentialexamples are indocs/security.mdonly.Tests
Secretunit tests, seal/open round trip (400 cases up to 8 KiB), every byte flipped (two bits each) and every truncation is an error, random and header-forged input is an error, PKCS#12 no-panic loops.contains(\"another key\").rust:1.99.1-trixie):cargo test --workspace --lockedall green;cargo clippy --workspace --all-targets --locked -- -D warningsclean. Native Windows:cargo build,cargo clippy -D warnings,cargo fmt --all --check,cargo deny check(advisories, bans, licenses, sources ok).koppel-contract, UI tests, a real systemd credential or Docker secret (the code reads a file; tests use files), an install with a real upgrade.Docs
docs/security.md,docs/config.md,docs/decisions.md.Changelog notes:
secrets.json,connection.json,ui-auth.jsonandui-session.keyare written again with a key that is not in the volume (the container format is unchanged, the key id differs). Do not delete the outside key: the files cannot be read without it.KOPPEL_KEY_FILEenvironment variable (Linux and Docker); a systemd credential or Docker secret namedkoppel-keyis used when present. Migration: set the source, start, wait for the log line that files were sealed again, then movekoppel-secrets.keyout of the keys directory.koppel-secrets.<anything>.keyfiles in the keys directory are now read as older keys.Secret,KeySource,KeySources,SecretBox::{with_sources, source, keys_read, reseal}; the secret fields of the file structs changed type.🤖 Generated with Claude Code