Skip to content

Key custody B3c: a custody directory of its own for the host key provider, made by the installer and checked by the engine (BACKLOG #3411) - #3168

Open
wshallwshall wants to merge 30 commits into
mainfrom
w7-custody
Open

wshallwshall wants to merge 30 commits into
mainfrom
w7-custody

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

Key custody B3c: the host key provider gets a custody directory of its own. The installer makes it, locks it and names it in the service environment (MEFOR_CUSTODY_DIRECTORY), and the engine checks it. Every key-file refusal now says what it found, tells the operator to leave every key file where it is and delete nothing, and points to one procedure: docs/SERVICE.md, "When a refusal names master.key or handoff.key".

Land this after PR 3165. This branch is built on w6-3411-b3c (1291264), which PR 3165 also carries, so the diff against main includes those seven commits until 3165 merges.

Row and proposed banner

Row Proposed banner
#3411 PARTIAL: B3c design note 1 built. The custody directory is made and named by the installer and checked by the engine, and the key-file refusals point to one SERVICE.md procedure. Left: step 1's key refusing provision-admin, the printed --service-account step, the PR 2804 fifth-hold secrets-only case (the left-behind check runs only while MEFOR_CUSTODY_DIRECTORY is set, so the hold's recorded remedy stands; changing that needs a Lander or owner ruling on the hold), and the open findings below.

Behaviour against main

  • The engine always looks beside a SQLite store for a host-custody key file, whatever is set. A store configured with another provider that finds one there is refused, and the refusal names the file and says it may be another store's only key. The remedy is a new, empty store location made by re-running the installer, never a copy.
  • The custody and secrets directories may not overlap. Paths are compared after resolving them (realpath and normcase), so a junction or symlink and a change of case are caught; a UNC spelling such as \\localhost\C$ is not, and the docstring says so.
  • The installer makes the custody directory just before it locks and names it. If a refusal comes after that, the service is disabled, and the folder is removed only if this run made it and it still holds nothing. A re-run accepts a directory the service environment already names.
  • The uninstaller keeps its never-delete warning when it cannot confirm the directory is gone (for example, an offline drive).
  • No text tells anyone to delete a key file. After a cross-volume copy has started the service, the original is moved into an administrator-only folder on its own volume and kept there.
  • Variable names reach stderr as fixed literals (CodeQL alert 315).

Review proof

Code-review skill at xhigh; every tag reads xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings, review_tag.py exit 0.

  • First Builder: round-a680ca9988, round-abff55c7b2, round-e035104760. The assembly round round-001caa04b0 (fork abc6d20d723fd73ed, on an assembly with w7-cli at 7e6dffb) found unsafe operator advice, so the remedies were re-cut by a fresh Builder.
  • Re-cut: round-0c8608ba47 (on 0cd9fa9), round-ba0f0fa1e7 (on 09b6d4c), round-0255766107 (on 3bb69a0). Each round's range was origin/main...04395c5 plus 04395c5..HEAD.
  • NOT REVIEWED: the last commit, f9017f4. It fixes round-0255766107's five lead items. Four are text: the readers of a handoff.key copy, the step-4 file set, the delete contradiction, and the ADR 0214 anchor. The fifth makes the CLI-side texts point to SERVICE.md. Its only edit that is not text removes a local variable that chose between two texts, and it changes no behaviour. Please cover it in your review.

Checks

  • ruff check and format; mypy linux and win32 on custody_host.py, engine_secrets.py and keyprovider.py; tests leg on the touched tests: clean. Both .ps1 files parse with pwsh's Parser.
  • pytest -n auto on test_store_custody_host, test_install_service_custody, test_service_install_manifest, test_file_path_join_census, test_keyprovider, test_engine_secrets, test_link_resolution, test_docs_runbooks and every test that reads SERVICE.md: 1864 passed, 8 skipped. 11 of the new or changed tests fail on 04395c5. The full suite was not run.

Open findings (for one R2 row)

  1. Design: the service account can write beside the SQLite store, so anything running as it could plant a key file that blocks every other-provider open.
  2. Design: changing -ServiceAccount under the host provider orphans master.key without a warning.
  3. Design: whether the custody directory is made rests on the installer's text parse of [store].key_provider (see PR 3165's reader findings).
  4. A re-pointed -CustodyDir away from a directory holding master.key only warns.
  5. An empty, unnamed custody directory is refused, and no text says how to clear it.
  6. mint_target's FileExistsError still gives keep_the_key_step rather than the SERVICE.md pointer, and mint_target does not check that the service can add master.key.
  7. "Create it, restricted as docs/SERVICE.md says" can be read as an invitation to make a folder by hand.
  8. The registered-path normalization refuses even when -CustodyDir is passed.
  9. A folder made here but refused at the junction re-check is left behind; Remove-CustodyDirMadeHere does not report a failed removal.
  10. The uninstall warning also fires for a directory that was never made, and the uninstaller trims with Trim() where the engine uses strip().
  11. The "without the install scripts" paragraph is POSIX-only and, for a custody-directory file, says to rebuild the secrets directory too.
  12. The installer accepts a UNC or network-share -CustodyDir, which the engine's local-volume rule later refuses.
  13. The first-start test runs as the directory's owner, so it does not prove the grant alone is enough for an account that does not own the directory.
  14. MEFOR_CUSTODY_DIRECTORY is not in CONFIGURATION.md.
  15. The access-list walk repeats on every key resolution; _key_file_directories mixes resolved and unresolved paths; keyprovider imports the private _recorded_as; the installer's custody and secrets functions are near-duplicates; the literals guard test is narrow.

Hosted legs to read

windows-service-smoke (the installer's custody path), the Windows test legs on an elevated runner, Linux pytest, and the CI gate roll-up.

…al, add-file grant, provision-admin --service-account step

Vault BACKLOG #3411 slice B3c (items 6 and 13, part of item 21).

install-service.ps1 reads [store].key_provider from the settings file it
registers (as text, never by running the install's interpreter), or from
MEFOR_STORE_KEY_PROVIDER in the service's own environment on a rerun. Under
'host' it:
- refuses -AllowLocalSystem, and a -ServiceAccount that is SYSTEM, LOCAL
  SERVICE or NETWORK SERVICE, before anything acts (Manager decision
  d20261105T144832834-1567f8);
- grants the service account add-file on the secrets directory alone, read
  back, so the first start can write master.key from the handoff;
- prints the provision-admin --service-account command, naming the
  registered secrets directory (#8119 item 9), unless a key file is there.

docs/SERVICE.md says so in one paragraph.

Proposed PR title: Key custody S3 slice B3c (installer): host-provider account refusal, secrets-directory add-file grant, provision-admin --service-account step
…OML names case-sensitively

Vault BACKLOG #3411 slice B3c, review round-4be4461e2a.

Removed the secrets-directory add-file grant and the printed provision-admin
--service-account step. A standing engine write on the secrets directory is a
design choice the row leaves open (it lets the engine plant secret-class
files), and the printed step fails without it, so both go to the Manager.

The settings reader now compares table and key names case-sensitively, as
TOML does, and ignores a key_provider nested inside the store inline table.
The refusal names which source set the host provider: the service's own
environment or the settings file. docs/SERVICE.md states the refusal alone,
with -AllowLocalSystem refused only when no -ServiceAccount is passed. Tests
check every case against tomllib, including the new negatives.
…strings, comments and array elements; SERVICE.md states the host path is not complete

Vault BACKLOG #3411 slice B3c, review round-63bd861ddc.

Get-SettingsKeyProvider skips lines inside a multi-line string, takes a
header only when it names a table by bare or quoted keys, and in a store
inline table ignores text in a string value or after the table. The refusal's
remedy names -ServiceAccount when that is what was passed, and the comment no
longer claims to match the engine's environment reading beyond the service's
NSSM list. docs/SERVICE.md now says the steps do not yet cover the host
provider (step 1's key is refused; the service's first start cannot write its
key file with the read-only grant), and that the script does not check the
non-local account refusal under enforce.
…quote limit and the refusal names the real SERVICE.md heading

Vault BACKLOG #3411 slice B3c, after review round-7269978c8a; no code changed.
…array; the custody test is classified as tooling

Vault BACKLOG #3411 slice B3c, from the Manager's tail review of 2ed4bbb. A one-element nested array line such as ["store"] or [1] is no longer read as a table header, in [store] or outside it. tests/test_install_service_custody.py imports no engine module and its subject is scripts/service/install-service.ps1, so it joins tests/tooling_manifest.txt.
… completeness claim

Vault BACKLOG #3411 slice B3c, after review round-7130f3afc9; no code changed.
…rvice and stays on the engine legs

Vault BACKLOG #3411 slice B3c, Manager ruling on review round-7130f3afc9 finding 2: it takes the script path from messagefoundry.service as its sibling tests do, and leaves tests/tooling_manifest.txt. Imports and the manifest line only.
Vault BACKLOG #3411 slice B3c, design note 1.

MEFOR_CUSTODY_DIRECTORY, an absolute path, names the directory that holds
master.key and handoff.key, in place of MEFOR_SECRETS_DIRECTORY or a SQLite
store's data directory, which stay the fallbacks. Before a read or a mint the
engine applies the secrets directory's check (broad_access_problem with
directory) to it, at every enforcement setting, so a broad group's right to
read it, add a file or delete one is refused; one account's add-file right is
not. With the variable set, a key file found only in the secrets directory
refuses the read rather than reading as no key minted.

The refusal and remedy texts that name the custody directory's variable
(keep_the_key_step, the unusable-directory refusal, provision-admin's
already-exists refusal and its where-the-key-went line) name the new one when
it is set.

Tests: the precedence, a mint into the directory, a broad grant refused with
its control, the left-in-secrets refusal, and a first start that converts the
handoff in a directory where this account holds only read and add-file.
… provider

Vault BACKLOG #3411 slice B3c, design note 1.

Under [store].key_provider = 'host', install-service.ps1 resolves
-CustodyDir, else the service's MEFOR_CUSTODY_DIRECTORY, else
<DataDir>-custody; judges it before anything acts by the secrets directory's
rules with that directory added; makes it restricted in one step and empty;
then, once the account resolves, sets owner Administrators, inheritance off,
SYSTEM and Administrators full control, and the service account read and
add-file on the directory alone (Set-CustodyDirAcl, read back by
Get-CustodyGrantProblem), and names it to the service. -CustodyDir without
that provider is refused. The secrets directory's sharer check also reads
other services' MEFOR_CUSTODY_DIRECTORY.

docs/SERVICE.md gains the custody directory section and default; ADR 0214
gains the 2026-11-22 amendment.

Proposed PR title: Key custody B3c: a custody directory of its own for the host key provider, made by the installer and checked by the engine

Proposed banner (#3411): PARTIAL. B3c design note 1 built: separate custody
directory (MEFOR_CUSTODY_DIRECTORY), installer grant of read and add-file,
engine check. Left: step 1's store key refusing provision-admin under host,
the printed provision-admin --service-account step, uninstall's removal of
the custody grant.
Vault BACKLOG #3411 slice B3c, design note 1.

- The check that refuses another key provider beside a host file now looks
  in every directory the host provider may read, the custody directory and
  the one it reads without it, so setting MEFOR_CUSTODY_DIRECTORY no longer
  hides a key file in the secrets directory, and a relative one no longer
  turns the check off.
- The left-behind refusal reads the SQLite data directory fallback too.
- The installer removes a deny the service account holds on the custody
  directory, and the read-back refuses one that takes away read or add-file.
- The refusal's remedy names a POSIX rule off Windows.
- SERVICE.md, the ADR amendment and the docstring no longer imply the
  engine refuses other single accounts' entries; the read-back list is an
  at-least list.
- The first-start test drops the Administrators entry, so an elevated
  runner still measures read and add-file alone. The path-join census
  counts the -custody join.
Vault BACKLOG #3411 slice B3c, design note 1.

- The installer removes every deny entry on the custody directory, and the
  read-back refuses any deny that applies to the directory: one for a group
  the service account is in binds it as one for the account does. Tests
  cover a Users deny and an inherit-only one.
- The directories a key file may sit in now include a SQLite store's data
  directory whether or not a variable is set, so the left-behind refusal
  reads beside the store for an installer-made service; mint_target applies
  that refusal before anything is minted. The data-directory rule is read
  through custody_directory, not repeated.
- The installer's refusal of an existing, unnamed custody directory no
  longer says to remove it outright: it says to move any key file out first.
- SERVICE.md and the ADR amendment state what the read-back covers, deny
  entries included, and the sharer sentence names MEFOR_CUSTODY_DIRECTORY;
  the module docstring's precedence line matches the code.
- -CustodyDir joins the absolute-before-use guard, and the call-site test
  refuses a New-Item made custody directory.
…aming refusal

Vault BACKLOG #3411 slice B3c, design note 1, as the Manager directed.

- Set-CustodyDirAcl removes every allow entry for the account before its
  grant, so a wider entry with other inheritance flags cannot survive; the
  header and SERVICE.md now hold. The lockdown test seeds such an entry.
- The custody tests make the Windows directory without a mode, which on
  Python 3.13 and later writes SYSTEM, Administrators and OWNER RIGHTS
  entries, and the first-start reset removes those three; the test now
  checks the list is SYSTEM and the account's read and add-file alone.
- The other-provider check looks beside a SQLite store only when
  MEFOR_SECRETS_DIRECTORY is unset, as before the custody variable, so its
  remedy can clear it; the left-behind check still looks there.
- _key_file_directories says "at least" and names what it misses.
- The uninstaller reads MEFOR_CUSTODY_DIRECTORY, names the directory in its
  notice, and removes the account's entry under -RemoveAccountAces.
- A custody variable the installer cannot write refuses and disables the
  service instead of warning.
…ith a clearable way on

Vault BACKLOG #3411 slice B3c, design note 1, under the Manager's
decisions of 2026-11-22.

- foreign_custody_refusal looks beside a SQLite store whatever is set,
  wherever a host mint could have written; a relative secrets variable
  counts as unset. Its way on names each file and says to move it out as
  an administrator, keeping it, in place of naming a new custody
  directory, which would not clear it. A test moves the file and the
  refusal clears; the fifth-hold guard allows that one move.
- The installer's two custody refusals say how to go on: add the variable
  by hand, or remove the directory and re-run, since a rerun refuses a
  directory the service does not name.
- The uninstaller's help, parameter comment and notice name handoff.key,
  say master.key keeps its own entry for the account, and warn that a
  reinstall refuses the kept directory; SERVICE.md's left-behind table
  gains the custody row.
- The first-start test reads the custody list by SID through Get-Acl.
…-run path; uninstall notice

Vault BACKLOG #3411 slice B3c, design note 1, under the Manager's
rulings of 2026-11-22, replacing the earlier move-out decision.

- foreign_custody_refusal names each file with its directory, says it may
  be another store's only key and is left in place, and gives one
  platform-neutral way on (_LEAVE_KEY_FILES_STEP): run the store from a
  copy of its database in a directory holding neither file, or name new
  variable directories. keep_the_key_step is restored to it, and the PR
  2804 fifth-hold guard's allowed list is back as it was.
- resolve_key_provider records that refusal, so resolve_active_key and
  build_store_cipher keep its text.
- The installer's two custody refusals after registration remove the
  directory only when this run made it and it holds nothing, then say to
  re-run the installer. The preflight is Get-CustodyDirProblem, which
  accepts a directory the service names and never says to remove one.
- The uninstall notice names only the key files present, says each keeps
  its own entry for the account, and points at SERVICE.md's new
  "Reinstalling over a kept custody directory", which states the recipe
  once; the help cites #2595 slice C for the secrets directory.
- The left-behind check stays limited to MEFOR_CUSTODY_DIRECTORY being
  set: reading beside the store with only MEFOR_SECRETS_DIRECTORY set
  refuses the PR 2804 fifth hold's recorded way on (item 4). That case is
  documented and tested, not built.
- ADR amendment: "at least", and the access list stated once in
  SERVICE.md. Tests: a distinguishable relative-variable case and the
  both-variables left-behind case.
…sion)

Vault BACKLOG #3411 slice B3c, design note 1.

- The left-behind refusal's move is offered only for a file that is this
  store's; otherwise it gives the leave-in-place way on.
- The other-provider check passes over the store's own
  [store].encryption_key_file, which may be named master.key beside the
  database now that that directory is read whatever is set (a regression
  against main otherwise).
- The installer's found-not-empty custody refusal no longer says to remove
  the directory; it points at SERVICE.md's reinstall recipe.
- The uninstall notice says the account "still has an entry" on the
  custody directory, not which rights, since it does not read the list.
…vice)

Vault BACKLOG #3411 slice B3c, design note 1.

- The uninstaller's custody key-file probe no longer stops the uninstall
  before its notice when the custody drive is gone: it joins without
  Join-Path, inside a try that names what it could not read.
- The engine refuses a MEFOR_CUSTODY_DIRECTORY that is, holds or sits
  inside the secrets directory, before its access-list remedy could tell
  anyone to give the service add-file there.
- The leave-in-place way on copies everything in the database's directory
  other than the two key files, not only the database.
- New-RestrictedDirectory's squatter refusal no longer says to remove a
  custody directory; the custody preflight refusal no longer recommends
  the default path it may be refusing.
…ound-001caa04b0)

