Skip to content

fix(config): the secrets audit never prints a config line it cannot parse, and an unparsable file is not reported clean #1022

Closed

Description

@dan-petty

Problem

devops config audit-keys fails open and can print the secret it is looking for. _scan_yaml_for_secret_keys (src/devops_cli/commands/config.py:495-515, at 79e1e93) parses each config file with yaml.safe_load. On a yaml.YAMLError it logs "Failed to parse config file %s for secrets audit: %s" with the error (:513-514) and returns [] (:515). PyYAML's error message quotes the offending line. No logging handler is configured in src, so Python's last-resort handler prints the warning to stderr. Reproduced offline twice: a malformed api_key: <value>: x line printed the value, and the file was reported with no plaintext secrets.

The audit also reads Path.cwd()/config.yaml and .devops/config.yaml, which load_settings need not parse first, so a malformed file there can show as "CLEAN (0 Plaintext)". Reviews flagged this through Semgrep's logger-credential-disclosure rule in S2 to S6, and a deterministic syntax check invalidated it each time because "Failed to parse" in the quoted log message reads as a syntax claim (.data/review-evaluation-20261002-s5.md, sections 3.3 and 6.3).

Acceptance criteria

  • The parse-failure log carries the file, the error class and the line and column (err.problem_mark), never the error message or the snippet. A test with a malformed line holding a fake key value asserts the value is not in stderr or the log records.
  • A file the audit cannot read or parse is reported as unaudited, not clean, and the command exits non-zero. A test asserts the exit code and the "unaudited" row.
  • --json output lists unaudited files separately from files with leaks.
  • Tests run offline in tmp directories and each runs well under 1 s.
  • changelog.d/1022.md records the fix under ### Security. CHANGELOG.md is not edited.
  • uv run devops ci passes.

Key questions

Depends on: none.
Order: any time; touches only commands/config.py and its tests.
Related: #972 (config from the tree under review), #1000 (one Settings module).

Activity

  1. added
    type/security
    scope/security
    scope/config
    priority/p2-medium
    on Oct 2, 2026
  2. added this to the v0.2.30 milestone on Oct 8, 2026
  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Placed in v0.2.30 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: P1 secret and sandbox-boundary fixes, the review tools lock, kube-linter finding identity and a faster gate. Position 3 of 10 in the release's planned merge order. Its board Status is set to Ready, so the release-start fill keeps it.

  4. dan-petty-bot commented on Oct 9, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1461, merged into release/v0.2.30 as a6f8474.

    Summary

    devops config audit-keys used to log PyYAML's error message when a config file did not parse. That message quotes the offending line, so a malformed api_key: <value>: x line printed the value to stderr. The audit then reported the file clean and exited 0.

    • _scan_yaml_for_secret_keys (src/devops_cli/commands/config.py) returns None for any file it cannot read or parse. That includes a non-UTF-8 file and a value PyYAML can read but cannot build, such as an impossible date or an integer past Python's digit limit (a plain ValueError). The warning reads Could not audit config file <path>: <error class> at line L, column C. It never includes the error message, its mark, problem or context, any of which can quote the file.

    • _detect_keyring_secret_leaks returns (leaks, unaudited).

    • While any file is unaudited, audit_keys_cmd:

      • shows UNAUDITED instead of CLEAN (0 Plaintext);
      • lists the files under unaudited_config_files in --json, separate from plaintext_leaks;
      • marks every key and the report not compliant;
      • prints the file paths, never their content, and exits 1.

      The MCP config_audit_keys tool needs no change, because the non-zero exit becomes a tool error.

    • The help text now says the command exits 1 when a config file cannot be read or parsed. docs/commands/config.md, docs/CLI_REFERENCE.md and the README command row are regenerated.

    8 file(s) changed.

    How it was verified

    Check runs at 7dd9dad:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Static Analysis: pass
    • Analyze (actions): pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1022-secrets-audit-unparsable-config.md:

    • The parse-failure log carries the file, the error class and the line and column, never the error message or the snippet: test_config_audit_keys_never_logs_an_unparsable_line (tests/test_config_audit_keys.py) asserts FAKE-1022-value is in neither the output, stderr nor any log record, and that one record names the file, ScannerError and line 2, column 27.
    • A file the audit cannot read or parse is reported unaudited, not clean, and the command exits 1: test_config_audit_keys_reports_an_unparsable_file_unaudited (table, no CLEAN (0 Plaintext) and no success line), test_config_audit_keys_reports_an_undecodable_file_unaudited (a non-UTF-8 file, logged with its error class and no position) and test_config_audit_keys_reports_an_unconstructable_value_unaudited (an impossible date).
    • --json lists unaudited files separately from leaks: test_config_audit_keys_json_lists_unaudited_files_apart_from_leaks.
    • Tests run offline in tmp directories: the module's autouse _audit_in_tmp_dir fixture runs every audit in tmp_path, so a developer's own config.yaml is never scanned, and the tests only read and write files.
    • changelog.d/1022.md records the fix under ### Security; CHANGELOG.md is not edited.
    • uv run devops ci passes: the PR's passing checks.
  5. added a commit that references this issue on Oct 9, 2026
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/p2-mediumscope/configscope/securitytype/security

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions