From de3db3ca3236fd73e3e3174ba699521bb40eb67f Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Tue, 27 Oct 2026 22:12:31 +0000 Subject: [PATCH] fix(devcontainer): provide reset remedy on wrong keyring password When an existing keyring rejects the password, devops devcontainer unlock-keyring printed only that the password was wrong and the keyring remained locked. The message provided no remedy. What changes: - devops devcontainer unlock-keyring now formats the error message with the path of the existing keyring file and instructions to move the file to a backup and run devops devcontainer unlock-keyring again. - ERRORS.devcontainer.keyring_wrong_password in src/devops_cli/lang/en/errors.py names the keyring path placeholder and the reset instructions. - tests/test_devcontainer.py tests that the command output holds the path and the reset instructions. Evidence: - Root cause analysis and evaluation posted to #2340. Keyrings persist across devcontainer rebuilds through the mounted home volume. Upstream gnome-keyring binary format and encryption remain identical between versions. Password recovery without the original password is not possible because the file uses AES-128 encryption. - uv run devops ci fail-to-pass --base origin/main passed: 1 failed on base (tests.test_devcontainer::test_unlock_keyring_reports_a_wrong_password) and 109 passed. - uv run pytest tests/test_devcontainer.py passed (110 passed). - uv run devops openspec check passed. Closes #2340 Change: openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/ --- .../.openspec.yaml | 2 ++ .../design.md | 10 ++++++ .../proposal.md | 36 +++++++++++++++++++ .../specs/devcontainer-keyring-unlock/spec.md | 16 +++++++++ .../tasks.md | 7 ++++ .../specs/devcontainer-keyring-unlock/spec.md | 16 +++++++++ src/devops_cli/commands/devcontainer.py | 2 +- src/devops_cli/lang/en/errors.py | 5 ++- tests/test_devcontainer.py | 6 +++- 9 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/.openspec.yaml create mode 100644 openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/design.md create mode 100644 openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/proposal.md create mode 100644 openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/specs/devcontainer-keyring-unlock/spec.md create mode 100644 openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/tasks.md create mode 100644 openspec/specs/devcontainer-keyring-unlock/spec.md diff --git a/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/.openspec.yaml b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/.openspec.yaml new file mode 100644 index 0000000000..97e3642024 --- /dev/null +++ b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-10-27 diff --git a/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/design.md b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/design.md new file mode 100644 index 0000000000..ae74028895 --- /dev/null +++ b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/design.md @@ -0,0 +1,10 @@ +# Design + +`_unlock_keyring` checks `_keyring_is_locked()` after running `gnome-keyring-daemon --replace --unlock`. When locked is True, it formats `ERRORS.devcontainer.keyring_wrong_password` with `path=_login_keyring_file()`. + +The message states that the keyring is still locked, names the path of the keyring file, and gives the shell command to move the file to a backup and run `devops devcontainer unlock-keyring`. + +## Rejected alternatives + +- **Automated file deletion or overwrite without backup:** Overwriting or deleting the existing keyring automatically destroys existing credentials without confirmation. If the user remembers the password later, the secrets would be lost. Rejected. +- **Add a `--reset` option to `unlock-keyring`:** Moving the file explicitly with `mv` is transparent, standard, and requires no additional CLI flags or options. Rejected. diff --git a/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/proposal.md b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/proposal.md new file mode 100644 index 0000000000..3302a1ff74 --- /dev/null +++ b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/proposal.md @@ -0,0 +1,36 @@ +# Proposal + +## Why + +Issue #2340: After a devcontainer rebuild from a new image, `devops devcontainer unlock-keyring` rejects the keyring password when the entered password differs from the password used to create the persisted keyring file. The current error message ("Wrong password; the keyring is still locked.") provides no remedy or way forward. + +## What Changes + +- When an existing keyring rejects the password, `devops devcontainer unlock-keyring` prints an error message that names the keyring file path and provides the exact procedure to back up the file and reset the keyring. +- The error message text in `src/devops_cli/lang/en/errors.py` is updated to include the file path and reset instructions. +- A test in `tests/test_devcontainer.py` verifies that the error output contains the path and reset command. + +## Capabilities + +### New Capabilities + +- `devcontainer-keyring-unlock`: requirements for reporting keyring unlock failure with actionable remediation steps. + +### Modified Capabilities + +None. + +## Impact + +- `src/devops_cli/commands/devcontainer.py`, `src/devops_cli/lang/en/errors.py`, `tests/test_devcontainer.py`. + +## Feasibility + +- Upstream `gnome-keyring` source code (`pkcs11/secret-store/gkm-secret-binary.c`, `egg/egg-symkey.c`) confirms that the binary keyring format (`GnomeKeyring\n\r\0\n`, AES-128-CBC, SHA-256 key derivation with salt and iterations, MD5 integrity check) has remained unchanged across versions (42 through 51.1). +- The rejection occurs because the user's home volume persists `~/.local/share/keyrings/login.keyring` across image rebuilds, and the password entered does not match the master password used to encrypt the file. +- Because AES-128 encryption protects the keyring, recovering data without the original password is not possible. +- Naming the path and the reset command (`mv .bak` and `devops devcontainer unlock-keyring`) gives the user a clear way forward. + +## Existing Tool Considered + +No outside tool applies. The change updates an error message string and formats it with the existing keyring file path in the `unlock-keyring` command. diff --git a/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/specs/devcontainer-keyring-unlock/spec.md b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/specs/devcontainer-keyring-unlock/spec.md new file mode 100644 index 0000000000..32b2e05bd6 --- /dev/null +++ b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/specs/devcontainer-keyring-unlock/spec.md @@ -0,0 +1,16 @@ +# Spec Delta + +## Purpose +How `devops devcontainer unlock-keyring` handles password verification and provides actionable remediation when an existing keyring rejects the password. + +## ADDED Requirements + +### Requirement: Keyring wrong password error provides clear remediation +When `devops devcontainer unlock-keyring` runs against an existing keyring file and `gnome-keyring-daemon` fails to unlock it, the command SHALL exit with status 1. The output SHALL print an error message that states the keyring is locked, names the keyring file path, and specifies the command to move the file to a backup and rerun `devops devcontainer unlock-keyring`. + +#### Scenario: Wrong password entered for existing keyring +- **WHEN** an existing keyring file exists at `~/.local/share/keyrings/login.keyring` +- **AND** the entered password does not unlock the keyring +- **THEN** the command exits 1 +- **AND** the error output names the keyring file path +- **AND** the error output contains the instruction to move the file to a backup and run `devops devcontainer unlock-keyring` diff --git a/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/tasks.md b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/tasks.md new file mode 100644 index 0000000000..5c0bc50ddc --- /dev/null +++ b/openspec/changes/archive/2026-10-27-2340-devcontainer-keyring-wrong-password/tasks.md @@ -0,0 +1,7 @@ +# Tasks + +- [x] 1.1 Write failing test in `tests/test_devcontainer.py` asserting that a wrong password on an existing keyring prints the file path and reset instructions. +- [x] 1.2 Update `ERRORS.devcontainer.keyring_wrong_password` in `src/devops_cli/lang/en/errors.py` with the path placeholder and remediation instructions in ASD-STE100. +- [x] 1.3 Update `_unlock_keyring` in `src/devops_cli/commands/devcontainer.py` to format `ERRORS.devcontainer.keyring_wrong_password` with `_login_keyring_file()`. +- [x] 1.4 Run `devops ci fail-to-pass --base origin/main` to verify the check passes. +- [x] 1.5 Run `devops openspec check` and full checks `devops ci`. diff --git a/openspec/specs/devcontainer-keyring-unlock/spec.md b/openspec/specs/devcontainer-keyring-unlock/spec.md new file mode 100644 index 0000000000..2dcec0eb8a --- /dev/null +++ b/openspec/specs/devcontainer-keyring-unlock/spec.md @@ -0,0 +1,16 @@ +# devcontainer-keyring-unlock Specification + +## Purpose +How `devops devcontainer unlock-keyring` handles password verification and provides actionable remediation when an existing keyring rejects the password. + +## Requirements + +### Requirement: Keyring wrong password error provides clear remediation +When `devops devcontainer unlock-keyring` runs against an existing keyring file and `gnome-keyring-daemon` fails to unlock it, the command SHALL exit with status 1. The output SHALL print an error message that states the keyring is locked, names the keyring file path, and specifies the command to move the file to a backup and rerun `devops devcontainer unlock-keyring`. + +#### Scenario: Wrong password entered for existing keyring +- **WHEN** an existing keyring file exists at `~/.local/share/keyrings/login.keyring` +- **AND** the entered password does not unlock the keyring +- **THEN** the command exits 1 +- **AND** the error output names the keyring file path +- **AND** the error output contains the instruction to move the file to a backup and run `devops devcontainer unlock-keyring` diff --git a/src/devops_cli/commands/devcontainer.py b/src/devops_cli/commands/devcontainer.py index 5c5d8c1d7c..6661f560b2 100755 --- a/src/devops_cli/commands/devcontainer.py +++ b/src/devops_cli/commands/devcontainer.py @@ -1469,7 +1469,7 @@ def _unlock_keyring(*, timeout: int | None) -> bool: print_error(ERRORS.devcontainer.keyring_not_created) return False if locked: - print_error(ERRORS.devcontainer.keyring_wrong_password) + print_error(ERRORS.devcontainer.keyring_wrong_password.format(path=_login_keyring_file())) return False pending.unlink(missing_ok=True) diff --git a/src/devops_cli/lang/en/errors.py b/src/devops_cli/lang/en/errors.py index feb2214f88..1d4a72ac9b 100644 --- a/src/devops_cli/lang/en/errors.py +++ b/src/devops_cli/lang/en/errors.py @@ -163,7 +163,10 @@ class DevcontainerErrorMessages: "Refusing an empty password: the keyring would store every secret in plain text." ) keyring_password_mismatch: str = "Passwords do not match; the keyring was not created." - keyring_wrong_password: str = "Wrong password; the keyring is still locked." + keyring_wrong_password: str = ( + "Wrong password; the keyring is still locked. To reset the keyring, " + "move {path} to a backup file and run 'devops devcontainer unlock-keyring'." + ) keyring_not_created: str = "The keyring could not be created or reached over D-Bus." diff --git a/tests/test_devcontainer.py b/tests/test_devcontainer.py index b6b2c759ef..62b7edbf7c 100644 --- a/tests/test_devcontainer.py +++ b/tests/test_devcontainer.py @@ -1902,7 +1902,11 @@ def test_unlock_keyring_reports_a_wrong_password( result = runner.invoke(app, ["unlock-keyring"]) assert result.exit_code == 1 - assert "Wrong password" in result.output + assert "Wrong password; the keyring is still locked." in result.output + assert ( + f"To reset the keyring, move {keyring_file} to a backup file and run 'devops devcontainer unlock-keyring'." + in result.output + ) def test_unlock_keyring_needs_gnome_keyring(