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

Add Gradle dependency verification metadata #116

Merged
merged 5 commits into from
Nov 28, 2023

Conversation

PatrykMis
Copy link
Collaborator

@PatrykMis PatrykMis commented Nov 27, 2023

Description

Speak Touch is an accessibility service with access to screen content and user input, emphasizing the need for rigorous security measures. This pull request introduces Gradle dependency verification metadata.

To generate this metadata, the following command should be executed each time a dependency is updated:

./gradlew --write-verification-metadata sha512 clean build --no-daemon --rerun-tasks

Why is this important?

  1. Security First: Given the nature of our accessibility service, which interacts with screen content and user input, prioritizing security is paramount. The inclusion of dependency verification metadata ensures the ongoing integrity and security of the dependencies used in our project.

  2. Protection Against Supply-Chain Attacks: In the event of unauthorized changes to dependencies or potential supply-chain attacks, the verification process serves as an early warning system, fortifying the accessibility service against potential security threats.

This pull request underscores our commitment to security, ensuring a robust and secure environment for the Speak Touch accessibility service.

More reading: Android Security: Securing Your Gradle Builds from Baddies.

Signed-off-by: Patryk Miś <[email protected]>
@PatrykMis PatrykMis added the build Build settings label Nov 27, 2023
@PatrykMis PatrykMis added this to the MVP milestone Nov 27, 2023
@PatrykMis PatrykMis self-assigned this Nov 27, 2023
@PatrykMis PatrykMis requested a review from Irineu333 November 27, 2023 20:25
@PatrykMis PatrykMis marked this pull request as draft November 27, 2023 23:25
@Irineu333
Copy link
Member

Very good! I saw some time ago a news about a supply-chain attack on npm, but I didn't go in depth to understand how it is done and how to protect against it. In this sense, you are being a true security analyst for Speak Touch

@Irineu333
Copy link
Member

Irineu333 commented Nov 27, 2023

⚠️ I am receiving a verification error in the lib org.codehaus.groovy:groovy:3.0.1 when trying to synchronize the gradle.

Dependency verification failed for org.codehaus.groovy:groovy:3.0.17
One artifact failed verification: groovy-3.0.17.pom (org.codehaus.groovy:groovy:3.0.17) from repository Gradle Libs

@PatrykMis PatrykMis force-pushed the feature/gradle-verification-metadata branch from 32c2112 to bbc3ee2 Compare November 27, 2023 23:38
@PatrykMis PatrykMis marked this pull request as ready for review November 27, 2023 23:38
@Irineu333
Copy link
Member

Irineu333 commented Nov 27, 2023

Some questions and considerations:

  1. What are the purposes of the arguments --no-daemon --rerun-tasks?
  2. Is any ci/cd needed to run the verification? Or will it fail in Validate Gradle Wrapper?
  3. To get the most out of this security, should we have an action to generate the apk and aab, right? If done locally, it could be bypassed.

@PatrykMis
Copy link
Collaborator Author

I am receiving a verification error in the lib org.codehaus.groovy:groovy:3.0.1 when trying to synchronize the gradle.

Are you using InteliJ or Android Studio? Which version? It can be bug related to https://youtrack.jetbrains.com/issue/IDEA-258328 and have a workarround.

  1. What are the purposes of the arguments --no-daemon --rerun-tasks?

I do that to make sure no task will be skipped and also to not use currently running Gradle deamons.

  1. Is any action needed to run the verification? Or will it fail in Validate Gradle Wrapper?

It just fail if something can't be validated if gradle/verification-metadata.xml is present.

  1. To get the most out of this security, should we have an action to generate the apk and aab, right? If done locally, it could be bypassed.

Everything can be bypassed, like removing sha-256 hash from gradle-wrapper.properties. It just ads one more layer of protection. Anyway, if we'll build as an action, the apk/aab should be signed, too which is not we want. Finally, the apk should be signed by admin - you before it will be published as release and to stores like Accrescent / Play Store.

I'm considering to make an action for push/pull though, to check independantly if everything is valid before merging pull request. Let me know and I'll do it in separat PR.

@Irineu333
Copy link
Member

Are you using InteliJ or Android Studio? Which version? It can be bug related to https://youtrack.jetbrains.com/issue/IDEA-258328 and have a workarround.

I use Android Studio, Android Studio Hedgehog | 2023.1.1 RC 3.

It just fail if something can't be validated if gradle/verification-metadata.xml is present.

I understand, but my question is whether the validation will be done by a specific pipeline. I will do a test by sending a commit changing a dependency, and see if the Validate Gradle Wrapper fails

@Irineu333
Copy link
Member

The Validate Gradle Wrapper did not fail. So, a GitHub action is needed to check this

@PatrykMis
Copy link
Collaborator Author

Exactly. Validate Gradle Wrapper checks wrapper jar checksum only.

@Irineu333
Copy link
Member

Anyway, if we'll build as an action, the apk/aab should be signed, too which is not we want. Finally, the apk should be signed by admin - you before it will be published as release and to stores like Accrescent / Play Store.

Why don't we want it to be signed? We can encode the keystore in the GitHub secrets to sign automatically.

@PatrykMis
Copy link
Collaborator Author

Do you have more trust to GitHub servers than your own machine?

@PatrykMis
Copy link
Collaborator Author

I will rebase this PR. It seams InteliJ Idea 2023.1 has this issue, and Android Studio version you use is based on this version.

Android Studio is the customized fork of InteliJ.

@Irineu333
Copy link
Member

Irineu333 commented Nov 28, 2023

Do you have more trust to GitHub servers than your own machine?

Well, since I have a separate machine for work, I trust it a lot. I can't say what would be more likely; some failure on GitHub allowing the leakage of the keystore or me inadvertently installing malicious software on my machine. I think either scenario is quite unlikely, I would like a pipeline to generate the APK more for convenience really.

@PatrykMis
Copy link
Collaborator Author

Ok, shall I do it in separate Pr or just here?

@PatrykMis PatrykMis force-pushed the feature/gradle-verification-metadata branch from ec6a8d4 to c41f2a6 Compare November 28, 2023 00:35
@Irineu333
Copy link
Member

I will rebase this PR. It seams InteliJ Idea 2023.1 has this issue, and Android Studio version you use is based on this version.

Android Studio is the customized fork of InteliJ.

I can use the latest version of IntelliJ while waiting for a new release of Android Studio, but then it's necessary to indicate the reduced compatibility in the README.

@PatrykMis
Copy link
Collaborator Author

PatrykMis commented Nov 28, 2023

I've just added a workarround. Can you try now?

@Irineu333
Copy link
Member

Irineu333 commented Nov 28, 2023

Ok, shall I do it in separate Pr or just here?

If you are talking about github action to generating the APK/AAB, I wasn't suggesting doing it now. We can discuss more about this. But I think a GitHub action to run the dependency check is necessary, it would be annoying to find out that the validation is failing after merging the pull request.

We need to ensure that the develop and master branches are always functioning, eliminating human errors. So, I will add this action as a requirement for merging the pull request

@Irineu333
Copy link
Member

Irineu333 commented Nov 28, 2023

Ok, shall I do it in separate Pr or just here?

It worked!

@Irineu333
Copy link
Member

@Irineu333 Irineu333 force-pushed the feature/gradle-verification-metadata branch from 15b2374 to abe9a2b Compare November 28, 2023 22:15
@PatrykMis PatrykMis merged commit a54a3c4 into develop Nov 28, 2023
4 checks passed
@PatrykMis PatrykMis deleted the feature/gradle-verification-metadata branch November 28, 2023 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build settings security
Projects
Status: Ready For Production
Development

Successfully merging this pull request may close these issues.

2 participants