Skip to main content
An agent in a container, on a server, or in a CI job connects to one vault with a one-use connect token. You make the token where you are signed in, then run one line where the agent runs. That place gets its own agent credential and proxy settings, never your key and never a stored secret. The gateway adds the secret to each call on the way out. You need onecli 3.4 or later where you make the token, signed in with onecli login. The place you connect needs only sh and curl. See the Quickstart.

Make a connect token

Find the vault the agent should use:
Make a token. Name the agent so you can tell your agents apart, and name the provider, such as docker or aws-ec2:
The token works once, and expires after 15 minutes unless you pass --expires-in (1m to 60m). It is a credential: pass it only to the place it is for, and don’t log or save it. Use install_command where onecli is not installed. Use connect_command where it is. Run either one as the user the agent runs as. It writes agent.env (mode 0600) with the agent’s credential and proxy settings, and a line in the shell profile that reads it.

Docker

Run install_command inside the running container:
Put the whole install_command in place of <install_command>, as it is. The script sees it runs in a container and records the agent’s runtime as docker. If you self-host OneCLI on the same machine at a localhost address, the container reaches it through host.docker.internal. Start the container with --add-host=host.docker.internal:host-gateway when it cannot resolve that name. Proxy settings only route tools that respect them. To make the gateway the container’s only way out, see Lock down Docker and Linux agents.

Your own server

Open a shell on the server, as the user the agent runs as, and run install_command there. For example over SSH:
A new login shell reads agent.env, so start the agent from one, such as a new SSH session. For a systemd service, read agent.env in ExecStart, as in the Linux lock-down recipe.

CI

A CI runner that stays up, such as a self-hosted runner, is a server: connect it once, as above, and its jobs read agent.env. A job on a fresh runner cannot use a connect token, because a token works once. Give CI its own agent instead. Its credential (oc_agent_...) reaches one vault and can only call APIs through the gateway. Never put your managing key in CI: it manages every vault you can use.
1

Make the CI agent once, on your own machine

Use a vault that holds only the items CI needs. Make the agent with the managing key onecli login saved, and give it an expiry. We recommend 30 days, so a leaked credential stops on its own. The API takes 5 minutes to 90 days.
On Linux, use date -u -d '+30 days' +%Y-%m-%dT%H:%M:%SZ. The key goes to curl as a header file, so it is not in the command line other users on the machine can list. The answer holds the credential once. The pipe stores it straight in a CI secret, so it never shows on screen. The answer also holds the agent’s id, vaultId, expiresAt and gateway.
2

Connect in the job

Run the connection script with the credential instead of a token. It writes agent.env and the gateway certificate:
A login shell reads agent.env, so the agent’s calls go through the gateway.
3

Replace it before it expires

When the agent reaches its expiresAt, its calls answer 401. Make a new one as in the first step, and disconnect the old one with onecli agents disconnect <agent-id> --yes.
With CI set, onecli never asks a question and never updates itself.

Check the agent is connected

Then make the same call twice where the agent runs. Around OneCLI, it answers 401:
Through OneCLI, it answers 200, because the gateway added the Test key. A login shell reads the proxy settings:
In a container, run each one with docker exec research-container sh -lc '...'.

When something fails

Next steps