Let me trim it down to target range. Most security advice for AI agents focuses on the model. The harder problem is the access you give it. An agent that can open pull requests or query production is an identity with privileges. The model decides what to do next; the credentials decide how much damage.
For a business owner, that translates into three exposures: unexpected cloud spend, customer data leaving systems it should not, and changes to production that are hard to attribute. None of these require a sophisticated attacker. A confused agent with broad permissions is enough.
Agent tooling often arrives through the side door. A developer wires up a proof of concept, pastes a long-lived cloud key into an environment file, and the agent does useful work. Later, nobody remembers which key it uses, who owns it, or what happens if that developer leaves. This guide avoids that without turning a small DevOps team into a security department. The goal is proportional control: enough to contain a mistake, not so much that shipping stalls.
Ask what an attacker could do with the agent’s credentials alone if the model is compromised by a malicious prompt or poisoned document. If the answer is “read one repo and open a draft PR,” it’s manageable. If it’s “assume the production role,” it’s a business continuity problem.
Agents chain tools together non-deterministically. A retrieval step can pull untrusted text that influences the next tool call. The OWASP Top 10 for LLM Applications treats prompt injection and excessive agency as separate risks for this reason. Both have authorization dimensions. You cannot reliably filter prompt injection, but you can limit what it can reach.
Before buying tooling, list every credential an agent can use. For each, record the system, permissions, environment, accountable person, rotation method, and storage. Include personal access tokens, service account keys, webhook URLs with embedded secrets, database passwords in CI variables, and OAuth refresh tokens.
This unglamorous step exposes shared credentials, keys that outlived projects, and tokens with write access that only needed read. Those fixes are usually cheaper than any platform purchase. If you can’t produce the list, adding more agents adds unknown risk.
Broad permissions are easier to grant than to debug. Give each agent its own identity per environment, never a shared “automation” account. Grant permissions on specific resources, not wildcards. Separate read-only analysis from agents that mutate infrastructure.
In Kubernetes, RBAC is additive with no deny rules, so a broad ClusterRole binding overrides namespace-scoped design. Use namespaced RoleBindings and admission policies when needed. In cloud IAM, permission boundaries stop agents from granting themselves more access. Template roles and review them with the agent’s code to keep overhead bounded.
Kubernetes also mounts a service account token into pods by default. Disable automounting where the workload never calls the API server, and set an explicit audience on projected tokens so a token issued for one service is not accepted by another.
Remove long-lived secrets when possible. Let the runtime prove its identity and receive temporary credentials. GitHub Actions can use OpenID Connect to assume a cloud role without stored keys. Kubernetes can project time-bound, audience-bound service account tokens. SPIFFE and SPIRE extend this across clusters and clouds.
For OAuth-based tools, request tokens for a specific resource. RFC 8707 defines resource indicators: a token for one API should be useless against another.
Short-lived credentials add identity-provider dependencies, make local debugging harder, and break tooling that only accepts static keys. Clock skew and misconfigured trust policies cause failures that look like app bugs. Make them default for new integrations, isolate legacy systems that can’t support them, and put exceptions on a rotation schedule with named owners. The identity provider becomes a tier-one dependency, so monitor it and document what happens when token exchange fails.
Kubernetes Secrets are base64-encoded, not encrypted, and stored in etcd. Encryption at rest must be configured deliberately; without it, anyone with etcd access or a backup has the secret. The Kubernetes documentation states Secrets are not encrypted by default.
Options: cloud-native secret managers (mount or sync), External Secrets Operator (leaves copies in etcd), Secrets Store CSI driver (mounts as files without persisting as Secrets), or self-hosted Vault (dynamic secrets and auditing but you operate a critical stateful service).
Choose by team capacity. A small team on managed Kubernetes usually gets more security per hour from a cloud secret manager plus etcd encryption than self-hosting Vault. Also avoid passing secrets via environment variables where possible: use tightly permissioned files or a sidecar to limit exposure in crash dumps and child processes.
Apply default-deny egress so agents reach only approved APIs. Run untrusted code in a sandbox. Put a gateway in front of tool calls for authorization, rate limits, and logging in one place.
For Model Context Protocol servers, treat each as a third-party integration. The MCP security guidance calls out token passthrough, confused deputy scenarios, and session hijacking. Don’t forward a user’s token to an API that didn’t issue it, verify the server acts for its principal, and bind sessions to the creating user.
Require human approval for destructive or irreversible actions: deleting data, changing production networking, or rotating credentials. Reserve approvals for expensive, hard-to-reverse actions.
Log every tool invocation with agent identity, delegated user if any, target resource, decision, and a correlation ID. Cloud and Kubernetes audit logs cover infrastructure; your gateway covers intent. Redact prompts/responses at ingestion, restrict access, and set retention; log storage is a quiet cost.
Alert on behavior: new source IPs, bursts of permission-denied responses, unusual tool-call patterns, or one credential used from two regions. Costs include secret managers, gateways, sandboxes, logs, identity providers, and engineering time. Per-secret and per-request pricing can dominate when you store many small credentials, so consolidate where it does not weaken isolation and cache reads instead of fetching on every tool call. Short-lived credentials and gateways move spend from incident response to budgetable engineering. Fix cheapest high-impact items first: unused keys, shared identities, etcd encryption, and audit logging.
None of this requires a large program. It requires treating agent credentials as production identities and applying the controls you’d expect for them.
Are Kubernetes Secrets safe for agent credentials?
Acceptable as transport, not a security boundary. Enable encryption at rest, restrict Secret access in the namespace, and prefer a secret manager or CSI-mounted files for high-value credentials.
Do we need a separate identity for every agent?
At least per agent and per environment. Shared identities make least privilege impossible and audit logs ambiguous. Template roles and review them with agent code to manage overhead.
Can better prompts fix prompt injection?
No. Treat it as an authorization problem. Assume untrusted text can influence tool calls, then limit reach through scoped credentials, egress rules, and approval gates.
What to do first with limited budget?
Inventory and delete unused credentials, split shared accounts, enable audit logging, and turn on encryption at rest. Add a gateway and short-lived credentials next.
How often should agent credentials rotate?
Prefer credentials expiring in hours and issued on demand. Where static secrets are unavoidable, rotate on a risk-based schedule, automate it, and record an owner. Manual rotation nobody performs isn’t a control.
Does this slow down development?
Initially yes. Scoped identities and gateways add setup and access-denied errors broad permissions would hide. The return is fewer emergency rotations, clearer audits, and a smaller incident when something goes wrong.
If you’re building agents on Kubernetes and want a second set of eyes on identity, secret, and network boundaries before production, Kubeify can review the design and help prioritize fixes. Talk to our team.
Kubeify's team decrease the time it takes to adopt open source technology while enabling consistent application environments across deployments... letting our developers focus on application code while improving speed and quality of our releases.
– Yaron Oren, Founder Maverick.ai (acquired by OutboundWorks)
Let us know what you are working on?
We would help you to build a
fault tolerant, secure and scalable system over kubernetes.