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

Gradle dependency checksum and signature checks #252

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

AndyScherzinger
Copy link
Member

@AndyScherzinger AndyScherzinger commented Jan 23, 2024

Adding checksums to Android repos like android-common for gradle based build toolchain, see https://docs.gradle.org/current/userguide/dependency_verification.html.

In order to do so, one must:

  • add org.gradle.dependency.verification.console=verbose to gradle.properties so future CI runs would provide the info in case the HTML report isn't accessible
  • run in the project root
    • ./gradlew --write-verification-metadata pgp,sha256 help
    • ./gradlew :sample:generateDebugLintReportModel --write-verification-metadata pgp,sha256 help
    • ./gradlew :core:spotlessKotlinCheck --write-verification-metadata pgp,sha256 help
    • ./gradlew --export-keys
    • ./gradlew :sample:generateDebugLintReportModel --export-keys
    • ./gradlew :core:spotlessKotlinCheck --export-keys
  • ensure you commit verification-keyring.keys but not the binary very so git is able to diff the key changes. not executing the last command and commiting its results leads to the GH action trying to download the keys, this slows down the execution and leads to red checks since it'll fail for many keys, hence shipping them in the repo it the best option.

A next step will have to be to move to renovatebot which is capable of update checksums when updating dependencies, see https://docs.renovatebot.com/modules/manager/gradle/


Note

  • Due to poor signature management in the library world, many libraries aren't signed or their keys aren't retrievable❗
  • The above command bootstraps the whole checksum+signature information and "blindly" trusts the given key. In theory all key would need to be verified. So this setup mechanism will only secure dependency changes of the future - an already compromised dependency would not be detected/detectable this way. While keeping in mind that a legit signature isn't an absolute statement in terms of the package being legit. It just means built and published by somebody with access to the keys.

@AndyScherzinger AndyScherzinger force-pushed the chore/noid/dependencyChecksums branch 2 times, most recently from 564bce1 to 514fc27 Compare January 23, 2024 15:40
@stefan-niedermann
Copy link
Member

Slightly Off Topic: I am currently using the gradle/wrapper-validation-action GitHub action in all of my gradle repositories (Example). It's for validating the gradle wrapper itself though, not for dependencies.

@AndyScherzinger
Copy link
Member Author

@AndyScherzinger AndyScherzinger changed the title Gradle dependency checksums Gradle dependency checksum and signature checks Jan 23, 2024
@stefan-niedermann
Copy link
Member

Aah, it's a separate workflow, that's why I missed it 🙈

@AndyScherzinger AndyScherzinger force-pushed the chore/noid/dependencyChecksums branch 3 times, most recently from 07babab to a071e31 Compare January 23, 2024 17:59
@AndyScherzinger
Copy link
Member Author

Fun stuff....

getting the checks to turn green is a major pain - as expected since metadata quality on libraries / dependency management are rather poor, especially for Android / Google artifacts.

I'll keep working on it but might keep going for the approach to put them on a trusted list because there is no way for my to maintain checksums manually because they aren't available anywhere :(

@AndyScherzinger AndyScherzinger force-pushed the chore/noid/dependencyChecksums branch 8 times, most recently from 6172eba to 5e09d9e Compare January 23, 2024 19:32
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@AndyScherzinger AndyScherzinger merged commit 6670d3f into main Jan 23, 2024
12 checks passed
@AndyScherzinger AndyScherzinger deleted the chore/noid/dependencyChecksums branch January 23, 2024 19:45
<configuration>
<verify-metadata>true</verify-metadata>
<verify-signatures>true</verify-signatures>
<trusted-artifacts>
Copy link
Member Author

Choose a reason for hiding this comment

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

some artifacts, thanks Google can't be verified, so put them in a trusted list

<trust group="org.jetbrains.kotlin" name="kotlin-stdlib-common" version="1.9.0" reason="Broken: artifact was signed but all keys were ignored, checksum is missing from verification metadata"/>
</trusted-artifacts>
<ignored-keys>
<ignored-key id="a41f13c999945293" reason="Key couldn't be downloaded from any key server"/>
Copy link
Member Author

Choose a reason for hiding this comment

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

some keys aren't available via any dependency repo, so they will get added to an ignore list automatically

<ignored-key id="5f69ad087600b22c" reason="Key couldn't be downloaded from any key server"/>
</ignored-keys>
<trusted-keys>
<trusted-key id="015479e1055341431b4545ab72475fd306b9cab7" group="com.googlecode.javaewah" name="JavaEWAH" version="1.2.3"/>
Copy link
Member Author

Choose a reason for hiding this comment

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

same for found keys, they will be added to a trusted list

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.

None yet

2 participants