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.
share
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
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.
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).
- Personal and service account keys stop with their identity; a legacy workspace key outlives its creator.
claude mcp add --envstores the value in the scope's file, so a committed.mcp.jsonuses${VAR}.- Watch each key: usage by API key, the Activity Feed for who acted, and disable before you delete.