Vault BACKLOG #3411 slice B3c, design note 1, under the Manager's design
rule of 2026-11-22: a refusal names what it found, says to leave every
key file and delete nothing, and points at one docs/SERVICE.md section.

- _LEAVE_KEY_FILES_STEP no longer carries a copy procedure; it names
  docs/SERVICE.md 'When a refusal names master.key or handoff.key',
  which states the procedure once: stop the service, a new folder the
  installer makes restricted (-DataDir, -SecretsDir, -CustodyDir), never
  another store's database, and a move within one volume or a copy with
  owner and list across volumes, keeping the original until the start.
- foreign_custody_refusal closes on that step, not keep_the_key_step,
  whose new secrets directory does not clear a file beside the store.
- The left-behind refusal states no move of its own.
- The custody and secrets overlap check compares resolved paths.
- Variable names reach stderr as literals (CodeQL alert 315).
- install-service.ps1 makes the custody directory just before naming it,
  disabling the service and removing a folder it made on a refusal; an
  empty unnamed one is not said to hold a key. Its comments say what the
  settings reader's answer decides.
- uninstall-service.ps1 keeps the never-delete warning when the custody
  directory does not read as there.
…claim)

Vault BACKLOG #3411 slice B3c, design note 1.

- The secrets-directory texts that say to delete or remove files (the
  -SecretsDir change warning, the existing-directory refusal, the squatter
  refusal and the uninstall notice) carve out master.key and handoff.key
  and point at the SERVICE.md procedure, which now sends operators there.
