Task statement 7.4 · Security and safety

7.4 · Identity, Secrets, and Key Management

Shelfwise, the course example, has two secrets: the Claude key its service sends with every request, and the stock feed key its MCP server sends to the feed. Both exist on the engineers' laptops and in the production container, and a copy that leaks or outlives its owner hands over Shelfwise's access.

Why it's tested

The tempting setup is one key everywhere: an engineer creates a key, pastes it into the container and their own shell, and moves on. It fails later because that key acts as the engineer. A laptop leak then means rotating production, usage reports cannot tell the service from the engineer, and when the engineer leaves, the key stops and the chat widget stops answering.

KnowledgeKeys across development and production

An API key is a static secret, shown once when you create it in the Claude Console, that each request sends as a bearer token in the Authorization header. Its type decides whose identity it carries. A personal key acts as you, with your roles, and stops working when you leave the organisation. A service account key acts as a service account, a named identity for a workload with no email, password or login, and stops when that account is archived. The legacy workspace key belongs to no one and outlives its creator. A key can be scoped to one workspace (7.2), so keep development and production keys in separate workspaces, where a leaked development key reaches nothing in production.

Keep keys out of a settings file's env block, which holds values as plain text. A secrets manager injects them into the environment instead, where the SDKs read ANTHROPIC_API_KEY (5.2). An expiration set at creation limits how long a leaked copy works, and a request with an expired key gets a 401. Shelfwise's service runs on a service account key scoped to its own workspace, injected with the production feed key from the team's secrets manager, and each engineer uses Claude Code with their own login.

Interactive · separate credentials limit what one event can reach

Shelfwise's credentials in two columns. Development, on each engineer's laptop: the engineer's own account, which signs in to Claude Code, which stores the login in the Keychain or .credentials.json; Claude Code registers the stock server in ~/.claude.json with the engineer's own development feed key. Production, in the service's container: the team's secrets manager injects two keys into the container's environment, ANTHROPIC_API_KEY, a service account key scoped to Shelfwise's workspace, and STOCK_FEED_KEY, the production feed key copied to stock_mcp. A leaked development key or a departing engineer changes only the development column. Development · each engineer's laptop Production · the service's container Engineer's own account ROLES IN THE ORGANISATION REMOVED signs in registers the stock server ~/.claude.json · stock OWN DEVELOPMENT FEED KEY REPLACE THIS KEY REVOKE ITS KEY Team's secrets manager HOLDS BOTH PRODUCTION KEYS injects at start CONTAINER ENVIRONMENT (DASHED) ANTHROPIC_API_KEY SERVICE ACCOUNT KEY · OWN WORKSPACE UNTOUCHED KEEPS WORKING STOCK_FEED_KEY → stock_mcp PRODUCTION FEED KEY UNTOUCHED KEEPS WORKING

Choose what happens to one credential.

A development feed key leaks: that engineer's key is disabled at the feed and replaced, and they register the server again with the new one. Production holds its own feed key and its own Claude key, so the stock widget keeps answering.

An engineer leaves: removing their account ends their own Claude access, and their development feed key is revoked. The service acts as its own service account, so nothing in production changes.

Each column holds its own credentials. Amber marks what must change, green what keeps working.

KnowledgeIdentity validation and authentication

Authentication should verify who is calling (7.1), but a key proves only that the caller holds the string. Workload Identity Federation validates identity instead. A workload on a cloud platform, in CI or on Kubernetes presents a signed JWT from its identity provider. Anthropic checks it against a federation rule, and the SDK gets a short-lived token for a service account, with no key to store. Claude Code signs a developer in through the browser and keeps the credential in the macOS Keychain, or in ~/.claude/.credentials.json (mode 0600) on Linux. The apiKeyHelper setting names a command whose output becomes the key, cached for five minutes and rerun after a 401 or 403. When both are set, an exported ANTHROPIC_API_KEY outranks it.

KnowledgeAccess approval and level verification

Access approval decides who may obtain a credential, and level verification checks what each credential can reach. Organisation roles (user, claude_code_user, developer, billing, admin) and workspace roles (7.2), such as Workspace Developer, decide who may create keys, and only admins create Console Admin API keys, which have no selectable scopes. A personal key acts with its owner's roles, so granting a role approves access. To verify, an admin lists keys through the Admin API, which shows each key's status, workspace scope and expires_at but never the secret. On a laptop, Claude Code asks before using project-scoped MCP servers from a committed .mcp.json. Granting no more than a task needs is least privilege (7.2).

More precise than the guide. The docs name no feature "access approval" or "level verification" (as of 2026-10-05). They document roles that decide who may create keys, keys that act with their owner's permissions, and Admin API listings of each key's scope, status and expiry. Exam answer: approve access through roles and workspace membership, then verify each key's type, scope and expiry.

KnowledgeAuthorized access monitoring

