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

fix: Add PackageLicenseExpression for /src #236

Merged
merged 9 commits into from
Nov 23, 2023

Conversation

bartelink
Copy link
Contributor

@bartelink bartelink commented Nov 22, 2023

Applies a PackageLicenseExpression to projects under /src tree, in order that this information pass through to the emitted .nupkg files.

The field is used by automated security vulnerability scanning tools to avoid having to parse a potentially ambiguous license file. I believe this to be standard practice in recent years:

@bartelink
Copy link
Contributor Author

bartelink commented Nov 22, 2023

Key differences this makes:

  1. it prevents triggering Unknown License Identified alerts in commercial vulnerability scanners
  2. nuget provides a direct link (i.e. the third link is only available for the FsCodec version with the expression included)
image

Copy link
Collaborator

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

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

Thank you! I didn't realize PackageLicenseFile wasn't enough.

@TheAngryByrd
Copy link
Collaborator

Hmm, looks like this doesn't mix well.

Error: /usr/share/dotnet/sdk/7.0.404/Sdks/NuGet.Build.Tasks.Pack/buildCrossTargeting/NuGet.Build.Tasks.Pack.targets(221,5): error NU5033: Invalid metadata. Cannot specify both a PackageLicenseExpression and a PackageLicenseFile.

@bartelink
Copy link
Contributor Author

bartelink commented Nov 22, 2023

Ah, doh! I'll research how to resolve it later...

(I actually made the change locally in a clone but neglected to try to build it, 🤦)

@bartelink
Copy link
Contributor Author

  • It seems the correct resolution is to include the file in the package, but switch to PackageLicenseExpression.
  • It also seems adding a Copyright (which will flow through to the nuget) is generally the done thing - but should that specify demystifp or something else (is there a CLA?). FSharp.Control.TaskSeq uses <Copyright>Copyright 2023</Copyright>, but the license file names Abel (and uses 2022)

Will have a deeper read to understand the nuance though. e.g. microsoft/MSBuildSdks#312

I'll work on the assumption you want to preserve the inclusion of the license file in the nupkg (though FSharp.Control.TaskSeq does not do that)

cc @abelbraaksma did you have a particular reasoning for not including the license in the package and/or are you aware of a convention? Or, if you want me to do a PR to align FS.C.TS with this (i.e. include the MIT license file in the nupkg?)

@TheAngryByrd
Copy link
Collaborator

I'll work on the assumption you want to preserve the inclusion of the license file in the nupkg

It doesn't matter that much to me but it's more surprising, that since this is a typical scenario of including the file, the scanner you're using can't support it.

@bartelink
Copy link
Contributor Author

bartelink commented Nov 22, 2023

I believe the TL;DR of the issue is that the NuGet PackageLicenseExpression assertion is more complete; it's saying "no need to parse the text of any license - the author of the package has, by specifying it this way, made an assertion that all licensing end to end is in compliance with the definition of that license", thus adding the PLE means that the link from FsCodec's nuget page is to https://licenses.nuget.org/Apache-2.0, not to the license text.

That means that the scanner software and/or people leaning on the conclusions it draws are "not on the hook for" and/or having to having to lean on the heuristics such as those used in the rendering of https://github.com/demystifyfp/FsToolkit.ErrorHandling/blob/master/License which presumably does some form of textual comparison that's tolerant of whitespace diffs and a copyright clause at the top (though IIRC it ignores stuff after too, which would probably give Lawyers kittens).

The PLEs are references to https://spdx.org/licenses/

FWIW the scanner in question is Black Duck, but I have no reason to believe that it's unique in following this approach.

@TheAngryByrd
Copy link
Collaborator

I get it's a lot easier to just look for a key in a xml file than doing all the extra work, it's just strange to me that tool lacks some ability for this since there's 45k results in a naive search across github with people using PackageLicenseFile.

https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5033
Use one or the other. If you are using a well known license that's part of the standard license list, consider using an expression. Otherwise please use a license file.

Yeah just remove the license file from the packing.

@bartelink
Copy link
Contributor Author

Yeah just remove the license file from the packing.

Thanks, Will do (later)

I get it's a lot easier to just look for a key in a xml file than doing all the extra work, it's just strange to me that tool lacks some ability for this since there's 45k results in a naive search across github with people using PackageLicenseFile.

I suspect the reason for that it is primarily that it's a relatively recent addition to NuGet's tooling.

And I definitely agree that scanners can be assess, and there needs to be reasonable pushback e.g. serilog/serilog-sinks-console#145 (comment)

But it is pretty clear that this is the correct path for packages on mainstream licenses: https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/nuget#important-nuget-package-metadata

@bartelink
Copy link
Contributor Author

OK, applied https://learn.microsoft.com/en-us/nuget/create-packages/package-authoring-best-practices
Pretty much every one of these settings/policies are applied consistently on active github.com/jet projects

<IsTestProject>false</IsTestProject>
<PackageTags>f#;fsharp;railway oriented programming;ROP;result type;error handling</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile> <!--https://docs.microsoft.com/en-gb/nuget/reference/msbuild-targets#packagereadmefile -->
<PackageTags>f#, fsharp, railway oriented programming, ROP, result type, error handling</PackageTags>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

<IsTestProject>false</IsTestProject>
<PackageTags>f#;fsharp;railway oriented programming;ROP;result type;error handling</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile> <!--https://docs.microsoft.com/en-gb/nuget/reference/msbuild-targets#packagereadmefile -->
<PackageTags>f#, fsharp, railway oriented programming, ROP, result type, error handling</PackageTags>
<!-- Sourcelink -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These settings can be consolidated via DotNet.ReproducibleBuilds which @baronfel introduced me to, e.g. https://github.com/jet/equinox/blob/master/Directory.Build.props#L19C39-L19C57

But that's a step too far for this PR/batch of changes in this space

@@ -6,7 +6,7 @@
<LangVersion>preview</LangVersion>
<DebugType>portable</DebugType>

<PackageTags>($PackageTags);fable-library;fable-dotnet;fable-javascript;fable-python</PackageTags>
<PackageTags>$(PackageTags), fable-library, fable-dotnet, fable-javascript, fable-python</PackageTags>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bartelink
Copy link
Contributor Author

bartelink commented Nov 23, 2023

OK, I think I'm happy with this as it is now
Ping me when it releases and I'll do a validation of
a) the "shut up the scanner" objective being achieved
b) everything else looking correct on nuget

Note there's no rush on merging and/or releasing - we'll feed it through as and when it happens

And finally, thanks for the stewardship of the project; as a newcomer to the project in recent times I've found the docs do a good job in general

Copy link
Collaborator

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

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

Thank you for fixing up all those other places too!

@TheAngryByrd TheAngryByrd merged commit bdf075b into demystifyfp:master Nov 23, 2023
25 checks passed
@bartelink bartelink deleted the patch-1 branch November 23, 2023 11:19
TheAngryByrd added a commit that referenced this pull request Nov 23, 2023
- [fix: Add PackageLicenseExpression for /src](#236) Credits @bartelink
- [Fix netstandard2 package version drift](#237) Credits @TheAngryByrd
@bartelink
Copy link
Contributor Author

Thanks for the release - I can confirm the scan is now clear, and the NuGet listing looks like everything has percolated correctly

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.

2 participants