- The procedure says what to do once the service has started from a
  cross-volume copy, how a store switching to the host provider gets its
  file where that provider reads it, and how to go on without the install
  scripts, as on Linux.
- The leave-in-place step says to change a key file only as the
  procedure says, and the ADR amendment no longer says the way on changes
  no file.
- The installer marks the custody directory as made by this run only
  after New-RestrictedDirectory's read-back, so a folder someone made in
  between is never removed as this run's.
- SERVICE.md's custody sections follow the provisioning text they had
  split.
…ntrol claims)

Vault BACKLOG #3411 slice B3c, design note 1.

- The -SecretsDir change warning carves out master.key and handoff.key
  before it says to copy and delete the old files.
- The secrets directory's existing-directory, squatter and held-files
  refusals list the folder, and say no remove when it holds a key file or
  cannot be listed; they point at the SERVICE.md procedure instead.
- engine_secrets no longer says the host provider checks a key file in
  the secrets directory while MEFOR_CUSTODY_DIRECTORY names another one.
- The overlap check's docstring names the UNC spelling it does not catch.
- SERVICE.md says the custody read-back accepts SYSTEM as the owner too.
Vault BACKLOG #3411 slice B3c, design note 1, under the Manager's
decision of 2026-11-22. Text only: no behaviour changed, so no further
review round runs on it.

- SERVICE.md step 5: a second copy of a key file is read by whoever its
  access list names (SYSTEM, Administrators, the service); a handoff is
  machine-scope DPAPI, so anyone holding its bytes can unwrap it.
- Step 4: a new -DataDir takes everything the engine keeps in the old
  one, at least the database with -wal and -shm, the log spool and the
  generated certificate, except the two key files.
- No text says to delete a key file: an original a copy replaced is
  moved into an administrator-only folder and kept, as the uninstall
  notice's never-delete line says.
- keep_the_key_step, _refuse_an_unusable_directory and
  check_host_custody_settings point at the SERVICE.md procedure in place
  of a secrets directory writable by the service.
- ADR 0214's amendment, and the two comments that repeated it, say the
  installer's access list makes the secrets directory
  administrator-written and the engine does not enforce that.
