r/androiddev • u/ikingdoms • 7d 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?
35
u/PhilMcGraw 7d ago
Are these just static keys for calling the API?
90
u/robertlandrum 7d 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.
11
u/mbonnin 7d 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/
16
u/kernald31 7d 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.propertiesfile 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.7
u/FarAwaySailor deployment, help 7d 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 7d 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.
8
u/cliffr39 7d 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.
3
u/pyrulyto 7d 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.
3
u/yangbuilds 6d 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/FickleBumblebeee 7d 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
u/sosickofandroid 7d ago
You are about to learn the bitter lesson of building clients
1
u/Tuffstuff_Mcgee 7d 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 7d 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 7d 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 7d 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/jyling 7d ago
Use sops, it’s a good tool if you want to commit api keys, but some api keys i mean to go public not all is secrets
1
u/budius333 5d ago
Your current lead is wrong and your past startup as well (although slightly less wrong).
1
u/BloodDragonSoftware 5d ago
I was taught never to include sensitive information like that in a repo. The secrets feature exists for security. Both external and internal security. It may be inconvenient, but an extra layer of security may prove valuable if anything bad ever happens. I would push back at least a little bit (politely) unless the lead has already made it clear their decision is final.
1
u/Lucifernistic 4d ago
As the top comment mentions this is normal if its a public facing key, though there are cleaner ways to do it then baking into the codebase. If its secret keys, then yes, he's insane and it needs to be escalated to security.
1
u/Wartz 4d ago
Of the many stupid things I’ve seen on the Internet since I first pulled up a chair and fired up my modem in 1997, saving passwords and API keys to a place where somebody could find them easily is always near the top of the stupid list.
1
u/api-tester 2d ago
There’s not really a way to hide these keys. If you bundle them with the app, anyone who decompiles it can see the keys. If you have the app fetch them on launch then anyone who intercepts the network requests can see the keys.
The best you can do is to avoid having globally scoped API keys and instead restrict access to resources by user. That way you don’t even have a key to hide from others.
1
u/Effective_Kiwi5359 2d ago edited 2d ago
How come your lead with no basic common sense becomes the lead? I have a co-worker who did that too all the time and I deleted his code every time he did that. Even his coding agent deleted the keys he put in the code; but for some reason he just kept doing that. Amazingly the manager was fine with this until one day the audit department gave warnings to the code base.
IMHO, you should push back as hard as you can because it is just not the way to go. This will never pass a security audit if your company has that department. The startup approach you mentioned is the bare minimum.
1
u/Foreign_Awareness614 1d ago
They should not be your lead.
-1
u/Inttegers 7d ago
This is a sufficiently silly idea so as to make me question their judgement.
0
u/yknx4 7d ago
Ejson is your answer
-3
u/JakeArvizu 7d ago
Seems like a performative question to ask a public channel. I think most would see "commit keys". Then agree with you.
2
u/[deleted] 7d ago
[removed] — view removed comment