Skip to content

refactor(security): one keyring seam owns the keyring and the Secret Service, with a shared fake and its contract suite - #2532

Merged
dan-petty merged 2 commits into
mainfrom
refactor/1318-keyring-seam
Oct 28, 2026
Merged

dan-petty merged 2 commits into
mainfrom
refactor/1318-keyring-seam

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

src/devops_cli/config/os_keyring.py is the one module that reaches the OS keyring and the Secret Service. Before, config/settings.py imported keyring in seven functions, callers imported its private names, and commands/devcontainer.py connected to the session bus and asked secretstorage for the lock state itself.

  • A KeyringEdge Protocol names the three questions the seam asks: the backend that the keyring library selected, whether a D-Bus daemon answers on the session-bus socket, and whether the default Secret Service collection is locked. SystemKeyring is the real edge, and set_keyring_edge / reset_keyring_edge install and restore it.
  • The keyring operations, the in-memory store for headless runs and SecretStorageError, KeyringLockedError and KeyringUnavailableError move into the seam. The private names become public operations (has_encrypted_backend, has_keyring_secret, store_keyring_secret, remember_secret, clear_remembered_secrets, backend_info), and each caller imports them from the seam. config/settings.py keeps no keyring code and no forwarding functions.
  • get_keyring_secret and has_keyring_secret catch only the errors of a keyring that cannot answer: KeyringError, and on Linux secretstorage's SecretStorageException, which keyring's Secret Service backend passes through when the session bus fails. Any other exception now propagates instead of reading as a missing secret. config/settings.py therefore loses three swallowed failures, and its ceiling falls from 5 to 2.
  • FakeKeyring moves to tests/support/fakes/keyring.py. It is both a keyring backend and a KeyringEdge, with a locked state, a replaceable selected backend, the session-bus and lock answers, and a record of reads, writes and bus checks. The keyring_store fixture installs it through the seam and replaces mock_keyring.
  • The floor installs a deny edge through the seam before each test, so a reach of the keyring or of D-Bus without a fake fails also when the code catches it. It keeps the library-level deny backend for third-party code, such as fastmcp's key-value store, that calls keyring itself.
  • tests/config/test_keyring_contract.py is the contract suite. The session-bus and lock checks run over the fake and over SystemKeyring with no program started. The entry cases run over the fake, whose answers follow keyring 25.7.0's Secret Service backend. Under the owner's rule of 2026-10-24, the real side over gnome-keyring-daemon is not built.

The tests that patch a devops-cli keyring name at its import site move onto keyring_store with their package items (#1321, #1327, #1332).

Closes #1318

Change: openspec/changes/archive/2026-10-28-1318-keyring-seam/

@dan-petty

Copy link
Copy Markdown
Owner Author

Test evidence:

  • Full uv run devops ci on the branch before the last rebase: all 19 gates passed in 5 m 3 s (test 4 m 49 s, typecheck, security, docs, openspec and the others).
  • Full uv run pytest tests after the rebase onto 0379f21e: 12124 passed, 2 skipped, in 5 m 30 s.
  • uv run devops ci fail-to-pass --base origin/main: 0 failed and 1926 errored on the base. Each changed test file errors on the base, because devops_cli.config.os_keyring and the keyring_store fixture do not exist there.
  • tests/config/test_keyring_contract.py: 12 passed, each test under 0.4 s.
  • The swallowed-failures ratchet counts 0 sites in config/os_keyring.py; uv run python -m tests.test_swallowed_failures_ratchet --lower lowered config/settings.py from 5 to 2.
  • The type: ignore counts did not rise: the seam's edge returns a backend, and the fake's selected is Any.

Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).

@dan-petty
dan-petty force-pushed the refactor/1318-keyring-seam branch from 78e9fd4 to c04675b Compare October 28, 2026 20:55
@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 21:03
…Service

`src/devops_cli/config/os_keyring.py` is the one module that reaches the OS
keyring and the Secret Service. A `KeyringEdge` Protocol names the
selected backend, the session-bus check and the lock check;
`SystemKeyring` is the real edge, and `set_keyring_edge` installs
another. The keyring operations, the in-memory store and the three
keyring errors move into the seam from `config/settings.py`, and the
D-Bus checks move into it from `commands/devcontainer.py`. Each caller
imports the public operations of the seam.

`FakeKeyring` moves to `tests/support/fakes/keyring.py` behind the
`keyring_store` fixture, which replaces `mock_keyring`. The floor
installs a deny edge through the seam before each test, and
`tests/config/test_keyring_contract.py` is the fake's contract suite.

The lenient reads now catch only the errors of a keyring that cannot
answer, so `config/settings.py` loses three swallowed failures.
@dan-petty
dan-petty force-pushed the refactor/1318-keyring-seam branch from c04675b to 7286976 Compare October 28, 2026 21:05
@dan-petty
dan-petty merged commit 866d2cb into main Oct 28, 2026
17 checks passed
@dan-petty
dan-petty deleted the refactor/1318-keyring-seam branch October 28, 2026 21:15
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.11.3](v0.11.2...v0.11.3)
(2026-10-28)


### Bug Fixes

* **roadmap:** refine wraps no link in the model's code, and wraps each
reference and link that GitHub makes from its text
([#2540](#2540))
([2d38f8d](2d38f8d)),
closes [#2525](#2525)


### Code Refactoring

* **docker:** DockerEngineService is the Docker engine seam, with an
in-memory engine fake and its contract suite
([#2534](#2534))
([1244cbf](1244cbf)),
closes [#1316](#1316)
* **security:** one keyring seam owns the keyring and the Secret
Service, with a shared fake and its contract suite
([#2532](#2532))
([866d2cb](866d2cb)),
closes [#1318](#1318)
* **telemetry:** OTLP export goes through one exporter seam, and tests
read exported spans and metrics from a shared fake
([#2541](#2541))
([8da35e6](8da35e6)),
closes [#1319](#1319)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite

1 participant