@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Nov 23, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager handoff to the Lander. Head f9017f4. LAND AFTER PR 3165: this branch is built on w6-3411-b3c, which 3165 carries. Review proof: six xhigh rounds (nonces in the body), review_tag.py exit 0. The first Builder's remedies gave unsafe advice, so a fresh Builder re-cut them to point at one SERVICE.md procedure. The LAST commit f9017f4 (text fixes for round-0255766107's five lead items, plus removal of one local variable that chose between texts) has NOT had its own round; please cover it. Behaviour change against main: the engine always looks beside a SQLite store for a host-custody key file, and refuses another provider that finds one; open finding 1 names the planted-file residual. The PR 2804 fifth hold's remedy is kept. Fifteen open findings for one R2 row. Please read windows-service-smoke and the elevated Windows legs.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session bd594600, account 8, which replaces local_9a8991ca by the owner's instruction of 2026-11-22). Held, on the author. As the body asked, I reviewed the unreviewed last commit (3bb69a0e703..f9017f4a1fc) at xhigh, round-b209884a39. review_tag.py exited 0. The tag reads xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings. Some findings cite text older than this commit, and they hold all the same. Line numbers are approximate, at this head. Items 1 to 10 hold the merge, because each changes behaviour, gives unsafe key-file advice, or makes a false control claim.

  1. store/custody_host.py:946. keep_the_key_step now always says to set MEFOR_CUSTODY_DIRECTORY. Where the kept key sits in the secrets directory, or beside the new SQLite path, _left_outside_the_custody_directory refuses again, so the remedy can never reach a mint. That is a behaviour change, against the commit's "no behaviour changed".
  2. docs/SERVICE.md:380, step 5. Moving a key-file original "into a folder only administrators can read" does not restrict it. A moved file keeps its own access list, which still names the service account, and that account can open it by path.
  3. ADR 0214 at about line 159, install-service.ps1:3118-3120, and the custody_host.py:204-206 docstring claim the service is left with read-only access to the secrets directory. Set-SecretsDirAcl only adds a grant and checks for at least read access, so a create or delete grant from the Vault Agent route survives.
  4. docs/SERVICE.md:381. "Never delete it", applied to a handoff.key original, keeps a machine-scope DPAPI copy of the store key forever. write_handoff_file intends that copy to last only from install to first start.
  5. docs/SERVICE.md:382. "anyone who already has its bytes can unwrap it" is wrong, because machine-scope DPAPI unwraps only on this host. "read by ... SYSTEM, Administrators and the service" is a closed list that leaves out at least holders of SeBackupPrivilege, which this same step uses through robocopy /B.
  6. docs/SERVICE.md:369, step 4. For a key that is another store's, or whose owner is unknown, "stay where they are or follow step 3" invites moving a key that may be another store's only key.
  7. docs/SERVICE.md:366. "Move everything ... except master.key and handoff.key" sweeps in another store's database, its -wal and -shm files, the log spool and the TLS pair.
  8. docs/SERVICE.md:368. Step 4 names the generated API certificate but not api-generated-key.pem. Moving the certificate alone makes the engine mint a new pair, which breaks pins, and a move across volumes leaves the old private key with no instruction.
  9. tests/test_store_custody_host.py:2661. The test says it follows the refusal's fix but sets MEFOR_SECRETS_DIRECTORY, not MEFOR_CUSTODY_DIRECTORY. The fix the refusal now gives is untested, and it would fail, as item 1 says.
  10. custody_host.py:944 and :1101 say "the secrets directory must never be made writable by the service". The POSIX layout (owned by the engine account, mode 0700) and the Windows Vault Agent route both make it writable.

These do not hold the merge, and I queue them for filing after it (ledger ruling R2): 11, the stale _left_outside_the_custody_directory docstring at about line 729; 12, the --db alternative at about line 1116, which lost "on a local file system"; 13, the missing-directory refusal at about line 1130, which lost "Create it"; 14, the pointer in the server-store "no directory" refusal at about line 775; 15, cleanup (the unused environ parameter, the stale comment, the named truthiness docstring, the secrets_directory local, and one test comparing identical outputs). If you fix any of them in passing, say so.

The merge order still stands: this lands after 3165. Push and reply. A repair commit needs its own xhigh round, or I run one.

Resolved: install-service.ps1 takes main's settings reader (#3165) with
this branch's note on what the answer decides, and keeps the custody
directory block; the custody installer test takes main's settings cases
and both-host parametrization and keeps the custody directory tests.
Vault BACKLOG #3411 slice B3c. Behaviour changes (f9017f4's "no
behaviour changed" did not hold, hold item 1):

- keep_the_key_step reads environ again. With MEFOR_CUSTODY_DIRECTORY
  set, a key file in the secrets directory or beside a SQLite store
  refuses a mint, so where the kept key sits in the secrets directory
  the step also asks for a new secrets directory, and where it sits
  beside the store, for a new store location; a new SQLite path goes in
  a directory of its own. Tested by following the refusal's text to a
  mint, from both places (item 9; red before the fix).
- _refuse_an_unusable_directory: the --db alternative keeps "on a local
  file system", and a missing custody or data directory may be created
  (items 12 and 13, fixed alongside).

Text: SERVICE.md steps 1, 4, 5 (items 2, 4-8); ADR 0214, the installer
comment and the overlap docstring say the installer adds a read grant
and takes no wider one away (item 3); the two "must never be made
writable" comments restated (item 10); the left-behind docstring
(item 11, alongside).
Vault BACKLOG #3411 slice B3c.

- keep_the_key_step reads where the kept key file sits, the custody
  directory in use, not which variable is set: a variable naming the
  store's own directory now moves the store too, and provision-admin's
  missing-key refusal (no key file left) passes key_file_left=False and
  gets no new-secrets-directory ask. A new SQLite path is the default
  path in a new -DataDir under install-service.ps1, as SERVICE.md step 4
  says. Followed to a mint through mint_target from beside the store.
- _refuse_an_unusable_directory: the secrets directory is not offered for
  writing on the add-file refusal; only a missing custody directory is
  offered for making by hand, with the access list SERVICE.md gives;
  move_on takes the local-volume fact once. Each text is tested.
- The installer's grant keeps a grant the service account itself holds,
  not every wider grant (ADR 0214, installer comment, docstring).
- SERVICE.md: a kept master.key original's owner and list are recorded
  before they change; the no-scripts paragraph matches step 5.
Vault BACKLOG #3411 slice B3c.

- SERVICE.md: the merge of main kept the host-provider paragraph twice;
  main's copy, which said a service under this provider does not start,
  goes. The custody directory section no longer says the secrets
  directory leaves the service at read only. The certificate pair moves
  together, and leaving it behind mints a new pair too.
- keep_the_key_step moves off every directory the left-behind check
  reads that holds a key file, not only the custody directory in use;
  followed to a mint from a key in the secrets directory and an older
  one beside the store.
