this post was submitted on 18 Aug 2024
75 points (97.5% liked)

Programming

17432 readers
155 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
 

I know that pushing a commit with an API key is something for which a developer should have his balls cut off, but...

...I'm wondering what I should do if, somehow, I accidentally commit an API key or other sensitive information, an environment variable to the repo.

Should I just revoke the access and leave it as is, or maybe locally remove this commit and force-push a new one without the key? How do you guys handle this situation in a professional environment?

you are viewing a single comment's thread
view the rest of the comments
[–] thesmokingman@programming.dev 85 points 3 months ago (2 children)

Other answers have only called out rotating the secret which is how you fix this specific failure. After you’ve rotated, delete the key from the repo because secrets don’t belong in repos. Next look at something like git-secrets or gitleaks to use as a local pre-commit hook to help prevent future failures. You’re human and you’re going to make mistakes; plan for them.

Another good habit to be in is to only access secrets from environment variables. I personally use direnv whose configuration file is globally ignored via the core.excludesfile.

You can add other strategies for good defense-in-depth such as a pre-receive hook checking for secrets to ensure no one can push them (eg they didn’t install hooks).

[–] jet@hackertalks.com 21 points 3 months ago

The smoking man clearly has engineered with humans before. Kudos for excellent advice.

[–] FizzyOrange@programming.dev 9 points 3 months ago (3 children)

only access secrets from environment variables

I kind of think this is a bad idea because environment variables can be read from anywhere and aren't designed to be secret.

But I'm not sure what a better solution is tbh.

[–] calcopiritus@lemmy.world 13 points 3 months ago (1 children)

Storing them in files with correct permissions.

[–] cupcakezealot@lemmy.blahaj.zone 3 points 3 months ago

also storing them outside of the webserver directory

[–] pupbiru@aussie.zone 3 points 3 months ago

you’re not entirely wrong, but this is the current standard/accepted advice for local development - probably what we’re talking about given this thread is about git commits - because the chance of exploit via this mechanism requires local access… with such access, you’re pretty screwed in far more ways

[–] umami_wasbi@lemmy.ml 1 points 3 months ago

Sops, or OpenBao