r/androiddev • • 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?

137 Upvotes

60 comments sorted by

35

u/PhilMcGraw 7d ago

Are these just static keys for calling the API?

17

u/ikingdoms 7d ago

Keys used to initialize SDKs, for analytics, paywalls, feature flags, cloud providers etc.

82

u/tadfisher 7d ago

Those are public anyway once you ship your app.

33

u/otherworld-dev 7d ago

Yeah, the CTO is correct here.

Those keys can be pulled by decompilation/mitm proxy

Or if you consider webapp, they can be captured by devtools

3

u/Ahmouse 7d ago

It doesn't hurt to obfuscate them if you want to discourage reverse engineering. They should be considered publicly accessible though.

1

u/pyrulyto 7d ago

Yeah, if it’s a key/secret pair, it is even good to have the keys there, as long as the secret stays away. GitHub et all offer ways to store secrets that are tied to its security (which is an actual security model, unlike git’s, which is mostly a public ledger)

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.

6

u/nichogenius 4d ago

I don't see anything in OP's post that implies public keys are in play.

5

u/tarwn 7d ago

And then to add to that, if you're using a KMS you may actually store secrets in git, but they're encrypted and the decryption keys are somewhere else protected with limited access 

2

u/star-ace-66 3d ago

Why do you suspect this? Very clearly he's talking about private keys

2

u/ObviousTrick7 1d ago

Because that’s so dumb no one could seriously think about internationally commiting real secrets

1

u/star-ace-66 1d ago

Well he did say this as a replacement to a secrets vault, there would be no reason to keep public keys in a secrets vault

1

u/ObviousTrick7 1d ago

I will say as personal practice due to effort involved in editing env vs secrets it is way easier to shove almost everything including public keys into secrets.

Really I was just trying to come up with some possible justification for the statement

-5

u/kernald31 7d 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 7d ago

With stuff like the Bitrise hack recently you can no longer guarantee that your private git repo is actually private

4

u/kernald31 7d 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.

-2

u/Equivalent_Help_4690 5d ago

It’s best practice to expose neither.

10

u/appmapper 5d ago

Huh? No. Public keys are just that, public. Meant to be published.

1

u/platinummyr 2d ago

It's probably still ideal to not bake the public key directly, but ensure you have some scheme for rotation in the inevitable event you have to revoke a key

1

u/appmapper 1d ago edited 1d ago

Bruh, that’s not how keys work. A public key stops working the second you rotate it (api) or change the private key you sign with (PKI)*.

Public keys are called that because they are the key that is supposed to be exposed.

If your setup relies on your public keys not being exposed, that’s not a public key, that’s a private key.

*pending CRL depending on how you want to define it

1

u/platinummyr 1d ago

Right. I guess I was thinking about it like "make sure it's easy to change the public key so that when you need to rotate the private key, it is easy to update the public key and you don't brick a bunch of clients" but you can just release a new version of the client and then everyone has to update or else it won't connect because the private key is different.

1

u/star-ace-66 3d ago

Depends on the purpose. Every website you visit exposes their SSL public key. Something like Bitcoin, you might want to hide it for privacy.

If you use SSH for GitHub, FYI, GitHub exposes all of your SSH public keys to everyone

-1

u/MissionGround1193 4d ago

C : Hello, who are you claiming to be?

S : Fuck Off.

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/

3

u/sam_dc73 5d ago

Agree, I have this argument with Infosec teams at every single client I ever work with.

If it ends up in a public binary, it can go in source control, full stop

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.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 7d 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.

0

u/xThomas 5d ago

What the fuck website builder is this

Ok, i found it. Thank you for lmk this is a thing the shitty software i (don’t) use can do.

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.

4

u/SirFrankoman 7d 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/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).

  • production keys goes in CI secrets vault and almost no one ever has access to, maybe the CTO.
  • dev keys goes into password protected secret vault distributed to the team (something like 1password or keypass) and added to the local dev environment via something on .gitignore OR environment variables

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.

1

u/NatoBoram 7d ago

Surprisingly enough, top answers are in favour of committing API keys.

3

u/tadfisher 7d ago

API keys that ship with your app are not secrets.

2

u/[deleted] 7d ago

[removed] — view removed comment

1

u/androiddev-ModTeam 3d ago

Use your own voice when writing. Posts and comments which appear to be generated, including those with excessive flourish, gushing or emojis, will be removed.