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

Avoid alerting CG when an intermediate nupkg contains "vulnerable" dependencies #13935

Merged

Conversation

mmitche
Copy link
Member

@mmitche mmitche commented Aug 1, 2023

This change resolves dotnet/source-build#3559.

When a repo restores the source build intermediates and places them in the package cache, it's essentially populating a local nuget feed. This feed should as a set of packages that may be used, but are not necessarily used. When a package is restored from this feed, it is extracted and appears in the package root. Component Detection, unfortunately, picks up any .nupkg file that exists under the source or artifacts directories, which picks up the local package cache, even if those packages are not used by the repo. This tends to generate noise for repos because of SBRP's contents.

To fix this issue, we apply two changes:

  • Delete the intermediate nupkg's extracted location after populating cache - The PackageReferences used to obtain the source build intermediates populate the nuget package root. We then copy the nupkg contents (nupkgs themselves) into the package cache. At this point, the original extracted nupkg is of no use. Deleting it removes one location where CG may detect .nupkgs that are available, but not necessarily used, by the repo.
  • Use an explicit CG scanning step that excludes the package cache - Alter the source-build template to exclude the package cache (local feed).

This leaves the nuget package root "cleaner" as it should contain only .nupkg files that are actually utilized by the repo, and detection will include only the packages that are actually used by the repo.

To double check:

…pendencies.

This change resolves dotnet/source-build#3559.

When a repo restores the source build intermediates and places them in the package cache, it's essentially populating a local nuget feed. This feed should as a set of packages that _may_ be used, but are not necessarily used. When a package is restored from this feed, it is extracted and appears in the package root. Component Detection, unfortunately, picks up any .nupkg file that exists under the source or artifacts directories, which picks up the local package cache, even if those packages are not used by the repo. This tends to generate noise for repos because of SBRP's contents.

To fix this issue, we apply two changes:
- Delete the intermediate nupkg's extracted location after populating cache - The PackageReferences used to obtain the source build intermediates populate the nuget package root. We then copy the nupkg contents (nupkgs themselves) into the package cache. At this point, the original extracted nupkg is of no use. Deleting it removes one location where CG may detect .nupkgs that are available, but not necessarily used, by the repo.
- Use an explicit CG scanning step that excludes the package cache - Alter the source-build template to exclude the package cache (local feed).

This leaves the nuget package root "cleaner" as it should contain only .nupkg files that are actually utilized by the repo, and detection will include only the packages that are actually used by the repo.
@mmitche mmitche force-pushed the delete-intermediate-dir-after-populating-cache branch from 1c3b051 to 2025b01 Compare August 1, 2023 23:14
@mmitche mmitche requested a review from a team August 1, 2023 23:15
oleksandr-didyk
oleksandr-didyk previously approved these changes Aug 2, 2023
@mmitche mmitche merged commit 769f8b1 into dotnet:main Aug 2, 2023
This was referenced Dec 7, 2023
mikem8361 pushed a commit to dotnet/diagnostics that referenced this pull request Dec 9, 2023
Prebuilt detection no longer detects Microsoft.SourceBuild.Intermediates
as prebuilts due to dotnet/arcade#13935.

Addresses dotnet/source-build#3010
rainersigwald pushed a commit to dotnet/msbuild that referenced this pull request Dec 12, 2023
Prebuilt detection no longer detects Microsoft.SourceBuild.Intermediates as prebuilts due to dotnet/arcade#13935.

Addresses dotnet/source-build#3010
@ViktorHofer
Copy link
Member

ViktorHofer commented Jan 9, 2024

Is it possible to backport this change into release/8.0? Asking as command-line-utils downgrades from Arcade 9 to Arcade 8 because of the .NET SDK requirement.

dotnet/command-line-api@a0782c8

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.

Devise a strategy to deal with component governance alerts from SBRP
4 participants