GitLab accounts

Give an agent managed accounts on one or more GitLab instances: a glab CLI and git push over HTTPS, both authenticated by operator-supplied access tokens, with no manual glab auth login.

An agent can hold any number of accounts, each under a label you choose. Two labels can name two instances, such as gitlab.com and a self-hosted one. Provisioning needs no per-agent nix declaration and no rebuild: the agent fetches its tokens from the swarm secret store itself.

Linking an account

In the swarm UI, open an agent, choose link account, then gitlab account. Fill in a label, the instance URL (it starts as https://gitlab.com) and the token. The form shows the recommended scopes and the controller's answer if it refuses the input. The linked account appears in the agent's list of linked accounts with a delete action. The UI calls the controller's API, which you can also call directly:

PUT /api/hives/{hive}/agents/{agent}/gitlab-accounts/{label}
{"url": "https://gitlab.example.org", "token": "<access token>"}

A label that holds an account already answers 409; delete it first (DELETE .../gitlab-accounts/{label}), then link again. No route hands a token back. GET /api/hives/{hive}/agents/{agent}/linked-accounts lists the account as kind gitlab, with its label and URL.

Linking also allows the instance's host in the agent's egress, as a link:gitlab:<label> entry on the swarm's allowed-domains list. swarm-controller derives the host from the URL it stored, so nothing the agent writes can widen its egress. Deleting the account removes the entry.

What the agent gets

An agent with a store identity (services.hyperhive.agent.bao.addr) has:

The unit logs in to the store with the agent's own certificate, lists swarm/agents/<agent>/gitlab/, reads each account, and writes two files in <state>/glab/ (mode 0600) on boot and every two minutes, replacing a file only when its content changed:

The unit generates both files. A deleted account leaves them on the next run, and a hand edit doesn't survive. glab keeps one token per host: when two labels name the same host, the first label in alphabetical order wins. If the unit can't read one of the accounts, it replaces nothing and retries, so the files keep the last complete set.

The unit fails fast and restarts itself every 30 seconds for up to a day, as the other store fetches do, so a store that's down or sealed never holds the container's boot open.

Rolling out

The endpoint, the store path and the agent unit are new, and each end ignores what it doesn't know. An old controller has no GitLab route, so no account gets linked. An old agent has no unit, so a stored account sits unused. A new agent under an old controller lists a store directory that doesn't exist and writes an empty glab configuration.