Skip to content

cert: fix GenerateCA returning nil error on self-signed cert failure - #2802

Open
bhuvan-somisetty wants to merge 2 commits into
kubearmor:mainfrom
bhuvan-somisetty:fix/cert-generateca-error-propagation
Open

cert: fix GenerateCA returning nil error on self-signed cert failure#2802
bhuvan-somisetty wants to merge 2 commits into
kubearmor:mainfrom
bhuvan-somisetty:fix/cert-generateca-error-propagation

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown

Purpose of PR?:

In the GenerateCA function in KubeArmor/cert/cert.go, when GenerateSelfSignedCert fails, the error was logged and swallowed, returning an empty CertBytes struct with a nil error value (return &CertBytes{}, nil). Calling code was thus unable to detect certificate generation failures and proceeded with uninitialized or empty TLS certificates.

This change ensures that GenerateCA propagates the error returned by GenerateSelfSignedCert.

Fixes #2689

Does this PR introduce a breaking change?

No

If the changes in this PR are manually verified, list down the scenarios covered::

  1. Added unit test TestGenerateCA_Success verifying CA certificate generation under normal conditions.
  2. Added unit test TestGenerateCA_ErrorPropagationOnSelfSignedCertFailure verifying that errors during self-signed certificate creation are properly returned to the caller.

Checklist:

@bhuvan-somisetty

Copy link
Copy Markdown
Author

Hi @Aryan-sharma11 @achrefbensaad @AryanBakliwal @daemon1024 @nyrahul — could someone please take a look at this PR when you get a chance? It fixes #2689 by propagating errors from GenerateSelfSignedCert in GenerateCA() rather than swallowing them. Also added unit tests in cert_test.go. Thanks!

@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix/cert-generateca-error-propagation branch 2 times, most recently from 0afc753 to 0a80103 Compare July 24, 2026 22:13
Comment thread KubeArmor/cert/cert.go
Comment thread KubeArmor/cert/cert_test.go Outdated
When GenerateSelfSignedCert failed inside GenerateCA, the error was logged
and discarded, returning &CertBytes{} with a nil error. This caused callers to
mistakenly treat CA generation failures as successful.

Propagate the error returned by GenerateSelfSignedCert when self-signed certificate
generation fails, ensuring calling code receives error notifications.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
…onfig in tests

Address review feedback:

- GenerateCA now logs the self-signed cert failure before returning the
  error, matching the logging style used elsewhere in the file.
- cert tests take a value copy of DefaultKubeArmorCAConfig instead of
  taking its address, so the package-level default is not mutated for
  the rest of the test process.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
@AryanBakliwal
AryanBakliwal force-pushed the fix/cert-generateca-error-propagation branch from c547c44 to 36d809e Compare August 19, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cert/cert.go: GenerateCA returns nil error on self-signed cert generation failure

4 participants