The Data Protection key ring is encrypted at rest: with a configured certificate on every platform, or with DPAPI on Windows when none is set #42

Closed
opened 2026-10-31 12:41:55 -04:00 by claude · 0 comments
Owner
  • Draft: REL-31
  • Priority: medium (anyone who reads the data folder can decrypt every stored secret)
  • Agent: coder
  • Depends on: none
  • Decisions: Q-REL-12 (= Q-BUG-5), R2-KEYRING

Why

Program.cs:186-189 persists the key ring with PersistKeysToFileSystem and no
ProtectKeysWith* (grep finds none in src/dotnet/src). On Linux the folder is owner-only
(Program.cs:172-179); on Windows the README tells the operator to restrict it with icacls. The
release notes list this as an accepted risk (OD-B19-d = a, owner 2026-10-16). The key ring unlocks
TSIG secrets, DNSSEC private keys, TOTP keys, the OIDC client secret, the SMTP password, cloud and
webhook credentials and the ACME account key.

What changes

  • New options class DataProtectionKeyRingOptions, section DataProtection, read in Program.cs
    before the key ring is configured: CertificatePath (a PFX), CertificatePassword (a secret),
    and PreviousCertificatePath / PreviousCertificatePassword for a certificate change.
  • Protection order (owner decision R2-KEYRING):
    1. A certificate is configured, on any platform including Windows: ProtectKeysWithCertificate,
      plus UnprotectKeysWithAnyCertificate with the current and previous certificates, so keys
      written under the previous certificate still decrypt while both are configured.
    2. No certificate, on Windows: ProtectKeysWithDpapi. Decide and justify the scope (machine or
      the service account); the service account is the stricter choice when it is stable across
      upgrades.
    3. No certificate elsewhere: as today (owner-only folder).
  • Existing unprotected keys still decrypt (Data Protection reads them); new keys are written
    protected. Check and document what happens on Windows when a certificate is added after DPAPI
    was used: DPAPI-protected keys must still decrypt on the same machine and account.
  • Keep: backup and restore of the key ring
    (Ninlil.Dns.Server.Backup/SystemBackupService.cs:508-515,831) and cluster nodes that share a
    ring. Check what a restore does today when the restored keys cannot be unprotected (DPAPI from
    another machine, a missing certificate) and make the error name the cause and the setting.
  • README Security section: the three cases; a DPAPI-protected ring cannot be read on another
    Windows machine or account; anyone who may restore a backup on another machine should
    configure a certificate
    , on Windows too, and back the certificate up separately from the data
    directory. CHANGELOG Unreleased (the accepted risk is updated).
  • OptionsEnvironmentVariableRegistry (new top-level class), ENVIRONMENT.md rows and totals.

Acceptance

  • Web.Tests and Backup.Tests: with a test certificate configured, a new key file holds no
    plaintext <masterKey>; a secret stored before the switch still decrypts; a backup restored
    on the same host decrypts; with the certificate replaced and the old one set as previous,
    old secrets still decrypt.
  • A restore whose keys cannot be unprotected fails with a message naming the cause.
  • dotnet test src/dotnet/tests/Ninlil.Dns.Identity.Tests passes.
  • On Lofnheim: with no certificate, the key file written by the exe is DPAPI-protected and the
    service restarts and reads its secrets; with a certificate configured, the new key file is
    certificate-protected, not DPAPI, and a backup restored on another Windows machine with the
    same certificate decrypts.
  • Env-var tests pass with the new totals.

Source

d-design.md:393 ("protect Data Protection keys at rest (ProtectKeysWith*, OD-B19-d)"),
bughunt-plan.md:509,534. Merged from BUG-40 (DEDUPE.md).
Owner decision 2026-10-31 (Q-REL-12 = Q-BUG-5): "DPAPI on Windows + optional certificate on Linux".
Owner decision 2026-10-31, round 2 (R2-KEYRING): "certificate preferred on Windows too when set,
DPAPI only as fallback; README advises the certificate for anyone who may restore on another
machine".

