Repository navigation
Labels
effort/highEffort High: much work, in one pull requestpriority/p2-mediumPriority P2: standard workscope/configSettings, OS Keyring, environment variables, and defaultsscope/securitySecurity linters (trivy, bandit, gitleaks, kubeconform) and Vaulttype/refactorType refactor: a new structure, same behaviorvalue/mediumValue Medium
Description
Problem
- The keyring is imported inside seven functions. config/settings.py imports
keyringat :136, :733, :756, :777, :813, :832 and :845. Backend selection (_ensure_keyring_backend:134), reads, writes and presence checks each reach the library on their own, with an in-memory fallback for headless runs (_EPHEMERAL_CI_SECRETS:729). - Callers reach past it. commands/config.py imports
keyringand asks it for the active backend (:530, :535), imports the private_keyring_has(:22, :533), anddevops config auth-headlesswrites the private_EPHEMERAL_CI_SECRETSdirectly (:433, :443). k8s/credentials.py:17 and commands/k8s/stack_lifecycle.py:456 import the private_keyring_set. commands/devcontainer.py talks to D-Bus itself: it connects to the session-bus socket (_is_session_bus_running:1279, AF_UNIX at :1283) and asks Secret Service whether the default collection is locked (_keyring_is_locked:1392,secretstorageat :1396). SecretProvideris not this seam. The Protocol at security/secrets.py:116 is the secret resolver's read-only source interface; itsKeyringProvider(:129) sits on top of the settings functions above.- Tests patch the library or the privates. The census counts about 66 patch sites at this edge [measured: census of 2026-10-07].
mock_keyringpatcheskeyring.get_passwordandkeyring.set_password[code: tests/conftest.py:710]; tests/test_config_cmd.py names the private_ensure_keyring_backend13 times, and tests/test_headless_auth.py imports_EPHEMERAL_CI_SECRETS,_keyring_getand_keyring_set[measured: grep at 5c45b1e]. The one real fake,FakeKeyring[code: tests/cluster_secret_fakes.py:37], is an in-memoryKeyringBackendthat can be locked, but tests install it by patchingkeyring.get_keyring[code: tests/test_k8s_push_secrets.py:83].
Acceptance criteria
Seam
- One module owns the keyring: choosing a usable encrypted backend (today
_ensure_keyring_backend) and naming it; reading, writing and checking entries; the headless in-memory fallback; and the Secret Service state the devcontainer reads (whether the session bus answers, whether the default collection is locked). A Protocol names these operations. The real implementation is thekeyringlibrary's selected backend, withsecretstoragefor the lock state. - The settings functions (
keyring_read,keyring_write,get_keyring_secret,set_keyring_secret,require_persistent_keyring) and their private helpers delegate to the seam, and no module inconfig/other than the seam importskeyring. - The two D-Bus checks move into the seam from commands/devcontainer.py:1279 and :1392, and devcontainer.py calls the seam;
secretstorageand the session-bus socket are reached only there. - The headless in-memory store moves into the seam with a public write, which
devops config auth-headlesscan call, and a public reset, which the fixture below calls at teardown. - The remaining direct users (commands/config.py:22, :433, :443, :530, :533; k8s/credentials.py:17; commands/k8s/stack_lifecycle.py:456) are left to their package items.
Fake and fixture
-
tests/support/fakes/keyring.pypromotesFakeKeyring: entries in memory; a locked state that raisesKeyringLockedas the Secret Service backend does; a no-backend state; the session-bus and lock answers; and a record of reads and writes. Its two importers import it from the new module. - A fixture installs it through the seam and returns it, registered once from the root conftest. It replaces
mock_keyring, whose 2 users (tests/test_ai_benchmark.py:231, test_embedding_benchmark.py:363) request the new fixture instead. - If test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 has landed, its deny backend is installed through the seam's hook instead of
keyring.set_keyring, and each test that installsFakeKeyringwithkeyring.set_keyringrequests the fixture instead, unless its code still importskeyringitself; those go with the package item that routes that code.
Contract suite
- One suite in
tests/config/runs each operation against the fake and against the real seam over gnome-keyring-daemon on a private session bus, started withdbus-run-sessionundertmp_path, never the developer's bus. Cases: write then read, a missing entry, a locked collection, no usable backend, the active backend's name and the session-bus check. It is a live test, skipped only wheregnome-keyring-daemonordbus-run-sessionis missing; both are installed in the devcontainer [measured: which].
Migration
- tests/test_headless_auth.py drives the seam's public operations and imports no private name. The backend-selection tests in tests/test_config_cmd.py (from :176) and the 6 lines of tests/test_devcontainer.py that patch
_keyring_is_locked(from :1488) use the fake or the contract suite, and patch nokeyringname and no devops_cli name (paths before test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313's move). - Apart from the live contract test, tests touch no D-Bus and run offline; each test runs under 1 s.
- If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its ceilings drop by the sites this PR removes (the private imports in tests/test_headless_auth.py and the
_ensure_keyring_backendand_keyring_is_lockedsites in tests/test_config_cmd.py and tests/test_devcontainer.py among them). -
uv run devops cipasses.
Key questions
- Is
SecretProviderthe seam? (proposed) No. It is the resolver's read-only view over several sources (keyring, environment, settings, Vault), while devops-cli also writes keyring entries, picks the backend and reads the lock state. The keyring seam sits beneathKeyringProvider, whose tests move with test(security): scanner, secret and crypto tests run on the executor, process, http and keyring fakes, and scanners stop looking for mocks #1332. - Why a live test for the real side? (proposed) gnome-keyring-daemon on a private bus under
tmp_pathis a real local tool that touches no real secret, and the floor already keeps tests off the developer's bus [code: tests/conftest.py:325]. The daemon starts once per worker, so each test stays under 1 s. - May a test call
keyring.set_keyring()? (proposed) No: only the seam selects the backend. A test installs the fake through the fixture, never by patchingkeyring.get_keyring. - Fixture name? (proposed)
keyring_store.
Strategic alignment
- Depends on: test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312. Blocks: test(github): github/ is tested through its public interface over the gh process and session fakes, with no internal patches or private imports #1321, test(k8s): k8s/ is tested through its public interface over the Kubernetes API, process, HTTP and keyring fakes, with no internal patches or private imports #1322, test(k8s): devops k8s commands are thin adapters tested over edge fakes, and the _K8sModule patch forwarding is gone #1323, test(ci): devops ci, test, devcontainer, workspace, install-tools, uv, branches and pipeline are tested over edge fakes, with no lazy patch targets or PYTEST_CURRENT_TEST checks #1325, test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326, test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327, test(ai): Wire rag once in ai/rag, test with edge fakes #1329, test(mcp): mcp, agent and tool tests run on edge fakes #1330, test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331, test(security): scanner, secret and crypto tests run on the executor, process, http and keyring fakes, and scanners stop looking for mocks #1332, test(cli): Use edge fakes and real git; drop test rebind hooks #1333, test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334, test(infra): infrastructure tests run on edge fakes #1335. Related: test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 (the floor's D-Bus isolation, deny backend and state resets).
- Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase D).
Update 2026-10-08: refinement
#709 added keyring_delete (config/settings.py:856-869, used by commands/vault.py:538); the seam owns delete, and the contract suite adds 'write, delete, read finds nothing' and 'deleting a missing entry returns False'. commands/ai.py:416 also imports _keyring_has.
Proposed design
Problem statement
The keyring library is imported in seven functions across multiple modules. Callers reach past the settings module to private names. Tests patch the library or private names directly. This makes the keyring hard to test and maintain. One module must own all keyring operations. A shared fake and a contract suite replace the current patch-based tests.
Acceptance criteria
- Criterion 1: One seam module owns backend selection, read, write, delete, presence check, headless fallback, and Secret Service lock state.
Verification: No module in config/ other than the seam imports keyring. A Protocol in the seam names every operation. - Criterion 2: Settings functions delegate to the seam.
Verification: keyring_read, keyring_write, get_keyring_secret, set_keyring_secret, require_persistent_keyring, and keyring_delete call the seam. grep for 'import keyring' in config/ returns only the seam module. - Criterion 3: D-Bus checks move into the seam from commands/devcontainer.py.
Verification: devcontainer.py calls the seam for session-bus and lock state. secretstorage and the session-bus socket appear only in the seam module. - Criterion 4: The headless in-memory store moves into the seam with a public write and a public reset.
Verification: devops config auth-headless calls the seam public write. The fixture calls the seam public reset at teardown. - Criterion 5: Remaining direct users import from the seam, not from keyring or private names.
Verification: commands/config.py, k8s/credentials.py, commands/k8s/stack_lifecycle.py, and commands/ai.py import from the seam. grep for '_keyring_set', '_keyring_get', '_keyring_has', '_EPHEMERAL_CI_SECRETS' in these files returns no results. - Criterion 6: tests/support/fakes/keyring.py holds the promoted FakeKeyring.
Verification: The fake has in-memory entries, a locked state that raises KeyringLocked, a no-backend state, session-bus and lock answers, and a read/write record. Its two importers import from the new module. - Criterion 7: A fixture named keyring_store installs the fake through the seam.
Verification: The fixture is registered once from the root conftest. tests/test_ai_benchmark.py and tests/test_embedding_benchmark.py request keyring_store instead of mock_keyring. - Criterion 8: A contract suite in tests/config/ runs each operation against the fake.
Verification: Cases include write-then-read, missing entry, locked collection, no usable backend, active backend name, session-bus check, write-delete-read-finds-nothing, and deleting a missing entry returns False. - Criterion 9: The real side of the contract suite is opt-in or removed.
Verification: The default test run starts no system program. The real side is either an opt-in suite for the devcontainer or absent. The choice is recorded in the change. - Criterion 10: tests/test_headless_auth.py drives the seam public operations.
Verification: The file imports no private name. grep for '_EPHEMERAL_CI_SECRETS', '_keyring_get', '_keyring_set' in the file returns no results. - Criterion 11: Backend-selection tests in tests/test_config_cmd.py use the fake or the contract suite.
Verification: The tests patch no keyring name and no devops_cli private name. The 6 lines in tests/test_devcontainer.py that patch _keyring_is_locked use the fake. - Criterion 12: All tests run offline and each test runs under 1 second.
Verification: uv run pytest tests/ --timeout=1 passes. No test starts a system program. - Criterion 13: uv run devops ci passes.
Verification: The CI pipeline completes with all checks green.
Key questions
- Is SecretProvider the seam?: No. It is the resolver read-only view over several sources. The keyring seam sits beneath KeyringProvider. (proposed)
- Why a live test for the real side?: The owner rule of 2026-10-24 states that tests start no system program and run the same in the devcontainer and on a stock GitHub runner. The real side is either an opt-in suite for the devcontainer or it goes. Record the choice when this item is built. (proposed)
- May a test call keyring.set_keyring()?: No. Only the seam selects the backend. A test installs the fake through the fixture. (proposed)
- Fixture name?: keyring_store. (proposed)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
effort/highEffort High: much work, in one pull requestpriority/p2-mediumPriority P2: standard workscope/configSettings, OS Keyring, environment variables, and defaultsscope/securitySecurity linters (trivy, bandit, gitleaks, kubeconform) and Vaulttype/refactorType refactor: a new structure, same behaviorvalue/mediumValue Medium
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
3 remaining items
dan-petty-bot commentedon Oct 8, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
It improves testability and maintainability of a security-adjacent module but does not fix a defect or unblock a release, so it is important but not urgent.It reduces 66 test patch sites and eliminates private-helper coupling across five modules, making the keyring boundary easier to test and evolve, but it adds no new capability for end users.It requires creating a new seam module, moving D-Bus and in-memory-store code, updating at least seven import sites, promoting FakeKeyring, adding a root-conftest fixture, and migrating roughly 66 test patch sites.dan-petty commentedon Oct 24, 2026
The owner's rule of 2026-10-24 replaces one criterion of this item: "tests are tests of my src python code" and start no system program, and every test runs the same in the devcontainer and on a stock GitHub runner with no package install. #2143 changes ADR 0007 and docs/TESTING.md to say so.
So the real side of the keyring contract suite (gnome-keyring-daemon on a private session bus under
dbus-run-session) cannot be part of the default test run. The fake side of the suite and the seam stay as written. The real side is either an opt-in suite for the devcontainer, outside the default run and outside CI, or it goes; record the choice when this item is built. The rest of this item is unchanged.dan-petty commentedon Oct 26, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
This change improves code structure and testability but is not critical to core functionality.Improves developer experience and reduces complexity in secret management.Requires refactoring multiple modules, changing how keyring is used throughout the codebase, and updating tests.Both items work on keyring functionality, but the candidate refactors the keyring seam while item #454 fixes a keyring backend availability issue.dan-petty commentedon Oct 28, 2026
Status set to Ready at 69636b6 (see proposed design in issue body).
refactor(security): one keyring seam owns the keyring and the Secret …
chore(main): release 0.11.3 (#2539)