Fix cleartext credential exposure in gNMI PAM auth (GHSA-fr8g-q48c-qpc4) - #779
Open
marvellgit wants to merge 1 commit into
Open
marvellgit wants to merge 1 commit into
marvellgit wants to merge 1 commit into
Conversation
Replace ssh.InsecureIgnoreHostKey() with sshd host key pinning read from /mnt/host/etc/ssh/. Fail closed if keys cannot be loaded and bound a 5-second connect/handshake timeout to prevent rogue listener hangs. Signed-off-by: marvellgit <marvellgit@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
qiluo-msft
approved these changes
Sep 8, 2026
qiluo-msft
reviewed
Sep 8, 2026
| // SONiC's host-ssh-keygen.sh generates an RSA key by default; ecdsa/ed25519 | ||
| // are also accepted in case sshd is configured with them. | ||
| var sshHostKeyPaths = []string{ | ||
| "/mnt/host/etc/ssh/ssh_host_ed25519_key.pub", |
Collaborator
There was a problem hiding this comment.
The fix is correct, but there are no unit tests for sshdHostKeyCallback or the new UserPwAuth logic. To make them testable without a running sshd, change sshAuthAddr from a const to a var (matching what was already done for sshHostKeyPaths):
// const sshAuthAddr = "127.0.0.1:22"
var sshAuthAddr = "127.0.0.1:22"Then a pam_auth_test.go can cover all the key paths using an in-process SSH server on a random loopback port:
// sshdHostKeyCallback tests
TestCallback_AcceptsPinnedKey // happy path
TestCallback_RejectsUnpinnedKey // key mismatch returns error
TestCallback_AcceptsAnyPinnedAmongMultiple // multi-key pinning
TestCallback_SkipsMissingFiles // partial missing → still ok
TestCallback_FailsClosedWithNoReadableFiles // all missing → error
TestCallback_FailsClosedWithInvalidContent // bad PEM → error
TestCallback_FailsClosedWithTrailingData // trailing bytes → error
// UserPwAuth tests (override sshHostKeyPaths + sshAuthAddr)
TestUserPwAuth_FailsClosedWhenNoHostKeys // no key files → false, non-nil err
TestUserPwAuth_AcceptsValidCredentials // correct password → true
TestUserPwAuth_RejectsWrongPassword // wrong password → false
TestUserPwAuth_RejectsRogueListener // server with different key → falseTestUserPwAuth_RejectsRogueListener is the most valuable: it spins up a local SSH server whose host key does not match the pinned one, asserts that UserPwAuth returns false/error without transmitting credentials — directly exercising the F020 attack scenario end-to-end.
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.
Replace ssh.InsecureIgnoreHostKey() with sshd host key pinning read from /mnt/host/etc/ssh/. Fail closed if keys cannot be loaded and bound a 5-second connect/handshake timeout to prevent rogue listener hangs.
Why I did it
How I did it
How to verify it
Which release branch to backport (provide reason below if selected)
Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type:
Tested branch
Test result
Description for the changelog
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)