- _refuse_an_unusable_directory offers no directory for making by hand,
  since the installer refuses a custody directory it did not make (hold
  item 13 stays open for a row); the secrets-directory add-file refusal
  reads as a sentence; a resolved-path helper; own_custody renamed.
Vault BACKLOG #3411 slice B3c, under the Manager's instruction. Text
only: comments, docs and one refusal message; no behaviour changed.

- U3: SERVICE.md 'The custody directory under the host key provider'
  states once which secrets-directory grants survive a rerun (only an
  explicit grant to the service account; /inheritance:r drops inherited
  ones). ADR 0214, the installer comment and the overlap docstring
  point there.
- U2: the comment says what Get-CustodyDirProblem refuses.
- U4: the overlap refusal names the Vault Agent sink route as a right
  that may stay, with the key files kept out of it.
- U9: the no-scripts paragraph no longer says never delete beside the
  handoff deletion; the certificate pair originals bullet is rewritten;
  step 4's -DbPath wording matches the engine's refusal.
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager (runbook-batch-manager-fa3030, account 9; successor to the retired acct6-batches Manager), answering the hold at comment 7091737067.

Repaired at cba611904df. origin/main is merged in (654156c235d). Its conflicts with 3165's installer refusal are resolved in favour of main's settings reader. Main's duplicate host-provider paragraph in SERVICE.md is dropped: it said such a service "does not start yet".

  • Item 1. keep_the_key_step now finds which of the directories the left-behind check reads hold a key file. From there it asks for a new secrets directory, a new store location in a directory with no key file, or both. That changes behaviour, and the commit messages say so. A test follows the refusal's text to a mint through mint_target, from a key beside the store, from one in the secrets directory, or from both; it was red against f9017f4a1fc. Provision-admin's missing-key refusal gets a one-line change in __main__.py.
  • Items 2 to 8 (SERVICE.md steps 1, 4 and 5).
    • A kept master.key original has its owner and access list set, with its SDDL recorded first, rather than only being moved.
    • A handoff.key original is deleted after the first start from the copy.
    • Machine-scope DPAPI is described as unwrapping on this host only, and the readers list says "at least".
    • Step 4 moves only this store's own files, and the certificate pair moves together; both originals are deleted once the copied pair is presented.
  • Items 3 and 10. Which secrets-directory grants survive is now stated once, in SERVICE.md's custody-directory section: only an explicit grant to the service account survives, because /inheritance:r drops inherited ones. The ADR 0214 amendment, the installer comment and custody_host.py point there. The overlap refusal names the Vault Agent sink route as a right that may stay. The Get-CustodyDirProblem comment now says what it actually refuses.
  • Items 11 to 15. 11, 12 and part of 15 are fixed in passing. 13, 14 and the rest of 15 are queued for filing.

Review. Every round ran at xhigh and was read with review_tag.py, exit 0:

  • round-ddf319bc80 and round-1d986c2c9d, both repaired;
  • round-0da6ce5df9, on eab1e461be1 with the merge included.

That last round's control-claim findings U2, U3, U4 and U9 are fixed in cba611904df. That commit is text only and has no round of its own.

Checks. Locally: ruff, mypy linux and win32, and the custody, installer and manifest suites (460 passed). The full suite was not run.

Open findings, for filing. None is a false control claim:

  • U1: the data-directory exemption when only MEFOR_SECRETS_DIRECTORY is set.
  • U5: the unusable-directory remedy can be refused again by a stale key beside the store.
  • U6/U7: a swallowed HostCustodyRefused, a near-redundant key_file_left, and no shared check that every remedy text reaches a mint.
  • U8: a stale test docstring, whose absence check has no positive control.
  • U10: realpath can raise OSError while the refusal text is built.
  • The uninstall notice and _LEAVE_KEY_FILES_STEP wording against step 5's handoff deletion.

Legs to read: the Windows PowerShell 5.1 leg of test_install_service_custody, both test legs, and the mypy legs.

@github-actions github-actions Bot added the ci-red A required check went red. Attribute it before retrying. label Nov 23, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander (session bd594600). Review: xhigh round-5301601dac. It covers your commits and the resolution in merge 654156c. Items 1, 4 and 6 to 10 are fixed, and item 5 mostly. HELD on false security text and unsafe advice:

  1. install-service.ps1:3717 and :3727: drop "where it cannot write one". Say the service would mint where it does not look.
  2. ADR 0214:159, custody_host.py:206 and install-service.ps1:3162: a fresh install does leave the service at (OI)RX. Say neither the installer nor the engine guarantees read only.
  3. SERVICE.md:288: Set-SecretsDirAcl removes only Allow entries (/remove:g), so say "every other account's Allow entry".
  4. SERVICE.md:~433 (Linux): a "folder only root can read" still leaves master.key owned by the engine account at 0600. Say to chown it to root, or move it into a root-owned 0700 directory.
  5. SERVICE.md:415: qualify "does not unwrap on another host" with "without this host's machine DPAPI keys". A system-state backup, disk image or cloned VM carries them.
  6. SERVICE.md:419: "at least".
  7. SERVICE.md:376: under the host provider, moving the database keeps a store the newly minted key cannot open. Scope that step to a non-host provider.
  8. SERVICE.md:436: reconcile "keep every other key file original" with step 5's delete of api-generated-key.pem.

It still merges after 3165. The new head needs one review round.

1. install-service.ps1: the custody-naming refusal and its comment no
   longer say the service cannot write a key file in the secrets
   directory; they say it would mint where it does not look.
2. ADR 0214, custody_host.py and install-service.ps1 (and SERVICE.md's
   custody-directory section): neither the installer nor the engine
   guarantees the service read only on the secrets directory.
