Skip to content

Add Gradle-level verification of dependency SHAs - #22859

Open
msfroh wants to merge 7 commits into
opensearch-project:mainfrom
msfroh:gradle_sha_verification
Open

Add Gradle-level verification of dependency SHAs#22859
msfroh wants to merge 7 commits into
opensearch-project:mainfrom
msfroh:gradle_sha_verification

Conversation

@msfroh

@msfroh msfroh commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Description

This provides an extra level of defense against supply-chain attacks, as it verifies SHAs of buildSrc dependencies, by using a built-in feature provided by Gradle.

When I opened #22770, I was kind of surprised that I didn't have to update/add the SHA for apache-rat.

Related Issues

N/A

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@msfroh
msfroh requested a review from a team as a code owner August 26, 2026 21:31
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

PR Code Analyzer ❗

AI-powered 'Code-Diff-Analyzer' found issues on commit 680a462.

Hard block: Issues at Medium severity or above will block this PR from merging.

PathLineSeverityDescription
gradle/verification-metadata.xml1highNew Gradle dependency verification metadata file recording SHA-256 checksums for all build artifacts (~3800 entries). Per mandatory supply chain rules, any new build configuration controlling dependency trust must be flagged. Maintainers must independently verify the listed checksums against known-good artifact registries (Maven Central, etc.) before merging, as a tampered checksum here would allow a substituted malicious artifact to pass build verification.
gradle/verification-metadata.xml6highTwo artifact groups ('opensearch-distribution' and 'opensearch-distribution-snapshot') are added as trusted-artifacts, completely bypassing SHA-256 checksum verification for those groups. While the documentation justifies this for snapshot builds, this blanket trust bypass is a mandatory flag — a supply chain attacker who can influence the distribution download path could serve tampered artifacts that skip all integrity checks.
gradle/verification-metadata.xml4mediumverify-metadata is set to false, disabling checksum verification of Maven POM and module metadata files. Dependency resolution metadata (transitive dependencies, repository redirects, plugin configurations) is therefore unverified, allowing a compromised or MITM'd repository to manipulate dependency graphs without detection even when artifact JARs pass their checksums.
gradle/verification-metadata.xml5mediumverify-signatures is set to false, disabling PGP/GPG signature verification for all downloaded artifacts. The configuration relies solely on SHA-256 checksums rather than publisher cryptographic signatures, reducing the ability to detect artifacts re-signed or re-uploaded by an attacker who has compromised a repository but not the original publisher's signing key.

The table above displays the top 10 most important findings.

Total: 4 | Critical: 0 | High: 2 | Medium: 2 | Low: 0


Pull Requests Author(s): Please update your Pull Request according to the report above.

Repository Maintainer(s): You can bypass diff analyzer by adding label skip-diff-analyzer after reviewing the changes carefully, then re-run failed actions. To re-enable the analyzer, remove the label, then re-run all actions.


⚠️ Note: The Code-Diff-Analyzer helps protect against potentially harmful code patterns. Please ensure you have thoroughly reviewed the changes beforehand.

Thanks.

@msfroh
msfroh force-pushed the gradle_sha_verification branch 2 times, most recently from f91d2d3 to 2d25cca Compare August 26, 2026 21:37
msfroh added 2 commits August 26, 2026 14:43
This provides an extra level of defense against supply-chain attacks,
as it verifies SHAs of buildSrc dependencies, by using a built-in
feature provided by Gradle.

Signed-off-by: Michael Froh <m_froh@apple.com>
Signed-off-by: Michael Froh <m_froh@apple.com>
@msfroh
msfroh force-pushed the gradle_sha_verification branch from 2d25cca to f9638a8 Compare August 26, 2026 21:52
These artifacts will need to be updated on every release, but that is
not a huge burden.

Signed-off-by: Michael Froh <m_froh@apple.com>
@msfroh msfroh added the skip-diff-analyzer Maintainer to skip code-diff-analyzer check, after reviewing issues in AI analysis. label Aug 26, 2026
@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit 02e0157)

Here are some key observations to aid the review process:

🧪 No relevant tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

⚠️ Review coverage: The following files were not included in this review because of the token budget:

  • gradle/verification-metadata.xml

@github-actions

Copy link
Copy Markdown
Contributor

❌ Gradle check result for 680a462: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Michael Froh <m_froh@apple.com>
@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit b12e5bb

These are pulled in as part of :server:detachedConfiguration1, so
they're not easy to ask Gradle to emit. I ended up just adding them
by hand.

Signed-off-by: Michael Froh <m_froh@apple.com>
@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 3cb37ef

Comment thread gradle/verification-metadata.xml
@github-actions

Copy link
Copy Markdown
Contributor

✅ Gradle check result for 3cb37ef: SUCCESS

@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.59%. Comparing base (7c635d7) to head (02e0157).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #22859      +/-   ##
============================================
+ Coverage     71.53%   71.59%   +0.05%     
- Complexity    77249    77322      +73     
============================================
  Files          6170     6170              
  Lines        359710   359710              
  Branches      52460    52460              
============================================
+ Hits         257318   257520     +202     
+ Misses        81965    81805     -160     
+ Partials      20427    20385      -42     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@msfroh
msfroh marked this pull request as draft August 27, 2026 16:17
Signed-off-by: Michael Froh <m_froh@apple.com>
@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 7c6d484

@github-actions

Copy link
Copy Markdown
Contributor

❌ Gradle check result for 7c6d484: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Michael Froh <m_froh@apple.com>
@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 02e0157

@msfroh
msfroh marked this pull request as ready for review August 27, 2026 20:25
@github-actions

Copy link
Copy Markdown
Contributor

✅ Gradle check result for 02e0157: SUCCESS

Comment thread DEVELOPER_GUIDE.md
Comment on lines +402 to +404
./gradlew <task that resolves the changed dependency> -Dorg.gradle.dependency.verification=off
./gradlew --write-verification-metadata sha256 <same task> --offline
```

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This two-step process to update dependencies can save a lot of time, since the default "online" mode for --write-verification-metadata seems to read from the various artifactories for every single task (as I understand it).

The :qa:os subprojects iterate through every listed OS and every version of OpenSearch defined in Version.java and fetches Jackson + JUnit dependencies. On my laptop, the online mode takes over 6 minutes (though I've seen it go as high as 9 minutes), while the offline mode is closer to 1 minute.

Removing the :qa:os subprojects and removing most of the unused constants in Version.java cuts the online metadata regeneration time to 1m30s, which is much closer to our old updateSHAs task.

The two-step process exists as a workaround until then, but it didn't work for me with -Dsandbox-enabled=true, because it insisted that arrow-compression-18.1.0.jar was not cached for offline verification (though I could clearly see it in my Gradle cache).

So, to summarize:

  1. If you're updating dependencies, not in sandbox, this two step process works and is fast.
  2. If you're updating sandbox dependencies, you need to do the online regeneration with something like ./gradlew --write-verification-metadata sha256 precommit -Denable.sandbox=true. Go grab a coffee.
  3. If we remove the :qa:os tasks and remove some cruft from Version.java, then this whole section can be a lot shorter and just document the online regeneration step (since it will be decently fast).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-diff-analyzer Maintainer to skip code-diff-analyzer check, after reviewing issues in AI analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants