Back to paths

Agent Identity and least-privilege access

An agent that runs as a broad service account turns one prompt injection into a breach. Give each agent its own identity, grant it only the roles its tools need, and cap its reach with a Principal Access Boundary.

intermediate~40 min#agentic-ai#agents#security#iam
Chapter 6Secure and governLesson 2 of 5Show

Prerequisites: The agent threat model, The Google Cloud agent platform map


One injection, one breach

The last lesson set a rule: least privilege limits the damage of any attack that gets through. This lesson makes it concrete on Google Cloud.

Access on Google Cloud is managed by IAM. A principal (a user, a group, a workload) is granted a role (a set of permissions) on a resource, such as a project or a single bucket, through an allow policy. A service account is a principal for software rather than a person.

Many first agents run as a service account that some other workload already uses, with a broad role on the project. That works, until the agent reads a document with an injected instruction. The agent can then do anything that account can do: read the HR database, change production, reach into other projects. Nothing in the logs says which agent did it, because several share the account.

Three changes shrink that blast radius, and they build on each other.

Step 1: give the agent its own identity

gives each agent a dedicated principal on Google Cloud. It is based on , an open standard for workload identity: each agent gets a cryptographic identity with an X.509 certificate that Google Cloud provisions and manages on the agent. Agent Runtime, Gemini Enterprise, Cloud Run and GKE support it.

Compared with a shared service account, an agent identity:

  • belongs to one agent. Agent identities are not shared by multiple workloads by default, so a grant to one reaches only that agent.
  • is the principal you grant to. You grant roles directly to the agent's identifier, so each agent's access is set on its own.
  • shows up in audit logs. The logs record the agent and, when it acts for a user, that user, so you can tell which agent did what.
  • is harder to steal. It cannot be impersonated, it allows no long-lived keys, and its access tokens are bound to the agent's certificate, which is designed to stop a stolen token being reused elsewhere.

For agents governed by Agent Gateway, Context-Aware Access enforces that binding by default. The agent reaches Google Cloud APIs and Agent Gateway over mTLS (mutual TLS, where both sides present certificates) with certificate-bound tokens. Agent Gateway terminates mTLS, so beyond it the binding is carried by DPoP (Demonstrating Proof-of-Possession, RFC 9449): proofs signed with the agent's private key, which Context-Aware Access checks. Google's words for the result: "compromised tokens are useless outside of their intended, trusted runtimes."

What an agent principal looks like

Each agent identity has a SPIFFE ID and a matching IAM principal identifier. For an agent on Agent Runtime in an organization, the principal is:

principal://agents.global.org-ORGANIZATION_ID.system.id.goog/resources/aiplatform/projects/PROJECT_NUMBER/locations/LOCATION/reasoningEngines/ENGINE_ID

The part before /resources is the trust domain: agents.global.org-ORGANIZATION_ID.system.id.goog for an organization, or agents.global.proj-PROJECT_NUMBER.system.id.goog for a project with no organization. The rest names the resource that hosts the agent (Gemini Enterprise agents use discoveryengine in place of aiplatform). You grant roles to that identifier the way you grant them to any principal. To grant one role to every agent in a project, use the principal set principalSet://agents.global.org-ORGANIZATION_ID.system.id.goog/attribute.platformContainer/aiplatform/projects/PROJECT_NUMBER; principalSet://agents.global.org-ORGANIZATION_ID.system.id.goog/* covers every agent in the organization. Prefer the single agent, for the same reason as Step 2 below.

Two lifecycle rules follow from the identity being derived from the hosting resource's ID:

  • A redeployed agent is a new principal. Delete an agent and deploy a replacement, even with the same name, code and configuration, and it gets a new resource ID and so a new identifier. The old grants don't apply to it; grant the roles again.
  • Deleting an agent leaves its grants behind. Its IAM bindings stay in your policies as inactive grants. Remove them when you decommission the agent.

Where the agent's credentials come from

Agent Identity supports three kinds of credential. The agent's X.509 certificate is provisioned on it automatically, valid for 24 hours and kept current by Google Cloud. For Google Cloud APIs (*.googleapis.com) it gets short-lived OAuth 2.0 access tokens, which Application Default Credentials fetches from the metadata server, so Google Cloud client libraries use the agent's identity with no code change. For services outside Google, and for Cloud Run or GKE endpoints, it can get OIDC ID tokens: signed JWTs whose sub claim is the agent's SPIFFE ID (in Preview at the time of writing).

An ID token lets a service outside Google trust the agent without holding any Google secret. The receiver fetches the issuer's public keys from an unauthenticated JWKS endpoint, checks the token's issuer, audience and expiry, and then compares sub against its own allowlist of agent SPIFFE IDs. By default the token's cnf claim also carries the fingerprint of the agent's certificate, so a receiver that requires mTLS can reject a token presented with any other certificate.

Follow the invoice agent in Where an agent's credentials come from. Predict what a copied access token can do, then step through its two calls on its own authority, one inside Google Cloud and one outside it, and the replay at the end.

Simulation: agent-credential-flow

Explain it: BigQuery and the partner API each trust the agent, but through different tokens. What does each one check, and why does the partner never need a Google credential?

Step 2: grant only what the tools need

An identity of its own does nothing for the blast radius if it holds a broad role. Work out access from the tools:

  1. List what each tool touches. The invoice tool reads one bucket; the lookup tool reads one dataset. Nothing writes.
  2. Grant the narrowest role on the narrowest resource. A read-only role on that bucket, and one on that dataset, granted to the agent's principal. Avoid project-wide grants and the broad basic roles (Owner, Editor), which reach most resources in the project.
  3. Assume the injection will succeed. Ask what a hijacked agent could do with exactly these grants. Here: read invoices and one dataset, nothing else.

A permission error is a cheap, visible failure that you fix by adding one narrow grant. Broad access fails silently, on the day someone exploits it.

Step 3: cap the reach with a boundary

Grants drift. Another team adds a role for a new feature; someone grants a broad role to debug and forgets it. A (PAB) policy guards against that. It defines the resources the principals it covers are eligible to access. If a resource is outside the boundary, they cannot reach it (for the permissions the boundary supports), regardless of the roles they have been granted. A boundary applies to a set of principals that includes the agent, rather than being written into each role grant.

Roles grant; a boundary caps. A PAB policy can only block or not block; it never grants. So you use both:

  • the role grants say what the agent can do;
  • the boundary says the furthest it can ever reach, such as the finance project only, whatever is granted later.

Three limits to know. By default, with no PAB policy, a principal is eligible to access any Google Cloud resource; the cap exists only once you add one. A PAB policy only blocks access that involves the permissions it supports, so it backs up narrow grants rather than replacing them. And when several PAB policies apply to the same principal, for example set at different scopes, their eligible resources combine: a finance-only boundary does not cancel another applicable policy that also makes HR eligible. The finance-only cap holds only if every policy that applies allows only finance.

Which control would stop a broad role, granted to an agent by mistake next month, from reaching the HR project?

Try it: which doors can the agent open?

In Which doors can the agent open?, an invoice contains an injected request for Finance exports, HR payroll and Production backups. The agent attempts those reads as well as its intended invoice read. These attempts are scripted: IAM checks permissions; it does not decide whether the text is malicious.

Start with an invoices-only read grant and the Finance boundary on. Predict which doors will open if someone adds an organization-wide read grant. Choose an answer, then press Add broad read grant. Next, press Remove all grants and watch what happens while the boundary stays in place.

Simulation: access-boundary-explorer

Explain it: Why did the broad grant open Exports but leave Payroll closed? Why did Invoices close when you removed all grants, even though it stayed inside the Finance outline?

This fixture uses four private Cloud Storage buckets in three projects under one organization. The read role is roles/storage.objectViewer, granted on the Invoices bucket or inherited from the organization. Each attempt reads one existing object using storage.objects.get, which PAB enforcement version 1 covers. Uniform bucket-level access is enabled; there are no public grants, ACL grants, other role grants, deny policies or conditional bindings. The map shows these object reads, not every permission in the role or every IAM check.

There is exactly one applicable Finance PAB when the boundary is on, and none when it is off. With several applicable PABs, eligible resources combine by union: another policy can make HR eligible. The outline represents resource eligibility, not a network firewall.

Put it together

Steps
  1. See what a broad grant adds

    In Which doors can the agent open?, press Reset, choose a prediction, and press Add broad read grant with the Finance boundary on. Name the newly readable bucket and the two buckets that remain outside the boundary.

  2. Separate eligibility from permission

    Keep the Finance boundary on and press Remove all grants. Explain why zero buckets are readable even though two remain eligible.

  3. Choose the narrow grant

    Press Restore invoices-only grant, then Add broad read grant and turn the Finance boundary Off. Compare four readable buckets with two when it is On. Press Reset to return to the grant needed by the invoice tool alone.

  4. Name the two tokens

    In Where an agent's credentials come from, step to 3 and then to 6. Name the token each call carries, who issued it, and what BigQuery and the partner API each check before they let the call through.

  5. Explain the failed replay

    Pick an answer, then step to 7. Say why the copied access token can't be replayed from the laptop, and which default policy enforces that.

