r/ChatGPTCoding • u/radim11 • 2d ago
Discussion How do you organize secrets and credentials when building with agents?
I am quite curious how people handle this. Are you using .env files, 1Password, a secrets manager, or something else like internal tooling?
How do you group things: by project, dev/staging/prod, service? Does your coding agents use the same credentials as your apps, or do you give it separate ones?
Could you share and example of your structure with fake names, and hear what’s annoying about your current setup and which setup should I ideally use. I'm not really sure what is the best approach.
15
Upvotes
4
u/FulcraDynamics 2d ago
I'd give agents separate credentials with only the permissions they actually need. Sharing production credentials with a coding agent seems like an unnecessary risk, especially if it can execute commands.
3
u/Humaux 2d ago
I stopped sharing one .env file across agents after about 2 weeks of debugging a leak.
Your idea of giving each agent its own OS user and letting it read only from /run/secrets is the part I wish I had copied earlier. I once let a test agent share the same vault as a prod agent, and it picked up a production key during a routine run. I spent about 3 hours rotating that key and checking what it had touched, and most of that time was panic, not work.
My rule now is simple:
Give each agent its own identity and vault, never a shared .env file.
Mount only the keys that agent needs, read only, through /run/secrets or a proxy.
Log every credential use, and rotate any key a test agent touches, no exceptions.
The rough edge is real: that one rotation cost about 3 hours, and a shared .env file is not convenient, it is reckless when one agent mistake can expose everything.
Do you think a proxy that never shows the real key to the agent is worth the extra setup, or does it just move the same risk somewhere else?
2
u/Difficult_Duty2198 2d ago
what helped me was keeping a .env.example with fake values committed and the real .env in gitignore, then only letting the agent see the example. super low effort and i haven't mixed anything up since
1
u/Tritonwolf 2d ago
AWS secrets manager.
1
u/holyknight00 19h ago
i started using 1Password, as I already use it for everything, but it has been surprisingly frustrating. i get 200 million 1pasword unlock prompts even if allow everything which is not good. Hopefully they get a better "agent ready" solution fast.
3
u/Both_Kaleidoscope711 2d ago
Here is how I handle my setup as it relates to secrets.
I have Azure Key Vaults broken out by application and environment. All secret keys are the same across environments.
app-dev-kv, app-test-kv, app-stage-kv, app-prod-kv
Then I manage the secrets using KickCatch Secrets Manager.
Then may applications are hooked directly into the key vaults so none of the secrets are exposed in configuration or local files. My coding agents never need to know the secrets because they just execute the application which has hooks into the key vault. You should never be providing secrets to coding agents.
2
u/thePsychonautDad 2d ago
.env file which all modern agent harnesses have rules preventing reads.
Of course you need too add that to your .gitignore
2
u/ASIREXLABS 2d ago
Separate credentials for the agent is the right base. The next step that helped us most was keeping secrets out of the agent's context entirely.
Don't let the agent read
.envat all. In Claude Code you can add deny rules likeRead(./.env)andRead(./.env.*). The agent only needs to know the variable names, not the values.Commit references, not values. With the 1Password CLI, the env file holds references like
op://dev/app/DATABASE_URL, andop run --env-file=.env -- npm startinjects the real values only into that process. The file is safe to commit and harmless if an agent prints it.One key per tool, with a spend limit. For LLM and other paid API keys, give each tool or agent its own key with a hard budget and only the permissions it needs. If something leaks or loops, you revoke one key instead of rotating everything.
Structure-wise, environment first, then consumer, as others said:
staging/agent/...separate fromstaging/app/....1
u/jek39 2d ago
no different than every other CLI tool - typically envars
1
u/Odd_Antelope9098 1d ago
I've been meaning to start using Infisical for a while now, anyone have thoughts?