Skip to content
Anlyon
Esc
↑↓navigate↵open⌘Jpreview
On this page

Log in and profiles

Log the anlyon CLI in with your browser or an API key, and control which workspace and environment each command acts in.

Every command acts with one credential, and that credential is bound to one workspace and one environment on the server. The CLI never picks the target itself. That is what keeps a command typed in the wrong terminal from landing in production: the target is fixed when you log in, and a command that would reach anywhere else stops before it sends anything.

anlyon auth login            # opens your browser; approve on the Anlyon consent screen
anlyon whoami                # who, which workspace, which environment
anlyon auth scopes           # what this login allows, command by command

Choose how the CLI authenticates

You are Use Why
A person at a terminal Browser login: anlyon auth login You act as yourself, with your role. Nothing to copy or paste. The session renews itself while you use it.
A CI job, a script or a server An API key in ANLYON_API_KEY No browser and no credential store needed. The key carries exactly the scopes it was created with.
A machine you return to, with a key An API key stored in a profile: anlyon auth login --api-key-stdin The key stays in the credential store instead of your shell environment.

Log in with your browser

anlyon auth login

The CLI opens your browser at the Anlyon consent screen. If you belong to more than one workspace, choose the workspace and environment there. With one workspace, the login is bound to its default environment. The server records the binding. The CLI only reads it back.

Logged in. Profile "default" → https://api.anlyon.com
  workspace    <workspace-id>
  environment  production (<environment-id>)
  consent      anlyon:actions, anlyon:observability
  stored in    macos-keychain
  This is now the default profile.

The first profile you log in to becomes the default. The command waits up to 10 minutes for you to finish in the browser.

Browser login is OAuth 2.1 for a native app (RFC 8252):

  • PKCE (S256).
  • A one-shot listener on 127.0.0.1, on a random port, receives the redirect.
  • A state check on the redirect.
  • No embedded client secret. The CLI registers itself as a public client for each login.

To refuse a login bound to the wrong environment, assert it. Nothing is saved if it does not match:

anlyon auth login --profile production --environment production

Log in without opening a browser

--no-browser (or ANLYON_NO_BROWSER=1) prints the login URL instead of opening a browser:

anlyon auth login --no-browser

The redirect still goes to 127.0.0.1 on the machine running the CLI, so open the URL in a browser on that same machine. On a remote server with no browser, use an API key.

Ask for more permissions

A default login asks for openid profile email offline_access anlyon:actions anlyon:observability. More sensitive permissions are consent groups you name with --scope. The consent screen lists each one you ask for.

anlyon auth login --scope anlyon:approvals.decide
anlyon auth login --scope anlyon:approvals.decide,anlyon:secrets

A login replaces the profile’s previous login and revokes its refresh token. Name every extra group you need in the same login.

You want to You need
Read actions, invocations, approvals, effects and impact limits A default login (anlyon:actions), or an API key with actions:read, approvals:read or impact-limits:read
Read runs A default login (anlyon:observability), or an API key with runs:read
Invoke an action A default login, or an API key with actions:invoke. --wait also needs actions:read
Declare what an action changes A default login, or an API key with actions:write. Changing what a governed action already declares also needs actions:govern: an operator API key only
Approve or deny --scope anlyon:approvals.decide, or an API key with approvals:decide and approvals:read
List, add, check or reconnect connected accounts --scope anlyon:secrets, or an API key with secrets:read and secrets:write
Read approval policies An operator API key with policies:read. No consent group grants it

anlyon:actions also grants actions:write and actions:invoke. For a credential that can only read, use an API key created with read scopes. anlyon auth scopes shows exactly what the current credential can run, command by command, and for anything it cannot, the --scope that grants it or API key only.

Use an API key

For scripts, CI and servers, set ANLYON_API_KEY. Profiles are then ignored.

export ANLYON_API_KEY=anlyon_live_...
anlyon whoami
$env:ANLYON_API_KEY = "anlyon_live_..."
anlyon whoami
  • The key decides the target. A key belongs to one environment. anlyon whoami prints which.
  • One credential source at a time. Setting ANLYON_API_KEY and also --profile or ANLYON_PROFILE stops the command with exit code 2, rather than guessing which one you meant.
  • Another API origin. ANLYON_API_URL sets the API the key is sent to. The default is https://api.anlyon.com.

Create the key in Settings → API Keys with only the scopes the job needs. For a job that invokes actions and waits on approvals, that is actions:invoke, actions:read and approvals:read. Leave Require an end user off: the CLI sends no end-user header, so Anlyon refuses such a key’s calls with 400 END_USER_REQUIRED. See API keys and scopes.

Store a key in a profile

To keep a key in the credential store under a profile, pipe it in. The CLI refuses to read it from a terminal, so it never appears in argv or shell history:

printf %s "$KEY" | anlyon auth login --api-key-stdin --profile ci
anlyon whoami --profile ci

--scope does not apply here. An API key carries the scopes it was created with.

Know where the credential is kept

The credential is kept in the operating system’s credential store, under the service name anlyon-cli, one entry per profile:

OS Store
macOS login Keychain (security)
Windows Credential Manager
Linux Secret Service (gnome-keyring, KWallet) via secret-tool (package libsecret-tools)

Where no OS store is available, such as a headless server, use ANLYON_API_KEY. As an explicit opt-in, ANLYON_CREDENTIAL_STORE=file keeps credentials in 0600 files under the config directory. Those files are not encrypted. anlyon auth status and anlyon doctor say so whenever the file store is in use. The CLI never falls back to a file on its own.

