Logging in and profiles
The CLI authenticates every request with a personal access token
(clapat_...), sent as Authorization: Bearer <token>. It never stores
your password.
Logging in¶
clarive login --url https://clarive.example.com
The CLI asks for your username (or email) and your password, sends them
once to the auth.login operation, and stores the token the server mints
for it. The token belongs to you: everything the CLI does runs with your
roles and permissions, exactly as the web interface would.
Options of login:
| Option | What it does |
|---|---|
--url <server> |
The Clarive server, e.g. https://clarive.example.com |
-u, --username <user> |
Username or email; asked for when missing |
--password-stdin |
Read the password from the first line of stdin instead of asking |
--read-only |
Ask for a read token: it can only call operations that change nothing |
--expires-days <n> |
Days until the token expires (default 90; the server allows two years at most) |
--description <text> |
Shown in the token list (default clarive cli on <host>) |
--token <clapat_...> |
Store an existing token instead of logging in with a password |
--profile <name> |
The profile to store it in (see below) |
Examples:
clarive login --url https://clarive.example.com -u jdoe clarive login --url https://clarive.example.com -u jdoe --password-stdin < ~/.secrets/clarive clarive login --profile prod --url https://prod.example.com --read-only --expires-days 30 clarive login --url https://clarive.example.com --token clapat_0123456789abcdef
Logging in also downloads the server's operation catalog, so the commands match that server from the start.
Failed logins are throttled per address with the same settings as the web login, so a script that keeps retrying a wrong password gets slower answers.
Who am I¶
clarive whoami clarive whoami --actions # also the permission actions you hold
whoami shows the user (name, email, language), whether you are an
administrator, your roles, the projects you belong to, and the token in use:
its prefix and whether it is a read or a write token. clarive user
roles-projects <user> shows which role you hold in which project, and
clarive auth list-tokens the expiry of your tokens.
Logging out¶
clarive logout
logout revokes the token on the server, so it stops working at once, and
removes it from the profile. Revoking is the right thing to do on a shared
machine or when a token may have leaked.
Profiles: several servers or users¶
A profile holds a server URL, a username and a token. The first login
creates the profile default. Use more profiles for more servers, or for a
read-only and a read-write token on the same server:
clarive login --profile test --url https://clarive-test.example.com clarive login --profile prod --url https://clarive.example.com --read-only clarive profile list # every profile; the current one is marked clarive profile use prod # make prod the current profile clarive profile show [name] # its server, user, token (masked) and expiry clarive profile delete test # forget it (logout first to revoke its token) clarive --profile test job list # one command against another profile
Where the configuration lives¶
Profiles are kept in $XDG_CONFIG_HOME/clarive/config.yaml, which is
~/.config/clarive/config.yaml unless you set XDG_CONFIG_HOME. Set
CLARIVE_CONFIG to use another file. The CLI writes it with mode 0600,
readable only by you, because it holds tokens.
The operation catalog of each profile is cached in
$XDG_CACHE_HOME/clarive/ (~/.cache/clarive/ by default); a server used
without a profile, only with --url or CLARIVE_URL, under its URL.
Settings and their precedence¶
Every setting can come from a flag, an environment variable or the profile. The first one found wins:
- flags:
--profile,--url,--token,--insecure - environment:
CLARIVE_PROFILE,CLARIVE_URL,CLARIVE_TOKEN,CLARIVE_INSECURE - the profile in the configuration file
Other environment variables:
| Variable | What it does |
|---|---|
CLARIVE_CONFIG |
The configuration file to use |
CLARIVE_NO_REFRESH=1 |
Never refresh the cached catalog automatically |
CLARIVE_NO_NOTICE=1 |
Don't print the server's notices on stderr (for example, that the Agent Instructions need preparing) |
XDG_CONFIG_HOME, XDG_CACHE_HOME |
Where the configuration and the cache live |
--insecure (or CLARIVE_INSECURE=1) skips TLS certificate checks. Use it
only against a test server with a self-signed certificate.
A token goes only to its own server¶
A profile's token is only ever sent to the server it was made for. If
--url or CLARIVE_URL points to another server, the CLI does not send
the profile's token there; the command fails with
no token for <url>: use --profile or --token (exit code 3) unless you
give a token for that server with --token or CLARIVE_TOKEN. This keeps
a mistyped URL, or a URL from an untrusted script, from collecting your
token.
CI pipelines, scripts and agents¶
On a build agent there is no one to type a password. Give the job a token and the URL in the environment; no configuration file is needed:
export CLARIVE_URL=https://clarive.example.com export CLARIVE_TOKEN=clapat_0123456789abcdef # from your CI's secret store clarive job create QA 101,102 --wait --logs
Good practice for these tokens:
- Make one token per pipeline or agent, with a description that says what it is for, so you can find it and revoke it alone.
- Use a dedicated Clarive user with only the roles the pipeline needs.
- Make it a read token when the pipeline only reads (reports, checks).
- Give it an expiry and rotate it.
A user can mint tokens for themselves. auth.create_token makes a read
token unless you ask for write:
clarive auth create-token --description "gitlab deploy QA" --permissions write --expires-days 180 clarive auth create-token --description "nightly report"
The token is shown once, in the answer; store it in the CI's secret store right away. An administrator can also mint a token for any user on the Clarive server itself, without that user's password:
cla api-token --user ci-deployer --days 180 --description "gitlab deploy QA" -c <config>
See cla api.
Managing tokens¶
clarive auth list-tokens # your tokens: prefix, description, permissions, expiry, last use clarive auth list-tokens --username jdoe # another user's (user administrators) clarive auth update-token clapat_0123 --description "gitlab QA" clarive auth set-token-active clapat_0123 --active=false # disable without deleting clarive auth revoke-token clapat_0123 # delete: it stops working at once
Tokens are identified by their prefix (the first characters, shown in the lists); the full token is never shown again after it is created. Deleting a user deletes their tokens.
Tokens made for git in Preferences, and tokens limited to some
repositories, are git credentials only; the API refuses them. A token made
by clarive login or auth.create_token works for git too. See
Personal Access Tokens.