Repository navigation
🐛 Log certificates that follow a non-certificate PEM block - #3217
Open
andretorresdg wants to merge 1 commit into
Open
andretorresdg wants to merge 1 commit into
andretorresdg wants to merge 1 commit 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
|
|
[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 branch has not been deployed
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
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