Repository navigation
Handle known_hosts markers using native net-ssh entries - #589
Open
richardkemp-ocn wants to merge 1 commit into
Open
richardkemp-ocn wants to merge 1 commit into
richardkemp-ocn wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The cached known-hosts reader treats the first field as the host list. For
@cert-authorityand@revokedlines, that field is the marker; the actual host pattern then fails the key-type check, silently dropping the entry.This rejects host certificates trusted only through a CA, and prevents net-ssh's revocation checks from seeing revoked host or CA keys. SSHKit installs this reader by default.
Fixes #588. Related: basecamp/kamal#1814 concerns the same cached reader, but its separate multiple-hashed-key lookup problem is not changed here.
Change
Net::SSH::KnownHosts, retaining its entry objects, host-pattern/hash matching, andcheck_host_ipbehavior. Cache these lookups by host and relevant matching option;addinvalidates them as before.Net::SSH::HostKeyswhen supported, so net-ssh's own verifiers enforce revocation and certificate constraints. No custom verifier or dependency-floor change.Full revocation/constraint behavior is tested with net-ssh 7.3.10 and 8.2.0. Compatibility is capability-based (
HostKeys#revoked?/KnownHosts#revoked_keys_for), not a version-string comparison. Older net-ssh keeps its native limitations: 7.3.0 supports CA entries but does not enforce revocation or the newer certificate constraints; this change does not backport those checks.Minimal reproduction
With a net-ssh version supporting revocation, this uses only a freshly generated, throwaway key and makes no network connections:
Before this change, native net-ssh reports
truebut SSHKit reportsfalse, leaving the same key trusted by the ordinary entry. After this change, both reporttrue; net-ssh's verifier refuses the key. The certificate regression tests additionally exercise successful CA verification and rejection of expired, wrong-principal, user, and unsupported-critical-option certificates.Tests
bundle exec rake test:units: 230 tests, 3460 assertions, 0 failures/errors/skips, separately with net-ssh 8.2.0 and 7.3.10 (Ruby 3.4.11).sshkit: the pre-existing deprecation-logger test hard-codes that directory name in a regexp and fails in a checkout namedsshkit-upstream, on both clean master and this branch. No tests were excluded or modified to obtain the green runs.rake lintis blocked by the existing RuboCop/parser dependency's missingracc/parserunder Ruby 3.4; the identical failure occurs on clean master.Written by Codex