- **Draft:** REL-31 - **Priority:** medium (anyone who reads the data folder can decrypt every stored secret) - **Agent:** coder - **Depends on:** none - **Decisions:** Q-REL-12 (= Q-BUG-5), R2-KEYRING ### Why `Program.cs:186-189` persists the key ring with `PersistKeysToFileSystem` and no `ProtectKeysWith*` (grep finds none in `src/dotnet/src`). On Linux the folder is owner-only (`Program.cs:172-179`); on Windows the README tells the operator to restrict it with `icacls`. The release notes list this as an accepted risk (OD-B19-d = a, owner 2026-10-16). The key ring unlocks TSIG secrets, DNSSEC private keys, TOTP keys, the OIDC client secret, the SMTP password, cloud and webhook credentials and the ACME account key. ### What changes - New options class `DataProtectionKeyRingOptions`, section `DataProtection`, read in `Program.cs` before the key ring is configured: `CertificatePath` (a PFX), `CertificatePassword` (a secret), and `PreviousCertificatePath` / `PreviousCertificatePassword` for a certificate change. - Protection order (owner decision R2-KEYRING): 1. A certificate is configured, on any platform including Windows: `ProtectKeysWithCertificate`, plus `UnprotectKeysWithAnyCertificate` with the current and previous certificates, so keys written under the previous certificate still decrypt while both are configured. 2. No certificate, on Windows: `ProtectKeysWithDpapi`. Decide and justify the scope (machine or the service account); the service account is the stricter choice when it is stable across upgrades. 3. No certificate elsewhere: as today (owner-only folder). - Existing unprotected keys still decrypt (Data Protection reads them); new keys are written protected. Check and document what happens on Windows when a certificate is added after DPAPI was used: DPAPI-protected keys must still decrypt on the same machine and account. - Keep: backup and restore of the key ring (`Ninlil.Dns.Server.Backup/SystemBackupService.cs:508-515,831`) and cluster nodes that share a ring. Check what a restore does today when the restored keys cannot be unprotected (DPAPI from another machine, a missing certificate) and make the error name the cause and the setting. - README Security section: the three cases; a DPAPI-protected ring cannot be read on another Windows machine or account; **anyone who may restore a backup on another machine should configure a certificate**, on Windows too, and back the certificate up separately from the data directory. CHANGELOG `Unreleased` (the accepted risk is updated). - `OptionsEnvironmentVariableRegistry` (new top-level class), ENVIRONMENT.md rows and totals. ### Acceptance - [ ] Web.Tests and Backup.Tests: with a test certificate configured, a new key file holds no plaintext `<masterKey>`; a secret stored before the switch still decrypts; a backup restored on the same host decrypts; with the certificate replaced and the old one set as previous, old secrets still decrypt. - [ ] A restore whose keys cannot be unprotected fails with a message naming the cause. - [ ] `dotnet test src/dotnet/tests/Ninlil.Dns.Identity.Tests` passes. - [ ] On Lofnheim: with no certificate, the key file written by the exe is DPAPI-protected and the service restarts and reads its secrets; with a certificate configured, the new key file is certificate-protected, not DPAPI, and a backup restored on another Windows machine with the same certificate decrypts. - [ ] Env-var tests pass with the new totals. ### Source `d-design.md:393` ("protect Data Protection keys at rest (`ProtectKeysWith*`, OD-B19-d)"), `bughunt-plan.md:509,534`. Merged from BUG-40 (DEDUPE.md). Owner decision 2026-10-31 (Q-REL-12 = Q-BUG-5): "DPAPI on Windows + optional certificate on Linux". Owner decision 2026-10-31, round 2 (R2-KEYRING): "certificate preferred on Windows too when set, DPAPI only as fallback; README advises the certificate for anyone who may restore on another machine".
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil#42
No description provided.