Skip to content

Commit

Permalink
Enable wrapper-validation by default in setup-gradle (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz authored Aug 1, 2024
2 parents 479297d + 73f1290 commit 06905c7
Show file tree
Hide file tree
Showing 20 changed files with 559 additions and 51 deletions.
5 changes: 5 additions & 0 deletions .github/actions/init-integ-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ runs:
distribution: 'temurin'
java-version: 11

- name: Configure environment
shell: bash
run: |
echo "ALLOWED_GRADLE_WRAPPER_CHECKSUMS=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" >> "$GITHUB_ENV"
# Downloads a 'dist' directory artifact that was uploaded in an earlier 'build-dist' step
- name: Download dist
if: ${{ env.SKIP_DIST != 'true' && !env.ACT }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integ-test-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- name: Run wrapper-validation-action
id: setup-gradle
uses: ./setup-gradle
with:
validate-wrappers: true
env:
ALLOWED_GRADLE_WRAPPER_CHECKSUMS: ''
continue-on-error: true

- name: Check failure
Expand Down
15 changes: 15 additions & 0 deletions dependency-submission/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ inputs:
description: The Develocity short-lived access tokens expiry in hours. Default is 2 hours.
required: false

# Wrapper validation configuration
validate-wrappers:
description: |
When 'true' the action will automatically validate all wrapper jars found in the repository.
If the wrapper checksums are not valid, the action will fail.
required: false
default: false

allow-snapshot-wrappers:
description: |
When 'true', wrapper validation will include the checksums of snapshot wrapper jars.
Use this if you are running with nightly or snapshot versions of the Gradle wrapper.
required: false
default: false

# DEPRECATED ACTION INPUTS

# EXPERIMENTAL ACTION INPUTS
Expand Down
20 changes: 18 additions & 2 deletions docs/setup-gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,30 @@ Since Gradle applies init scripts in alphabetical order, one way to ensure this

## Gradle Wrapper validation

Instead of using the [wrapper-validation action](./wrapper-validation.md) separately, you can enable
wrapper validation directly in your Setup Gradle step.
By default, this action will perform the same wrapper validation as is performed by the dedicated
[wrapper-validation action](./wrapper-validation.md).
This means that invalid wrapper jars will be automatically detected when using `setup-gradle`.

If you do not want wrapper-validation to occur automatically, you can disable it:

```yaml
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
validate-wrappers: false
```

If your repository uses snapshot versions of the Gradle wrapper, such as nightly builds, then you'll need to
explicitly allow snapshot wrappers in wrapper validation.
These are not allowed by default.


```yaml
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
validate-wrappers: true
allow-snapshot-wrappers: true
```

If you need more advanced configuration, then you're advised to continue using a separate workflow step
Expand Down
23 changes: 15 additions & 8 deletions docs/wrapper-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This action validates the checksums of _all_ [Gradle Wrapper](https://docs.gradl

The action should be run in the root of the repository, as it will recursively search for any files named `gradle-wrapper.jar`.

The `setup-gradle` action will perform wrapper validation on each execution. If you are using `setup-gradle` in your
workflows, it is unlikely that you will need to use this action.

## The Gradle Wrapper Problem in Open Source

The `gradle-wrapper.jar` is a binary blob of executable code that is checked into nearly
Expand Down Expand Up @@ -90,18 +93,22 @@ We recommend the message commit contents of:

From there, you can easily follow the rest of the prompts to create a Pull Request against the project.

## Reporting Failures
## Validation Failures

If this GitHub action fails because a `gradle-wrapper.jar` doesn't match one of our published SHA-256 checksums,
we highly recommend that you reach out to us at [security@gradle.com](mailto:security@gradle.com).
A wrapper jar can fail validation for a few reasons:
1. The wrapper is from a snapshot build of Gradle (nightly or release nightly) and you have not set `allow-snapshots`
or `allow-snapshot-wrappers` to `true`.
2. The wrapper jar is from a version of Gradle with an unverifiable wrapper jar (see below).
3. The wrapper jar was not published by Gradle, and could be compromised.

**Note:** `gradle-wrapper.jar` generated by Gradle 3.3 to 4.0 are not verifiable because those files were dynamically generated by Gradle in a non-reproducible way. It's not possible to verify the `gradle-wrapper.jar` for those versions are legitimate using a hash comparison. You should try to determine if the `gradle-wrapper.jar` was generated by one of these versions before running the build.
If this GitHub action fails because a `gradle-wrapper.jar` was not published by Gradle,
we highly recommend that you reach out to us at [security@gradle.com](mailto:security@gradle.com).

If the Gradle version in `gradle-wrapper.properties` is out of this range, you may need to regenerate the `gradle-wrapper.jar` by running `./gradlew wrapper`. If you need to use a version of Gradle between 3.3 and 4.0, you can use a newer version of Gradle to generate the `gradle-wrapper.jar`.
#### Unverifiable Wrapper Jars
Wrapper Jars generated by Gradle versions `3.3` to `4.0` are not verifiable because those files were dynamically generated by Gradle in a non-reproducible way. It's not possible to verify the `gradle-wrapper.jar` for those versions are legitimate using a hash comparison. If you have a validation failure, you should try to determine if the `gradle-wrapper.jar` was generated by one of these versions before running the build.

If you're curious and want to explore what the differences are between the `gradle-wrapper.jar` in your possession
and one of our valid release, you can compare them using this online utility: [diffoscope](https://try.diffoscope.org/).
Regardless of what you find, we still kindly request that you reach out to us and let us know.
- If the Gradle version in `gradle-wrapper.properties` is outside of this range, you can regenerate the `gradle-wrapper.jar` by running `./gradlew wrapper`. This will generate a new, verifiable wrapper jar.
- If you need to run your build with a version of Gradle between 3.3 and 4.0, you can use a newer version of Gradle to generate the `gradle-wrapper.jar`.

## Resources

Expand Down
9 changes: 8 additions & 1 deletion setup-gradle/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,16 @@ inputs:
# Wrapper validation configuration
validate-wrappers:
description: |
When 'true', the action will perform the 'wrapper-validation' action automatically.
When 'true' (the default) the action will automatically validate all wrapper jars found in the repository.
If the wrapper checksums are not valid, the action will fail.
required: false
default: true

allow-snapshot-wrappers:
description: |
When 'true', wrapper validation will include the checksums of snapshot wrapper jars.
Use this if you are running with nightly or snapshot versions of the Gradle wrapper.
required: false
default: false

# DEPRECATED ACTION INPUTS
Expand Down
Loading

0 comments on commit 06905c7

Please sign in to comment.