Improve error message for encrypted SSH keys without password#2013
Open
ogulcanaydogan wants to merge 1 commit intofluxcd:mainfrom
Open
Improve error message for encrypted SSH keys without password#2013ogulcanaydogan wants to merge 1 commit intofluxcd:mainfrom
ogulcanaydogan wants to merge 1 commit intofluxcd:mainfrom
Conversation
When a password-protected SSH private key is provided without the 'password' field in the Secret, the error message was misleading: "SSH agent requested but SSH_AUTH_SOCK not-specified" This change detects encrypted SSH keys early by attempting to parse the identity with ssh.ParseRawPrivateKey and checking for PassphraseMissingError. When detected, a clear error is returned pointing the user to add the 'password' field to their Secret. Fixes fluxcd#802 Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
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.
Description
When users provide a password-protected SSH private key in their Secret but forget the
passwordfield, the current error is misleading:This doesn't hint at the actual problem. The fix detects encrypted keys early by parsing the identity with
ssh.ParseRawPrivateKeyand checking forssh.PassphraseMissingError. When detected, the error now reads:Changes
internal/controller/gitrepository_controller.go: Added encrypted key check ingetAuthOpts()after SSH auth options are constructed. Usesgolang.org/x/crypto/ssh.ParseRawPrivateKey+PassphraseMissingErrordetection.How it works
git.NewAuthOptions()returns with SSH transportIdentityis present butPasswordis emptyPassphraseMissingError, the key is encryptedNo behavior change for unencrypted keys or when password is provided.
Fixes #802