Skip to content

feat(security): in-container keyring scoped to the home-volume identity #452

Closed

Description

@dan-petty

Context & Rationale

The Debian sid devcontainer runs no freedesktop Secret Service (no D-Bus session bus, no keyring daemon). As a result:

  • gh auth login falls back to writing the OAuth token in plain text to ~/.config/gh/hosts.yml ("Authentication credentials saved in plain text").
  • Python keyring resolves to keyring.backends.fail.Keyring, so devops cannot persist secrets. _ensure_keyring_backend in src/devops_cli/config/settings.py correctly rejects plaintext backends, leaving no usable store.
  • Git HTTPS credentials go through the VS Code Dev Containers credential helper, which forwards to the host credential store.

Forwarding to the host is not an option, because several devcontainers run at once under different identities (personal vs work). Identity follows the /home/vscode named volume (home_volume in src/devops_cli/templates/devcontainer.json.j2):

  • One home volume = one identity. Every container that mounts the same home volume uses that identity and shares one live set of credentials and auth sessions. A login, token refresh or logout in one container is immediately effective in the others.
  • A different home volume = a separate identity. A project with its own home volume shares no credentials or sessions with any other volume.

This also closes a gap against the AGENTS.md rule: "Never store plaintext secrets… Always use OS Keyring or secure secret stores."

Scope & Deliverables

  • Keyring selection*: Evaluate in-container Secret Service implementations hands-on in throwaway debian:sid containers: gnome-keyring-daemon, pass + pass-secret-service, oo7-daemon, and KeePassXC/KWallet run headless. Compare them with baselines that need no daemon: --insecure-storage, an encrypted GH_TOKEN, git-credential-cache or -oauth, git-credential-manager with its gpg store, and the kernel keyring. Test each against the gh (go-keyring), git HTTPS and Python keyring==25.7.0 clients.
  • Identity = home volume*: Store all keyring data on the home volume, so it is the single source of truth for that identity. Only runtime state (bus and agent sockets) stays container-local under /run/user/1000, not on the shared /tmp volume. Verify all of the following:
    • A secret written, rotated or deleted in one container is visible in every other running container on the same volume, without restarting or re-unlocking.
    • Concurrent writes from two containers do not clobber each other.
    • Nothing is visible across different home volumes.
    • Data survives a restart and a rebuild.
  • Unlock model*: Define the unlock step for a container with no desktop session: a password at start, pinentry-tty, or auto-unlock. Document exactly what is encrypted at rest and how it compares with a 0600 file on a per-identity volume.
  • Lifecycle integration*: Install the chosen daemon in .devcontainer/Dockerfile. Expose a static DBUS_SESSION_BUS_ADDRESS through containerEnv/remoteEnv so VS Code terminals, extensions, Claude Code and MCP servers can find the bus. Start the daemon idempotently from devops devcontainer post-start (_run_post_start_lifecycle), reusing the existing background-daemon pattern, and mirror the changes in devcontainer.json.j2.
  • Client configuration & migration*: Point gh, git (gh auth git-credential or a libsecret helper) and devops at the in-container keyring. Document how to turn off VS Code host credential forwarding (dev.containers.gitCredentialHelperConfigLocation). Move the existing plaintext hosts.yml token into the keyring and delete the plaintext copy.
  • Automated verification*: Add a post-start health check that reports the active keyring backend and warns when gh or devops would fall back to plaintext or the fail backend.

Strategic Alignment

  • Milestone: v0.2.23 (Foundational Architectural Guardrails & Project Hygiene)
  • Roadmap Reference: docs/ROADMAP.md

