Prerequisites
- An access bundle with a service for each API the agent calls
- A running proxy that the agent’s machine can reach
- The Admin role in Agent Vault, or an Agent Vault admin who can complete Step 1 for you
Step 1: Set up a machine identity
Your code creates sessions as a machine identity, so that sessions don’t depend on a person’s account.1
In Agent Vault, go to Access Control > Machine Identities and select Add Machine Identity.
2
On the Create New tab, enter a Name, choose Member in Role, then select Create. Infisical creates the machine identity with Universal Auth and opens its page.
3
On the machine identity’s page, select Universal Auth under Authentication. Copy the Client ID, then select Add Client Secret and copy the client secret.
4
Go to Access Bundles and open the access bundle the agent uses. Select Options > Manage Access, then select Grant Access. Select the machine identity, then select Grant Access.
Step 2: Log in as the machine identity
Call the login endpoint for Universal Auth with the client ID and client secret:https://app.infisical.com with the address of your instance, here and in every later request.
The response includes an accessToken, which you send with each request in the next steps, and expiresIn, the number of seconds until the access token expires. Log in again when the access token expires.
Step 3: Create a session
Call the endpoint that creates a session with the name of the access bundle and how long the session should last:accessBundlestakes a list, but a session can have only one access bundle, so the list must have exactly one namettlaccepts a duration of at least one minute, such as30m,8h, or7d, ornever, and defaults to7d(see Choose how long a session lasts to pick a value)
Choose how long a session lasts
Pick thettl based on how long your agents run:
Step 4: Start the agent with the session token
The agent uses the session token to authenticate to the proxy. How you pass the token to the agent depends on how you start the agent:- With the CLI
- Without the CLI
Start the agent with The CLI trusts the proxy’s certificate for the agent and sends the agent’s requests through the proxy.
infisical agent-vault run, and pass the session token and the proxy’s address:Step 5: Revoke the session
When the agent finishes, call the endpoint that revokes a session with the session’s ID:finally block or an exit handler. If your code exits before it can revoke the session, the session stops working when its ttl runs out.
Step 6: Verify it works
In Agent Vault, go to Sessions and select All Sessions. The Identity column shows the machine identity’s name for the session you created. The session’s Status is Active while the agent runs, and Revoked after Step 5. If you’ve set up session logs, view the session’s logs to check which requests the agent made during the session.Your code now creates a session for each agent run, and the agent’s credentials stop working when you revoke the session or its
ttl runs out.Troubleshooting
Creating the session fails with "No access bundle named ... is granted to you"
Creating the session fails with "No access bundle named ... is granted to you"
The machine identity doesn’t have a grant on the access bundle, or the name in
accessBundles is wrong. Check the name on the Access Bundles page, and grant the bundle to the machine identity.Creating or revoking a session fails with 401 after your code has run for a while
Creating or revoking a session fails with 401 after your code has run for a while
The machine identity’s access token expired. Log in again to get a new access token. Sessions you already created keep working, because a session doesn’t depend on the access token that created it.
Next steps
Your own agent
Send your agent’s requests through the proxy from your own code.
Session logs
Record every request an agent makes during a session.