---
title: Should AI agents on Google Cloud use service account keys?
url: https://opencontroller.lyzr.com/blog/should-ai-agents-on-google-cloud-use-service-account-keys
published: 2026-11-17
updated: 2026-11-17
author: Lyzr
---

# Should AI agents on Google Cloud use service account keys?

**No, not by default. A service account key is a long-lived credential that works from anywhere until someone deletes it, which is the opposite of what an agent should hold. Google Cloud organizations created on or after 3 May 2024 block key creation and upload by default. Use an attached service account, Workload Identity Federation, short-lived impersonation, or agent identity on Agent Engine instead.**

Agents built on Google Cloud often start life in a notebook with a downloaded JSON key. When those agents move to production, the key tends to come along. This guide covers why that is a problem and what to use instead.

## What does Google Cloud enforce by default?

Google applies a set of secure-by-default organization policies to organizations created on or after 3 May 2024 (some created between February and April 2024 may have them too). Seven constraints are enforced, including:

- **Disable service account key creation** (`iam.managed.disableServiceAccountKeyCreation`), which prevents users creating persistent keys for service accounts.
- **Disable service account key upload** (`iam.managed.disableServiceAccountKeyUpload`), which prevents uploading external public keys.
- **No automatic Editor grants to default service accounts**, so default compute identities do not start with broad project access.

If your organization is older, these constraints may not be on. Checking them is a quick first step in any agent security review.

## What should agents use instead of keys?

| Agent runs on | Recommended identity | Credential lifetime | Notes |
|---|---|---|---|
| Cloud Run, GKE, Compute Engine, Cloud Functions | Attached service account via the metadata server | Short-lived tokens, refreshed automatically | One service account per agent |
| GKE pods | Workload Identity Federation for GKE | Short-lived | Maps a Kubernetes service account to IAM |
| Vertex AI Agent Engine | Agent identity (per-agent IAM principal) | Short-lived; no long-lived keys | Cannot be impersonated; see [agent identity on Agent Engine](/blog/vertex-ai-agent-engine-agent-identity) |
| Another cloud, on premises, CI | Workload Identity Federation | Short-lived tokens via Security Token Service | Trust scoped by issuer, audience and subject |
| A developer testing locally | User credentials or service account impersonation | Short-lived | No downloaded keys on laptops |

Federation works by exchanging a signed token from the agent's own platform for short-lived Google credentials, so no secret is stored. The mechanics across clouds are in [workload identity federation for AI agents](/blog/workload-identity-federation-for-ai-agents), and the Kubernetes specifics in [Kubernetes workload identity for agent pods](/blog/kubernetes-workload-identity-for-agent-pods).

## When is a key acceptable, and how do you contain it?

Sometimes a third-party agent platform can only accept a JSON key. If there is no federation option, treat the key as an exception:

1. **Grant a documented, time-limited exception** at the narrowest scope (one project), not by relaxing the organization policy.
2. **Create a dedicated service account** for that one agent, with only the roles it needs.
3. **Set a key expiry** if your organization uses the key expiry constraint, and rotate on a fixed schedule.
4. **Store the key in a secrets manager**, never in code, notebooks or agent configuration files.
5. **Monitor key use** with Cloud Audit Logs and alert on use from unexpected networks.
6. **Record an owner and a removal date** in your agent inventory.

The broader trade-offs between static keys and token-based access are covered in [API keys vs OAuth for AI agents](/blog/api-keys-vs-oauth-for-ai-agents).

## How do you find existing keys that agents use?

Start with an inventory. List service accounts with user-managed keys, the age of each key and when it was last used. Then link each service account to the agent or workload that uses it. Keys with no clear owner, or that have not been used in months, are candidates for disabling. Keys used by agents that could move to an attached identity are candidates for migration.

Pay attention to service accounts shared across several agents. One key compromise then affects all of them, and audit logs cannot tell you which agent acted. The case against sharing is in [should AI agents share a service account](/blog/should-ai-agents-share-a-service-account).

This fits the wider pattern for [governing agents across platforms](/blog/how-to-govern-ai-agents-across-platforms): one identity per agent, short-lived credentials, and an owner for every credential.

## How Opencontroller does this

Opencontroller auto-discovers agents, models and API keys across AWS, Azure and Google Cloud, so keys and the service accounts behind them appear in the inventory with owners. Posture detects risky permission and configuration patterns. Opencontroller supports agent workload identity federation and delegated on-behalf-of identity, and has a runtime adapter for Vertex AI. See the [capability reference](/capability-reference) or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Is service account key creation blocked in every Google Cloud organization?**
No. The secure-by-default constraints apply to organizations created on or after 3 May 2024, and some created between February and April 2024. Older organizations should check and enable them.

**What should an agent on Cloud Run use instead of a key?**
An attached, dedicated service account. The runtime obtains short-lived tokens from the metadata server, so nothing is stored.

**Can agents outside Google Cloud avoid keys?**
Yes. Workload Identity Federation exchanges a token from the agent's own platform, such as another cloud or a CI system, for short-lived Google credentials.

## Key facts

- Google Cloud organizations created on or after 3 May 2024 (and some created February to April 2024) enforce secure-by-default organization policies, including iam.managed.disableServiceAccountKeyCreation and iam.managed.disableServiceAccountKeyUpload, plus no automatic Editor grants to default service accounts.
- AI agents on Google Cloud should use attached service accounts (metadata server tokens), Workload Identity Federation for GKE or for external platforms, short-lived impersonation, or per-agent agent identity on Vertex AI Agent Engine instead of JSON keys.
- Where a key is unavoidable: project-scoped time-limited exception, dedicated service account, rotation, secrets manager storage, audit log monitoring, recorded owner and removal date.
- Opencontroller by Lyzr auto-discovers agents, models and API keys across AWS, Azure and Google Cloud, runs Posture checks, supports agent workload identity federation and on-behalf-of identity, and has a Vertex AI runtime adapter.
- Opencontroller pricing starts from $250K per deployment per year.

## Related

- [How does workload identity federation work for AI agents?](https://opencontroller.lyzr.com/blog/workload-identity-federation-for-ai-agents.md)
- [How does agent identity work in Vertex AI Agent Engine?](https://opencontroller.lyzr.com/blog/vertex-ai-agent-engine-agent-identity.md)
- [Should multiple AI agents share one service account?](https://opencontroller.lyzr.com/blog/should-ai-agents-share-a-service-account.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
