← Blog

October 20, 2026 · Steve Johnson

Scoping API Keys to Minimum Required Capabilities

Scoping API keys to minimum required capabilities is blast-radius engineering. The permissions attached to a key define the ceiling on what an attacker can do with it. Keeping that ceiling low requires deliberate choices at issuance, through storage and rotation, and across agent systems. Scope is a first-class engineering decision to make before launch.

Why API key scope is a blast-radius decision, not a security checkbox

An API key authenticates the key itself. It provides no cryptographic proof of caller identity, so a stolen key is indistinguishable from a legitimate one. Whoever holds it has the access, with no second factor behind the request. That makes a static API key quite different from short-lived, cryptographically-bound credentials.

Broad permissions weaken that boundary before an application reaches production. A key with access to every method and service is easier to test because fewer requests fail during setup. But the convenience does not belong only to the developer. An attacker inherits the same freedom to make calls that the application never needed. Successful integration is not evidence that the permission boundary is correct.

A payment key makes the distinction concrete. A key limited to charge creation presents a categorically different incident from one that can also issue refunds and read customer data. The exposure begins with the same stolen credential, but the available damage differs because of an engineering choice made at issuance. Minimum scope constrains the consequences of theft.

How retroactive privilege expansion turns old decisions into new exposures

The boundary set at issuance can also change without the owner changing the key. Truffle Security's February 2026 research showed that existing unrestricted Google API keys in a Cloud project automatically gained access to the Generative Language API when Gemini was enabled on that project. The key owner received no warning. A key published safely in 2023 could therefore become a Gemini credential in 2025 because someone else in the organization enabled a new service. An old publication decision had acquired a new security consequence.

The mechanism was the absence of an explicit service restriction. These keys were unrestricted, rather than confined to the API for which they had originally been used. Their reach could expand with the project's enabled services. A restriction to one specific API would have contained that expansion. The relevant boundary was not simply which project owned the key, but which service the key could invoke.

Google responded by rejecting unrestricted standard keys from 19 June 2026 and migrating Gemini to service-account-backed "auth keys." Google Cloud's official guidance says to plan a move to IAM policies and short-lived service account credentials and to follow least-privilege practices. For API keys, Google Cloud's documentation gives the immediate countermeasure. Restrict access to specific APIs so enabling another service does not automatically extend the key's reach.

What a breach with broad-scoped keys actually looks like at scale

Exposed credentials can turn a repository breach into access to connected infrastructure. In the October 2025 Red Hat internal GitLab breach, the cybercrime group "Crimson Collective" exfiltrated data from tens of thousands of repositories on Red Hat's internal consulting GitLab instance. The leaked material included API keys, database credentials, authentication tokens, and VPN configurations. Affected organizations included Bank of America, JPMorgan Chase, IBM, Cisco, the U.S. Navy, and the NSA. The attacker claimed to have used harvested credentials to pivot directly into customer infrastructure, though that claim could not be independently confirmed.

In the OpenCode Console breach, keys issued before a March 2026 auth migration remained valid on the legacy endpoint until engineers disabled it globally on October 16. Console Lite had stored API key hashes under weaker rules for rotation and with no OAuth device binding. The move to Console Pro brought in hardware security module-backed signing, organization SSO, and per-project scoped keys. Yet legacy credentials outlived the system intended to replace them.

Harvested credentials give attackers a way into other systems, while credentials that still work keep old routes open even after newer controls are in place. GitGuardian's State of Secrets Sprawl 2026 reported that hardcoded secrets added in 2025 represented the largest single-year jump in the report's history. Exposure continues at scale, and migration completeness is part of scope hygiene.

The two mechanisms that keep blast radius wide: permission sprawl and credential persistence

Permission sprawl begins when a key receives more access than its workload needs. Platforms that issue unrestricted keys by default make narrowing an opt-out task. A developer adds a production key for a hotfix, and a contractor later inherits it through a shared admin account. Months later, the team no longer has a clear account of who holds access to what.

Credential persistence extends that uncertainty through time. A key may remain valid after the task, person, or system that justified it has changed. Migration tooling makes this clear because it can need broad access for a short-term job. Completing the migration does not itself revoke the credential.

These patterns reinforce each other. A long-lived static key can be kept safe in a secrets manager and still have more permissions than it needs. Storage protects the credential without correcting its scope, and infrequent rotation leaves that scope in place. An old secret remains a grant of authority whose purpose may no longer be understood. A key that starts broad and is never revoked can accumulate blast radius.

Scoping keys at issuance: the one-key-one-job principle and environment separation

The issuance rule is one key, one job, one environment. Where the provider allows separation, a cron job should not share a key with a public-facing application. An AI provider key used only for inference should not also manage billing or fine-tuning. An application that needs one API should receive access only to that API.

Provider-supported restrictions can narrow the boundary further. These include IP ranges, allowed referrers, and client types. Backend-only workloads should use server-side restrictions where available. A key still needs the minimum permissions for its job even when its allowed usage context is restricted.

