Schluessellose KI-Agenten auf Google Cloud: Eigene Identitaeten statt kopierten API-Keys
Ein Leitfaden zeigt, wie KI-Agenten auf Google Cloud statt hartcodierter API-Keys und Service-Account-JSONs eine eigene verifizierbare Identitaet mit vermittelten OAuth-Tokens und passenden VPC Service Controls erhalten.

Veröffentlicht am 24. Nov. • Ursprünglich veröffentlicht auf prabhakaranjm.medium.com
Wie man aufhört, API-Keys und Service-Account-JSONs in Agents einzufügen, und jedem Agent seine eigene überprüfbare Identität, vermittelte OAuth-Tokens und einen Perimeter gibt, der weiß, wer er ist
Die meisten Agent-Prototypen, die ich sehe, folgen demselben Muster. Der Agent läuft auf Cloud Run oder Agent Runtime unter einem gemeinsam genutzten Service Account, ein Jira- oder Salesforce-Client-Secret liegt in einer Umgebungsvariable oder im Secret Manager, und Aufrufe an eine andere Cloud nutzen einen langlebigen Access Key. Es funktioniert, aber es ist ein Design mit flacher Vertrauensstruktur:
Auf dem Google Cloud Security Summit im November 2026 kündigte Google eine Reihe von Kontrollmechanismen an, die genau darauf abzielen: Auth Manager (Teil von Agent Identity) ist jetzt allgemein verfügbar, die Unterstützung von Agent Identity JWT (OIDC ID Token) befindet sich in der Preview, und VPC Service Controls Ingress- und Egress-Regeln, die IAM-Rollen verwenden, sind allgemein verfügbar. Dieser Artikel zeigt, wie die Bausteine zusammenpassen und wie man sie mit der dokumentierten CLI und den Client-Bibliotheken verdrahtet.
Das nützliche mentale Modell ist: Der Agent weist mit seiner eigenen Identität nach, wer er ist, Auth Manager entscheidet, welche externen Credentials er verwenden darf, und der Perimeter entscheidet, welche Daten er und von wo aus berühren darf.
Die folgenden Code-Snippets orientieren sich an der offiziellen Dokumentation von November 2026. Einige Funktionen befinden sich in der Preview, betrachten Sie den Code daher als illustrativ und prüfen Sie die aktuelle Dokumentation, bevor Sie ihn ausführen. Ersetzen Sie die Platzhalter in Großbuchstaben.
Für einen containerisierten Agent auf Cloud Run ist Agent Identity ein Flag zum Zeitpunkt der Bereitstellung:
gcloud run deploy support-agent \ --image=REGION-docker.pkg.dev/PROJECT_ID/agents/support-agent:latest \ --identity-type=agent-identity \ --no-allow-unauthenticated Vollbildmodus öffnen Vollbildmodus verlassen Für Agent Runtime legt man den Identitätstyp bei der Erstellung der Engine mit dem Vertex AI SDK fest:
remote_app = client. agent_engines. create ( agent = app, config = { "identity_type": types. IdentityType. AGENT_IDENTITY, "requirements": [ "google-cloud-aiplatform[agent_engines,adk]" ], }, ) Vollbildmodus öffnen Vollbildmodus verlassen Ab hier vergibt man IAM-Rollen an den Principal des Agents, nicht an einen gemeinsam genutzten Service Account. Diese eine Änderung liefert Ihnen Audit-Trails pro Agent.
Angenommen, der Agent ruft einen Jira-MCP-Server mit Client Credentials auf. Anstatt das Secret beim Agent zu speichern, erstellen Sie einen 2-legged Auth Provider:
gcloud agent-identity auth-providers create jira-mcp-2lo \ --location= "us-central1" \ --two-legged-oauth-client-id= "CLIENT_ID" \ --two-legged-oauth-client-secret= "CLIENT_SECRET" \ --two-legged-oauth-token-url= "TOKEN_URL" gcloud agent-identity auth-providers list \ --project= "PROJECT_ID" --location= "us-central1" Vollbildmodus öffnen Vollbildmodus verlassen Erlauben Sie anschließend nur diesem Agent, Credentials von diesem Provider abzurufen, indem Sie dem SPIFFE-Principal des Agents roles/agentidentity.user auf die Provider-Ressource gewähren:
Beachten Sie den Namen der IAM API: Die Dokumentation empfiehlt die Agent Identity API und sagt, dass die frühere IAM Connectors API (Preview) nicht allgemein verfügbar werden wird. Migrieren Sie also, falls Sie dort angefangen haben.
Das ist der Teil, den ich für Multi-Cloud-Architekten am interessantesten finde. Mit der Unterstützung von Agent Identity JWT (Preview) fordert der Agent ein OIDC ID Token für eine Ziel-Audience an. Das Token bestätigt die SPIFFE-Identität des Agents und wird von Schlüsseln der Trust-Domain des Agents signiert. Empfänger verifizieren es über öffentliche, nicht authentifizierte Endpunkte auf sts.googleapis.com ( /.well-known/openid-configuration und /openid/jwks ), benötigen also überhaupt keine Google Cloud Credentials.
Im Agent erledigt die Bibliothek google-auth die Arbeit, einschließlich Caching und Erneuerung über den Metadata Server:
from google. auth. transport. requests import AuthorizedSession from google. oauth2 import id_token target_audience = "https://api.example.com" credentials = id_token. fetch_id_token_credentials ( audience = target_audience ) session = AuthorizedSession ( credentials ) resp = session. post ( "https://api.example.com/v1/tickets", json = { "summary": "Created by agent" } ) Vollbildmodus öffnen Vollbildmodus verlassen Der Issuer, dem Ihr Empfänger vertrauen muss, ist der Workload Identity Pool der Trust-Domain des Agents, zum Beispiel https://sts.googleapis.com/v1/organizations/ORGANIZATION_ID/locations/global/workloadIdentityPools/TRUST_DOMAIN.
Auf der AWS-Seite ist ein Standardmuster, diesen Issuer als IAM OIDC Identity Provider zu registrieren und den Agent sein Token mit AssumeRoleWithWebIdentity einlösen zu lassen. Das Folgende ist ein illustrativer Entwurf, der auf dem generischen AWS-OIDC-Federation-Ablauf basiert, nicht auf einem Google-Beispiel. Prüfen Sie daher zuerst die Claim-Namen anhand eines echten Tokens:
# Nur illustrativ aws iam create-open-id-connect-provider \ --url "https://sts.googleapis.com/v1/organizations/ORGANIZATION_ID/locations/global/workloadIdentityPools/TRUST_DOMAIN" \ --client-id-list "sts.amazonaws.com" Vollbildmodus öffnen Vollbildmodus verlassen Schreiben Sie danach die Role Trust Policy so, dass sie aud und sub des Agents (seine SPIFFE ID) exakt abgleicht, sodass nur genau dieser eine Agent die Rolle annehmen kann.
Zwei Details aus der Dokumentation, die man kennen sollte:
Wenn die Daten des Agents in BigQuery oder Cloud Storage innerhalb eines VPC-SC-Perimeters liegen, kann eine Ingress-Regel jetzt IAM-Rollen nennen, statt jede Methode einzeln aufzulisten. Die dokumentierte YAML-Form ist:
- ingressFrom: identities: - PRINCIPAL_IDENTIFIER sources: - accessLevel: ACCESS_LEVEL ingressTo: roles: - roles/bigquery.dataViewer resources: - projects/PROJECT_NUMBER Vollbildmodus öffnen Vollbildmodus verlassen Die Regel erlaubt dann nur Aktionen, die von den Berechtigungen dieser Rolle abgedeckt sind. Bevor Sie sich auf eine Rolle verlassen, prüfen Sie, ob sie unterstützt wird:
gcloud access-context-manager supported-permissions describe roles/bigquery.dataViewer Vollbildmodus öffnen Vollbildmodus verlassen Custom Roles im Format projects/PROJECT_ID/roles/... werden in diesen Regeln nicht akzeptiert. Planen Sie also, vordefinierte oder Custom Roles auf Organisationsebene zu verwenden.
Die Änderung ist syntaktisch klein, aber in ihrer Wirkung groß: Ein Flag --identity-type=agent-identity, eine Handvoll gcloud agent-identity Befehle und eine rollenbasierte Perimeter-Regel ersetzen gemeinsam genutzte Service Accounts, eingefügte Secrets und langlebige Cross-Cloud-Keys. Wenn Sie heute Agents auf Google Cloud bauen, würde ich damit anfangen, einem Agent seine eigene Identität zu geben, ein SaaS-Secret in Auth Manager zu verschieben und zu sehen, wie viel sauberer das Audit-Log wird.
Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.
Original (Englisch) anzeigen
Posted on Nov 24 • Originally published at prabhakaranjm.medium.com
How to stop pasting API keys and service account JSON into agents, and give each agent its own verifiable identity, brokered OAuth tokens and a perimeter that knows who it is
Most agent prototypes I see follow the same pattern. The agent runs on Cloud Run or Agent Runtime under a shared service account, a Jira or Salesforce client secret sits in an environment variable or Secret Manager, and calls to another cloud use a long-lived access key. It works, but it is a flat-trust design:
At the Google Cloud Security Summit in November 2026, Google announced a set of controls aimed squarely at this: Auth Manager (part of Agent Identity) is now generally available, Agent Identity JWT (OIDC ID token) support is in preview, and VPC Service Controls ingress and egress rules that use IAM roles are generally available. This article walks through how the pieces fit together and how to wire them up with the documented CLI and client libraries.
The useful mental model is: the agent proves who it is with its own identity, Auth Manager decides which external credentials it may use, and the perimeter decides what data it may touch and from where.
The snippets below follow the official documentation as of November 2026. Several features are in preview, so treat the code as illustrative and check the current docs before running it. Replace the upper-case placeholders.
For a containerised agent on Cloud Run, Agent Identity is a deploy-time flag:
gcloud run deploy support-agent \ --image=REGION-docker.pkg.dev/PROJECT_ID/agents/support-agent:latest \ --identity-type=agent-identity \ --no-allow-unauthenticated Enter fullscreen mode Exit fullscreen mode For Agent Runtime, set the identity type when you create the engine with the Vertex AI SDK:
remote_app = client. agent_engines. create ( agent = app, config = { "identity_type": types. IdentityType. AGENT_IDENTITY, "requirements": [ "google-cloud-aiplatform[agent_engines,adk]" ], }, ) Enter fullscreen mode Exit fullscreen mode From here, grant IAM roles to the agent's principal, not to a shared service account. That one change gives you per-agent audit trails.
Say the agent calls a Jira MCP server using client credentials. Instead of storing the secret with the agent, create a 2-legged auth provider:
gcloud agent-identity auth-providers create jira-mcp-2lo \ --location= "us-central1" \ --two-legged-oauth-client-id= "CLIENT_ID" \ --two-legged-oauth-client-secret= "CLIENT_SECRET" \ --two-legged-oauth-token-url= "TOKEN_URL" gcloud agent-identity auth-providers list \ --project= "PROJECT_ID" --location= "us-central1" Enter fullscreen mode Exit fullscreen mode Then allow only this agent to retrieve credentials from that provider by granting roles/agentidentity.user on the provider resource to the agent's SPIFFE principal:
Note the IAM API name: the docs recommend the Agent Identity API and say the earlier IAM Connectors API (preview) will not become generally available, so migrate if you started there.
This is the part I find most interesting for multi-cloud architects. With Agent Identity JWT support (preview), the agent requests an OIDC ID token for a target audience. The token asserts the agent's SPIFFE identity and is signed by keys for the agent's trust domain. Receivers verify it through public, unauthenticated endpoints on sts.googleapis.com ( /.well-known/openid-configuration and /openid/jwks ), so they need no Google Cloud credentials at all.
In the agent, the google-auth library does the work, including caching and renewal from the metadata server:
from google. auth. transport. requests import AuthorizedSession from google. oauth2 import id_token target_audience = "https://api.example.com" credentials = id_token. fetch_id_token_credentials ( audience = target_audience ) session = AuthorizedSession ( credentials ) resp = session. post ( "https://api.example.com/v1/tickets", json = { "summary": "Created by agent" } ) Enter fullscreen mode Exit fullscreen mode The issuer your receiver must trust is the workload identity pool for the agent's trust domain, for example https://sts.googleapis.com/v1/organizations/ORGANIZATION_ID/locations/global/workloadIdentityPools/TRUST_DOMAIN.
On the AWS side, a standard pattern is to register that issuer as an IAM OIDC identity provider and let the agent exchange its token with AssumeRoleWithWebIdentity. The following is an illustrative sketch built from the generic AWS OIDC federation flow, not from a Google worked example, so validate the claim names against a real token first:
# Illustrative only aws iam create-open-id-connect-provider \ --url "https://sts.googleapis.com/v1/organizations/ORGANIZATION_ID/locations/global/workloadIdentityPools/TRUST_DOMAIN" \ --client-id-list "sts.amazonaws.com" Enter fullscreen mode Exit fullscreen mode Then write the role trust policy to match aud and the agent's sub (its SPIFFE ID) exactly, so that only this one agent can assume the role.
Two details from the docs worth knowing:
If the agent's data lives in BigQuery or Cloud Storage inside a VPC-SC perimeter, an ingress rule can now name IAM roles rather than enumerating every method. The documented YAML shape is:
- ingressFrom: identities: - PRINCIPAL_IDENTIFIER sources: - accessLevel: ACCESS_LEVEL ingressTo: roles: - roles/bigquery.dataViewer resources: - projects/PROJECT_NUMBER Enter fullscreen mode Exit fullscreen mode The rule then only allows actions covered by that role's permissions. Before relying on a role, check it is supported:
gcloud access-context-manager supported-permissions describe roles/bigquery.dataViewer Enter fullscreen mode Exit fullscreen mode Custom roles in the projects/PROJECT_ID/roles/... format are not accepted in these rules, so plan to use predefined or organisation-level custom roles.
The shift here is small in syntax and large in effect: a --identity-type=agent-identity flag, a handful of gcloud agent-identity commands and a role-scoped perimeter rule replace shared service accounts, pasted secrets and long-lived cross-cloud keys. If you are building agents on Google Cloud today, I would start by giving one agent its own identity, moving one SaaS secret into Auth Manager, and seeing how much cleaner the audit log becomes.