Skip to content

fix(security): ssh rotate puts a host-only key on GitHub #6339

Closed

Description

@dan-petty

Problem Description

devops ssh rotate gives each rotated key GitHub access and makes it the git signing key, also for a key that is only for SSH to hosts. make ssh-rotate in dan-petty/homelab runs devops ssh rotate --prefix ansible. The key of that prefix is the Ansible key: devops infra gives it to Ansible to reach the nodes, and it has no other use.

After rotate (src/devops_cli/commands/ssh.py:235) makes the new key, it does these steps for each prefix:

  1. register_key_on_github (src/devops_cli/github/ssh.py) adds the public key to the GitHub account as an authentication key and as a signing key.
  2. _configure_git_signing calls configure_git_signing (src/devops_cli/crypto/ssh_keys.py:327). It sets the key as the SSH commit signing key in the global git config, and in the local config of the working directory when that is a repository (the homelab clone).
  3. It says that the old key stays on GitHub for the grace days, and that a person removes it by hand.

Effects for a key that is only for the nodes:

  • Each place that holds the Ansible key then holds a GitHub credential with the access of the account.
  • The commits of the person are signed with the node key in each repository that has no local signing key.
  • The GitHub account gets one more authentication key and one more signing key at each rotation.

The current key of the prefix is from 2026-09-09. With ssh.rotation_days 90, its first rotation is due on 2026-12-08.

Reproduction Steps

  1. Read rotate in src/devops_cli/commands/ssh.py.
  2. In the homelab clone, run devops ssh rotate --prefix ansible --dry-run (2026-11-18). The plan lists these requests for the node key:
1. POST /user/keys  {"title": "ansible-20261118", "key": "<public key>"}
3. POST /user/ssh_signing_keys  {"title": "ansible-20261118", "key": "<public key>"}
5. git config --global gpg.format ssh
6. git config --global user.signingkey <path>
7. git config --global commit.gpgsign true
8-10. the same three keys with git -C <homelab clone> config --local

Expected vs Actual Behavior

Expected: the rotation of a key that is only for hosts makes the new key and tells the person to put the public key on the hosts. It makes no GitHub request and no change of the git config.

Actual: the rotation registers the node key on GitHub for authentication and signing, and points the git commit signing at it.

Proposed Fix

Let each key prefix state its uses. For example, rotate registers on GitHub and sets the signing only for the project prefix (ssh.key_prefix), or a setting names the prefixes that are only for hosts. The homelab role ansible/roles/common/tasks/user.yaml already puts a key on the hosts with authorized_key.

Acceptance Criteria

  • A test: rotate of a prefix that is only for hosts makes no GitHub request and does not change the git config. It fails on main (devops ci fail-to-pass).
  • A test: rotate of the project prefix still registers the key and sets the signing.
  • The dry run of a prefix that is only for hosts lists no GitHub request.
  • The help and the reference of devops ssh rotate tell which prefixes go to GitHub.

Alternatives check of 2026-11-19: none.
Tool: none found.
Reason: Four searches found no open tool; the results were unrelated reference pages, and the need is a conditional inside the project's own rotate command and plan builder, which no external tool supplies.

Lacks:

  • No tool tells a host-only prefix from the project prefix
  • No tool gates GitHub key registration and signing by prefix
  • No tool edits the dry-run plan to drop GitHub requests

Proposed design

Problem statement

Apply GitHub registration and git signing only to the project prefix in devops ssh rotate. The command registers every rotated key on GitHub and sets it as the git signing key. It does this also for a key that only reaches hosts. The Ansible key then becomes a GitHub credential and signs commits. A host-only rotation prints the public key and tells the person to put it on the hosts.

Acceptance criteria

Requirement: Host-only prefix skips GitHub

devops ssh rotate SHALL make no GitHub key registration request for a prefix that is not the project prefix.

Scenario: Rotate the Ansible prefix

  • WHEN A test calls rotate with --prefix ansible and the project prefix project. The test uses a temporary HOME and a temporary git repository, and it patches register_key_on_github in src/devops_cli/github/ssh.py.
  • THEN The test asserts that register_key_on_github was not called and that the new key file exists in the ansible prefix directory.

Requirement: Host-only prefix keeps git config

devops ssh rotate SHALL leave the global and local git config unchanged for a prefix that is not the project prefix.

