TExcelTAD
Home › Mobile Build Pipelines: Gradle/AGP, Xcode, SwiftPM & Fastlane › Field Notes: Keys, Secrets & Version Codes

Field Notes: Keys, Secrets & Version Codes

Practical lessons from teams that ship mobile apps every week. Almost every one of them was learned from an incident.

Never commit a keystore or its passwords

A leaked upload key lets someone push "updates" that Play accepts until you notice; a leaked app signing key (if you manage it yourself) can't be fixed at all. Keystores end up in repositories in boring ways: git add . after copying the file "just for a minute", a keystore.properties with passwords next to build.gradle.kts, a CI debug step that cats the decoded file.

Defence in depth:

  1. .gitignore for *.jks, *.keystore, *.p12, *.p8, *.mobileprovision, keystore.properties, local.properties.
  2. A pre-commit / CI check that inspects content, not just names (people rename files).
  3. Secrets only in the CI secret store, injected as ORG_GRADLE_PROJECT_* variables (Signing Configs) and written to $RUNNER_TEMP, never into the workspace.
  4. Play App Signing, so the key you could leak is only the upload key.

Here's such a check as a real session: it looks at every staged file and asks keytool whether it is a keystore, whatever its name, and greps staged text for password assignments:

bash · try it yourself
mkdir -p app && cd app && git init -q
printf '*.jks\n*.keystore\nkeystore.properties\n' > .gitignore
cat > check-secrets.sh <<'SH'
#!/bin/bash
# Fails if a staged file is a Java keystore (any name) or contains a password assignment.
status=0
for f in $(git diff --cached --name-only --diff-filter=ACM); do
  if keytool -list -keystore "$f" -storepass x >/dev/null 2>&1 || \
     keytool -list -keystore "$f" -storepass x 2>&1 | grep -q 'password was incorrect'; then
    echo "BLOCKED: $f is a keystore"; status=1
  elif grep -qiE '(store|key)Password *= *"[^"$]+"' "$f"; then
    echo "BLOCKED: $f contains a password: $(grep -iE -o '(store|key)Password *= *"[^"$]+"' "$f" | head -1)"; status=1
  fi
done
[ $status -eq 0 ] && echo "OK: nothing secret staged"
exit $status
SH
chmod +x check-secrets.sh
echo 'storePassword = providers.gradleProperty("releaseStorePassword").get()' > signing.gradle.kts
git add .gitignore check-secrets.sh signing.gradle.kts && ./check-secrets.sh
echo "--- someone copies the keystore under an innocent name"
cp ~/release.jks app-icon-backup.png
git add app-icon-backup.png && ./check-secrets.sh
echo "--- and hard-codes a password"
git rm -q --cached app-icon-backup.png
echo 'storePassword = "learner-pass"' >> signing.gradle.kts
git add signing.gradle.kts && ./check-secrets.sh; echo "exit code: $?"
echo "--- the .gitignore at least stops the obvious name"
cp ~/release.jks release.jks && git add release.jks 2>&1 | head -1
OK: nothing secret staged
--- someone copies the keystore under an innocent name
BLOCKED: app-icon-backup.png is a keystore
--- and hard-codes a password
BLOCKED: signing.gradle.kts contains a password: storePassword = "learner-pass"
exit code: 1
--- the .gitignore at least stops the obvious name
The following paths are ignored by one of your .gitignore files:

A dedicated scanner (gitleaks, trufflehog, GitHub secret scanning with push protection) covers far more patterns; the point of the session is the content-based check: the keystore renamed to .png sailed past .gitignore.

If a key leaks anyway: rotate first, investigate second. For an upload key: generate a new one, request an upload key reset in Play Console, update the CI secret, and remove the old key from history (git filter-repo) and treat it as compromised regardless. For iOS: revoke the certificate in the developer portal (or fastlane match nuke + regenerate) and the API key in App Store Connect.

Keys outlive teams

Store the upload keystore and its passwords in a password manager or KMS owned by the organisation, with at least two people able to recover it. An app whose only key sat on a departed developer's laptop is a common, painful story. Write down, next to the key: what it signs, its SHA-256 fingerprint, where the CI copy lives, and the Play/App Store procedure for rotating it.

Apple certificates expire (distribution certificates after a year); profiles expire with them. Put the expiry dates in a calendar or a scheduled CI job (security cms -D -i profile.mobileprovision), or the release pipeline will discover it on release day.

versionCode comes from CI, reproducibly

  • Derive, don't type. A hand-edited versionCode = 57 collides as soon as two branches release. Use tag + CI build number (versionCode & versionName Strategy).
  • Same inputs, same code. Re-running the release job for a tag must produce the same versionCode; a value from the wall clock or an auto-incrementing file committed by CI breaks that (and creates bot commits that fight with humans).
  • One authority per app. If iOS and Android share a version scheme, compute it in one script both pipelines call.
  • Leave headroom. Moving CI systems resets run numbers: start new schemes with an offset (10_000_000 + run) so codes keep growing.
  • Check before upload. Compare against the store's latest code (google_play_track_version_codes, latest_testflight_build_number) and fail early with a clear message rather than after a 20-minute build.

Debug keys and debug builds stay home

  • The debug keystore is the same well-known file pattern on every machine; anything signed with it is effectively unsigned. Check the certificate digest in CI (Verifying APKs).
  • Different developers have different debug keys, so Google Sign-In/Maps API keys registered for "the debug key" work for one person only. Commit a shared debug keystore for the team if you need stable debug fingerprints (it's not a secret), never the release one.

Test yourself

Why did the session's check catch app-icon-backup.png when .gitignore didn't?

  1. PNG files are always blocked
  2. It asked keytool whether the file is a keystore, checking content rather than the name
  3. git refuses binary files
  4. The file was too large

Your upload key leaked. What comes first?

  1. Investigate who leaked it
  2. Rotate: new upload key, upload key reset in Play Console, update CI secrets
  3. Delete the repository
  4. Nothing; upload keys aren't sensitive

Why is a versionCode computed from the current time a problem?

  1. Play rejects timestamps
  2. Rebuilding the same release gives a different code, so builds aren't reproducible (and parallel builds can collide)
  3. It's always too large
  4. Gradle can't read the clock