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

NuGetPackageDownloader: Stop verifying the package signature on Mac and queue off of the environment on Linux #47321

Merged
merged 8 commits into from
Mar 9, 2025

Conversation

edvilme
Copy link
Member

@edvilme edvilme commented Mar 6, 2025

Fixes #46857
Customer Scenario
dotnet tool install/restore is checking the package signature on Mac with 9.0.200. However, we shouldn't be doing that as macos doesn't fully support the signature store that nuget uses to verify signatures. This is already disabled for nuget restore.

Fix
Match the logic NuGet uses where we are always on for windows, default off for Mac, default on for Linux, and honor the env variable to override the values.

Justification
There are half a dozen customer comments on the linked issues saying they are blocked in 9.0.200.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Workloads untriaged Request triage from a team member labels Mar 6, 2025
@edvilme edvilme force-pushed the edvilme-tool-mac-sign branch from 023840e to 2cd84a8 Compare March 6, 2025 23:34
@edvilme edvilme changed the base branch from main to release/9.0.2xx March 6, 2025 23:34
@edvilme edvilme marked this pull request as ready for review March 6, 2025 23:37
@Copilot Copilot bot review requested due to automatic review settings March 6, 2025 23:37

Choose a reason for hiding this comment

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

PR Overview

This PR updates the NuGetPackageDownloader to disable signature verification on macOS and Linux by ensuring that the _verifySignatures flag is only true when running on Windows.

  • Added documentation comments to describe the temporary disabling of signature verification on non-Windows OSes.
  • Updated the constructor to combine the verifySignatures parameter with an OperatingSystem check.

Reviewed Changes

File Description
src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs Modified _verifySignatures initialization to disable signature verification on macOS and Linux; added documentation comments explaining the change.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

@@ -65,7 +69,7 @@ public NuGetPackageDownloader(
_restoreActionConfig = restoreActionConfig ?? new RestoreActionConfig();
_retryTimer = timer;
_sourceRepositories = new();
_verifySignatures = verifySignatures;
_verifySignatures = OperatingSystem.IsWindows() && verifySignatures; // This is temporarily disabled for macOS and Linux.
Copy link
Member

Choose a reason for hiding this comment

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

@dtivel should signature verification on linux be kept and only Mac disabled?

Copy link
Member

@nagilson nagilson Mar 7, 2025

Choose a reason for hiding this comment

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

It looks like we should enable it on Linux based on this doc https://learn.microsoft.com/en-us/dotnet/core/tools/nuget-signed-package-verification#linux. However, there is also an environment variable which seems to control this, so maybe we should base the check off the environment variable. I assume this is OFF by default on Mac, but that doesn't seem to be the case based on the code below. If we don't respect DOTNET_NUGET_SIGNATURE_VERIFICATION, this may be a breaking change since it impacts more than dotnet tool.

We have some logic for this

internal static readonly string DotNetNuGetSignatureVerification = "DOTNET_NUGET_SIGNATURE_VERIFICATION";
but that just forwards the environment variable to NuGet. I assume they do most of the processing. @dtivel Should this logic to turn it on by default
return string.Equals(bool.FalseString, value, StringComparison.OrdinalIgnoreCase)
only be true on Linux and Windows, which also might fix this bug?

Copy link
Member

@nagilson nagilson Mar 7, 2025

Choose a reason for hiding this comment

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

Ok this code ignores the env var if its not linux.
Its possible that A - did this environment variable never work correctly? And nobody realized because nobody is using it as true on mac because it doesn't work anyway, and maybe its enabled by default somewhere else on Windows.

B- the point of that class is not to be a source of truth for the verification enablement but just a way to enable it by default on Linux without touching other stuff

We'd still have to respect it on Linux, though

Copy link
Contributor

Choose a reason for hiding this comment

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

Matching NuGet's signed package verification support is sensible.

  1. Always enabled on Windows. DOTNET_NUGET_SIGNATURE_VERIFICATION is ignored.
  2. Enabled on Linux by default. Users can opt out by setting DOTNET_NUGET_SIGNATURE_VERIFICATION to false.
  3. Disabled on macOS by default. Users can opt in by setting DOTNET_NUGET_SIGNATURE_VERIFICATION to true, but this is neither recommended nor supported.

https://github.com/dotnet/sdk/blob/main/src/Cli/dotnet/NuGetSignatureVerificationEnabler.cs does the work of enabling on Linux by default.

https://github.com/NuGet/NuGet.Client/blob/594bfe4554893a7364d9ec1d31a22574fba3115c/src/NuGet.Core/NuGet.Packaging/PackageArchiveReader.cs#L519-L557 is where NuGet respects the environment variable. The problem is that FirstPartyNuGetPackageSigningVerifier opens a package and verifies its signature without checking if it's safe to verify signatures.

You should perform this "can verify signatures" check before deciding that you to verify signatures or you risk deviating from what NuGet supports.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the context. I think for this change, a reasonable option would then be to enable it if on windows || by checking the NuGetSignatureVerificationEnabler.cs
on linux to see if it should be turned on, on linux.

Then in the future we could improve the rest of this like mentioned above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that seems reasonable.

PackageArchiveReader.CanVerifySignedPackages(...) is a bit inconvenient. It doesn't access instance members and could have been a static method somewhere. You could open an issue on NuGet/Home for a more convenient "is signed package verification enabled" method.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. I just didn't want to disable this check on Linux if it were working as that would be a security takeback.

Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

...other than the linux thing

@edvilme edvilme enabled auto-merge (squash) March 7, 2025 23:39
@Forgind Forgind disabled auto-merge March 7, 2025 23:55
@edvilme edvilme changed the title NuGetPackageDownloader: Only verify signing on windows NuGetPackageDownloader: Only verify signing on windows by default Mar 8, 2025
@edvilme edvilme requested a review from Forgind March 8, 2025 00:46
edvilme and others added 2 commits March 7, 2025 22:02
Co-authored-by: Noah Gilson <OTAKUPENGUINOP@GMAIL.COM>
Co-authored-by: Forgind <12969783+Forgind@users.noreply.github.com>
@edvilme edvilme force-pushed the edvilme-tool-mac-sign branch from 7e3beb0 to 8b6ec3a Compare March 8, 2025 04:02
Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

Looks good! 🚢

@edvilme edvilme merged commit f6c2a6e into dotnet:release/9.0.2xx Mar 9, 2025
30 checks passed
@marcpopMSFT marcpopMSFT changed the title NuGetPackageDownloader: Only verify signing on windows by default NuGetPackageDownloader: Stop verifying the package signature on Mac and queue off of the environment on Linux Mar 11, 2025
@edvilme
Copy link
Member Author

edvilme commented Mar 11, 2025

/backport to release/10.0.xx-preview2

Copy link
Contributor

Started backporting to release/10.0.xx-preview2: https://github.com/dotnet/sdk/actions/runs/13794782769

Copy link
Contributor

@edvilme an error occurred while backporting to "release/10.0.xx-preview2", please check the run log for details!

Error: The specified backport target branch "release/10.0.xx-preview2" wasn't found in the repo.

@edvilme
Copy link
Member Author

edvilme commented Mar 11, 2025

/backport to release/10.0.1xx-preview2

Copy link
Contributor

Started backporting to release/10.0.1xx-preview2: https://github.com/dotnet/sdk/actions/runs/13794799185

Copy link
Contributor

@edvilme backporting to "release/10.0.1xx-preview2" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: NuGetPackageDownloader: Only verify signing on windows
Applying: Update comments
error: sha1 information is lacking or useless (src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0002 Update comments
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

edvilme added a commit to edvilme/sdk that referenced this pull request Mar 11, 2025
…tnet#47321)

Co-authored-by: Noah Gilson <OTAKUPENGUINOP@GMAIL.COM>
Co-authored-by: Forgind <12969783+Forgind@users.noreply.github.com>
@marcpopMSFT marcpopMSFT added this to the 9.0.4 milestone Mar 11, 2025
dotnet-bot pushed a commit that referenced this pull request Mar 18, 2025
…ws by default (#47321)

NuGetPackageDownloader: Only verify signing on windows by default (#47321)

Co-authored-by: Noah Gilson <OTAKUPENGUINOP@GMAIL.COM>
Co-authored-by: Forgind <12969783+Forgind@users.noreply.github.com>

----
#### AI description  (iteration 1)
#### PR Classification
Bug fix to ensure package signing verification is only performed on Windows by default.

#### PR Summary
This pull request modifies the `NuGetPackageDownloader` to verify package signing only on Windows by default, with an option to enable it on other operating systems via an environment variable.
- `src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs`: Added logic to conditionally verify package signatures based on the operating system and environment variable. Introduced error handling to delete the package file if verification fails.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Workloads Servicing-approved untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotnet tool restore started failing on macOS with NU3037 and NU3028 errors after 11th February
6 participants