Skip to main content

Securing production AI agents: what we should have been doing with SREs all along

Β· 11 min read
Idriss Neumann
founder cwcloud.tech

Our feeds are full of posts about securing secrets on developers' workstations against coding agents: keep your .env files away from them, sandbox the agent, don't let it read your SSH keys or your cloud credentials. Useful advice indeed. Meanwhile at the same time, we're pushing agents that do the work of SREs, in production: they call APIs on our behalf, read clusters, install Helm charts, open merge requests, investigate incidents. And that side of the subject doesn't seem to be dug into nearly enough: what credentials do we hand these production agents, for how long, and who watches what they do with them?

The answer we keep coming back to is: tokens, certificates and keys that are short-lived, scoped and revocable, with everything the agent does logged and audited. But the more we work on it, the more obvious it gets that none of these requirements is specific to AI. They have always applied to the human SREs and DevOps engineers who administrate our platforms, and we rarely enforced them.

One thing should be clear though: in 2026, long-lived keys and secrets are no longer acceptable, for agents or for anyone else.

Agents make an old problem impossible to ignore​

An agent is a program that decides by itself which calls to make, with inputs it doesn't fully control (a prompt, a web page, an issue comment, a log line...). It can be manipulated with prompt injection, it can hallucinate a destructive command, and whatever it's handed may end up in a model provider's logs, a tool trace or an observability backend.

So the rules for an agent's credentials are pretty straightforward:

  • expirable and short-lived: minutes or hours, not months, and never "no expiration";
  • scoped: the agent gets exactly the rights it needs for the task at hand, not the ones of the person or service account that launched it;
  • revocable at any time, including while the agent is still working;
  • never the human's own session: a leaked agent credential must not be a leaked user.

Now replace "agent" with "SRE" in that list. How many of us have seen an engineer leave a company while keeping a working kubeconfig on their laptop, an SSH key still authorized on a bastion, a personal access token without expiration, or a cloud IAM user nobody remembered to delete? Those requirements have always been just as valid for humans. Agents simply make the risk too visible to ignore: they run 24/7, they can be told what to do by text, and there will soon be many more of them than us.

In 2026, a long-lived secret is a liability​

Let's be blunt: in 2026, it's no longer normal to have long-lived keys or secrets. An API key without expiration, a cloud access key created three years ago, a kubeconfig with a client certificate valid for ten years, a database password shared in a vault folder and never rotated, an SSH key authorized "temporarily" on every server: each of them is a breach waiting for a leak.

The excuses don't hold any more:

  • every major cloud provider exchanges OIDC tokens for short-lived credentials (workload identity federation, assumed roles), so CI/CD pipelines and workloads don't need static access keys;
  • Kubernetes issues bound, expiring ServiceAccount tokens by default, and SSO-backed kubeconfigs are easy to set up;
  • secret managers can generate dynamic credentials (databases, cloud, PKI) that live only as long as the session that needs them;
  • public TLS certificates are moving to ever shorter lifetimes, and automating their renewal is the norm, not the exception;
  • SSH and Kubernetes access can be granted with certificates valid for a few hours, issued after an SSO login.

A secret that lives for months will leak sooner or later: in a git history, a laptop backup, a CI log, a screenshot, an LLM prompt. The only question is whether it's still valid when it does. Short lifetimes, automatic rotation and the ability to revoke instantly turn that leak from an incident into a non-event. Any long-lived secret left today should be treated as technical debt with a security cost, and listed, owned and scheduled for removal.

A recent example in the Discord ecosystem: in October 2026, Double Counter, a widely used Discord security bot, was compromised through a retired server that was no longer part of production but still exposed an old analytics instance. On that forgotten machine, the attacker found a cloud service-account key with administrator rights and an administrator's saved command-line session. With them, they added their own SSH key to the cloud project, exported databases, pulled the bot's Discord token from a running container and used it to spread through about 50 large communities, and once the key was revoked, they kept going with the stolen admin session. Roughly 28 million Discord accounts were reported exposed (GBHackers, Cyber Security News). None of these credentials should have been long-lived, and none should have been left lying on a machine nobody was watching.

AI agents only raise the stakes: they multiply the number of identities and the places where a credential can end up.

Example 1: CWAI's temporary API key​

In CWAI, the AI assistant of CWCloud, the model is an agent with a cwcloud_api tool that calls the CWCloud API as you. Until recently, those tool calls carried the JWT of the connected user. We changed that: your session credential never reaches the assistant's tools any more.

The assistant's temporary API key: CWCloud API -> key -> agent -> LLM

For each prompt:

  • the CWCloud API mints a dedicated API key belonging to you, named ai-agent- followed by 6 random characters, and the tools authenticate with it (X-Auth-Token header) instead of your X-User-Token;
  • the key is deleted as soon as the model has answered, whether the prompt succeeded or failed;
  • should that deletion fail, it expires by itself after 2 hours (configurable) and is purged at the next prompt;
  • it's listed with your API keys, labelled as an AI agent temporary key, and you can delete it at any time, even while the agent is still working: its next calls get a 401, and the assistant stops and tells you it lost access;
  • minting fails closed: if the key can't be created, the tools get no credential at all, never a fallback on your session.