Environment separation applies the same reasoning to data and deployment access. Development, staging, and production must each have their own keys, so a leaked development key cannot reach production data. Developers should have dev/staging access for the projects they work on, while CI/CD runners should have machine access to just one environment and one deploy target. Production responders should receive temporary, auditable access during incidents. Concrete implementations include Vercel environment variable visibility controls, AWS IAM roles for workloads replacing shared static credentials, and per-project and per-environment roles replacing one global secret bucket.

This discipline introduces useful friction. A "forbidden" error during setup can confirm that a permission boundary is working and that additional access requires a deliberate decision. The task is to grant only the missing capability while preserving the boundary. A small setup inconvenience is preferable to discovering months later that the key had wide-open access.

Where to store scoped keys and how to keep them scoped through rotation

Secrets belong in a dedicated secrets manager such as AWS Secrets Manager, GCP Secret Manager, or HashiCorp Vault. They do not belong in source control, client bundles, checked-in plain files, or hardcoded scripts. A git-ignored .env file is acceptable for local development, but .gitignore only prevents some accidents. It cannot stop someone from pasting a secret into a config file, Docker Compose YAML, or a GitHub Actions workflow, so commit and push controls are also required.

Exposure requires revocation. Deleting a line does not invalidate the credential or remove its history. A leaked key should be revoked first, followed by history cleanup. That order differs from planned rotation because an exposed credential is already a liability. Keeping it valid while tidying the repository leaves the access available.

For model integrations, an LLM gateway provides a useful architectural pattern. The provider key then needs to be rotated only once, at the gateway. The gateway also centralizes spend caps, rate limits, retries, and audit logging. This is a way to concentrate key management while maintaining the need for narrowly scoped internal access.

Rotation should follow a schedule to limit how long an undetected leaked key remains useful. For planned zero-downtime rotation, issue the replacement, verify that it works, and then revoke the old key. The gateway pattern avoids downstream service redeploys when the provider key changes. Employee departure, any suspicion of exposure, and a security scan finding are triggers for immediate rotation.

AI agents and MCP servers: why multi-agent systems multiply the scoping surface

An agent mesh multiplies the credential surface because each MCP server can carry its own access to other resources. If those credentials are shared or broadly scoped, a compromise of one server can extend across the system. GitGuardian's 2026 report found thousands of unique secrets exposed in MCP configuration files on public GitHub and confirmed that a sizable share still worked. Popular setup guides add to the problem by putting keys straight into configuration files, command-line arguments, or embedded connection strings. Credential exposure can therefore become part of the onboarding pattern.

The authorization model can compound that exposure. Most MCP implementations still rely on static API keys. Early developers commonly gave agents a copy of the user's API key or an admin token, carrying maximum authority into the agent layer. A compromised or malicious server can then use broad credentials to reach resources it was never intended to touch. Tool shadowing is the agent-layer analog of lateral movement in traditional infrastructure.

The architectural response is dedicated credentials for every MCP server. Each should have its own API key, service account, or OAuth client, with no credentials shared across servers. Server A's credentials should give no access to the resources connected to Server B. Progressive least-privilege adds a capability boundary by starting with discovery and read operations, then elevating scope only when a privileged operation is attempted. As of the July 2026 MCP specification update, this model is documented guidance rather than a protocol requirement, so most teams must implement the elevation logic themselves.

Applying these principles at the early-stage startup: where scope decisions compound fastest

Early-stage startups make these choices when moving fast is most tempting. A broad key issued at pre-seed can become a legacy credential by Series A, while the growing codebase makes correction harder. AI-assisted prototyping adds a specific form of scoping debt because API keys are among the first artifacts mishandled. Separating keys from client code is therefore a standard early corrective action in startup security audits. Experienced engineers review AI-generated code for these patterns as part of the same work that establishes data isolation and vets database migrations and business logic.

Broadly-scoped credentials issued for migration tooling must be revisited and revoked when the migration closes. A static, rarely-rotated secret should not survive in an environment variable simply because the tooling shipped successfully. The OpenCode Console case shows why deploying a replacement is not enough. Completion includes verifying that legacy access has ended.

By Series A, what is expected for security and compliance also brings earlier choices to light. SOC 2 Type 1 is usually due by this stage, and key management practices become visible during due diligence. Establishing the scoping model before that pressure arrives is cheaper than remediating it during fundraising. The case for an embedded fractional CTO or senior technical partner is therefore operational. The role establishes conventions at stack selection, enforces issuance and environment boundaries through CI/CD controls, and owns migration completeness and rotation schedules.

That ownership also makes the trade-offs legible to non-technical founders. A payment key limited to creating charges is a concrete, auditable product boundary. Scope decisions build on each other quickly because later systems use the access patterns set up early. A fractional CTO earns value by getting those first-class engineering decisions right before they become expensive to undo.