In Which doors can the agent open?, why does adding the organization-wide read grant change access from one bucket to two, even with the Finance boundary on?

Recap

  • Give each agent its own identity: per-agent grants, per-agent audit, an identity not shared by default, and no long-lived keys.
  • An agent principal is a SPIFFE-based identifier derived from the resource that hosts it: a redeployed agent is a new principal, and a deleted one leaves inactive grants to remove.
  • The agent's own credentials: a 24-hour X.509 certificate, certificate-bound access tokens for Google Cloud APIs, and OIDC ID tokens that services outside Google verify with public keys.
  • Grant the narrowest roles on the narrowest resources its tools need, and design as if prompt injection will succeed.
  • Roles grant; a Principal Access Boundary caps. Use both, so a mistaken grant later still cannot reach past the boundary.

Sources

Show 11 sourcesHide sources
SourcePublisherWhat it supports
Agent Identity overview (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-17, rechecked 2026-11-19 for the principal format, trust domains, "Each X.509 certificate is valid for 24 hours", the three credential types, and the identity and permission lifecycle: a replacement agent "receives a new resource ID and therefore a new principal identifier", and deleting an agent leaves its bindings as inactive grants; a cryptographic identity per agent based on the SPIFFE standard; X.509 certificates auto-provisioned and managed on the agent; access tokens bound to the agent's certificates to prevent token theft; "not shared by multiple workloads by default, can't be impersonated, and don't allow developers to generate long-lived service account keys"; audit logs record the agent and the delegating user; permissions granted directly to the agent's identifier; supported by Agent Runtime, Gemini Enterprise, Cloud Run and GKE
Authenticate to Google Cloud using an agent's own identity (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-19: client libraries use Agent Identity automatically, with Application Default Credentials fetching the token from the metadata server; principal sets for all agents in a project or organization; a default Context-Aware Access policy enforces DPoP and requires mTLS for Agent Gateway, so "only the intended, trusted runtime environment ... can use the certificate-bound tokens"
Authenticate to external services using an agent's own identity (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-19, Preview: OIDC ID tokens whose sub is the agent's SPIFFE ID; receivers verify iss, aud, iat and exp against the public discovery and JWKS endpoints, cacheable for 24 hours, and authorize on an allowlist of SPIFFE IDs; the cnf x5t#S256 claim carries the certificate fingerprint by default; external verifiers need no IAM roles or Google credentials
Context-Aware Access for agents (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-17: certificate-bound workload access tokens; mTLS to Google Cloud APIs and Agent Gateway; DPoP per RFC 9449 beyond the gateway; "compromised tokens are useless outside of their intended, trusted runtimes"
Principal Access Boundary policies (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-17: PAB policies "let you define the resources that principals can access"; they "can only block or not block access—they can't grant access"; by default principals are eligible to access any resource; an ineligible principal's access is limited "regardless of the roles they've been granted"; only supported permissions are blocked; when several policies apply to a principal, the principal is eligible for the resources any of them allows, per the "Principal access boundary policy evaluation" section
LLM06:2025 Excessive Agency (opens in a new tab)github.comOWASP GenAI Security Projectretrieved 2026-11-17: minimise extension permissions
Policy types (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-17: allow policies grant access; PAB policies limit eligible resources
Resource hierarchy access control (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-17: descendants inherit grants from organization and project ancestors
Cloud Storage IAM roles (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-17: Storage Object Viewer includes object reads
Read objects (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-17: reading an object requires storage.objects.get
Permissions blocked by principal access boundaries (opens in a new tab)docs.cloud.google.comGoogle Cloudretrieved 2026-11-17: PAB enforcement version 1 covers storage.googleapis.com/objects.get

Suggested videos

Show 2 videosHide videos

Review

Flashcards1 / 6

What is the difference between an IAM role grant and a Principal Access Boundary?

Check yourself

Quick exam1 / 7 · 0 correct

An agent's only tool reads invoice files from one Cloud Storage bucket. A teammate suggests giving it the Owner role on the project 'so it never fails with a permission error'. What should you grant instead?

Go deeper

Your notes on this lesson