Skip to content

fix(config): devops config audit-keys scans each config file that the settings merge - #2516

Merged
dan-petty merged 14 commits into
mainfrom
fix/2426-audit-keys-scans-global-config
Oct 28, 2026
Merged

dan-petty merged 14 commits into
mainfrom
fix/2426-audit-keys-scans-global-config

Conversation

@dan-petty

@dan-petty dan-petty commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

devops config audit-keys scans each config file that the settings merge: the global config file and the project config file. Before this change, the audit scanned only get_active_config_path(), which is the one file that a settings save writes. When DEVOPS_CLI_CONFIG was set, or the directory walk found a project file, the audit did not scan the global file. A plaintext secret in the global file went into the settings, but the audit reported the config compliant and exited 0. The devcontainer always sets DEVOPS_CLI_CONFIG, so there the audit never read the global file.

  • The new public function config_layer_paths() in src/devops_cli/config/settings.py gives the global config file and the project config file. load_settings reads the files of this function through _config_layers, and audit_keys_cmd scans the same files. Thus the load and the audit use one rule for their files.
  • The audit also scans config.yaml and .devops/config.yaml in the current directory, as before.
  • The audit refuses each error of the YAML loader that the settings load refuses (_YAML_LOAD_ERRORS, fix(config): a config file that does not parse never prints its line from any command that loads settings #1468). It reports the file unaudited and quotes no text of the file. Before, a value such as !!bool <text> stopped the audit with a KeyError that held the value.
  • Each leak names the full path of its file, as <path>:<section>.<key>. The global file and a project file can both have the name config.yaml.
  • The command help names the files that the audit scans, and the generated documents have the same text.
  • The config-commands spec has three new requirements for these behaviors.

Closes #2426

Change: openspec/changes/archive/2026-10-28-2426-audit-keys-scans-global-config/

@dan-petty dan-petty added scope/config Settings, OS Keyring, environment variables, and defaults type/security Type security: a vulnerability or a leak labels Oct 28, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results for the head of this branch, after the rebase onto origin/main (0137f23).

Targeted tests:

  • uv run devops ci test tests/test_config_audit_keys.py tests/test_config_settings_cache.py tests/config/test_config_file_that_is_not_yaml.py tests/test_zero_plaintext_invariants.py: 36 passed.
  • uv run devops ci test tests/test_cli_format_adoption.py tests/test_fastmcp_contracts.py: 75 passed.
  • uv run devops docs check: all documentation files are up to date.
  • uv run devops openspec archive 2426-audit-keys-scans-global-config: the archive is done, and every spec and change validates.
  • The pre-push hook (fast static checks) passed.

Fail-to-pass, uv run devops ci fail-to-pass --base origin/main on the current head, exit code 0. 11 tests failed on the base and 9 passed on the base:

  passed on base: tests.test_config_audit_keys::test_config_audit_keys_json_lists_unaudited_files_apart_from_leaks
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_a_global_config_file_that_the_yaml_loader_cannot_load_unaudited[timestamp] (AssertionError: assert (0, [], [], True) == (1, ['/tmp/py...'], [], False))
  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_never_logs_an_unparsable_line
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_a_global_config_file_that_the_yaml_loader_cannot_load_unaudited[int] (AssertionError: assert (0, [], [], True) == (1, ['/tmp/py...'], [], False))
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_an_unparsable_file_unaudited
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_a_global_config_file_that_the_yaml_loader_cannot_load_unaudited[bool] (AssertionError: assert (0, [], [], True) == (1, ['/tmp/py...'], [], False))
  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_reports_an_unconstructable_value_unaudited
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_a_global_config_file_that_the_yaml_loader_cannot_load_unaudited[not-utf-8] (AssertionError: assert (0, [], [], True) == (1, ['/tmp/py...'], [], False))
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_dry_run
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_fails_on_a_plaintext_secret_in_the_json_report (AssertionError: assert ['config.yaml:grafana.token'] == ['/tmp/pytest...rafana.token'])
  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_global_config_file[True] (AssertionError: assert (0, True, [],...config.yaml']) == (1, False, ['...config.yaml']))
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_a_global_config_file_that_the_yaml_loader_cannot_load_unaudited[empty-int] (AssertionError: assert (0, [], [], True) == (1, ['/tmp/py...'], [], False))
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_fails_on_a_plaintext_secret_in_the_table (assert '/tmp/pytest-of-vscode/pytest-22222/test_config_audit_keys_fails_o2/.test_config/config.yaml:grafana.token' in "Security Alert: Found plaintext secrets stored in config files: ['config.yaml:grafana.token']. Migrate secrets to OS Keyring via 'devops config set <key> <val>', and delete any key that is not a config option.\n")
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_fails_on_a_plaintext_secret_in_the_global_config_file[False] (AssertionError: assert (0, True, [],...config.yaml']) == (1, False, ['...config.yaml']))
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_a_global_config_file_that_the_yaml_loader_cannot_load_unaudited[deep-nesting] (AssertionError: assert (0, [], [], True) == (1, ['/tmp/py...'], [], False))
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_json_output
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_table_names_the_path_of_the_global_config_file_that_holds_a_secret (assert 0 == 1)
11 failed on base (11 failed and 9 passed in tests/test_config_audit_keys.py; 0 errored).
Elapsed: 7.57s

An earlier fail-to-pass run, before the commits of task group 2, also exited 0. Both cases of test_config_audit_keys_fails_on_a_plaintext_secret_in_the_global_config_file ([True] and [False]) failed on the base with AssertionError: (0, True, [], one file) != (1, False, ['config.yaml:ai.api_key'], two files). The other 11 tests passed on the base.

  passed on base: tests.test_config_audit_keys::test_config_audit_keys_reports_an_unconstructable_value_unaudited
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_never_logs_an_unparsable_line
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_fails_on_a_plaintext_secret_in_the_global_config_file[True] (AssertionError: assert (0, True, [],...config.yaml']) == (1, False, ['...config.yaml']))
  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_fails_on_a_plaintext_secret_in_the_json_report
  passed on base: tests.test_config_audit_keys::test_config_audit_keys_fails_on_a_plaintext_secret_in_the_table
  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_reports_an_undecodable_file_unaudited
  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_dry_run
  failed on base: tests.test_config_audit_keys::test_config_audit_keys_fails_on_a_plaintext_secret_in_the_global_config_file[False] (AssertionError: assert (0, True, [],...config.yaml']) == (1, False, ['...config.yaml']))
  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_json_output
2 failed on base (2 failed and 11 passed in tests/test_config_audit_keys.py; 0 errored).
Elapsed: 13s

@dan-petty
dan-petty force-pushed the fix/2426-audit-keys-scans-global-config branch from 259dbff to 926def0 Compare October 28, 2026 19:41
@dan-petty

Copy link
Copy Markdown
Owner Author

Fix round 1: the Static Analysis check failed on mypy (py314 strict): src/devops_cli/commands/config.py:623: error: Exception type must be derived from BaseException (or be a tuple of exception classes). Mypy does not accept the starred tuple (*_YAML_LOAD_ERRORS, OSError) in an except clause. The typed module constant _AUDIT_READ_ERRORS: tuple[type[Exception], ...] now holds the same errors, and the scanner catches it. The behavior does not change.

The branch is rebased onto origin/main (e6230dc), and the archive of the change is again the last commit.

  • uv run devops ci typecheck: no issues found in 562 source files (it failed with the same error before the fix).
  • uv run devops ci test tests/test_config_audit_keys.py tests/test_config_settings_cache.py tests/config/test_config_file_that_is_not_yaml.py tests/test_zero_plaintext_invariants.py tests/test_cli_format_adoption.py tests/test_fastmcp_contracts.py: 111 passed.
  • uv run devops docs check and uv run devops openspec check: passed.

@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 19:48
@dan-petty
dan-petty force-pushed the fix/2426-audit-keys-scans-global-config branch from 926def0 to 058d821 Compare October 28, 2026 19:53
@dan-petty

Copy link
Copy Markdown
Owner Author

Fix round 2: a merge conflict with main. #2518 changed the settings load to pydantic-settings sources and deleted _read_config_layers and _merged_config_data. The branch is rebased onto origin/main (6a5447a).

  • config_layer_paths() now gives its files to _config_layers, which load_settings uses. The error of an unknown key keeps the code of main: it names layers.project_path and CONFIG_PATH, which are the same files.
  • The proposal and the design of the change name _config_layers in place of the deleted functions. The archive is again the last commit.

Results on the new head:

  • uv run devops ci typecheck: no issues found in 562 source files.
  • uv run devops ci test tests/test_config_audit_keys.py tests/test_config_settings_cache.py tests/config/ tests/test_zero_plaintext_invariants.py tests/test_cli_format_adoption.py tests/test_fastmcp_contracts.py tests/test_config_field_validation.py: 163 passed.
  • uv run devops ci test tests/test_config_commands.py tests/test_data_dir_configuration.py tests/test_config_save_round_trip.py tests/test_config_env_overrides.py tests/test_config_write_history.py tests/test_config_declarations.py tests/test_review_untrusted_tree.py tests/invariants/test_hermetic_floor.py: 109 passed.
  • uv run devops ci fail-to-pass --base origin/main: exit code 0. 11 failed on base, 9 passed on base, 0 errored (the same tests as in the first comment).
  • uv run devops docs check, uv run devops openspec check and the pre-push hook: passed.

The audit of devops config audit-keys scans each config file that the settings merge, so a plaintext secret in the global config file fails the audit.

Plans #2426
…global config file

The settings merge the global config file and the project file. The test puts ai.api_key in the global file and a clean project file in DEVOPS_CLI_CONFIG, or in .devcontainer/config.yaml for the directory walk. It expects exit 1, the leak and both files in the report (#2426).
… settings merge

The settings merge the global config file and the project config file. The audit scanned only the file of get_active_config_path(), which is the project file when one exists or DEVOPS_CLI_CONFIG is set. Thus a plaintext secret in the global file went into the settings, and the audit exited 0.

config_layer_paths() in config/settings.py now gives the files that the settings merge, in the merge order. The load, the error of an unknown key and the audit get their files from it, so the audit scans each file that gives a value to the settings (#2426).
…at the audit scans

The help names the global config file and the project config file that the settings merge, and config.yaml and .devops/config.yaml in the current directory. devops docs generate --sync-readme writes the same text into the generated documents (#2426).
…patch of CONFIG_PATH

docs/TESTING.md does not let a test patch `CONFIG_PATH` or another devops-cli attribute. The test of #2426 now writes the secret into the real global config file, `CONST_CONFIG_PATH`, in the isolated HOME of the worker. The teardown removes the file and the config directory, so the worker-home tripwire finds no state that stays. The test fails on the source of origin/main and passes on this branch.
… loader cannot load unaudited

The safe loader of PyYAML raises KeyError, AttributeError, IndexError or RecursionError for some files, and the message can quote the value. The settings load refuses these errors (#1468), but the scanner of the audit does not catch them. The audit then stops with the value in the output and in the log. This change reads the global config file in more cases (#2426), so the test puts each of these files there. The test fails in four of its six cases.
…loader that the settings load refuses

The scanner of the audit caught only YAMLError, OSError and ValueError. A tagged value that the safe loader cannot build, such as `!!bool <text>`, raised KeyError, and the audit stopped with the value in the output and in the log. The scanner now catches `_YAML_LOAD_ERRORS` of the settings load (#1468) and logs only the file, the type of the error and its position, with `_yaml_error_location`. The audit reports the file unaudited, prints the full report and exits 1. The load and the audit use one rule for these errors. The scan of the keys is outside the `try` block, so the broad error types catch only the load of the file.
…s config file

The audit now scans the global config file and the project config file, and both files have the name `config.yaml`. A leak that names only the file name does not tell which file holds the secret, and the table output does not show `scanned_config_files`. The tests now expect the full path of the file in each leak, in the table and in the JSON report.
…f its config file

The audit scans the global config file and the project config file, and both files can have the name `config.yaml`. A leak named only the file name, so the alert of the table did not tell which file holds the secret. A leak is now `<path>:<section>.<key>`, with the resolved path that `scanned_config_files` also shows.
…s in the change 2426

design.md now names the third case where the audit and `get_active_config_path()` differ: a `..` segment in `DEVOPS_CLI_CONFIG`. It adds decision 4 (the scanner refuses `_YAML_LOAD_ERRORS`, which delivers the audit item of #2451) and decision 5 (a leak names the full path of its file). The spec delta has a requirement for each of these behaviors. tasks.md adds group 2 and names the follow-up issues #2511 and #2513. The long sentences of the proposal and the design are shorter, as ASD-STE100 asks.
… typed tuple, which mypy accepts in an except clause
@dan-petty
dan-petty force-pushed the fix/2426-audit-keys-scans-global-config branch from 058d821 to db27754 Compare October 28, 2026 20:07
@dan-petty

Copy link
Copy Markdown
Owner Author

Fix round 3: the Changed-Line Coverage step of Tests & Coverage failed at 88% (floor 90%). After the rebase onto #2518, the diff has 18 changed lines, and 2 had no test: src/devops_cli/commands/config.py lines 631 and 635. These lines moved out of the try block of _scan_yaml_for_secret_keys, so they count as changed. They are the return [] for a config file whose YAML document is not a mapping, and the continue for a top-level key that is not a section.

Two new tests in tests/test_config_audit_keys.py cover them:

  • test_config_audit_keys_skips_a_top_level_setting_and_finds_the_secret_of_a_section
  • test_config_audit_keys_finds_no_secret_key_in_a_config_file_whose_document_is_a_list

The behavior does not change. Without the new tests, coverage of tests/test_config_audit_keys.py shows lines 631 and 635 as missing. With them, both lines are covered. The branch is rebased onto origin/main (305d3ba), and the archive is again the last commit.

  • uv run diff-cover <coverage of tests/test_config_audit_keys.py, tests/test_config_settings_cache.py and tests/config/> --compare-branch=origin/main --fail-under 90: 18 lines, 0 missing, 100%.
  • uv run devops ci typecheck: no issues found in 562 source files.
  • uv run devops ci test tests/test_config_audit_keys.py tests/test_config_settings_cache.py tests/config/ tests/test_zero_plaintext_invariants.py tests/test_cli_format_adoption.py tests/test_fastmcp_contracts.py tests/test_config_field_validation.py tests/test_config_commands.py tests/test_config_declarations.py: 199 passed.
  • uv run devops docs check, uv run devops openspec check and the pre-push hook: passed.

@dan-petty
dan-petty merged commit 57541df into main Oct 28, 2026
17 checks passed
@dan-petty
dan-petty deleted the fix/2426-audit-keys-scans-global-config branch October 28, 2026 20:14
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.11.1](v0.11.0...v0.11.1)
(2026-10-28)


### Bug Fixes

* **config:** devops config audit-keys scans each config file that the
settings merge
([#2516](#2516))
([57541df](57541df))
* **security:** the osv, internetdb, radar and cloudflare api clients
dial through the egress-checked factory at the public level
([#2509](#2509))
([0379f21](0379f21))


### Code Refactoring

* **k8s:** KubernetesService is the Kubernetes API seam, with a shared
fake cluster and its contract suite
([#2527](#2527))
([0f6b9af](0f6b9af)),
closes [#1315](#1315)

---
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 type/security Type security: a vulnerability or a leak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(security): devops config audit-keys scans the global config file that the settings merge

1 participant