Scenario: No signing change for the Ansible prefix

  • WHEN A test calls rotate with --prefix ansible and the project prefix project. The test uses a temporary HOME and a temporary git repository, and it patches register_key_on_github.
  • THEN The test asserts that git config --global and git -C <repo> config --local show no user.signingkey, no gpg.format and no commit.gpgsign value.

Requirement: Host-only rotation prints the host instruction

devops ssh rotate MUST print the new public key and an instruction to put it on the hosts for a host-only prefix.

Scenario: Read the host-only rotation output

  • WHEN A test calls rotate with --prefix ansible and the project prefix project. The test uses a temporary HOME, and it patches register_key_on_github.
  • THEN The test asserts that the output holds the new public key and a line that tells the person to put the public key on the hosts. The test also asserts that the output holds no GitHub removal message.

Requirement: Project prefix still registers and signs

devops ssh rotate MUST register the new key on GitHub and set it as the git signing key for the project prefix.

Scenario: Rotate the project prefix

  • WHEN A test calls rotate with --prefix project and patches register_key_on_github and configure_git_signing.
  • THEN The test asserts that register_key_on_github received the new public key and title, and that configure_git_signing received the new key path.

Requirement: Host-only dry run lists no GitHub request

The dry run of devops ssh rotate SHALL list no GitHub key request and no git config command for a host-only prefix.

Scenario: Plan the Ansible rotation

  • WHEN A test calls plan_rotate in src/devops_cli/github/ssh_plans.py with github_enabled=False for the new key.
  • THEN The test asserts that the plan holds no POST /user/keys, no POST /user/ssh_signing_keys and no GET request to either key endpoint. The plan also holds no git config line.

Requirement: The rotate help names the GitHub prefix

The help of devops ssh rotate MUST state that only the prefix in ssh.key_prefix registers on GitHub.

Scenario: Read the rotate help

  • WHEN A test invokes devops ssh rotate --help and reads the output.
  • THEN The test asserts that the help names ssh.key_prefix as the only prefix that registers on GitHub. The help says that every other prefix is for hosts only.

Requirement: The generated CLI reference holds the new help

The generated CLI reference MUST hold the new rotate help text after the change.

Scenario: Regenerate the CLI reference

  • WHEN A test runs uv run devops docs generate on the changed tree.
  • THEN git status --porcelain prints no path, so the generated reference holds the new help text.

Existing Tool Considered

The alternatives check in the issue body records the verdict none and no tool. Four searches found no open, maintained tool or library that covers this need. The block lists what no tool supplies. The change edits src/devops_cli/commands/ssh.py, src/devops_cli/github/ssh_plans.py, src/devops_cli/github/ssh.py and their tests. Written cost: about 30,000 tokens to build and test. It is about 5,000 tokens for each later change to keep, and less than one day of elapsed time.