Profiles live in config.json in the config directory: ~/.config/anlyon (or $XDG_CONFIG_HOME/anlyon) on Linux and macOS, %APPDATA%\anlyon on Windows, or the directory ANLYON_CONFIG_DIR names. A profile records the API origin, the kind of credential, the OAuth endpoints and the workspace and environment it resolved to at login. It never contains a secret.

Know how long a session lasts

Credential Lifetime
Browser login, access token 15 minutes. The CLI refreshes it about a minute before it expires.
Browser login, refresh token A login not used for 7 days expires. Then run anlyon auth login again.
API key Until it is deleted, or until the expiry it was created with. anlyon whoami prints it under expires.

Concurrent commands on one profile take turns to refresh, across processes, so parallel jobs never invalidate each other’s session.

Work with several profiles

A profile is a named target: an API origin, a credential, and the workspace and environment it resolved to at login. Use one profile per environment you work in.

anlyon auth login --profile staging
anlyon auth login --profile production
anlyon profile list
anlyon profile use staging        # default for new commands
export ANLYON_PROFILE=production  # pin this terminal only

On PowerShell, pin a terminal with $env:ANLYON_PROFILE = "production".

   NAME               API                     AUTH     WORKSPACE       ENVIRONMENT
*  staging (default)  https://api.anlyon.com  oauth    <workspace-id>  staging
   production         https://api.anlyon.com  oauth    <workspace-id>  production

* marks the profile commands in this terminal will use. Profile names are letters, digits, ., _ and -, up to 64 characters.

To act in another environment, log in again under another profile and choose that environment on the consent screen. With one workspace, the consent screen does not ask, so use an API key created in the other environment.

Know how a command picks its target

Before any request, every command resolves, in order:

  1. The profile: --profile, then ANLYON_PROFILE, then the default set by profile use, then default. With ANLYON_API_KEY set, there is no profile.
  2. The API origin: the profile’s, or ANLYON_API_URL for an API key.
  3. The credential: from the credential store, or ANLYON_API_KEY.
  4. The workspace and environment, from the server. The CLI asks Anlyon what the credential is bound to.

Each command resolves this once. A profile use in another terminal cannot move a command that is already running. Then:

  • --environment <id|slug> is an assertion. If the credential is bound to another environment, the command stops with exit code 10. The CLI never sends an environment override.
  • A rebound credential stops commands. If a profile’s credential now resolves to a different workspace or environment than it did at login, commands stop with exit code 10 until you log in to that profile again.
  • A credential only goes to its own API origin. ANLYON_API_URL pointing anywhere other than the profile’s API is refused with exit code 10.
  • Profiles are independent. Each has its own credential entry, OAuth client and server-side binding. Two terminals on different profiles cannot retarget each other.
anlyon whoami --profile production --environment production

Check your setup

anlyon auth status    # which profile, API and credential commands will use, and whether it works
anlyon doctor         # install, config, credential store, API, clock and credential
profile       default (from default)
api           https://api.anlyon.com
auth          oauth
credential    stored
store         macos-keychain
bound to      workspace <workspace-id>, environment production
server check  ok

anlyon auth status exits 0 when the credential works, 3 when nothing is stored, and the failing check’s exit code otherwise. --offline skips the server check. anlyon doctor exits 1 when any check fails and 0 otherwise.

Log out

anlyon auth logout
anlyon auth logout --profile staging --forget

auth logout revokes the profile’s refresh token and deletes its stored credential. --forget also removes the profile from config.json. An access token already issued stays valid until it expires, at most 15 minutes later. If the server does not confirm the revocation, the local credential is deleted anyway and the CLI says so.

Logging out does not touch ANLYON_API_KEY. Unset it yourself, and delete the key in the console if it should stop working.

Fix login errors

With --json, every error is one object on stderr with a stable code. See Scripting and CI.

Code Exit What it means What to do
NOT_LOGGED_IN 3 The profile has no stored credential. anlyon auth login, or set ANLYON_API_KEY.
SESSION_EXPIRED 3 The login was unused for 7 days, or it was revoked. The CLI deletes the dead credential. anlyon auth login again for that profile.
AUTHENTICATION_ERROR 3 The API rejected the credential (401), for example a deleted or expired API key. Check the key in the console, or log in again.
AUTHORIZATION_ERROR 4 The credential lacks a scope or role (403). The message names what is missing. anlyon auth scopes, then log in with the --scope it names, or use a key with that scope.
END_USER_REQUIRED 6 The API key was created with Require an end user. The CLI sends no end-user header. Use a key created without that option.
ENVIRONMENT_MISMATCH 10 --environment does not match the credential’s binding. Use a profile or API key bound to that environment.
BINDING_CHANGED 10 The profile’s credential now resolves to another workspace or environment than at login. anlyon auth login for this profile to confirm the new target.
API_URL_MISMATCH 10 ANLYON_API_URL differs from the profile’s API. Unset ANLYON_API_URL, or log in to a separate profile for that API.
USAGE 2 ANLYON_API_KEY and a profile are both set, --no-input was given to a browser login, --api-key-stdin was run from a terminal, or --scope named a consent group the server does not offer. Follow the hint line. Unset one credential source, pipe the key in, or use a group the hint lists.
CREDENTIAL_STORE_UNAVAILABLE 1 The OS credential store is locked or missing, for example no Secret Service on Linux. Unlock or install it. On a server, use ANLYON_API_KEY. ANLYON_CREDENTIAL_STORE=file is the unencrypted opt-in.
CONFIG_INVALID 1 config.json is not a valid config file. Fix or delete it. It holds no secrets.
PROFILE_NOT_FOUND 2 profile use named a profile that does not exist. anlyon auth login --profile <name> creates it.

If anlyon doctor warns that the OAuth issuer or token endpoint changed since login, log in again.

Was this page helpful?