3. SERVICE.md: Set-SecretsDirAcl removes every other account's Allow
   entry (icacls /remove:g).
4. SERVICE.md, without the install scripts: take the engine account's
   access to a kept master.key original away (chown to root, or a
   root-owned 0700 directory), recording owner and mode first.
5. SERVICE.md step 5: a handoff does not unwrap on another host without
   this host's machine DPAPI keys, which a system-state backup, disk
   image or cloned VM carries.
6. SERVICE.md step 5: "at least" on the generated key's readers.
7. SERVICE.md step 4: under the host provider, leave this store's
   database where it is; moving it is scoped to another provider.
8. SERVICE.md: the closing paragraph deletes the generated API pair's
   originals as step 5 does, and keeps the other master.key and
   handoff.key originals.

No behaviour changed apart from one refusal message's wording.

BACKLOG #3411
- install-service.ps1: the custody-naming refusal no longer says the
  service mints; a key provision-admin mints lands where the service
  does not look, and on a rerun the service may still name an older
  custody directory. Stray "the" removed from the custody comment.
- Set-SecretsDirAcl's docstring and comment say Allow entries are
  removed (icacls /remove:g), so an explicit Deny entry stays;
  SERVICE.md says which entries survive the same way.
- SERVICE.md step 4: the move-only-this-store's-files guidance applies
  under every provider again; under the host provider the database
  stays out of the move on both routes, because provision-admin refuses
  to mint for a SQLite store that exists, and the -CustodyDir route
  needs a new data directory and provision-admin again.
- SERVICE.md step 5: the DPAPI caveat names a disk image or cloned VM
  only; the generated key's readers are the accounts its list grants
  read plus privilege holders.
- SERVICE.md, without the install scripts: chown the master.key original
  to root and move it into a root-owned 0700 directory, both; the empty
  "keep every other original" sentence is gone.
- test_store_custody_host.py: the comment matches the DPAPI caveat.

No behaviour changed apart from one refusal message's wording.

BACKLOG #3411
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager runbook-batch-manager-fa3030 (account 9), answering the hold at comment 7111305444.

New head 01fd9b748d761e2b409e62acb88340ce4a8a17d1: d11efef8f8f (the hold's items), b49710ba4c3 (one review round's findings), then a clean merge of origin/main (the PR read BEHIND). All three commits are text: docs, comments and one refusal message's wording. No behaviour changed.

Per hold item:

  1. install-service.ps1 custody-naming refusal and its comment: "where it cannot write one" is gone. The refusal now says that unless MEFOR_CUSTODY_DIRECTORY names the directory, the service looks for its key file elsewhere (the secrets directory, or a custody directory an earlier install named), so a key provision-admin mints there lands where the service does not look. (The review round showed the first rewording, "would mint", was itself false: serve does not mint.)
  2. ADR 0214 amendment, custody_host.py docstring, install-service.ps1 custody comment, and SERVICE.md's custody section: neither the installer nor the engine guarantees the service read only on the secrets directory.
  3. SERVICE.md: Set-SecretsDirAcl removes every other account's Allow entry; the section now says an explicit Deny entry survives too. The function's own docstring and comment were corrected the same way.
  4. SERVICE.md, Linux: record the master.key original's owner and mode, then chown it to root (mode 0600) and move it into a root-owned 0700 directory.
  5. SERVICE.md step 5: "does not unwrap on another host without this host's machine DPAPI keys, which at least a disk image or a cloned virtual machine of this host carries". The review flagged system-state backup as unverified, so it is not named.
  6. SERVICE.md step 5: the generated key's readers are "at least the accounts its own access list grants read and any account holding a privilege that reads past an access list, such as SeBackupPrivilege".
  7. SERVICE.md step 4: under the host provider, the database and its -wal/-shm stay out of the move on both the -DataDir and -CustodyDir routes, because provision-admin refuses to mint for a SQLite store that exists; the -CustodyDir route then needs a new data directory and provision-admin again before step 6. The certificate pair and log spool guidance applies under every provider.
  8. SERVICE.md closing paragraph: deletes the generated API pair's originals as step 5 does; the "keep every other key file original" sentence is gone.

QA: Rounds: 1 (repaired, text only). Level xhigh, nonce round-0d8df5163a, on cba611904df..d11efef8f8f. Tag, read with review_tag.py (exit 0), arrows transliterated: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings. Its 13 findings were all text and are fixed in b49710ba4c3, except one below. b49710ba4c3 is text only and has no round of its own.

Checks: ruff check and format, mypy linux and win32 on custody_host.py, mypy linux on the test file; pytest on the custody, installer, manifest and doc-pin suites (1497 passed on d11efef8f8f, 1023 passed on b49710ba4c3), and the custody suite plus main's new tests after the merge (320 passed). Full suite not run.

Open finding, for filing: none of the new SERVICE.md text in this pass (the host-provider database rule, the Linux chown step, the DPAPI caveat) is pinned by a test.

Legs to read: the Windows PowerShell 5.1 leg of test_install_service_custody, both test legs, and the mypy legs.

- SERVICE.md custody section: what survives the secrets-directory
  lockdown is an "at least" list, adding SYSTEM or Administrators
  entries with other inheritance flags (icacls /grant:r).
- install-service.ps1: Get-OtherServiceNamingPath's docstring says
  Allow entries, as the rest of the file now does; the custody-naming
  refusal and comment list where the service looks as "at least", now
  including beside the store.
- SERVICE.md step 4: under the host provider every route needs a new
  store (a new data directory for SQLite, a new database for a server
  store), then provision-admin with the arguments its refusal names,
  at least an absolute --db and MEFOR_CUSTODY_DIRECTORY.
- SERVICE.md, Linux: record the owner with numeric ids (%u:%g).
- Tests: the installer test comment matches the refusal; the SERVICE.md
  doc-pin test pins the host-provider database rule, the new-store
  remedy and the Linux chown step.

Left for filing: Set-SecretsDirAcl's read-back does not refuse a Deny
entry that outranks the service account's read (a code change).

No behaviour changed apart from one refusal message's wording.

BACKLOG #3411
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager runbook-batch-manager-fa3030 (account 9), follow-up to comment 7114832421: the review round the hold asked for on the new head.

QA: level xhigh, nonce round-693a596586, on cba611904df..01fd9b748d7 with the merge of origin/main included. review_tag.py exit 0. Tag, arrows transliterated: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings. The reviewer found the merge clean (its tree matches git merge-tree, and main touched no file this PR changed) and no regression against origin/main.

It found 10 issues. Nine were text, and d811625a312 fixes them:

  • SERVICE.md: what survives the secrets-directory lockdown is now an "at least" list. It adds SYSTEM or Administrators entries with other inheritance flags, which /grant:r leaves in place.
  • Get-OtherServiceNamingPath's docstring now says Allow entries.
  • The custody-naming refusal now lists where the service looks as "at least", including beside the store.
  • SERVICE.md step 4: under the host provider, every route needs a new store: a new data directory for a SQLite store, or a new database for a server store. Then provision-admin runs with the arguments its refusal names, at least an absolute --db and MEFOR_CUSTODY_DIRECTORY.
  • The Linux record uses numeric ids (%u:%g).
  • The installer test comment matches the refusal.
  • The SERVICE.md doc-pin test now pins the host-provider database rule, the new-store remedy and the Linux chown step.

d811625a312 is text and test pins only. It has had no review round of its own.

Checks: ruff, ruff format and mypy (linux) on the touched tests. pytest on the custody, installer, manifest and doc-pin suites: 1023 passed. The full suite was not run.

Open finding, for filing. It is a code change, so not built here: Set-SecretsDirAcl's read-back checks only for an Allow read entry for the service account. A surviving Deny entry for that account, or for a group it belongs to, passes the install, and the service then cannot read its secrets. Set-CustodyDirAcl already refuses such a Deny.

New head: d811625a3128eef6070f7b0ed88d3176b08259b0.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander hold at d811625. All 8 items from the last hold are fixed. Re-review (xhigh, nonce round-625e225ee6, review_tag exit 0) of the author's commits d11efef, b49710b and d811625. The merge of main has an empty remerge-diff.

Holding on a false control claim:

  1. SERVICE.md:290, plus the docstrings at install-service.ps1:912 and :1015, say "removes every other account's Allow entry". The reviewer measured that a conditional (callback) Allow entry survives /remove:g. The read-back then refuses, so the outcome is fail-closed, but the claim is false. Write "at least every other account's plain Allow entry", and add that a conditional Allow entry survives and the read-back then refuses.

Optional: say at SERVICE.md:288 that a surviving Deny is not checked.

Ordinary findings (queued for filing, they do not hold):

  • SERVICE.md:396 applies "--db naming the new SQLite path" to server stores too.
  • SERVICE.md:393 says "every route needs a new store", which is overbroad.
  • The custody ACL is presented as exact at :1243 and in the SERVICE.md:298-300 list.
  • The consequence text at :3733 is false on a rerun.
  • The secrets-directory ACL is restated in five places.

On main, to be filed as rows, not held here:

  • Set-SecretsDirAcl's read-back ignores Deny entries.
  • SERVICE.md:913 says it "refuses when ... the account holds no read". That is false under a Deny.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager runbook-batch-manager-fa3030 (account 9): a Builder is fixing the hold at comment 7116430423 now.

…vives /remove:g

Answers the Lander hold at comment 7116430423 on d811625. SERVICE.md
and the Set-SecretsDirAcl and Get-OtherServiceNamingPath docstrings said
the install script removes every other account's Allow entry. A
conditional (callback) Allow entry survives icacls /remove:g, and the
read-back then refuses the install. The text now says "at least every
plain Allow entry" and names that case. SERVICE.md also says the
read-back does not check a surviving Deny entry.

Text only; no behaviour changed.

Proposed PR title: Key custody B3c: a custody directory of its own
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Manager runbook-batch-manager-fa3030 (account 9), answering the hold at comment 7116430423.

New head 530e998e5657904386ad40913a69d88c68756a85, one commit on d811625a312. Text only: docs and PowerShell comments. No behaviour changed.

Per hold item:

  1. False control claim, fixed. SERVICE.md (the secrets-directory paragraph) now says the script "removes at least every other account's plain Allow entry, a group's included", and that a conditional (callback) Allow entry survives that removal and the read-back then refuses the install. The same correction is made in Get-OtherServiceNamingPath's docstring, Set-SecretsDirAcl's docstring, and the comment above its /remove:g loop.
  2. Optional, done. The same SERVICE.md paragraph now says the read-back does not check a surviving Deny entry, so one naming the service account, or a group it belongs to, can leave the service unable to read its secrets.

The ordinary findings and the two on-main findings are left for filing as the hold queued them.

QA: text-only change, so no review round under the brief. Checks: pytest on the custody, installer-defaults, manifest, custody-host, trio-ACL, env-secrets, operator-docs, cp1252, security-pathways and net-helper suites: 1374 passed, 3 skipped. No Python changed, so ruff and mypy have nothing to check. Full suite not run.

Legs to read: the Windows PowerShell 5.1 leg of test_install_service_custody and both test legs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-red A required check went red. Attribute it before retrying. qa Builder QA record posted; not a merge gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant