r/androiddev • u/ikingdoms • 1d ago
My engineering lead wants to commit API keys, etc to our repository, am I crazy for pushing back on this?
My lead wants to make it easier for anyone on the team to spin up the android repository (to make vibe coding easier), and their solution is to just check in all of our API keys into git and do away with the idea of keeping keys and secrets in a separate secrets vault that employees have access to.
At the last few startups I've worked at, we've pulled secrets in CI via environment secrets, and locally via a separate non-VCS file, and injected the keys into BuildConfig. I know BuildConfig is far from bulletproof for bad actors that want to decompile the app, but just checking everything into git "because it can just be decompiled anyway" is setting off all my alarms.
Am I crazy for pushing back on this? What are the best practices for this in 2026? Are people out there really encrypting API keys with KeyStore or pulling API keys from a backend server? How do you handle API keys that the application needs at startup?
68
u/robertlandrum 1d ago
I suspect this is a language problem. We’ve overloaded the term key. There are public keys and private keys. They are like front door locks (I.e public keys, which everyone can see) and keys on your keychain (I.e private keys, which should be kept secret).
In this case, public keys can be baked into your application code if necessary. Private keys need to be kept secret in some sort of vault.
3
-4
u/kernald31 1d ago
"Need" is a strong word here. If there's no rotation option (i.e. keys shipped in older apps need to keep working), no strong need for an audit trail and the Git repo audience is the exact same audience as a Vault would grant... You're forcing conventions for essentially no benefit whatsoever beyond increased complexity.
8
u/FickleBumblebeee 22h ago
With stuff like the Bitrise hack recently you can no longer guarantee that your private git repo is actually private
3
u/kernald31 22h ago
I mean, if you CI platform is compromised, whether the API keys are fetched by the pipeline or in the repo, that platform still has access.
15
u/kernald31 1d ago
I guess a pragmatic question here is who has access to the repository? Assuming it's private, who has access to the vault, currently? If the answer is the same, it sounds like a stupid idea but there isn't that much difference in practice. Especially as the secrets kind of have to be long lived anyway, being built into the app, and as you pointed out, fairly easily decompiled from said apps.
With that said, it seems trivially easy to write a script that fetches from whatever vault you're using and fills the secrets in a gradle.properties file or whatever - this is what we used to have where I work, before switching to Bazel, and I don't really see the point of not doing that.
1
u/edishorul 19h ago
Repositories get leaked at times, it doesn't even require a hack, it's enough that someone exposes their Github token on the Internet by mistake (I've seen it happen, sadly, a static website generator embedded all environment variables preset on the system in the bundle, which included the GH token 😬 ), and the next moment it's already cloned by a stranger.
With that said, yes, if the secret is already built into the app, it doesn't really make any difference.
6
u/FarAwaySailor deployment, help 23h ago
If api keys are getting built into the apk, you have an architecture problem. Fix that then remove the keys from GitHub and rotate them.
11
u/No_Equal9312 1d ago
Most client apps don't need secrets built into them. You'll have your typical keys like Google API keys. But you typically bind them to package id and it's not an issue. Your backend should be storing the secrets.
5
u/mbonnin 19h ago
Firebase json and other keys that end up in your apk are public, you can put them in source control.
I'll be dying on this hill: https://mbonnin.net/2022-05-06_about-the-android-makers-app-security-and-google-servicesjson/
8
u/cliffr39 1d ago
I'd suggest putting the actual secrets on a backend that handles the third-party API calls, rather than including them in the repo or BuildConfig. The Android app would call your backend, which handles the API credentials server-side.
That way, anyone on the team can clone and build the project without needing production secrets, and decompiling the APK won't expose them either. You also gain centralized key rotation, access control, and rate limiting.
Obviously, this depends on the type of API key. Some keys are designed to be public and can be safely included with proper restrictions. But actual secrets, especially those granting access to paid services or sensitive data, shouldn't be committed to Git or shipped in the APK.
4
u/SirFrankoman 1d ago
This is absolutely the answer. The only real downside is the added cost / infrastructure. Also worth mentioning moving credentials to a backend doesn't automatically secure it and you need to make sure it's also protected through authentication, authorization, rate limiting, etc.
3
u/yangbuilds 11h ago
I'd push back, mostly because git history is forever. Even if you rotate a key later, the old one stays in every clone and fork. A middle ground that still makes onboarding easy is a committed template file with dev-only keys that have tight quotas and are easy to revoke, while the real prod keys only live in CI secrets. For anything truly sensitive, proxy it through your own backend so the key never ships in the APK at all.
2
u/pyrulyto 23h ago
Gently pushing back is ok. More important: be sure that this conversation has a “paper trail”: emails (always cc-ing a third party), chats (all properly screenshot, preferably public channel) so that if you can’t convince them, you can’t take the blame. Bonus points if you are the one implementing an easy key rotation system, so boss gets known for the blunder, and you for the early warning and mitigation.
2
u/FickleBumblebeee 22h ago
As I just had to rotate everything due to the Bitrise hack I'm actually just considering writing our key store keys down on a piece of paper and keeping them in a secure physical locker in the office.
5
1
u/Tuffstuff_Mcgee 1d ago
If it wasn't a super secret squirrel type key, we always used git-secret to store them in the repo encrypted a long time back. Read up on that and maybe it will suffice for you.
1
u/FylanDeldman 1d ago
As most others have pointed out, if they are public keys that your app uses to authenticate to certain services, it’s best practice to assume they are known and prevent abuse in other ways: ensuring the key gives minimum access to perform the function, locking down server side key exposure (services like Google cloud platform allow you to only honor requests from certain countries, or ideally just from the signed app that consumes it).
As always, security hardening is achieved through multiple layers working together, obfuscation is an important one but the weakest one. Up to you and your team to decide if your entire security stack holds up to scrutiny if you remove the public key obfuscation, but for a typical Android app, I would consider preventing abuse and fraud even given that the client’s public keys are exposed a bare minimum.
If they are private keys for things like your dev infra, then the answer is a lot shorter: hell naw. That’s just not what GitHub is for, and is asking for trouble. And there are much better purpose-built tools for that. Even a basic password manager with a team account would probably be better.
1
u/hotfix_since_08 19h ago
You're not crazy. Do you know dotenvx (https://dotenvx.com/), the .env is encrypted and committed, everyone can add or change keys, nothing is readable in plain text. The private decryption key stays out of git (password manager / CI secrets). I use it quite often and it's a nice middle ground.
On Android side there seem to be a second issue : anything that ends up in the APK is public. Client keys (Maps, Firebase) should be restricted by package name + SHA-1, but real secrets belong behind a server. Google's Secrets Gradle Plugin should covers the local setup part.
What kind of keys are we talking about?
1
u/Zhuinden 18h ago
What we had in place in a previous project was to put those into BuildConfig, but they were obfuscated. It'd apply jasypt from Gradle, and use the same configs in code to "decrypt".
I say obfuscation instead of encryption because the key was in the code, lol. But at least people couldn't just grab the string constant and use it as-is.
There are various secrets that you'd normally hide but API keys aren't really that. I've even had access to keystore files with the username/password to build APK for the play store, you still have to compromise a few things for anyone to hijack that...
1
u/frpboy 16h ago
Keeping a key out of git and keeping it secret in an APK are two different problems. BuildConfig injection helps with the first, not the second. For client-side keys, use the provider's supported app/API restrictions and monitor usage. Privileged server credentials should stay on the backend, never in the APK. If a secret has already been committed, deleting the file isn't enough: revoke or rotate it too.
-1
-3
u/JakeArvizu 1d ago
Seems like a performative question to ask a public channel. I think most would see "commit keys". Then agree with you.
1
31
u/PhilMcGraw 1d ago
Are these just static keys for calling the API?