fix(x509): return errors instead of panicking on unusable key material#1776
Open
arpitjain099 wants to merge 1 commit into
Open
fix(x509): return errors instead of panicking on unusable key material#1776arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
The x509 signer dereferenced the result of pem.Decode without a nil check, so a x509.pem secret that does not contain a valid PEM block crashed the controller with a nil pointer panic. It also asserted the parsed key to *ecdsa.PrivateKey unconditionally, which panicked for any other PKCS8 key type (for example an ed25519 key). Both cases now return a descriptive error so a misconfigured signing secret surfaces as a normal failure rather than a crash. Adds tests for a malformed PEM file and an unsupported key type. Signed-off-by: arpitjain099 <arpitjain099@gmail.com>
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
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.
Changes
While reading through the x509 signer I noticed two spots where a bad signing secret takes down the controller with a panic instead of a normal error.
In
x509Signer, the result ofpem.Decodeis used without a nil check. When thex509.pemsecret does not contain a valid PEM block (an empty file, base64 without the PEM headers, etc.),pem.Decodereturns nil and the next line dereferences it, so the process crashes with a nil pointer panic. Right below that, the parsed key is asserted to*ecdsa.PrivateKeyunconditionally, which panics for any other PKCS8 key type such as an ed25519 key (the ed25519 signing test is currently skipped, so this path isn't otherwise exercised).Both now return a descriptive error, so a misconfigured signing secret shows up as a normal failure rather than a crash. I added a couple of tests covering a malformed PEM file and an unsupported key type, and I confirmed the existing x509 tests still pass along with
go vet.Release Notes