Repository navigation
Description
Problem
Lines cited at dcafadf.
At 132ecc5, config/constants.py lines :2168-2355 moved down 1 and lines from :2356 on moved down 34 (:2296-2299 is :2297-2300, :2505 is :2539, :2512-2518 is :2546-2552, and the host-key block :2799-2830 is :2833-2864); every other cited file is unchanged.
Before devops repos clone (commands/repos.py:283) clones a GitHub SSH URL, clone_repo (git/operations.py:195-199) calls _prepare_clone_url (:187-192), which calls _ensure_known_host (:126-167). That function decides whether to pin GitHub's host key in ~/.ssh/known_hosts. To decide, it reimplements OpenSSH's known_hosts file format in Python. To get the key, it runs ssh-keyscan and fingerprints the output by hand. #364 (for #322) replaced ssh-keygen -F with this parser to save a process spawn. OpenSSH already checks known_hosts when it connects. The parser only decides whether the pinned key is written first.
Hand-rolled code:
crypto/known_hosts.py(272 lines) reimplements the format sshd(8) describes:- hashed
|1|entries, by recomputing HMAC-SHA1 (:83-101); */?patterns compiled to regexes (:116-128);!negation (:75-81);[host]:portspellings (:104-113);- markers (:49-57, :149-151);
- a line parser (:141-182).
- hashed
crypto/host_keys.py(163 lines) parses ssh-keyscan output and computes SHA256 fingerprints by hand. It compares them with three pinned fingerprints (config/constants.py:2823-2829).git/operations.py:90-105runsssh-keyscan -t ed25519and accepts the output after a substring test (hostname not in result.stdout, :100).git/operations.py:190decides whether to pin at all with a case-sensitivestartswithon two prefixes (git@github.com:andssh://git@github.com/,constants.py:500-501).
Confirmed defects. The parser was compared offline with ssh-keygen -F on 30 cases (OpenSSH 10.5p1), and the parser rows below were re-run at dcafadf:
- Fail-open on junk lines. For each of these lines, the parser reports github.com as already trusted. OpenSSH never uses any of them to trust GitHub's plain host key:
@cert-authority github.com …or@cert-authority * …. CA lines vouch only for certificates, and GitHub serves plain keys.- An unknown marker, such as
@foo github.com …. - A truncated key (
github.com ssh-ed25519 AAAA) or a key that does not decode as base64. - An unknown key type, or
ssh-dss(OpenSSH 10 removed DSA).
- What that does end to end. The flow was run through
_ensure_known_hostwith the subprocess mocked. In each of those cases, ssh-keyscan is never called and GitHub's verified key is never written.git clonethen falls back to the user'sStrictHostKeyCheckingsetting. Under the defaultask, that means a trust-on-first-use prompt. Underaccept-new, an unverified key is accepted silently. This is feat(cli): cryptography pure-python asymmetric key management & hardware token authentication research #322's defect again, through another path. The control case, an@revokedline, does write the key. - Silent scan failure. If ssh-keyscan fails,
_ensure_known_hostreturns and the clone goes ahead (operations.py:145-147).test_a_failed_scan_writes_nothing(tests/test_ssh_host_keys.py:520) pins this behaviour. - Spellings that skip pinning (the prefix test at :190):
git@GitHub.com:,ssh://git@github.com:22/,ssh://GIT@GITHUB.COM/,ssh://github.com/,git+ssh://git@github.com/…, scp-likegithubproxy.fjygbaifeng.eu.org:org/repo,org-123@github.com:, and ssh-config aliases such asgh-work:org/repo. - Dead code.
- The
allow_unverifiedbranch (:127, :149-162) has no production caller. The only call is at :191, with defaults. CONST_GITHUB_META_URL(constants.py:2830) is unused.- The comment at
constants.py:2822points to adevops git host-keyscommand that does not exist.
- The
- Raw clone errors.
commands/repos.py:283does not catch theGitCommandErrorthatRepo.clone_fromraises (operations.py:199), so a failed clone, a host-key failure included, surfaces as a raw GitPython exception. - Stale docs.
docs/KNOWN_ISSUES.md:29-31and :52 still describe trust on first use through ssh-keyscan, which fix(git): verify SSH host keys before trusting them (#322) #364 removed.
Acceptance criteria
-
Pinned lines.
config/constants.pyholdsCONST_GITHUB_KNOWN_HOSTS_LINES: Final[tuple[str, ...]], GitHub's three published known_hosts lines, in place of the block at :2799-2830:github.com ssh-ed25519 …,github.com ecdsa-sha2-nistp256 …andgithubproxy.fjygbaifeng.eu.org ssh-rsa ….- A comment cites the source:
https://api.github.com/meta(.ssh_keys) and GitHub's docs page "GitHub's SSH key fingerprints", which publishes these lines for known_hosts. - Measured: the three keys that
gh api meta --jq .ssh_keysserves today have the fingerprints pinned at :2825-2827. - Structure test. Each line is split once on the first space (
str.partition(" ")). The host field must begithubproxy.fjygbaifeng.eu.org. The rest,<type> <base64>, is loaded withcryptography'sload_ssh_public_key, andpublic_bytes(Encoding.OpenSSH, PublicFormat.OpenSSH)must equal it byte for byte. The host field is split off first becauseload_ssh_public_keyrejects a full known_hosts line (Unsupported key type: b'github.com'). cryptography 50.0.1 is already a direct dependency. - The structure test catches structural damage only. Measured with cryptography 50.0.1: truncated and non-base64 key data raise
ValueError; an unknown key type raisesUnsupportedAlgorithm, which subclassesException, notValueError; a well-formedssh-dsskey still loads, with aCryptographyDeprecationWarning. One changed base64 character inside the key material of the ed25519 or RSA key still loads and round-trips byte for byte, because the test re-encodes whatever bytes it is given. - Fingerprint test. For each pinned key, the test computes its SHA256 fingerprint with
serialization.ssh_key_fingerprint(key, hashes.SHA256())(present in cryptography 50.0.1), encodes it withbase64.b64encodewithout the=padding, and compares it with GitHub's published fingerprints. Those three fingerprints are test-only data, copied from the "GitHub's SSH key fingerprints" docs page (also served as.ssh_key_fingerprintsbyhttps://api.github.com/meta). That source is independent of the key lines, so a copy error in a pinned key fails the gate. Measured:ssh_key_fingerprintreproduces all three published fingerprints from the keys served today.
- A comment cites the source:
-
Write.
clone_repomakes sure each pinned line is in~/.ssh/known_hostsand appends any that are missing.- Lines are compared whole and verbatim, with
pathlib/osonly. - The directory is created with mode 0700 and the file is 0600.
- The comparison only stops devops-cli from writing its own lines twice. devops-cli itself does no host, pattern, hash or marker matching.
- The write runs once per process (
functools.cacheon the helper; tests call itscache_clear()), soclone-orgreads the file once and logs at most one warning. - Tests check that:
- the lines are written with modes 0600 and 0700;
- a second run adds nothing;
- a file without a trailing newline is not corrupted;
- an unwritable directory logs one warning, and the clone continues;
- no subprocess is spawned.
- Lines are compared whole and verbatim, with
-
Regression test for the fail-open. Start from a known_hosts file holding any one of these lines:
@cert-authority github.com …or@cert-authority * …;@foo github.com …;- a truncated key, or a key that does not decode;
- an
ssh-dssline; @revoked github.com <other key>;- a hashed
|1|…github.com entry.
The test checks that the existing line is kept byte for byte and that the pinned lines are still appended.
-
Every spelling. The write runs for every URL passed to
clone_repo, with no URL test. A parametrised test covers each spelling listed under Problem.devops repos clone-org(commands/repos.py:134) passes HTTPS URLs and also gets the write (see "Write unconditionally" below for the cost). -
Errors.
clone_repowraps everyGitCommandErrorfromRepo.clone_fromin aGitOperationErrorwhose message carries git's stderr (GitCommandError.stderr) passed throughmask_secrets(security/sanitizer.py:269).commands/repos.py:283reports it with the existingexit_on_error(GitOperationError)(core/cli.py:187-200), which prints the message without a traceback.- No string matching: ssh writes its own host-key message to that stderr, and git passes it through. For a changed key, which is how an interceptor's key for github.com appears once the pinned lines are present, that message names the host and the offending known_hosts file and line. A host-key-specific hint would need a substring test on stderr, because neither tool exposes a structured host-key status: ssh exits 255 for every failure, and git reports 128 for all of them.
clone-org's existingexcept Exception(commands/repos.py:136-137) still printsfail <repo>: …for each repository.- Tests, with a stubbed
GitCommandError, check that:- stderr holding ssh's "Host key for github.com has changed and you have requested strict checking." and "Host key verification failed." reaches the
GitOperationErrormessage; - a credential in a URL in that stderr (for example
https://user:<token>@example.com/o/r.git) is masked; devops repos cloneexits non-zero with the message and no traceback.
- stderr holding ssh's "Host key for github.com has changed and you have requested strict checking." and "Host key verification failed." reaches the
-
No construct left.
crypto/known_hosts.pyandcrypto/host_keys.pyare deleted.- Also deleted from
git/operations.py:_is_host_in_known_hosts,_scan_host_keyand_verified_host_key;- the keyscan and key-selection code in
_ensure_known_host; - the
allow_unverifiedbranch; - the prefix test at :190.
- The constants at
constants.py:2799-2830are deleted. OnlyCONST_GITHUB_KNOWN_HOSTS_LINEStakes their place. rg -n 'ssh-keyscan|has_trusted_host_key|crypto\.known_hosts|crypto\.host_keys|CONST_KNOWN_HOSTS_(HASH_PREFIX|MARKER_REVOKED|MARKER_CERT_AUTHORITY)|CONST_SSH_FINGERPRINT_PREFIX|CONST_SSH_HOST_KEY_TYPES|CONST_GITHUB_HOST_KEY_FINGERPRINTS|CONST_GITHUB_META_URL' srcprints nothing.- feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107's rules have no hit incrypto/known_hosts.py,crypto/host_keys.pyorgit/operations.pyat dcafadf, so this item removes nonet-*marker and leaves feat(ci): hand-rolled URL and address parsing failsdevops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107's ceiling as it is.
-
Out of scope.
_normalize_clone_url(operations.py:53-62) andCONST_GITHUB_SSH_PREFIX/CONST_GITHUB_SSH_URL_PREFIXstay as they are. They belong to a later git-remote-URL item that is not yet filed. -
Tests.
tests/test_ssh_host_keys.py: delete :61-456 (parsing, membership, append, fingerprint, keyscan and verification). Rewrite the integration block at :458-614 as the tests above.tests/test_git_operations.py: update :74-99, :102-110, :279-282 and :285-312, plus parts 1, 2, 3 and 5 of :315-381. Part 4 (_validate_clone_dest) stays.- Unaffected:
tests/test_review_page_line_numbers.pyandtests/golden/review_findings.json. They use "known_hosts.py" only as a label.
-
Docs.
docs/KNOWN_ISSUES.md:29-31and :52 describe the pinned lines and OpenSSH's own check.- A changelog.d fragment: Security (junk known_hosts lines no longer skip pinning, and a failed scan no longer skips it silently), Changed (a failed clone reports git's and ssh's message instead of a raw exception, and HTTPS clones also write the pinned lines) and Removed (the in-process parser and the ssh-keyscan call).
-
Gate. Tests run offline with no ssh binary and no network. The suite shrinks by the deleted parser tests.
uv run devops cipasses. -
Pending a person: with an empty
~/.sshand OpenSSH's defaultStrictHostKeyChecking ask,devops repos clone git@github.com:<org>/<repo>.gitclones with no host-key prompt. It does the same with an@cert-authority github.com …line already in~/.ssh/known_hosts.
Key questions
- What replaces the parser and ssh-keyscan? Proposed: GitHub's documented method. Add its published known_hosts lines to
~/.ssh/known_hostsand let OpenSSH handle hashing, patterns, negation, ports,@revokedand@cert-authority.- No new dependency is needed. OpenSSH is already required, because git's SSH transport uses it, and the full key lines remove the need to fingerprint anything at run time.
- Rejected: asyncssh 2.24.0. Its licence is EPL-2.0 OR GPL-2.0-or-later, against this MIT project, and it would keep a trust decision inside the devops-cli process.
- Rejected: paramiko 5.0.0's
HostKeyEntry.from_line. It has no marker handling and reads@revokedas a host name.
- Write to
~/.ssh/known_hosts, or to a file devops-cli manages? Decided (owner, 2026-10-03): the standard~/.ssh/known_hosts, the file today's code already writes. It works withcore.sshCommand, ssh-config aliases,fetch_allandpull_tracking(operations.py:202-221), and manual git commands.- Rejected: a managed file. Checked offline with a stub ssh, the variant that sets
GIT_SSH_COMMANDwithUserKnownHostsFile=<managed>andStrictHostKeyChecking=yesregresses in four ways:- The environment variable overrides the user's
core.sshCommand; the user's-ikey was never used. UserKnownHostsFile=<managed>on its own stops ssh from reading~/.ssh/known_hostsandknown_hosts2, so the user's@revokedlines stop applying.- With
StrictHostKeyChecking=yes, every non-GitHub SSH clone fails. - Applied to the clone alone,
fetch_allandpull_trackinglose GitHub's key.fetch_allswallowsGitCommandError(:208-209), so its fetches fail silently. Persistingcore.sshCommandat clone time needs GitPython'sallow_unsafe_options=True.
- The environment variable overrides the user's
- Rejected: a managed file. Checked offline with a stub ssh, the variant that sets
- Why not go back to
ssh-keygen -F? Proposed: keep no lookup at all.ssh-keygen -Fexits 0 when the file holds only an@revoked,@cert-authorityor truncated line. Using its exit status would be looser than today's@revokedhandling. - Write unconditionally, or parse the URL first? Proposed: unconditionally, in
clone_repo. It is three lines that are never written twice, and it needs no URL parsing. The deferred git-remote-URL work (giturlparse needs owner approval) therefore does not block this item.- Cost: HTTPS-only clones, every repository in
clone-orgincluded, now create~/.ssh(0700) and add the three lines toknown_hosts. In the devcontainer,~/.sshis the host's own directory, bind-mounted at.devcontainer/devcontainer.json:40(docs/KNOWN_ISSUES.mditem 5), so the lines land in the host's file, as today's SSH clones already do. - Cost: when
~/.sshis not writable (for example a host directory bind-mounted read-only), every run that clones logs the new warning. The once-per-process write keeps that to one warning perclone-orgrun. - Accepted: the lines are GitHub's own, are what GitHub's docs tell users to add, and never change a decision for another host.
- Cost: HTTPS-only clones, every repository in
- Is the new behaviour ever looser than today's? Proposed: in one case, accepted. It follows from the decided standard file: only the rejected managed-file variant forces
StrictHostKeyChecking=yesfor GitHub.- Stricter: junk lines, a failed scan, and no network.
- Equal:
@revokedlines, hashed files, and a key the user accepted earlier for github.com. ssh trusts any matching line, so that key stays trusted, as it does today. Removing it would need host matching again. - Looser: the first clone under interception, for a user whose ssh does not enforce
~/.ssh/known_hosts. Today the scan's fingerprint check fails,_verified_host_keyraisesGitOperationError(operations.py:120-123, called at :164), and the clone aborts before git runs. After this change:- With
StrictHostKeyChecking=no, the pinned lines make the interceptor's key a changed key. ssh_config(5) lets such a connection go ahead "subject to some restrictions", and those restrictions leave public-key authentication working, so the clone proceeds. - With
UserKnownHostsFilepointed elsewhere (in ssh_config orcore.sshCommand), ssh never reads the pinned lines and treats the key as new:accept-newtakes it silently andaskprompts.
- With
- Accepted, because in both cases the user turned off or redirected ssh's host-key checking, and every other path is stricter or equal. Keeping today's abort would mean keeping ssh-keyscan and the fingerprinting that this item deletes.
- What about
ssh.github.comon port 443? Proposed: out of scope. Today's code never pins it either. OpenSSH looks it up as[ssh.github.com]:443, and the pinned lines name github.com only, so the user's ssh decides, as today. - Strings or key objects for the constant? Proposed: strings, because they are written verbatim. The structure test checks their shape, and the fingerprint test against GitHub's published fingerprints checks their content.
- Key rotation? Proposed: as today, edit one constant and the fingerprints in its test; the last rotation was RSA, in March 2023. Lines written earlier stay in the file. A key GitHub withdraws can be added as an
@revoked github.com <key>line, which OpenSSH enforces.
Strategic alignment
- Priority P2: it fixes a confirmed fail-open in GitHub host-key pinning on junk known_hosts lines, and a silent skip when the scan fails.
- Proposed milestone: backlog (P2), picked by the release-start fill.
- Size: medium, one PR, mostly deletion (about −1,050 / +180 lines).
- Order: after feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107, in parallel with fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108, fix(security): URL credential masking uses urllib and httpx2, so passwords containing '@' and non-http schemes are masked and IPv6 hosts stay intact #1109 and fix(security): URL and host:port reads use the sending client's parser, so key trust, crawls, probes and settings act on the host actually dialled #1112.- It edits
config/constants.py, which fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897 (:2296-2299, :2505), fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108 (:2011-2018), fix(security): local names come from the public suffix list, and domains match on DNS labels, not string suffixes #887 (:2512-2518) and fix(security): URL and host:port reads use the sending client's parser, so key trust, crawls, probes and settings act on the host actually dialled #1112 (:269) also edit. feat(ci): hand-rolled URL and address parsing failsdevops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107 adds markers in that file, but none in the files this item deletes or rewrites. - The hunks are disjoint, so nothing beyond landing after feat(ci): hand-rolled URL and address parsing fails
devops ci, AGENTS.md makes the library the rule, and reviews stop discarding the findings #1107 needs serialising.
- It edits
- Library first: OpenSSH makes every trust decision.
cryptography(already locked) checks the pinned lines' structure and computes their fingerprints in the tests. Clone errors are reported with GitPython's ownGitCommandError.stderrand the existingmask_secrets, with no string matching. The only hand-maintained data left is GitHub's published keys and, in the tests, their fingerprints, which no library can know; their source is cited. - Related:
- fix(git): verify SSH host keys before trusting them (#322) #364 and feat(cli): cryptography pure-python asymmetric key management & hardware token authentication research #322: history. fix(git): verify SSH host keys before trusting them (#322) #364 replaced
ssh-keygen -Fwith this parser. Its own description rejected a pure-Python ssh-keyscan as "a hand-rolled partial protocol implementation in a security-sensitive path". - feat(cli): structured fuzzing of parsers and schema boundaries #416: drop known_hosts from its fuzzing targets once this lands.
- refactor(security): the scanner, sandbox and crypto tables move out of config/ next to their owners #1030: leaves the known_hosts and fingerprint constants in
config/whilecrypto/still reads them, neither moving nor deleting them; this item deletes them with their readers.
- fix(git): verify SSH host keys before trusting them (#322) #364 and feat(cli): cryptography pure-python asymmetric key management & hardware token authentication research #322: history. fix(git): verify SSH host keys before trusting them (#322) #364 replaced
- Use a changelog.d fragment only; CHANGELOG.md and ROADMAP.md are not edited.
Update 2026-10-08: refinement
#1332 plans tests for crypto/known_hosts.py and tests/test_ssh_host_keys.py, and #1333 fakes ssh-keyscan (git/operations.py:91-93). This item deletes both; whichever lands second drops those targets.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 8, 2026
Placed in v0.2.32 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: URLs and host keys read by the library that dials, ollama hardening, and pull-request test-quality tooling. 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.
dan-petty commentedon Oct 8, 2026
Linked: #1399 and #900. Each wraps a
GitCommandErrorfromgit/operations.pyin aGitOperationErrorwith git's stderr throughmask_secrets; whichever lands later reuses the shape. Found by the 2026-10-08 backlog review.fix(git): GitHub clones trust GitHub's published host keys through Op…
dan-petty-bot commentedon Oct 9, 2026
What changed
#1510, merged into
release/v0.2.32as 0efe7c8.10 file(s) changed.
How it was verified
Check runs at 0a878b3:
Acceptance Criteria of
docs/agent/tasks/task-1114-github-ssh-host-keys.md:No Acceptance Criteria section.
feat(release): v0.2.32 (#1516)