r/devops • • 2d ago

Discussion How are you managing secrets across multiple projects and environments?

I'm curious how other developers and small teams handle secrets when they have multiple projects and environments (Dev, Testing, Staging, Production).

I'm finding that the workflow gets messy surprisingly quickly when multiple people are involved. Sharing .env files, managing access, making sure someone doesn't accidentally overwrite production credentials, keeping everything organized across projects, etc.

What are you using? What frustrates you the most about your current setup?

37 Upvotes

57 comments sorted by

47

u/Efficient-Branch539 DevOps Engineer 2d ago

We manage secrets with Hashicorp Vault and inject in applications at the runtime. There are many ways you can do this depending on the infrastructure.

5

u/Motor_Plane_8036 2d ago

runtime injection really is the way to go, saves so many headaches compared to passing static files around

2

u/ravnmads 1d ago

I used to work on backend systems, and I do agree on your sentiment.

But how would you do it with Mobile Application? How would you do it there?

25

u/centech 2d ago

Mostly AWS Secrets Manager w/ ESO to expose them in EKS. Still SM when it's not EKS.. which for us mostly means Lambdas.

3

u/MediumPomelo6360 DevOps 2d ago

SM is a bit expensive ($0.40 per secret) to store a large number of secrets for small teams

4

u/Ok-Profession-7181 1d ago

Alternatively there is AWS Parameter Store which is much cheaper and still supports secret values. We used that at my old job and were happy with it, there are even tools like chamber and aws-env that will bulk load parameters as environment variables.

2

u/MediumPomelo6360 DevOps 1d ago

parameter store standard is free

1

u/Zenin The best way to DevOps is being dragged kicking and screaming. 1d ago

Just how many secrets does your small team have? You can pay the monthly for a couple hundred secrets for the cost of an hour of a jr dev's time.

1

u/derprondo 1d ago

Do you do anything special to manage the secret values? I'm on the platform team so I don't really have to deal with huge numbers of secrets myself, but we direct our customers to create the empty SM objects with Terraform and then use the AWS console or cli to set the values (to keep the values out of Terraform state files).

The issue I'm about to encounter is that we're working on using completely ephemeral branch environments instead of long lived static environments, which means dealing with secrets manually isn't feasible, but I still can't have secrets ending up in Terraform state files.

1

u/Zenin The best way to DevOps is being dragged kicking and screaming. 1d ago

Consider using ephemeral values and ro values where the provider supports it:

https://developer.hashicorp.com/terraform/language/manage-sensitive-data/ephemeral

1

u/rhysmcn 1d ago

Yes ephemeral is great when you need to supply a resource with a password at the time of creation. However, if the resource is not created via IaC and the secret is already created but you want to manage the secret resource itself via IaC what derprondo said is a good way to go.

I have used it plenty times, and works great.

16

u/New-Entertainer6392 DevOps 2d ago

I'm in azure and use azure key vault, assume the aws one is the same...

Vault per env, same named keys on each, just different values.

