Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCAN4NET-244 Add logging for ServerCertificateValidationChain #2324

Merged

Conversation

martin-strecker-sonarsource
Copy link
Contributor

@martin-strecker-sonarsource martin-strecker-sonarsource commented Feb 12, 2025

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title Add logging for ServerCertificateValidationChain SCAN4NET-244 Add logging for ServerCertificateValidationChain Feb 12, 2025
Comment on lines +189 to +194
logger.LogWarning(Resources.WARN_TrustStore_Chain_RootCertificateNotFound,
rootInChain.Certificate.Issuer,
rootInChain.Certificate.Thumbprint,
trustStoreFile,
SonarProperties.TruststorePath);
return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code path is untestable and likely unreachable (because it requires a exclusively "partial chain" error when the callback is invoked and a sub-sequent exclusively "untrusted root" error here which can only be achieved if the root ca is in the truststore file).

I would still keep the code path as is, just to be safe. If we ever encounter this in some logs, we can try to figure out the environment (most likely some OS specific scenario) in which this could happen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment there?

logger.AssertDebugLogged($"""
The remote server certificate is not trusted by the operating system. The scanner is checking the certificate against the certificates provided by the file '{trustStoreFile.FileName}' (specified via the sonar.scanner.truststorePath parameter or its default value).
""");
logger.Warnings.Should().ContainSingle(because: "the warning is either WARN_TrustStore_Chain_Invalid or WARN_TrustStore_OtherChainStatus depending on the environment.");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code path taken is different in CI and locally. It doesn't really matter what code path fails at the end, so having at least some warning is good enough).

See this CI failure for the two warnings that are issued locally and in CI:
https://dev.azure.com/sonarsource/DotNetTeam%20Project/_build/results?buildId=110200&view=logs&j=3635ba3c-75de-526b-7d9e-c1be443d4750&t=8957dee2-f992-5acc-d4ff-d7b1b1efb951&l=193

Copy link
Contributor

@sebastien-marichal sebastien-marichal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
I left an open question and a suggestion to mention the unreachable path inside the code.


* {x.StatusInformation.TrimEnd()}
"""), x => x.ToString()));
logger.LogWarning(Resources.WARN_TrustStore_OtherChainStatus, SonarProperties.TruststorePath, ChainStatusAsBulletList(chain));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have probably asked this before, my understanding is whenever we get an SSL trust issue, we will stop the execution of the scanner, then why do we log the messages as warnings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a warning followed by a terminating error next. I don't know what is best practice in such a case, but a warning seems fine to me.

Comment on lines +189 to +194
logger.LogWarning(Resources.WARN_TrustStore_Chain_RootCertificateNotFound,
rootInChain.Certificate.Issuer,
rootInChain.Certificate.Thumbprint,
trustStoreFile,
SonarProperties.TruststorePath);
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment there?

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
58.8% Coverage on New Code (required ≥ 95%)

See analysis details on SonarQube Cloud

@pavel-mikula-sonarsource pavel-mikula-sonarsource merged commit 5caa02c into feature/MMF_4168 Feb 13, 2025
14 of 15 checks passed
@pavel-mikula-sonarsource pavel-mikula-sonarsource deleted the Martin/SSL_LogServerCertErrors3 branch February 13, 2025 13:21
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.

3 participants