When AI generates configuration files for you, how do you deal with the API keys and secrets?
Initially, I even pasted Supabase key directly into prompt because of request from the agent. It found its way to the file that I was about to commit. I noticed it in the diff accidentally.
In any case, I formulated certain guidelines. Secrets reside exclusively in the environment files that appear in the gitignore list prior to the first commit. I never insert secrets into chat prompt, using only placeholders such as SUPABASE_URL. And before every push, I perform quick search for long seemingly random strings.
Despite this approach, the situation remains pretty fragile. In many cases, agents generate example of env file with actual secret values and sometimes they write something to the console that they should not.
One of my friends suggested me pre-commit hook that would prevent committing secrets based on pattern matching. It appears that I will try to implement it this week.
How do you protect yourself? Do you rely on secrets scanner, on secrets manager like Doppler or on personal discipline only? Has AI ever revealed some secret unexpectedly?
Replies
For the env file point you mentioned:
Not the agent itself, but where it works: our coding sessions each get a git worktree inside the repo folder, some with their own gitignored .env.local. A `.env.*` line in .dockerignore only matches at the root of the build context, so a Docker build from the main checkout takes all of those along; `**/.env.*` is the line that catches them.
One lever that gets overlooked: needing fewer keys at all. My backend calls Google's models through Vertex with the server's own service account, so there is no AI key anywhere, not in env files, not in chat. Real secrets live in a cloud secret manager and are bound to the single function that needs each one, and I set them myself on the command line, the agent never sees the values. Non secret config goes in a git ignored env file, with every key documented in a committed example file that holds no values. And the rules file says which config files are public identifiers and safe to commit, like the Firebase client configs, so the agent does not have to guess.