Some apps get the keys themselves from keyvault, some get them via env vars (and that's specially injected by k8s

30

u/nextlandia 2d ago • Bravo

Openbao

7

u/KevMar 2d ago

You keep the secrets in each environment. Either key vault or secrets manager. Then you only give devs direct access to the lower environments and the only thing that touches prod is the pipeline.

5

u/sp_dev_guy 2d ago

Different readdit posts - newest comment is the current password. Systems do a lookup on init.

Free storage, HA, no vault or master password to protect. Rotation & uptime are easy with no maintenance required

4

u/Aide_Sea 2d ago

Whatever tool you pick, I think the bigger fix is just that people don't have prod access at all. Devs read dev and staging, only the deploy pipeline can read prod. Then nobody can overwrite prod creds by accident, and offboarding is way less scary :)

4

u/raisputin 2d ago

I just set them all to “password” and call it good, nobody ever guesses that 🤣🤣🤣🤣🤣

J/k

6

u/scottgal2 2d ago

I use Infisical. Pretty easy to manage access & allow editing, auditing etc.

2

u/generic-d-engineer ClickOps 2d ago

Easier than vault ? There’s no seal/unseal nonsense?

Looked at this one but have never tried it so curious if you can compare to vault.

3

u/Fit-Main6094 1d ago

Infisical

2

u/kloudnative 2d ago

AWS secrets manager

2

u/Azy-Taku 1d ago

We have a self hosted instance of infisical, which gives project based access across environments.

3

u/___-____--_____-____ 2d ago

As a solo dev I make heavy use of sops. Nixos (which my compute hosts run) and FluxCD (which is how I configure workloads) both integrate with it pretty seamlessly. I've been happy with it so far. Having secrets be versioned kind of eliminates the overwrite scenario, and since everything just applies what is in git, rotating secrets etc is kinda nice. Or at least, a lot less hands-on than I was used to.

https://github.com/streetfortress/forts

2

u/akhilesh_gone 2d ago

U can use sops with sops u can push the envs to git as sops encrypt them

1

u/PrestigiousStrike779 2d ago

AWS secrets manager and IAC (CDK) to configure on deploy.  For most things we allow either a direct load of the value from environment variable or a secret.  The direct value works well for a local Postgres connection for example while a deployed environment loads from a secret.  Developers/QA only have access to the secrets in the develop account if it’s needed for local installs.  Everything is configured by environment variables (including what secret to load), no .env files are checked in.

1

u/snopedom 2d ago

We have SM per env, each env is its own AWS account. External Secrets binds them into k8s by app/namespace prefix, so every app only sees its own secrets. Nobody touches prod secrets by hand, so nothing gets overwritten by accident

1

u/NoPomegranate9625 2d ago

We have a strict ” everything on gcp secret manager” policy.

Each service we build fetch them directly so the k8s manifest only need to contain the name of the secret. (Combined with a simple secret name scheme it is super efficient)

For the few services we don’t build we resolve the secret into a three actual value at config generation time. They end up in the config but it is ok. (Minimal number of services have k8s api access in prod)

1

u/Official_BetterSWE 2d ago

the other half is having fewer static secrets to share at all. CI can use OIDC to get short lived cloud creds instead of a stored access key, and vault can hand out db creds that expire on their own. then the .env sharing problem shrinks to a handful of third party api keys, which is way easier to keep tidy

1

u/dusanodalovic 2d ago

sops with age here too, and what fixes the overwrite worry is one age key per environment. in.sops.yaml you add a creation_rule per path, so secrets/dev/ is encrypted for the team key and secrets/prod/ only for the key that lives in ci. devs still see the prod file in git, they just cant decrypt or edit it, so nobody overwrites prod with their local value by accident. one more reason to drop plaintext.env files: if you run coding agents in the repo, the agent and every tool it starts can read them. encrypted files in git dont have that problem

1

u/engineerL 1d ago

We avoid secrets like the plague. The one secret we can't get rid of, we put in GH Actions Secrets.

1

u/Downtown_Cat_7425 1d ago

For small projects, the thing that helped me was separating where a value lives from how the app reads it.

  • Keep a template in the repo with variable names only, never values.
  • Give each environment its own values outside git, and never let dev borrow production credentials.
  • Have the app read from environment variables at startup, so rotating a secret doesn't mean touching code.

The mistake I kept making was copying a staging value into production because the name matched. Prefixing each name with the environment and checking them at startup caught that.

Vault-style tools make sense as a team grows, but these basics remove most of the "who overwrote the credential" mess.

1

u/NoDevelopment206 1d ago

for a small team i'd keep it simple. parameter store or sops in the repo covers most of it and costs almost nothing. vault is great but you end up running and unsealing it, which is a real job on its own. the thing that bites people is prod secrets being editable by everyone, so i'd split access per environment first and worry about the tool after.

1

u/DoOmXx_ 1d ago

infisical or doppler if vault is overkill, just keep prod creds off laptops

1

u/jaeckanaquth 18h ago

Github secrets, aws secrets manager, Azure keyvault

1

u/java_bad_asm_good 2d ago • Bravo

Coming from AWS Secretsmanager and ESO, my current company uses SOPS and it‘s really grown on me. All secret changes are auditable in git, and write-only changes (by granting kms:Encrypt but not Decrypt) are straightforward.

3

u/OwwwnShip 2d ago

Storage is honestly the easy part, everything listed here works fine. What bites us is that nobody knows what a given secret is attached to, so rotating one turns into a day of pinging teams asking whether their thing still starts.

We ended up naming each secret after the service that owns it and putting the owner in the description. Rotation is still boring, at least now I know who to warn first.

1

u/Jan_Stepan 1d ago

And is it one service to one secret or can you have multiple services dependent on the same secret?

1

u/OwwwnShip 1d ago

Ideally one secret per service, but in practice a few end up shared, a database password that two or three services read is the usual one. For those we list every reader in the description, and whoever rotates it works down that list. Not elegant, but it beats finding out about a forgotten consumer from a page at 3am.

1

u/Jan_Stepan 14h ago

Seems reasonable. Better than any 3am shenanigans

1

u/carsncode 2d ago

Dev access: non-prod only, via 1pass op run using placeholder env files

Running services: separate vault per environment, synced in with ESO

0

u/khaled_shehata 2d ago

I've been reading about exactly this while studying DevOps. The pattern that comes up most in docs and talks: .env files stay local and out of git, pipeline variables (GitHub Actions / GitLab CI) hold the per-environment values, and for sharing across a team people usually point to SOPS or HashiCorp Vault. The mozilla/sops README on GitHub explains the SOPS approach well. Curious — for a team of 2-3 people, is Vault overkill compared to SOPS?

2

u/generic-d-engineer ClickOps 2d ago

I think so, vault can be pretty heavy for a smaller team

1

u/khaled_shehata 1d ago

That makes sense, thanks. I'm still learning, so I only know Vault from reading about it. For a small team, what do you use instead? Something like SOPS, or just the CI/CD variables?

1

u/generic-d-engineer ClickOps 1d ago

Sops for now, but if I had to scale up I’d try Infisical next cause trying to wrangle everyone’s sops keys manually can be a challenge once they start sprawling

-1

u/nickjj_ 2d ago edited 2d ago

One thing I came up with for a medium sized team that worked nicely was:

  • (1) encrypted and versioned S3 bucket

    • The versioned bucket helped keep track of changes as an audit log
  • Paths like myapp/.env.staging or anotherservice/.env.production
  • A ~200 line general purpose shell script to handle downloading, uploading and diffing which was called such as ./secrets myapp --env development, it had all sorts of quality of life things like protection against overriding files by accident, etc.

    • All it did was upload or download a file from S3 to the machine the script was run on, applications had no idea about S3, they just dealt with env variables

Developers loved it because keeping shared env files in sync was so easy, you can see what changed and it didn't involve copy / pasting values from anywhere.

It also worked nicely in CI and production because all access control was handled by IAM permissions. It was really easy to onboard and offboard folks since it was related to AWS access. It was also easy to limit access to production credentials.

It ticked every box we wanted and also had no problem passing various compliance checks. It was also extremely cost efficient (side bonus).

2

u/Zenin The best way to DevOps is being dragged kicking and screaming. 1d ago

Oh My God

1

u/nickjj_ 1d ago

What's wrong with that?

Security wise, it was good enough for a 500 million dollar FinTech company where multiple teams within the org had no problem with it.

If you don't need per secret access control, it's completely fine. I've never worked anywhere where someone could access foo=bar but not hello=world secret in the same environment file. It was always per environment (dev, prod, etc.) access control.

1

u/Zenin The best way to DevOps is being dragged kicking and screaming. 22h ago

What's wrong with that?

Where to even begin?

The specifics of the encryption you're using matter a great deal if you're able to actually audit it or not. And bucket versioning is not a substitute for an actual audit log. -That's what CloudTrail is for which only gets part of the story by default in your model even assuming you didn't screw up the encryption knobs.

Developers loved it because keeping shared env files in sync

Why do they have anything to keep in sync? In sync with what exactly?

Are you really syncing every <env> level secret to every single service regardless if it uses it or not?

Are you really reusing the same secrets across multiple services? Meaning if anything needs to talk with X they get the same secret (and thus identity) with the same access scopes?

Developers love all kinds of incredibly stupid ideas to the point that a large part of "DevOps" is both mentoring them on correct methods and enforcing them.

YOLOing a giant catch-all .env.production grab bag of secrets to every single "prod" service has got to be one the most gobsmack awful patterns I've heard of in ages. Did I misread something or is this really what is guarding a "500 million dollar FinTech company"?

and also had no problem passing various compliance checks.

Then your auditors are completely incompetent.

1

u/nickjj_ 10h ago edited 10h ago

assuming you didn't screw up the encryption knobs.

There's not a whole lot to screw up here given AWS will encrypt buckets by default. This has been the case for years.

Are you really syncing every <env> level secret to every single service regardless if it uses it or not?

What do you mean here? There is 1 file for each service and each service also has 1 file for each environment.

I think you misread something critically important in my post which was this bullet:

  • Paths like myapp/.env.staging or anotherservice/.env.production

You parsed that as everything shares everything, but that's not the case. "myapp" and "anotherservice" are different services, each with their own set of files.

Nothing is shared between services and nothing is shared across environments. Services only have secrets they use. There's also separate access control for each file controlled through IAM permissions.

1

u/Zenin The best way to DevOps is being dragged kicking and screaming. 4h ago

There's not a whole lot to screw up here given AWS will encrypt buckets by default. This has been the case for years.

If this is your take than I guarantee you've screwed up the knobs.

Study up on the differences between SSE-S3, SSE-KMS, CMKs, Bucket Keys, etc. The only thing your default bucket encryption has done for you is guard you against someone physically stealing a drive out of an AWS data center.

You also need to make sure you've enabled data events for S3 in your CloudTrail; they aren't recorded by default.

You also need to make sure you've enabled integrity validation in your CloudTrail; it wasn't always default and should always be confirmed.

...You also need to make sure you've enabled CloudTrail...something I shouldn't have to point out, yet sadly feel that it can't be assumed in this context. -It wasn't always enabled by default and should always be confirmed.

As I mentioned before, S3 versioning is not an audit trail.

What do you mean here? There is 1 file for each service and each service also has 1 file for each environment.

Better. Still not best practice, but it's (a little) better.

What is best practice? Each secret gets managed and lifecycled as a distinct entity.

I'm still not convinced from your statements so far that you aren't using the same secret values across multiple services even if each service has "its own file" in S3. For example, if apps A and B need to call service X do A and B each get their own unique secret or do they get the same secret saved to both A and B config files?

There's also separate access control for each file controlled through IAM permissions.

So let me see if I have this straight:

Object prefix based policies around a single bucket holding all the keys to the kingdom.

Multiple secrets stored in the same object.

Every last one of which "encrypted" with the same toothless default key.

No key segregation by domain.

No real audit trail, much less a tamper resistant or aware audit trail.

This reads like an ARTEX honeypot, not the keystone of a $500M FinTech estate.

---

The real question Nick, is why did you choose to reinvent this wheel?

Secrets management is a well-solved problem space. The tools, the patterns, the sharp edges, they're all hard won and very well understood.

What was it about the battle tested, first class options, most all of which cheap or free for the asking; what was the critical missing feature of all those options that forced you to climb this hill?

As a DIY homelab project for academic purposes, absolutely; Reinveting the wheel is a tried and true study technique. But to put such a thing in serious production, why? Can you share the thinking behind this critical ADR?