fix(certificate): guard against nil GetCertificateContext response in Update#174
Merged
spbsoluble merged 2 commits intoJun 30, 2026
Conversation
… Update The Update path called GetCertificateContext and, when it returned (nil, err), only logged a warning via hasAPIErrors before dereferencing certGetResp.ContentBytes — causing a SIGSEGV nil-pointer dereference during terraform apply (observed when flipping certificate_format to PFX on an in-place update). The Read path was hardened with certGetResp != nil guards in v2.9.0, but Update was missed. Update now returns a clean diagnostic error and bails out when the certificate GET fails or returns a nil response, before any dereference. All subsequent certGetResp accesses in Update were already nil-guarded. Adds TestUnitKeyfactorCertificateResource_UpdateNilGetResponse, an httptest-backed regression test that drives Update with a failing certificate GET and asserts a diagnostic error is surfaced instead of a panic.
…scoped diagnostic Add ERR_SUMMARY_CERTIFICATE_RESOURCE_UPDATE and use it in the defensive certGetResp == nil guard in Update, so the update path no longer borrows the read-path diagnostic summary. Correct the regression test's docstring/comments to describe what is actually exercised (GET 500 -> hasAPIErrors early return, not the format-change/parseLeafCert path) and note the certGetResp == nil guard is belt-and-suspenders for a (nil, nil) response not reproducible via the httptest harness. Trim the plan to only the fields load-bearing before the early return.
spbsoluble
merged commit Jun 30, 2026
8ee68c8
into
fix/template-role-binding-pagination
6 of 8 checks passed
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.
Summary
Fixes a confirmed
SIGSEGVnil-pointer-dereference crash in thekeyfactor_certificateresource's Update path. Reported against provider v2.8.1; the same unguarded code
path is present in v2.9.0 (released), v2.9.1-rc.0, and
v2— so this gates a cleanv2.9.1.
Crash
Triggered during an in-place update of an existing certificate (a
certificate_formatchange to
PFX) when the contextGET /Certificates/{id}fails or returns nil.Root cause
In
Update,hasAPIErrorslogged a warning but did not return, after which the codeimmediately dereferenced
certGetResp.ContentBytesinparseLeafCert. WhenGetCertificateContextreturned(nil, err)— e.g. a transient/remote API error,permission/key-recovery rejection, or an unretrievable cert — the nil deref crashed the
whole provider instead of surfacing the API error.
The Read path was hardened with
certGetResp != nilguards in v2.9.0; the samehardening was never applied to Update.
Fix
hasAPIErrors(GET errored), log and return —hasAPIErrorsalready appended theerror diagnostic.
certGetResp == nilguard that surfaces an explicitERR_SUMMARY_CERTIFICATE_RESOURCE_READdiagnostic and returns (covers the(nil, nil)case).
certGetResp.access through the end ofUpdate: all remaining accessesafter the early return were already nil-guarded (
checkCertDiagsis internally nil-safe;the
IsPendingRevocation,RevocationEffDate, and key-recovery blocks all usecertGetResp != nil &&). No second landmine.Regression test
TestUnitKeyfactorCertificateResource_UpdateNilGetResponse(unit, no lab) stands up anhttptestTLS server returning HTTP 500 onGET /Certificates/..., sets a PFX Plan over aPEM State, and calls
Updateinside a deferredrecoverso any panic fails the test.Asserts a clean diagnostic instead of a crash.
FAIL — Update panicked (nil-deref regression): runtime error: invalid memory address or nil pointer dereferencePASSgo build ./...clean;gofmtclean; fullTestUnitKeyfactorCertificate*suite passes.Notes
fix/template-role-binding-pagination(stacks on top of fix: paginate template lookup for keyfactor_template_role_binding #173) per request.