Key questions

  • Which prefixes register on GitHub and use the new key for git signing?: Only the prefix that equals the configured project prefix, ssh.key_prefix. Every other prefix is host-only: it skips register_key_on_github and configure_git_signing. This fails closed: a typo in --prefix makes a host-only key, never a GitHub credential. (best practice) [sources: src/devops_cli/commands/ssh.py:235, src/devops_cli/github/ssh.py, src/devops_cli/crypto/ssh_keys.py:327]
    • Chosen: Compare the active prefix with ssh.key_prefix. It uses the prefix that the command already resolves, so no second list can disagree.
    • Rejected: Add a list of host-only prefixes. A new prefix stays a GitHub key by default, so the defect remains.
    • Rejected: Add a --github or --no-github flag. A person must remember the flag on each run, and make ssh-rotate keeps the defect.
    • Rejected: Add a per-prefix use map to the config. It adds a schema and a migration for one distinction that the project prefix already makes.
  • Where does the shared prefix rule live?: In src/devops_cli/github/ssh.py as a pure function registers_on_github(prefix, project_prefix). commands/ssh.py and github/ssh_plans.py import it. This avoids the import cycle that a helper in commands/ssh.py would create, because ssh_plans.py is imported by the command module. (best practice) [sources: src/devops_cli/github/ssh.py, src/devops_cli/github/ssh_plans.py, src/devops_cli/commands/ssh.py]
    • Chosen: Helper in github/ssh.py. The plan builder already imports this module, so no cycle and one rule.
    • Rejected: Helper in commands/ssh.py. ssh_plans.py would import the command module and make a cycle.
    • Rejected: Copy the check at each call site. The copies drift, and one copy can skip the check.
  • What does a host-only rotation do after it makes the key?: It prints the new public key and one line that tells the person to put it on the hosts with the Ansible role. It makes no GitHub request and no git config change. It does not run devops infra apply, because that path needs a saved plan and an agent access level above none. (best practice) [sources: src/devops_cli/commands/ssh.py:235, src/devops_cli/github/ssh_plans.py, CONTEXT.md]
    • Chosen: Print the public key and a host instruction. It meets the expected behavior and needs no host access and no new scope.
    • Rejected: Write the key into the infra repo for Ansible. It couples the SSH command to one infra repo and needs a commit and a review for a key.
    • Rejected: Run devops infra apply to push the key. It couples key rotation to an infra plan and apply, which needs a saved plan and an access level.
  • How does the dry run learn that a prefix is host-only?: The command computes the decision with registers_on_github and passes github_enabled=False to plan_rotate. The plan builder then omits the two key requests and the git config commands. The plan builder does not read --prefix itself. (best practice) [sources: src/devops_cli/github/ssh_plans.py, src/devops_cli/commands/ssh.py:235, src/devops_cli/github/ssh.py]
    • Chosen: Pass a github_enabled flag to plan_rotate. The live run and the dry run use one decision, and the plan builder stays a pure request builder.
    • Rejected: Let plan_rotate read the prefix and config. It adds config and command concerns to the plan builder and can disagree with the live run.
    • Rejected: Build the plan in the command and skip ssh_plans. The dry run and the live run then have two request lists.
  • Which prefixes show the GitHub removal message for the old key?: Only the project prefix. A host-only rotation says that the old key stays on the hosts until the person replaces it, and it says nothing about GitHub. (best practice) [sources: src/devops_cli/commands/ssh.py:235, src/devops_cli/github/ssh.py]
    • Chosen: Show the removal message only for the project prefix. The old host key is not on GitHub, so a removal line for it is false.
    • Rejected: Show it for every prefix. It tells the person to remove a key that GitHub never held.
  • How do the tests prove the change with no network?: Patch register_key_on_github in src/devops_cli/github/ssh.py. Use a temporary HOME and a temporary git repository, and assert that the global and local user.signingkey values stay empty for the Ansible prefix. Patch register_key_on_github and configure_git_signing to assert the calls for the project prefix. Call plan_rotate with github_enabled=False for the dry run. (best practice) [sources: tests/crypto/test_ssh.py, src/devops_cli/github/ssh_plans.py, src/devops_cli/commands/ssh.py]
    • Chosen: Patch the two state-changing callers and inspect a temporary git config. The test needs no network, no GitHub account and no real user config.
    • Rejected: Use a real GitHub session. It needs a token and a live account, and it changes the account at each run.
    • Rejected: Read only the source code with no command run. It does not show that the command leaves the git config unchanged.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/security
    source/agent
    status/new
    effort/medium
    value/high
    on Nov 18, 2026
  2. dan-petty commented on Nov 18, 2026

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. A live high security issue: host-only keys gain GitHub authentication and signing access at every rotation, expanding the credential surface.
    • Related: feat(devcontainer): isolate project ssh signing keys and install pre-commit globally #66, which asks for a different change. Both concern SSH signing key configuration, but #66 isolates signing keys across devcontainers while the candidate stops rotate from registering host-only keys on GitHub.
  3. added
    priority/p1-high
    on Nov 18, 2026
  4. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.

  5. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (4)

    Searches run:

    • CLI tool manage multiple SSH key prefixes, skip GitHub registration for host-only keys, results: 5
    • tool rotate SSH keys per purpose, only one key registered on GitHub signing key, results: 5
    • gh cli ssh-key plugin add authentication key and signing key, results: 5
    • ansible authorized_key rotation tool for host SSH keys separate from GitHub keys, results: 5

    Sources:

  6. added
    status/ready
    and removed
    status/new
    on Nov 19, 2026
  7. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

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

  8. added
    owner/service
    and removed
    owner/service
    on Nov 19, 2026
  9. 11 remaining items

  10. added
    status/in-progress
    on Nov 19, 2026
  11. added
    status/in-review
    and removed
    status/in-progress
    on Nov 19, 2026
  12. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Pull request #6473 is ready for review. The checks passed.

    Spend: 99 model requests, 7371137 input tokens, 35243 output tokens.

  13. removed
    owner/service
    on Nov 19, 2026
  14. removed
    status/in-review
    on Nov 19, 2026
  15. devops-cli-service commented on Nov 20, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-20 00:02 UTC

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/securitysource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions