All posts

Machine Identities for the Claude Agent SDK: A Practical Guide

When a Claude‑powered agent can prove its machine identity without ever exposing a secret, every request is traceable, revocable, and scoped to the exact operation it needs. What teams do today Most teams embed static API keys, service‑account passwords, or long‑lived tokens directly in the Claude Agent SDK configuration. Those credentials are copied between environments, stored in source control, and often shared among multiple agents. The result is credential sprawl, no single point of revo

Free White Paper

Open Policy Agent (OPA) + Machine Identity: The Complete Guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free. No spam. Unsubscribe anytime.

When a Claude‑powered agent can prove its machine identity without ever exposing a secret, every request is traceable, revocable, and scoped to the exact operation it needs.

What teams do today

Most teams embed static API keys, service‑account passwords, or long‑lived tokens directly in the Claude Agent SDK configuration. Those credentials are copied between environments, stored in source control, and often shared among multiple agents. The result is credential sprawl, no single point of revocation, and no visibility into which agent performed which action.

Why that model falls short

When a secret lives in the agent process, the secret can be extracted by a compromised container, a malicious developer, or an automated script that gains access to the runtime. Because the request bypasses any enforcement layer, the target service sees only a valid credential and cannot distinguish a legitimate operation from a rogue one. Auditors cannot answer who ran a particular query, and compliance evidence is missing.

Machine identity as a prerequisite

Adopting a machine identity model means the Claude Agent SDK authenticates to an identity provider (OIDC or SAML) and receives a short‑lived token that represents the service account. The token proves who the agent is, but the request still travels directly to the backend resource. At this stage the request is authenticated, yet there is still no audit log, no inline masking of sensitive fields, and no just‑in‑time approval workflow.

Continue reading? Get the full guide.

Open Policy Agent (OPA) + Machine Identity: Architecture Patterns & Best Practices

Free. No spam. Unsubscribe anytime.

What to watch for

  • Token lifetime – short lifetimes reduce the window for abuse.
  • Audience and scope – ensure the token is issued only for the specific Claude service and the exact set of operations.
  • Rotation – automate token refresh and revoke compromised identities promptly.
  • Secure storage – keep the initial client secret (if any) in a secret manager, never in code.
  • Policy bypass – verify that the agent cannot fall back to a static credential if the identity provider is unavailable.

How a data‑path gateway completes the picture

This is where hoop.dev fits. The gateway sits between the Claude Agent SDK and the target infrastructure. Setup components – OIDC tokens, service‑account roles, and IAM policies – decide who the request is, but only the gateway can enforce controls. hoop.dev inspects traffic at the protocol layer and can:

  • Record each session for replay and audit.
  • Mask sensitive fields in responses, protecting PII even when the backend returns it.
  • Require just‑in‑time approval for risky commands before they reach the target.
  • Block disallowed commands outright, preventing accidental data loss.
  • Ensure the agent never sees the underlying credential used to reach the backend.

All of these enforcement outcomes exist because hoop.dev is the only component that sits in the data path. Without it, the machine identity would authenticate the request but provide no visibility, no protection, and no compliance evidence.

Integrating the Claude Agent SDK with hoop.dev

First, configure your identity provider to issue short‑lived tokens for the service account that the agent will use. Next, deploy the hoop.dev gateway using the getting‑started guide. The gateway runs a network‑resident agent that holds the long‑lived credential for the target resource, keeping it out of the SDK process. Finally, point the Claude Agent SDK at the gateway endpoint instead of the raw backend address. From the SDK’s perspective the connection flow is unchanged, but behind the scenes every request passes through hoop.dev where it is inspected, recorded, and, if necessary, paused for approval.

Lifecycle of a request

  1. The SDK obtains a fresh OIDC token and presents it to hoop.dev.
  2. hoop.dev validates the token, extracts the identity, and checks the policy for the requested operation.
  3. If the policy requires approval, hoop.dev routes the request to an approver before forwarding it.
  4. The gateway forwards the request to the backend using its stored credential.
  5. The backend response returns to hoop.dev, which may mask fields before sending it back to the SDK.
  6. The entire session is recorded for later replay and audit.

Common pitfalls and how to avoid them

  • Hard‑coding the token. Store only the client secret in a secret manager; let the SDK acquire fresh tokens at runtime.
  • Skipping gateway deployment in production. Development shortcuts are fine, but production must always route traffic through hoop.dev to get audit and masking.
  • Assuming token validation is enough. Validation proves identity; enforcement (approval, masking, blocking) requires the data‑path gateway.
  • Neglecting token revocation. Integrate your identity provider’s revocation hooks so that compromised service accounts are disabled immediately.

Short FAQ

  • Do I still need OIDC configuration? Yes. The identity provider authenticates the agent and issues the machine identity token. hoop.dev validates that token before allowing traffic.
  • Can hoop.dev mask data for all supported targets? The gateway applies inline masking on any protocol it proxies, including databases, SSH, and HTTP APIs.
  • Is session replay safe? Recordings are stored behind the gateway and are accessible only to authorized auditors, ensuring that the original secret never leaks.

Start by reviewing the getting‑started guide to deploy the gateway, then configure your Claude Agent SDK to use a short‑lived token from your identity provider. For the full source and contribution guidelines, explore the open‑source repository on GitHub.

Open source

Save the open-source gateway for agent data access

Hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.

Star and save the repo →More posts