Skip to content

fix(config): exit 1 when audit-keys finds a plaintext secret - #2401

Merged
dan-petty merged 2 commits into
mainfrom
fix/1469-audit-keys-leak-exit-code
Oct 28, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/1469-audit-keys-leak-exit-code

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

devops config audit-keys exited 1 for a config file that it could not read or parse (#1022), but exited 0 for a confirmed plaintext secret. Thus a CI step or a pre-commit hook failed on a broken file and passed on a leak. The owner decided that a confirmed leak fails the audit.

Changes:

  • audit_keys_cmd in src/devops_cli/commands/config.py now exits 1 when the audit is not compliant: when a config file holds a plaintext secret, or when it cannot read or parse a config file. Each output branch has one exit on the overall compliance, so the exit code agrees with is_compliant in the report.
  • The table output and each serialized output (--json, --format json|yaml|markdown) print the full report before the exit. The success line prints only on exit 0.
  • The MCP tool config_audit_keys runs the command, so it now reports a leak as a tool error that holds the full masked report. It already did this for a file that the audit cannot parse.
  • The command help states the exit codes. devops docs generate --sync-readme wrote the same text into README.md, docs/CLI_REFERENCE.md, docs/commands/config.md and docs/MCP_TOOLS.md.
  • tests/test_config_audit_keys.py replaces the test that expected exit 0 for a leak with two tests that expect exit 1, one for the table output and one for the --json report.
  • The OpenSpec change openspec/changes/1469-audit-keys-leak-exit-code/ records the plan, the premise check and the rejected alternatives. It adds a requirement for the exit codes to the config-commands capability.

Closes #1469

Plan #1469 as the OpenSpec change 1469-audit-keys-leak-exit-code.
Replace the test that expected exit 0 for a plaintext secret. The new
tests expect exit 1 for the table output and for the --json report.
devops config audit-keys exited 1 for a config file that it could not
parse, but exited 0 for a confirmed plaintext secret. A CI step or a
pre-commit hook thus failed on a broken file and passed on a leak.

Each output branch now exits 1 when the audit is not compliant, after
it prints the full report. The success line prints only on exit 0. The
command help and the generated documents state the exit codes.
@dan-petty dan-petty added scope/config Settings, OS Keyring, environment variables, and defaults scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak labels Oct 28, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Local results on e878c239 (devops-cli 0.8.2):

uv run devops ci fail-to-pass --base origin/main:

ℹ Quality gate root: <worktree>
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_json_output
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_table_rendering
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_an_unparsable_file_unaudited
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_dry_run
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_canonical_secret_leak_detected
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_json_lists_unaudited_files_apart_from_leaks
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_an_unconstructable_value_unaudited
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_fails_on_a_plaintext_secret_in_the_table (assert 0 == 1)
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_never_logs_an_unparsable_line
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_an_undecodable_file_unaudited
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_fails_on_a_plaintext_secret_in_the_json_report (assert 0 == 1)
2 failed on base (2 failed and 9 passed in tests/test_config_audit_keys.py; 0 errored).
Elapsed: 7.33s

uv run devops ci test tests/test_config_audit_keys.py tests/test_zero_plaintext_invariants.py tests/test_cli_format_adoption.py tests/test_fastmcp_contracts.py:

90 passed in 6.77s

Other checks:

  • ruff check and ruff format --check on the changed Python files: pass.
  • uv run devops docs check: all documentation files are up to date.
  • openspec validate 1469-audit-keys-leak-exit-code --strict: valid.
  • The pre-push hook (fast static checks): pass.

The real command, with DEVOPS_CLI_CONFIG set to a scratch file:

Config file audit-keys audit-keys --json
grafana.token with a value exit 1 exit 1
No secret value exit 0, success line exit 0
Not valid YAML not run exit 1

Before the fix, the leak case exited 0 in both outputs.

@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 14:02
@dan-petty
dan-petty merged commit ad0114f into main Oct 28, 2026
17 of 18 checks passed
@dan-petty
dan-petty deleted the fix/1469-audit-keys-leak-exit-code branch October 28, 2026 14:02
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.8.3](v0.8.2...v0.8.3)
(2026-10-28)


### Bug Fixes

* **ai:** the gateway sweep's URL error names no credential
([#2400](#2400))
([2e6f1fd](2e6f1fd)),
closes [#909](#909)
* **config:** exit 1 when audit-keys finds a plaintext secret
([#2401](#2401))
([ad0114f](ad0114f)),
closes [#1469](#1469)
* **security:** drop the Go ignores that the pinned gh build does not
need ([#2402](#2402))
([6052083](6052083)),
closes [#1492](#1492)
* **security:** refuse every loader and shell key that loads code into a
child ([#2405](#2405))
([86d5bce](86d5bce)),
closes [#2205](#2205)

---
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

scope/config Settings, OS Keyring, environment variables, and defaults scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault type/security Type security: a vulnerability or a leak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(config): devops config audit-keys exits 1 when it finds a plaintext secret

1 participant