Monitoring checks that only the expected identities use each key, at the expected volume. The Usage and Cost Admin API groups usage by API key and workspace (5.4), so a key whose traffic leaves its pattern stands out. Once an admin enables the Compliance API, its Activity Feed records authentication and administrative events, naming the api_key_id behind API activity. An Admin API key created after enablement can read the feed. The feed never backfills, so enable it early. Disable a suspect key first, while you investigate, because disabling is reversible and deleting is not.

SkillWorked example: a feed key in a committed file

Each engineer registers the stock server at local scope with claude mcp add stock --env STOCK_FEED_URL=… --env STOCK_FEED_KEY=… -- python -m stock_mcp (8.2), using their own development feed key. Local scope writes the server, key value included, into their own ~/.claude.json, outside git. A draft pull request shared it through a committed .mcp.json, made by the same command with --scope project:

# draft: claude mcp add stock --scope project --env STOCK_FEED_KEY=fk_dev_4b9e… …
"env": {"STOCK_FEED_KEY": "fk_dev_4b9e…"}        # the value, in git
# Claude's review on the pull request: a feed key in a committed file
"env": {"STOCK_FEED_KEY": "${STOCK_FEED_KEY}"}   # each engineer's environment
# the pushed key counts as leaked: disabled at the feed, replaced

The cause was the scope, because --env writes the value into whichever file the scope names, and ${VAR} expansion in .mcp.json keeps it out of a shared file. The draft was closed and the team kept local scope, but the pushed key was replaced. Production was untouched, since the service copies its own feed key from the container's environment, which also keeps both keys out of Claude's context (8.1).

Ask one question: who is the caller? A person at a keyboard → their own login or personal key, kept out of every shared file. A shared or unattended workload → a service account key scoped to its workspace, from a secrets manager. A workload with a cloud, CI or Kubernetes identity → Workload Identity Federation, with no static key.
Takeaway
  • Personal and service account keys stop with their identity; a legacy workspace key outlives its creator.
  • claude mcp add --env stores the value in the scope's file, so a committed .mcp.json uses ${VAR}.
  • Watch each key: usage by API key, the Activity Feed for who acted, and disable before you delete.

check yourself

0 / 3 answered

A data team's nightly GitHub Actions workflow summarises support tickets through the Claude API, reading a service account key from the repository's Actions secrets. A new security policy says no static Claude API key may reach the CI runner. The workflow can already obtain an OIDC token from GitHub for each run.Which approach best meets the policy while the workflow keeps running unattended?

Select one.

A Console organisation brings in four contractors for six weeks to build a prototype in a new workspace, adding them to the organisation with the user role. Each contractor must create and use API keys in that workspace and nowhere else, every key must trace to one contractor, and the security lead wants a weekly report of tokens used per key.Which TWO steps together best meet these requirements?

Select two.

A company sets apiKeyHelper in managed settings so that every developer's Claude Code fetches a short-lived key from the company vault. A week later, the Usage and Cost API shows one developer's requests still arriving on an old personal key that the vault never issued. Run by hand on that laptop, the helper command prints a valid vault key.What is the most likely root cause?

Select one.

sources

  1. Claude Platform Docs, "Authentication" and "Get your Claude API key": personal, service account and legacy workspace keys; identity-backed keys stop working when the identity is removed; workspace-scoped keys; key shown once; secrets manager, rotation, disable versus delete; expiration and the 401; Workload Identity Federation exchanging an identity provider's JWT. Checked 2026-10-05.
  2. Claude Platform Docs, "Workload Identity Federation": service accounts with no email, password or Console login; federation rules mapping a JWT to a service account; short-lived tokens. Checked 2026-10-05.
  3. Claude Platform Docs, "Workspaces" and "Admin API": workspaces to separate projects, environments or teams; organisation and workspace roles; listing and auditing API keys. And "Create an Admin API key": created by admins only, with no selectable scopes. Checked 2026-10-05.
  4. Claude Platform Docs, "Usage and Cost API", "Query the Activity Feed" and "Set up the Compliance API": usage filtered and grouped by API key and workspace; authentication and administrative events, api_key_id on API actors, six-year retention, no backfill; Admin API keys read the feed only if created after enablement. Checked 2026-10-05.
  5. Claude Code Docs, "Authentication" and "Settings reference": credential storage in the Keychain or .credentials.json; authentication precedence; apiKeyHelper caching, reruns and the trust prompt; env values as plain text. Checked 2026-10-05.
  6. Claude Code Docs, "Connect Claude Code to tools via MCP": local scope stored in ~/.claude.json and kept out of version control; project scope in .mcp.json with an approval prompt; ${VAR} expansion in env for sensitive values. Checked 2026-10-05.
  7. Shelfwise's service account key, the engineers' development feed keys and the closed .mcp.json pull request are this course's example details.