Repository navigation
🐛 Log certificates that follow a non-certificate PEM block - #3217
openshift-merge-bot[bot] merged 2 commits into
Conversation
logPem, used by NewCertPool at startup and by LogDockerCertificates after a TLS verification failure, called x509.ParseCertificate on every PEM block. When a file starts with a PRIVATE KEY block (as testdata/certs/good/Amazon_Root_CA_3.pem does, and as client.cert / client.key pairs in a certs.d directory commonly do), it logged "error in x509.ParseCertificate()" and stopped, so the certificate that x509.CertPool.AppendCertsFromPEM did load was never logged. Skip blocks whose type is not CERTIFICATE, the same way AppendCertsFromPEM does, and log them at the debug level instead. Add tests for the certificate logging helpers, which had none: NewCertPool and LogDockerCertificates log every certificate without error lines, LogDockerCertificates handles missing directories, empty files, subdirectories and non-directory entries, and LogCertificateVerificationError detects direct and wrapped tls.CertificateVerificationError values. Signed-off-by: Andre Devay <andretorresdg@alumni.usp.br>
👷 Deploy request for olmv1 pending review.Visit the deploys page to approve it
|
| // Skip private keys and other non-certificate blocks, as | ||
| // x509.CertPool.AppendCertsFromPEM does. | ||
| if block.Type != "CERTIFICATE" { | ||
| log.V(defaultLogLevel).Info("skipping non-certificate PEM block", "file", filename, "type", block.Type) | ||
| continue | ||
| } |
There was a problem hiding this comment.
I do wonder if we should still error out on unknown block.Type. But for the time-being this is ok.
There was a problem hiding this comment.
There's no explicit test here for the "skipping non-certificate PEM block" log message.
Signed-off-by: Andre Devay <andretorresdg@alumni.usp.br>
|
Thanks for the review. Pushed 7a92762: On erroring out for unknown block types: I kept the skip so that logging matches what |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: tmshort The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm |
edcd779
into
operator-framework:main
Description
logPemininternal/shared/util/http/certlog.gois used byNewCertPool(throughCertPoolWatcher, for the--catalogd-cas-dirand--pull-cas-dirdirectories, at startup and whenever they change) and byLogDockerCertificates(after an image pull fails TLS verification). It callsx509.ParseCertificateon every PEM block. If a file has a non-certificate block before the certificate, for example aPRIVATE KEYblock as intestdata/certs/good/Amazon_Root_CA_3.pem, or a combined key+certificate file in acerts.d/<host>directory, it logserror in x509.ParseCertificate()at error level and returns. The certificate thatx509.CertPool.AppendCertsFromPEMdid load from that file is then never logged, and the error message suggests the file is broken when it is not.This change skips blocks whose type is not
CERTIFICATE(asAppendCertsFromPEMdoes) and logs them at the debug level (V(4)), with only the block type.There were no tests for
certlog.go. This addscertlog_test.gowith afuncrlogger that captures V(4) output:NewCertPoolontestdata/certs/goodlogs a certificate for each of the three files and logs no errors (fails before the fix forAmazon_Root_CA_3.pem);LogDockerCertificateson a temporarycerts.dlayout logsca.crtand a key+certificateclient.cert, reports the empty file, ignores the subdirectory and the top-level non-directory, and logs no errors (fails before the fix forclient.cert);LogDockerCertificateslogs an error for a missing directory;LogCertificateVerificationErrorreturns false for nil and unrelated errors, and true (with one log line per unverified certificate) for a direct or wrapped*tls.CertificateVerificationError.How I tested
go test ./internal/shared/util/http/:TestNewCertPoolLogsCertificatesAfterNonCertificateBlocksandTestLogDockerCertificatesfail without the fix (the log shows"msg"="error in x509.ParseCertificate()" "error"="x509: malformed certificate" "file"="Amazon_Root_CA_3.pem"and no certificate line for that file) and pass with it. The whole package passes with-race.go tool golangci-lint run ./internal/shared/util/http/...: 0 issues.Reviewer Checklist
Summary by CodeRabbit