Skip to content

fix(config): devops config unset leaves the plaintext secret that it removes in its .bak copy #2645

Description

@dan-petty

Problem Description

devops config unset <key> copies the config file to <name>.bak-<YYYYMMDD-HHMMSS> before it removes the key. When the key is a plaintext secret, the copy holds the secret. The copy has the same file mode as the file, and the command keeps the newest 10 copies. Thus the removal of a plaintext secret leaves the secret on disk, and devops config audit-keys does not scan the copies, so it reports no leak.

The same holds for each write of a file that holds a plaintext secret, such as devops config set <key> <value>. The copy only repeats a secret that the file held before. The removal of a secret is the case that must leave no secret behind. Issue #2513 makes the alert of devops config audit-keys name the command that removes a leak, and that command leaves the copy.

Reproduction Steps

  1. Make a temporary HOME. Write ai: and api_key: FAKE-2513-value to $HOME/.config/devops-cli/config.yaml.
  2. Set PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring. Run devops config unset ai.api_key in a directory with no project config file.
  3. Run cat $HOME/.config/devops-cli/config.yaml.bak-*.

Expected vs Actual Behavior

Expected: after the removal of a secret key, no file that the command wrote holds the value of the secret.

Actual: step 2 exits 0 and prints the path of the copy. Step 3 prints api_key: FAKE-2513-value.

Environment Diagnostics

devops-cli 0.16.0 at origin/main 7dde54e, PyYAML 6.0.3, Python 3.14.10, Linux. The copy is made by back_up in src/devops_cli/config/write_history.py, called from _write_content in src/devops_cli/config/settings.py.

Logs, Traces, or Terminal Output

Removed ai.api_key from <tmp>/home/.config/devops-cli/config.yaml:2.
The file before the change is in <tmp>/home/.config/devops-cli/config.yaml.bak-20261029-141747.
$ cat <tmp>/home/.config/devops-cli/config.yaml.bak-20261029-141747
ai:
  api_key: FAKE-2513-value

Pre-Submission Checklist

  • I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
  • I have checked existing issues and pull requests to ensure this is not a duplicate.

Source: #2513

Proposed design

Problem statement

devops config unset removes a secret key from the config file, but the backup copy made before the removal still holds the secret's plaintext value. The copy is retained for 10 generations with the same file mode, so the secret persists on disk after the user intended to remove it. devops config audit-keys does not scan the copies, so it reports no leak.

Acceptance criteria

Requirement: Secret redacted in backup on unset

When devops config unset removes a key that is in the secret key set, the backup copy MUST NOT contain the plaintext value of that key.

Scenario: unset a secret key

  • WHEN devops config unset ai.api_key is run and the file held api_key: FAKE-2513-value
  • THEN the backup file does not contain FAKE-2513-value

Requirement: Non-secret keys preserved in backup on unset

When devops config unset removes a key that is not in the secret key set, the backup copy MUST contain the full previous state of the file.

Scenario: unset a non-secret key

  • WHEN devops config unset ai.model is run and the file held model: llama3
  • THEN the backup file contains model: llama3

Requirement: Redaction placeholder is visible

The redacted value in the backup MUST be a placeholder that indicates a value was present but is not shown.

Scenario: inspect redacted backup

  • WHEN the backup file is read after unsetting a secret key
  • THEN the key is present with a redaction placeholder value, not absent

Requirement: Retention unchanged

The backup retention of 10 copies MUST be unchanged after the redaction fix.

Scenario: multiple unsets

  • WHEN 12 unsets are performed on the same file
  • THEN exactly 10 backup copies remain

Existing Tool Considered

No open, maintained library covers redacting specific keys in a YAML backup file before retention. The project already owns the backup logic in src/devops_cli/config/write_history.py. The fix modifies back_up to accept a set of keys to redact and replaces their values with a placeholder in the copy, and updates the call site in src/devops_cli/config/settings.py. Written cost: about 20 lines in write_history.py for the redaction helper and the parameter, about 5 lines in settings.py to pass the secret key on removal, and about 40 lines of tests. Total build and maintenance cost is low because the change is one function and its caller.