And because the agent itself is instructed to never keep secrets (passwords, API keys or tokens it reads are masked and never passed into another call), a model, a provider or a tool trace that leaks what it's handed only exposes a key that is already revoked.

And this isn't specific to CWCloud: all our solutions implement this key exchange for their AI assistants, with the same ai-agent- keys, listed, revocable and deleted after each prompt: CWClock, CWMerch and StrongFish.

Example 2: an agent that tests Kubernetes addon upgrades​

CWAI is a "conversational" agent. The second example is an SRE agent in the strict sense: an agent we develop in Go, which validates upgrades of the Kubernetes addons deployed with Sveltos before they reach a fleet of clusters.

Functionally, when a merge request bumps the version of a Helm chart in a Sveltos ClusterProfile, the agent:

  1. installs the new version of the chart in a throwaway namespace of a sandbox cluster;
  2. lets an LLM investigate the result with kubectl and helm (pods, workloads, services, RBAC, events, webhooks, CRDs...) and run functional tests (deploy a client pod to call the service, create a minimal custom resource of an operator and wait for it to be ready, kill a pod to check that it comes back...);
  3. comments a validation report on the merge request with a verdict, then cleans everything up.

That means an LLM is typing commands against a real Kubernetes cluster. Here is what we consider the minimum for that kind of agent.

Ephemeral kubeconfigs​

The agent never uses the credentials of the service that runs it. For each validation, a dedicated Kubernetes ServiceAccount is created in the test namespace, and the LLM's tools get a kubeconfig holding a short-lived token for that identity only. Kubernetes itself enforces what it can do: everything inside the test namespace, read-only on a fixed list of cluster-scoped kinds, nothing in any other namespace, and Pod Security baseline on the pods it creates. When the validation ends, the binding and the namespace are deleted, and a janitor removes whatever a crash might have left behind.

On top of RBAC, a guard rejects what RBAC can't express: switching namespace or context, impersonation, reading Secrets, interactive or never-ending commands.

Ephemeral IAM access​

The same logic applies to the cloud side. An agent that needs to pull images from a private registry, read a bucket or query a cloud API should get temporary credentials for a role scoped to that task (STS-like assumed roles, workload identity federation, OIDC tokens exchanged for short-lived cloud credentials...), not a static access key stored in a config file. If the credential can't outlive the task, losing it doesn't matter much.

Bastions and audited sessions​

When an agent (or a human) needs to reach infrastructure that isn't exposed, it should go through a bastion, not a direct network path. Solutions like Teleport go a long way further than a plain SSH jump host:

  • access is granted with short-lived certificates issued after an SSO login, instead of long-lived SSH keys or kubeconfigs;
  • access can be requested just in time and approved for a limited duration;
  • every command and every session is recorded and audited, whether it's ssh, kubectl or a database session.

For an agent, this audit trail isn't a nice-to-have: it's the only way to know afterwards what it actually ran, as opposed to what it says it ran in its report. Our addon-testing agent already attaches all the commands it ran to its report, but a trace written by the agent itself is not an audit log: the record must come from the infrastructure, not from the actor.

Agents that watch agents​

Logging everything is useless if nobody reads the logs. And when agents run around the clock, nobody will read them in real time. That's a job for other agents.

An auditing agent can consume the audit trail (bastion session recordings, Kubernetes audit logs, cloud trails, API logs) and raise alerts when an SRE agent:

  • runs something outside the scope of its task (a namespace it shouldn't touch, a delete while it was supposed to read, an attempt to read secrets);
  • behaves unlike its usual pattern (volume of calls, time of day, unexpected targets);
  • shows signs of prompt injection (a command lifted from a log line or an issue comment rather than from its instructions).

The auditing agent must of course have read-only access to the audit trail and no access at all to what it audits: it can alert (and possibly revoke a credential), not act on production. Separation of duties, the same principle that keeps the person who approves a payment from being the one who issues it.

Conclusion: we should have been treating SREs this way all along​

None of what we described here is an AI invention. Short-lived and revocable credentials (and, in 2026, no long-lived key or secret left anywhere), ephemeral kubeconfigs and IAM access, bastions, recorded sessions, least privilege, separation of duties and someone (or something) reviewing the audit trail: it's exactly the treatment we should always have applied to production engineers (SREs) who administrate the platform.

We just didn't, because humans are trusted, because tooling was painful, because "we'll clean up the accesses when they leave". Agents remove those excuses: you can't trust an LLM the way you trust a colleague, and you can't count on it to remember to give its keys back.

So rather than building a special security model for AI agents, use their arrival to finally apply the right one to everyone who touches production, human or not. The best outcome isn't secure agents: it's a platform where no identity, human or agent, holds an access longer or broader than the task it's doing.

If you want to see these principles at work, have a look at the CWAI documentation, and if you need help securing your own agents or your production accesses, our SRE / DevOps services are there for that.