-
Notifications
You must be signed in to change notification settings - Fork 135
[AINFRA-1533] Adopt git-crypt in this repo #14979
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
f6bbde5
2400f0a
fe6e943
ec37818
974f371
b7f8151
5141352
bdd3842
7fabbbd
43f72b7
64af453
0509840
8370fe9
2e71ff0
3b0e1f3
3a21aac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| echo "$GIT_CRYPT_ENCRYPTION_KEY" | base64 -d | git-crypt unlock - |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,8 @@ APP_TO_BUILD="${1?You need to specify the app to build, WooCommerce or WooCommer | |
| echo "--- :rubygems: Setting up Gems" | ||
| install_gems | ||
|
|
||
| echo "--- :closed_lock_with_key: Installing Secrets" | ||
| bundle exec fastlane run configure_apply | ||
| echo "--- :closed_lock_with_key: Decrypting Secrets" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Underrated improvement: now we won't need to start Ruby, initialize the Fastlane runtime to start a lane, etc just for decrypting secrets (admittedly not that slow, but still... 😄) and leave that only once for the main lane. 💭 Which also makes me think we could call |
||
| .buildkite/commands/git-crypt-unlock.sh | ||
|
|
||
| echo "--- :hammer_and_wrench: Building ${APP_TO_BUILD}" | ||
| bundle exec fastlane build_and_upload_prototype_build app:"${APP_TO_BUILD}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| # This file is `source`'d before calling `buildkite-agent pipeline upload`, and can be used | ||
| # to set up some variables that will be interpolated in the `.yml` pipeline before uploading it. | ||
|
|
||
| export CI_TOOLKIT="automattic/a8c-ci-toolkit#5.4.0" | ||
| # "git-crypt-unlock" branch / https://github.com/Automattic/a8c-ci-toolkit-buildkite-plugin/pull/195 | ||
| export CI_TOOLKIT="automattic/a8c-ci-toolkit#0a3f10921096cee57c18ac5667fc64c1aaad4a7d" | ||
|
Comment on lines
-6
to
+7
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎗️ TODO: Revert back to pointing to a tag version once Automattic/a8c-ci-toolkit-buildkite-plugin#195 is merged and we have an official new version of the |
||
| export TEST_COLLECTOR="test-collector#v1.10.1" | ||
| export CLAUDE_PLUGIN="claude-summarize#v1.1.0" | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| RELEASE-NOTES.txt merge=union | ||
|
|
||
| .configure-files/*.enc binary | ||
| ######################################### | ||
| # Secrets files encrypted with git-crypt | ||
| ######################################### | ||
|
|
||
| secrets.properties filter=git-crypt diff=git-crypt | ||
| sentry.properties filter=git-crypt diff=git-crypt | ||
| google-services.json filter=git-crypt diff=git-crypt | ||
| firebase.secrets.json filter=git-crypt diff=git-crypt | ||
| google-upload-credentials.json filter=git-crypt diff=git-crypt | ||
| *.keystore filter=git-crypt diff=git-crypt | ||
| *.jks filter=git-crypt diff=git-crypt |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -38,8 +38,14 @@ | |||||
| $ cd woocommerce-android | ||||||
| ``` | ||||||
|
|
||||||
| 1. Copy `defaults.properties` to the secrets directory: `cp defaults.properties ~/.configure/woocommerce-android/secrets/secrets.properties`. See the [Configuration Files](docs/project-overview.md#configuration-files) section for a breakdown of the properties. | ||||||
| 1. Generate the developer oauth2 tokens. These values get copied into the `~/.configure/woocommerce-android/secrets.properties` file in the next step. See the [OAuth2 Authentication](docs/project-overview.md#oauth2-authentication) section for details. | ||||||
| 1. If you are a developer at Automattic: | ||||||
| 1. Make sure you have `git-crypt` installed (`brew install git-crypt`) | ||||||
| 1. Search for "WooCommerce Android git-crypt encryption key" in our Secret Store, and copy the Base64 value in your clipboard | ||||||
| 1. Run `pbpaste | base64 -d | git-crypt unlock -` to decrypt the encrypted files (including `secrets.properties` and `WooCommerce/google-services.json`) | ||||||
| 1. If you are an external contributor: | ||||||
| 1. Generate developer OAuth2 tokens. See the [OAuth2 Authentication](docs/project-overview.md#oauth2-authentication) section for details. | ||||||
| 1. Edit `defaults.properties` and adjust the values as needed—especiallyincluding `wp.oauth.*` ones. See the [Configuration Files](docs/project-overview.md#configuration-files) section for a breakdown of the properties. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 1. `cp WooCommerce/google-services.json-example WooCommerce/google-services.json` (to replace that encrypted file with placeholder content) | ||||||
| 1. In Android Studio, open the project from the local repository. This will auto-generate `local.properties` with the SDK location. | ||||||
| 1. Optional: Go to Tools → Device Manager and create an emulated device. | ||||||
| 1. Run. (Creates a default virtual device if you skipped the previous step) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ plugins { | |
|
|
||
| fladle { | ||
| variant = "vanillaDebug" | ||
| serviceAccountCredentials = rootProject.file(".configure-files/firebase.secrets.json") | ||
| serviceAccountCredentials = rootProject.file("firebase.secrets.json") | ||
| testTargets = [ | ||
| "notPackage com.woocommerce.android.e2e.tests.screenshot", | ||
| "notClass com.woocommerce.android.e2e.tests.ui.OrdersRealAPI", | ||
|
|
@@ -496,12 +496,13 @@ android.buildTypes.all { buildType -> | |
| } | ||
|
|
||
| // If Google services file doesn't exist, copy example file. | ||
| if (!file("google-services.json").exists()) { | ||
| def googleServicesFile = file("google-services.json") | ||
| if (!googleServicesFile.exists() || isFileEncrypted(googleServicesFile)) { | ||
| tasks.copyGoogleServicesExampleFile.copy() | ||
| } | ||
|
Comment on lines
+500
to
502
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
in the docs?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I updated the docs before first, then later realized I had to update the Good point then, we should indeed remove that extra step from the docs. |
||
|
|
||
| // Print warning message if example Google services file is used. | ||
| if ((file("google-services.json").text) == (file("google-services.json-example").text)) { | ||
| if ((googleServicesFile.text) == (file("google-services.json-example").text)) { | ||
| println("WARNING: You're using the example google-services.json file. Google login will fail.") | ||
| } | ||
| } | ||
|
|
@@ -514,6 +515,13 @@ static def loadPropertiesFromFile(inputFile) { | |
| return properties | ||
| } | ||
|
|
||
| static def isFileEncrypted(File file) { | ||
| def gitcryptHeader = [0x00, 0x47, 0x49, 0x54, 0x43, 0x52, 0x59, 0x50, 0x54] as byte[] // GITCRYPT header | ||
| def header = new byte[gitcryptHeader.length] | ||
| file.withInputStream { stream -> stream.read(header) } | ||
| return Arrays.equals(header, gitcryptHeader) | ||
| } | ||
|
|
||
| def isLeakCanaryEnabled() { | ||
| return developerProperties.get("enable_leak_canary") ?: true | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 Again thinking out loud, not sure if it's worth the trouble: what do you think of grouping encrypted / secret files in the same folder and making a convention out of this for all projects (well, kinda similar to what we had before but making it more obvious)? |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💭 I was wondering if there could be a way to be sure, in reviews, that this has in fact been encrypted or not specially given files like this are binary files. Then I've noticed all
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean like I do here? 😛 Indeed maybe we can write a Dangermattic plugin to detect which file in the PR are encrypted and add an inline comment on the file if so as an extra information? Is that what you meant? As for manually testing locally if a file is properly encrypted before pushing a commit to the remote, one can use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ha, yes, I realized that function was doing that after I posted the comment 😂
Yeah, though at the same time I find it a bit difficult to do that in a systemic way that will be useful (as we don't add secrets that often)...
👍 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,11 +13,8 @@ When creating your application, you should select "**Native client**" for the ap | |
| The "**Website URL**", "**Redirect URLs**", and "**Javascript Origins**" fields are required but not used for | ||
| the mobile apps. Just use "**[https://localhost](https://localhost)**". | ||
|
|
||
| Once you've created your application in the [applications manager][wp-com-apps], you'll | ||
| need to update the `wc.oauth.app_id` and `wc.oauth.app_secret` fields in `secrets.properties`. | ||
| See [setup instructions][setup] for more details about secrets file. Then you can compile and run the app on a device or an emulator and | ||
| try to login with a WordPress.com account. Note that authenticating to WordPress.com via Google is | ||
| not supported in development builds of the app, only in the official release. | ||
| Once you've created your application in the [applications manager][wp-com-apps], you'll need to update the `wc.oauth.app_id` and `wc.oauth.app_secret` fields in `defaults.properties` (copied from `defaults-example.properties`). See [setup instructions][setup] for more details. | ||
| Then you can compile and run the app on a device or an emulator and try to login with a WordPress.com account. Note that authenticating to WordPress.com via Google is not supported in development builds of the app, only in the official release. | ||
|
|
||
| Note that credentials created with our [WordPress.com applications manager][wp-com-apps] | ||
| allow login only and not signup. New accounts must be created using the [official app][wp-app] | ||
|
|
@@ -35,7 +32,15 @@ Read more about [OAuth2][oauth] and the [WordPress.com REST endpoint][wp-api]. | |
|
|
||
| #### `secrets.properties` | ||
|
|
||
| The `secrets.properties` file is used to store sensitive information that should not be checked into version control. This file is located at `~/.configure/woocommerce-android/secrets/secrets.properties`. | ||
| The `secrets.properties` file is used to store sensitive information that should not be checked into version control in clear text. | ||
| This file is encrypted (using `git-crypt`), and only developers working at Automattic have the decryption key. | ||
|
|
||
| If you are a developer working at Automattic, ensure you followed those instructions once after cloning the repo: | ||
| 1. Make sure you have `git-crypt` installed (`brew install git-crypt`) | ||
| 1. Search for "WooCommerce Android git-crypt encryption key" in our Secret Store, and copy the Base64 value in your clipboard | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I wonder, is it okay to provide a direct link to Secret Store? 🤔
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I hesistated on this too. It's probably OK I guess because it's just a link that won't be accessible by anyone outside Automattic, and those links just contain
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I also had second thoughts before suggesting this, but actually our security doesn't rely on obscurity of a url. I think it's fine to share the link here, MC requires multpile security measures anyway to get anything from it. |
||
| 1. Run `pbpaste | base64 -d | git-crypt unlock -` to decrypt the encrypted files (including `secrets.properties`) | ||
|
|
||
| If you are an external contributor, provide those variables in your `defaults.properties` instead: | ||
|
|
||
| | Property | Description | | ||
| |:---------------------------|:------------| | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the repo
git-crypt-unlocked during the branch dance that is done internally bycomment_with_manifest_diffcausedYour local changes to the following files would be overwritten by checkoutissues, especially if thegit-crypt'd files listed in.gitattributeson the HEAD branch are not the same as the ones in the BASE branch1Since we don't need any secret in practice to generate the manifest and call
process{variant}Manifest, the solution is simple: just don't bother unlocking the repo's secrets for that task.A better long-term solution to make
comment_with_manifest_diffmore resilient to situations like this would be to make it usegit worktreeinstead of switching branches in-place:git worktree add $TMP_DIR_FOR_BASE $BASE_BRANCH && cd $TMP_DIR_FOR_BASEthen run./gradlew process{variant}Manifesttherecd $CHECKOUT_DIR && rm $TMP_DIR_FOR_BASE && git worktree prunethen run./gradlew process{variant}ManifestthereThat way each checkout is done in independent folders, eliminating the risk of conflicts during the branch dance.
Footnotes
like will be the case during that transition to
git-crypt, or when we'll add a new secret file, especially if that secret file previously existed unencrypted in the BASE branch as an example file for external contributors I think? ↩