Key questions

  • How should the backup copy be modified to remove the secret value?: Redact the value of the removed key in the backup copy. Parse the copy as YAML, set the key's value to a redaction placeholder, and write it back. This preserves the rest of the file for undo while removing the secret. (best practice) [sources: src/devops_cli/config/write_history.py:32, src/devops_cli/config/settings.py:1454]
    • Chosen: Redact the key's value in the backup copy. Preserves the rest of the file for undo. The secret value is removed. The key name stays, which is not a secret.
    • Rejected: Skip the backup entirely when removing a secret key. Loses the ability to undo the removal. A person who unsets the wrong key cannot recover.
    • Rejected: Delete the backup after the write when the key is a secret. Same loss as skipping: no undo. Also leaves a window where the secret is on disk.
  • What placeholder value should replace the secret in the backup?: Use the string REDACTED. It is clearly not a valid credential, it signals that a value was present, and it matches the convention used by other tools for masked secrets. (best practice) [sources: src/devops_cli/config/settings.py]
    • Chosen: REDACTED. Clearly indicates a value was present. Not a valid credential. Matches common convention.
    • Rejected: Empty string. Ambiguous: could mean the key was unset or the value was empty.
    • Rejected: null (YAML null). Changes the type of the value. A restore would set the key to null, not to the original value.
  • How does the code determine whether a key is a secret?: The project already defines the secret key set. _SECRET_FIELDS in settings.py is built from secret_keys() in devops_cli.config.env. The fix checks whether the removed key is in that set. [sources: src/devops_cli/config/settings.py, src/devops_cli/config/env.py]
  • Should the redaction apply to all writes or only to unset (removal)?: Apply to unset (removal) only. The issue states that the removal of a secret is the case that must leave no secret behind. For set, the backup holds the old value, which was already on disk before the write. The new value goes to the keyring, not the file. (best practice) [sources: src/devops_cli/config/settings.py:1480]
    • Chosen: Redact only on unset (removal). The issue specifies this is the critical case. The old value in a set backup was already on disk. The new value goes to the keyring.
    • Rejected: Redact on all writes. Overly broad. A set write's backup holds the old value, which was already present. Redacting it there is not required by the issue.
  • Where should the redaction logic live?: In write_history.py, as a parameter to back_up. The function already owns the copy and the retention. Adding a redact_keys parameter keeps the redaction close to the copy it modifies, and the caller in settings.py passes the secret key on removal. (best practice) [sources: src/devops_cli/config/write_history.py:32, src/devops_cli/config/settings.py:1463]
    • Chosen: Parameter on back_up in write_history.py. The function already owns the copy and retention. The redaction is a property of the copy, not of the caller.
    • Rejected: Post-hoc redaction in remove_config_key in settings.py. Separates the redaction from the copy logic. The caller must know the backup path and re-open the file.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/security
    status/new
    value/high
    effort/medium
    on Oct 29, 2026
  2. dan-petty commented on Oct 29, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/security. The command leaves a plaintext secret on disk in a backup file after the user removes it.
    • Priority: P1-High. Removing a secret does not actually remove it from disk, which defeats the purpose of the operation.
    • Value: High. Users expect that removing a secret key removes the secret from all files the command wrote.
    • Effort: Medium. Requires changing the backup logic in write_history.py to redact or skip secrets and handling the 10 retained copies.
    • Related: fix(config): devops config audit-keys does not find a plaintext secret under a nested key such as service.github_app.private_key #2511, which asks for a different change. Both involve plaintext secrets in config files, but #2511 fixes audit key-depth scanning while this fixes backup file retention after unset.
  3. added
    priority/p1-high
    on Oct 29, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 29, 2026
  5. devops-cli-service commented on Oct 29, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at ec2f7f7 (see proposed design in issue body).

  6. added
    type/bug
    scope/config
    status/in-progress
    and removed
    type/security
    status/ready
    on Oct 30, 2026
  7. removed
    status/in-progress
    on Oct 30, 2026
  8. added a commit that references this issue on Oct 30, 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

    effort/mediumpriority/p1-highscope/configsource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions