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

feat(ci): add slsa provenance for release artifacts #263

Merged
merged 4 commits into from
Sep 28, 2022

Conversation

behnazh-w
Copy link
Contributor

The Open Source Security Foundation has been developing a standard for supply chain security called SLSA to allow users of open source projects to verify the artifacts and their build pipelines. To make that possible, the release pipelines should generate a provenance that provides verifiable information about how the software artifacts are built.

This PR adds a reusable GitHub Actions workflow to generate the provenance and publish that together with the artifacts as GitHub release artifacts. This would help users verify that the release artifacts are built from the release.yml workflow and not somewhere else. You can read more about this provenance generator here.

Looking forward to the feedback and discussions.

@CLAassistant
Copy link

CLAassistant commented Sep 7, 2022

CLA assistant check
All committers have signed the CLA.

./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
# Publish both locally and to Sonatype.
# The artifacts stored locally will be used to generate the SLSA provenance.
./gradlew publishToMavenLocal publishToSonatype closeAndReleaseSonatypeStagingRepository
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of publishing to maven local, which may (will) be polluted by many unrelated artifacts, you can use publishToBuildRepository. This will create a Maven-like repository in $ROOT/build/repo which will contain all the artifacts you want (plus the metadata files, pom, Gradle .module, version catalog, etc.).

Copy link
Contributor Author

@behnazh-w behnazh-w Sep 8, 2022

Choose a reason for hiding this comment

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

Instead of publishing to maven local, which may (will) be polluted by many unrelated artifacts, you can use publishToBuildRepository.

Thanks @melix. When I use publishToBuildRepository locally, it tries to authenticate with ge.micronaut.io:

A build scan was not published as you have not authenticated with server 'ge.micronaut.io'.
* What went wrong:
For more information, please see https://gradle.com/help/gradle-authenticating-with-gradle-enterprise.
Task 'publishToBuildRepository' not found in root project 'micronaut'.

Is there a way to use it locally for testing without authenticating?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry, this error is unrelated. It says that it won't publish a build scan on ge.micronaut.io, but this isn't the cause of the problem, it's because I used the wrong task name, it's publishAllPublicationsToBuildRepository (you can also use pAPTBR).

Copy link
Contributor Author

@behnazh-w behnazh-w Sep 9, 2022

Choose a reason for hiding this comment

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

Thanks @melix . Changed in commit bf15270.

# The artifacts stored locally will be used to generate the SLSA provenance.
./gradlew publishToMavenLocal publishToSonatype closeAndReleaseSonatypeStagingRepository
# Read the current version from gradle.properties.
VERSION=$(./gradlew properties | grep 'version:' | awk '{print $2}')
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be wrong, but I think that if you use the publishToBuildRepository task, then you don't need to search for the group or version anymore, and you can use the build/repo directory as the upload source for GH.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I still need to read the group because I need to resolve the path to the artifacts for uploading them as artifacts. The path can be different in different repositories that use this template.

I read the version just to make sure the artifacts are collected from the right path, but that is just to be extra cautious.

@behnazh-w
Copy link
Contributor Author

The final release artifacts would look something like this on micronaut-core for example:
image

It adds the provenance as attestation.intoto.jsonl and separate zip files for each module's artifacts. The user would need to unzip and verify the provenance against the unzipped artifacts.

@sdelamo @melix please let me know if it looks good or you have any questions.

@alvarosanchez
Copy link
Member

IMO that would clutter the release assets section. Is it possible to package all the ZIPs into a single archive?

# the provenance will attest to the artifact files and not the aggregated zip file.
run: |
ARTIFACTS=""
for dir in dist/* ; do
Copy link
Contributor

Choose a reason for hiding this comment

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

I seems a bit strange to look for the artifacts in build/repo, but then use those in dist for uploading. I think we should use build/repo for both. Also I agree with @alvarosanchez that it would be nice if we had a single zip, with possibly nested zips in it.

If it helps we could even have a Gradle task to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should use build/repo for both.

Sure, I'll change that.

@behnazh-w
Copy link
Contributor Author

@alvarosanchez

IMO that would clutter the release assets section. Is it possible to package all the ZIPs into a single archive?

@melix

Also I agree with @alvarosanchez that it would be nice if we had a single zip, with possibly nested zips in it.

I can definitely wrap all ZIP files in a single archive. But I thought having separate archives immediately shows to the end user that for example micronaut-core is generating 35 artifacts. So it's more transparent. Do you see any value in that?

@melix
Copy link
Contributor

melix commented Sep 12, 2022

I can definitely wrap all ZIP files in a single archive. But I thought having separate archives immediately shows to the end user that for example micronaut-core is generating 35 artifacts. So it's more transparent. Do you see any value in that?

I don't think users really care. In practice, you don't select each artifact separately, you'll likely depend on micronaut-core, which is going to bring a number of other artifacts transitively. Then, when you bundle the app, you can take a look at the artifacts you got and search for provenance. Ideally we should end up with tooling (e.g Gradle) doing this for us, once there's a standard way to get this information for each artifact.

@behnazh-w
Copy link
Contributor Author

behnazh-w commented Sep 15, 2022

I can definitely wrap all ZIP files in a single archive. But I thought having separate archives immediately shows to the end user that for example micronaut-core is generating 35 artifacts. So it's more transparent. Do you see any value in that?

I don't think users really care. In practice, you don't select each artifact separately, you'll likely depend on micronaut-core, which is going to bring a number of other artifacts transitively. Then, when you bundle the app, you can take a look at the artifacts you got and search for provenance. Ideally we should end up with tooling (e.g Gradle) doing this for us, once there's a standard way to get this information for each artifact.

@melix @alvarosanchez I've packaged all the artifacts into a single ZIP file. See commit 8938a2b.

@alvarosanchez alvarosanchez requested a review from melix September 21, 2022 10:02
.github/workflows/release.yml Outdated Show resolved Hide resolved
@melix melix merged commit 608ba93 into micronaut-projects:master Sep 28, 2022
timyates added a commit that referenced this pull request Nov 3, 2022
Due to an [ongoing issue](https://github.com/orgs/community/discussions/37942), Provenance regularly
fails when we are publishing a release.

We will remove it for now.

Revert "feat(ci): add slsa provenance for release artifacts (#263)"

This reverts commit 608ba93.
@timyates timyates mentioned this pull request Nov 3, 2022
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.

4 participants