Credentials, SSH, and infrastructure access
Good practices for granting AI agents controlled infrastructure access without exposing credentials to the model.
Updated: November 14, 2026
AI agents can help investigate problems, query databases, analyze logs, and administer infrastructure. However, these operations do not require passwords, tokens, or private keys to be supplied directly to the model.
The strategy is to provide previously authenticated tools and connections, with permissions limited to the necessary operations.
The agent should be able to perform authorized work without needing to know the credentials used to access services.
1. Credentials outside the AI context
Passwords, tokens, private keys, and other sensitive information should not be included in prompts, files such as AGENTS.md, or documentation accessible to agents.
Whenever possible, authentication should be managed by the execution environment, using mechanisms such as:
- Secret managers.
- Protected environment variables.
- SSH Agent.
- Managed identities and temporary credentials.
- Tools or MCP integrations with externally configured authentication.
The agent uses the capability provided by the tool without needing to receive the credential's value.
It is also important to prevent tools from returning sensitive information in logs, error messages, or command results.
Hiding credentials from the model does not eliminate the need to control the operations it can perform.
2. SSH and server access
To allow agents to investigate server problems, it is preferable to provide authenticated connections and controlled operations instead of supplying SSH key contents.
SSH Agent can manage keys used by the SSH client without requiring their private information to be included in the model's instructions.
Another alternative in AWS environments is Systems Manager Session Manager, which allows access to instances without distributing traditional SSH keys.
Permissions should match the purpose of access.
An agent responsible for investigating logs does not necessarily need authorization to modify configuration, restart services, or execute administrative commands.
When possible, use dedicated users, restricted permissions, and tools that expose only necessary operations.
For critical activities, retain approval mechanisms and records of executed operations.
3. Databases with limited permissions
Agents can query databases to investigate errors, check records, and analyze application behavior.
However, granting administrative credentials for these tasks creates unnecessary risk.
An alternative is to create dedicated users with read-only access to the necessary data.
For example, in MySQL:
CREATE USER 'ai_reader'@'%'
IDENTIFIED BY 'SENHA_GERENCIADA_EXTERNAMENTE';
GRANT SELECT ON app_database.orders
TO 'ai_reader'@'%';
The example grants read access to the orders table without write permissions. In production, connection origins must also be restricted and the credential protected.
The agent can use this identity through a SQL tool, authenticated client, or MCP server.
Also limit available data
Read permission does not mean an absence of risk.
A user with SELECT can still access sensitive information in authorized tables.
When necessary, use views with restricted fields, information masking, query limits, and read replicas.
For production investigations, prefer exposing only essential data and operations.
4. Tools and MCP servers as access interfaces
Tools and MCP servers can expose operations on internal systems without requiring the agent to manage credentials directly.
For example:
- Query application logs.
- Execute read-only SQL queries.
- Check service status.
- Query infrastructure resources.
- Access internal API information.
These integrations can encapsulate authentication, access restrictions, and specific validations.
However, not every integration needs MCP.
If an existing tool or controlled script already meets the need, creating an additional MCP server may increase complexity without offering advantages.
What matters most is enforcing restrictions technically, rather than merely describing them in agent instructions.
An MCP server connected to the database with administrative privileges, for example, does not become safe simply by receiving an instruction to execute only read queries.
5. Access to cloud services and APIs
For cloud services, prefer managed identities, roles, and temporary credentials over permanent keys with broad permissions.
On AWS, IAM Roles and mechanisms such as AWS STS provide specific permissions without maintaining long-lived credentials.
An agent tasked with investigating an EC2 instance can receive access to query its status and certain logs without authorization to delete resources or modify configuration.
The same principle applies to external APIs.
Whenever possible, use tokens with limited scopes, defined expiration, and access restricted to the necessary operations.
Administrative credentials should remain separate from those used for routine investigations.
6. Permissions according to the operation
Access level should be defined by the activity, not simply by the agent's identity.
| Need | Recommended access |
|---|---|
| Query database records | Read-only SQL user, restricted to necessary data |
| Investigate logs | Authenticated tool with access to relevant logs |
| Query AWS infrastructure | IAM Role with specific read permissions |
| Check an API | Token with minimum scopes |
| Run migrations | Dedicated identity for the operation, with approval when necessary |
| Perform deployment | Authorized pipeline or tool, with environment controls |
Whenever possible, separate investigation operations from operations that modify resources.
An investigation can begin with read-only access. If changes become necessary, execution can request additional authorization.
This avoids granting elevated privileges at the start of every task.
7. Temporary access, auditing, and revocation
Access granted to agents should be traceable and revocable.
Temporary credentials reduce exposure if a session, tool, or environment is compromised.
Recording relevant operations is also recommended, especially when they involve infrastructure, data, or external services.
Records should identify which identity performed a particular action and in which environment, without exposing credentials or sensitive information.
Once the task is complete, temporary access can be terminated and execution resources discarded.
For critical operations, retain approval checkpoints and mechanisms to interrupt or revoke access independently of the instructions provided to the agent.
Conclusion
Granting AI agents infrastructure access does not require supplying credentials directly to the model.
SSH Agent, IAM Roles, database users with limited permissions, authenticated tools, and MCP servers provide specific capabilities while keeping authentication under the environment's control.
The principle is simple: the agent should receive access to the operations necessary to perform its task, not unrestricted access to systems or the credentials protecting them.
This separation makes it possible to use agents for investigation, maintenance, and infrastructure operations with less exposure of sensitive data and greater control over executed actions.
Sources and further reading
- OpenSSH — ssh-agent
- AWS Systems Manager — Session Manager
- AWS IAM — Roles
- AWS Security Token Service (STS)
- MySQL 8.4 — GRANT Statement
Related articles
- Security of applications developed with agents
- Protecting context and sensitive data
- Harnesses, skills, tools, and MCP
- Isolated environments for agents and humans
Share this article
Sources & further reading
This note is a practical introduction, not a substitute for the original documentation. Check source dates and implementation details before making technical decisions.