Activity

  1. added this to the v0.2.23 milestone on Sep 23, 2026
  2. added
    type/security
    scope/security
    priority/p1-high
    scope/infra
    on Sep 23, 2026
  3. changed the title [-]feat(security): in-container secret service keyring for per-identity devcontainers[/-] [+]feat(security): in-container keyring scoped to the home-volume identity[/+] on Sep 23, 2026
  4. dan-petty commented on Sep 23, 2026

    @dan-petty
    OwnerAuthor

    Related symptom found while storing an API key (closed #454 as a duplicate of this issue): with no usable backend, _keyring_set falls back to the process-local _EPHEMERAL_CI_SECRETS dict, yet devops config set <secret-key> <value> still prints Secret '<key>' stored in keyring. and exits 0. The secret is lost when the process exits and devops config show then reports not set. Outside headless mode (DEVOPS_CLI_HEADLESS_AUTH), storing a secret without a usable backend should fail with a non-zero exit and guidance, so the loss is visible.

  5. dan-petty commented on Sep 23, 2026

    @dan-petty
    OwnerAuthor

    Decision: oo7-daemon in one sidecar per identity

    Status: the design is chosen and tested. An adversarial from-scratch reproduction is still running; the verified design and integration plan will follow in another comment.

    Why one daemon per identity

    Every reputable Secret Service we tested assumes it is the only writer to its store: gnome-keyring 51.1, oo7-daemon, KeePassXC 2.7.10 and KWallet. With one daemon per container on a shared home volume, every one of them lost writes or served stale data:

    • gnome-keyring: 6 of 12 and 21 of 40 concurrent writes survived.
    • oo7: it never reloads, and writes fail with "target file has changed".
    • KeePassXC: simultaneous writes were silently lost.

    So each home volume (identity) gets exactly one keyring daemon, and every container of that identity connects to it.

    Architecture

    • Sidecar: each identity gets a <home_volume>-keyring container running dbus-daemon 1.16.2 and oo7-daemon 0.7.0-beta as uid 1000. It is started idempotently from initializeCommand with docker compose up -d --no-recreate.
    • Keyring volume: the bus socket and keyring data live on a per-identity <home_volume>-keyring volume, not the home volume. A sidecar that creates the home volume first would skip Docker's copy-up of /home/vscode.
    • Devcontainers: they mount the keyring volume read-only, set a static DBUS_SESSION_BUS_ADDRESS=unix:path=/run/secret-service/bus in containerEnv, and run no daemon of their own.
    • Clients:
      • gh uses the keyring natively.
      • git uses gh auth git-credential. Host forwarding is turned off with dev.containers.gitCredentialHelperConfigLocation=none.
      • devops uses Python keyring through the SecretService backend, which _ensure_keyring_backend accepts.

    Why oo7-daemon

    • Upstream and adoption: GNOME's Rust successor to gnome-keyring (github.com/linux-credentials/oo7, MIT). GNOME 51 and GNOME OS use it by default, and Fedora 45 accepted it as the default provider.
    • Size: the sidecar image is 174 MB on debian:sid-slim, and the binaries link only libc, libm and libgcc_s. The gnome-keyring sidecar was 939 MB, because its package pulls in GTK3/4, mesa and llvm; KWallet adds 444 MB and KeePassXC 413 MB.
    • Encryption at rest: PBKDF2-SHA256 with 100k iterations and AES-128-CBC with HMAC-SHA256. gnome-keyring uses 1,583 iterations of SHA-256.
    • Stability: gnome-keyring 51.1 aborted with SIGABRT in 2 of about 5 concurrent read/write runs on a fresh keyring.

    Test evidence

    All tests ran on Docker-in-Docker with a personal and a work identity, several clients per identity, and fake tokens only:

    • Live sharing: gh login, rotate and logout, git credentials and Python set/get/delete all propagate between containers immediately, with no restart or re-unlock.
    • Concurrency: 60/60 and 300/300 concurrent writes survived. 20+20 writes to one key left a single item. A write takes about 19 ms.
    • Durability and unlocking: a write acknowledged just before SIGKILL survived. The user unlocks once per sidecar lifetime, and client restarts and recreates need no unlock.
    • Isolation: the work identity sees nothing of the personal one, and nothing lands on the shared /tmp volume.
    • Failure behaviour: locked or down states fail fast, and there is no bus activation that could respawn a locked daemon.
    • Launch: the real @devcontainers/cli 0.89.0 ran initializeCommand and started the sidecar. A second project of the same identity came up already unlocked.

    Known upstream issues and their mitigations

    Issue Mitigation
    Stable 0.6.0 exports /collection/Login and breaks gh Pin 0.7.0-beta (cargo install --locked, built with sid's rustc 1.95) and publish the image pinned by digest
    An empty password creates an unencrypted keyring The unlock tool refuses empty and short passwords; the health check scans the file for plaintext
    A keyring with zero items accepts any password Ask for the password twice on first unlock and store a canary item immediately
    oo7-cli unlock hangs forever on a wrong password Use devops keyring unlock (getpass, then UnlockWithMasterPassword over D-Bus); oo7-cli is optional
    CreateItem(replace=true) is not atomic, so readers racing a rotation get ItemNotFound Retry once in the devops read path; no write was ever lost
    Aborts when locked memory reaches RLIMIT_MEMLOCK MALLOC_ARENA_MAX=1, TOKIO_WORKER_THREADS=2
    Logs every item label at INFO RUST_LOG=warn and capped json-file logs

    Client-side caveat (applies to any daemon)

    gh 2.101 cannot be made fail-closed (cli/cli#10108). When the keyring is locked or down, gh auth login returns 0 and writes oauth_token to hosts.yml in plaintext. Mitigation: detection in post-start, devops keyring doctor and a shell prompt warning. An AGENTS.md rule tells agents never to fall back to --insecure-storage or GH_TOKEN.

    To migrate the existing plaintext token without minting a new one, run gh auth token -h github.com | gh auth login -h github.com --with-token. Avoid gh auth refresh and logout-then-login, because each mints a new token and GitHub keeps only 10 per user, app and scope. Do not use "Revoke access" on the GitHub CLI app: it kills every gh session for the account.

    Rejected

    • pass + pass_secret_service: the upstream is unmaintained and needed a patch shim.
    • Leader election among devcontainers: every leader change re-locks the keyring for all windows.
    • gnome-keyring: 517 MB of GUI dependencies (45 MB with equivs stubs), a weak KDF, and crashes under concurrency.
    • KWallet ksecretd: no D-Bus password unlock, a hidden dialog hangs clients when locked, and writes are only synced after 5 s.
    • KeePassXC: headless mode is unsupported and dialogs block D-Bus callers forever.
    • Linux kernel keyring (keyctl): every uid-1000 container on the kernel shares one user keyring across personal and work identities, and it is lost on reboot.
    • keyrings.cryptfile: no release since 2022, no headless unlock, and it makes keyring's ChainerBackend win, which bypasses the devops plaintext guard.
  6. dan-petty commented on Sep 24, 2026

    @dan-petty
    OwnerAuthor

    Final direction: Debian's gnome-keyring, one daemon per container

    This replaces the oo7-daemon sidecar design in the comment above. That design worked in testing, but it needed a host-side launch script in initializeCommand and engine-specific flags (rootless Podman needs --userns=keep-id). That is more machinery than this problem warrants. The simpler setup is implemented on branch feat/devcontainer-gnome-keyring (a62a0c5a):

    • Image: .devcontainer/Dockerfile installs Debian's gnome-keyring and dbus-x11, and creates /run/user/1000.
    • Bus address: containerEnv sets DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus, in both the repo devcontainer.json and devcontainer.json.j2.
    • Startup: devops devcontainer post-start starts the session bus if it is not already running, with XDG_RUNTIME_DIR=/run/user/1000. gnome-keyring is D-Bus-activated on first use. The bus and the keyring control socket stay container-local, because /tmp is a volume shared between containers.
    • Tests: an autouse fixture unsets the bus address, so unmocked keyring calls in tests never reach real secrets.

    Verified in a throwaway debian:sid container: post-start started the bus and left a running one alone, Python keyring chose SecretService and completed a set/get round trip, and the secret is encrypted in login.keyring. Full suite: 4,836 passed, plus one order-dependent k8s test that passes on its own.

    Usage

    The first time, and after every container restart, create or unlock the keyring from a terminal. Type the password, then press Ctrl-D without pressing Enter first, or the newline becomes part of the password:

    XDG_RUNTIME_DIR=/run/user/1000 gnome-keyring-daemon --replace --unlock --components=secrets

    Then move an existing plaintext gh token into the keyring without minting a new one:

    gh auth token -h github.com | gh auth login -h github.com --with-token

    Known limitations, accepted

    • Image size: gnome-keyring's GUI dependencies add about 500 MB.
    • Shared home volume: every container of an identity runs its own daemon on the same keyring file. gnome-keyring reloads the file when it changes, so occasional writes propagate, but two writes in the same second from different containers can lose one.
    • gh plaintext fallback: gh still writes a plaintext token when the keyring is locked (gh auth login should error if the system keyring is unavailable rather than falling back to insecure storage cli/cli#10108).
    • Git host forwarding: for github.com, git still uses VS Code's host credential forwarding unless the host setting dev.containers.gitCredentialHelperConfigLocation is none, or git is pointed at gh auth git-credential.

    Possible follow-ups (not done)

    • A post-start check that flags oauth_token lines in ~/.config/gh/hosts.yml.
    • Routing github.com git credentials through gh auth git-credential.
    • Tightening _ensure_keyring_backend so it distinguishes a locked keyring from a working one, and cannot be bypassed through ChainerBackend.
  7. dan-petty commented on Sep 24, 2026

    @dan-petty
    OwnerAuthor

    Closed by #485, merged into release/v0.2.23.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/infrascope/securitytype/security

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions