Give the agent a limited proxy identity, keep the real secret in a broker, and attach the credential only on the wire for approved destinations. That approach preserves the ability to search, read, or act while preventing the agent from ever seeing a reusable secret. It is the safest default for agentic systems.
Use a brokered proxy identity instead of exposing the agent’s own secret
When an agent needs to reach GitHub, internal APIs, or model providers, the safest pattern is to keep the reusable secret out of the agent and issue only a limited proxy identity that can act within tightly defined destinations and actions. That keeps the agent useful for search, read, and write tasks while preventing the model from ever holding a long-lived credential.
The design goal is not to remove autonomy, but to separate agent identity from secret custody. If the agent never sees the raw key, token, or password, then prompt leakage, logging, memory retention, or tool output cannot directly turn into reusable credential theft.
This pattern is also consistent with task-scoped authorization for AI agents, where the agent receives only the minimum access needed for the current action. In practice, that means the broker can allow one destination, one scope, or one action class at a time instead of handing the agent broad standing access.
Why attach credentials on the wire rather than in the agent context?
Injecting the credential only at request time means the secret exists briefly in the execution path and is never stored in the agent’s prompt, memory, workspace, or reasoning trace. This preserves a usable control boundary: the agent can request access, but the broker decides whether the destination, scope, and timing are approved.
For GitHub and API access, that usually means the broker exchanges the agent’s limited claim for a short-lived token or signed request bound to a specific host, repository, API, or model endpoint. For model keys, it means the calling service can reach the provider without giving the agent the provider secret itself.
That separation matters because agents often interact with multiple tools, and tool output is not a safe place for secrets. A limited proxy identity keeps the blast radius small if the agent is misled, over-verbose, or asked to relay content that should never contain reusable credentials.
What good implementation looks like across GitHub, APIs, and model keys
A sound broker pattern usually has three parts: an agent-facing identity, a policy-enforcing broker, and a destination-specific credential or signed exchange handled outside the model. The agent asks for an action, the broker checks policy, and the broker attaches the credential only when the request matches an approved destination and purpose.
For source control, that often means repository-scoped permissions, write access only where needed, and separate identities for read-only and commit-capable workflows. For APIs, it means destination allowlists, method restrictions, and short token lifetimes. For model keys, it means the key stays with the gateway or service wrapper, not inside the prompt or a developer script.
The same logic applies to brokered tool use in broader agentic systems, where zero trust for AI agents means verifying the request, the principal, and the destination every time. If the destination changes or the action exceeds policy, the broker should fail closed and require a new approval path.
Risk and Threat Considerations
Exposing a reusable secret to an agent increases the chance of accidental disclosure, credential reuse, and unauthorized downstream use. The main failure mode is not only theft by an attacker, but also ordinary agent behaviour such as over-sharing, copying secrets into logs, or reusing a high-value token for a broader task than intended.
Failure mechanism: The agent is tricked, instrumented, or simply over-tasked into revealing or replaying a credential that should have stayed inside a broker. Once the secret is visible to the model or its surrounding context, any later compromise of logs, traces, memory, or tool output can expose it again.
Impact: A single exposed token can become persistent access to GitHub, internal APIs, or model infrastructure, creating lateral movement, unauthorized code changes, data exfiltration, or costly model abuse. Long-lived secrets are especially dangerous because the compromise can remain useful long after the original request is complete.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10, OWASP Agentic AI Top 10 and OWASP API Security Top 10 address the attack and risk surface, while NIST SP 800-53 Rev 5 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | Agents exposed to reusable secrets risk accidental disclosure and replay. |
| NHI-07 — Long-Lived Secrets | Long-lived tokens magnify the blast radius if an agent context leaks them. | |
| NHI-05 — Overprivileged NHI | Brokered proxy identities should enforce least privilege for agent access. | |
| Recommendation — Keep reusable secrets out of agent context and broker them at request time. Replace long-lived secrets with short-lived, destination-bound credentials. Scope agent credentials to the minimum destination, action, and lifetime. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | Credential lifecycle and secret custody are central when agents use brokered access. |
| AC-6 — Least Privilege | Agent access should be narrowly scoped to approved actions and destinations. | |
| IA-9 — Service Identification and Authentication | Agent-to-service and brokered machine access are service authentication problems. | |
| Recommendation — Manage short-lived authenticator issuance, storage, rotation, and revocation centrally. Limit each agent credential to the smallest set of permitted actions. Authenticate service and workload calls without exposing secrets to the agent. | ||
| OWASP Agentic AI Top 10 | ASI03 — Identity & Privilege Abuse | Agents with broad or exposed credentials are vulnerable to privilege misuse. |
| Recommendation — Bind agent actions to per-request authorization and least privilege. | ||
| NIST Zero Trust (SP 800-207) | PR.AA-05 — Least Privilege | Zero trust for agents requires verifying each request and eliminating standing privilege. |
| Recommendation — Remove standing access and authorize every agent action individually. | ||
| OWASP API Security Top 10 | API2 — Broken Authentication | Brokered API access is meant to prevent misuse of exposed or weak credentials. |
| API5 — Broken Function Level Authorization | The broker must stop an agent from calling functions beyond its approved role. | |
| Recommendation — Use short-lived, scoped auth instead of sharing a reusable API key. Authorize each function call against the agent’s allowed scope. | ||
Practitioner Guidance
What to verify: Confirm that the agent never receives a reusable secret in prompt text, environment variables visible to the model, or tool output. The broker should mint or attach credentials only at the moment of use, and only for the approved destination and scope.
What good looks like: You can rotate or revoke the brokered credential without changing the agent, the agent can complete approved tasks with narrow permissions, and every sensitive action is attributable to a broker decision rather than to a secret embedded in the agent runtime.
Practitioner takeaway: If a model can read the credential, it can usually leak the credential; the durable control is to let the agent request access without ever letting it hold the secret.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 13, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org