Manage GitLab CLI authentication including login/logout, check auth status, switch accounts, and configure Docker registry access. Use when setting up glab for first time, troubleshooting auth issues, switching GitLab instances/accounts, or configuring Docker to pull from GitLab registry. Triggers on auth, login, logout, authentication, credentials, token, Docker registry.
Manage GitLab CLI authentication.
# Interactive login
glab auth login
# Browser/OAuth login without the prompt
glab auth login --hostname gitlab.com --web
# Check current auth status
glab auth status
# Login to different instance
glab auth login --hostname gitlab.company.com
# Logout
glab auth logout
glab auth loginglab auth status
glab auth loginsupports a complete setup flow:
--ssh-hostnameto explicitly set a different SSH endpoint for self-hosted instances--webto skip the login-type prompt and go straight to browser/OAuth auth--container-registry-domainsto preconfigure registry / dependency-proxy domains during loginExample: API hostname
gitlab.company.com, SSH hostnamessh.company.com
For personal access tokens, glab requires at least api and write_repository. GitLab 18.9 introduced https://<host>/-/user_settings/personal_access_tokens/legacy/new?scopes=api,write_repository; that route does not exist on earlier releases. GitLab 18.8 and earlier use https://<host>/-/user_settings/personal_access_tokens?scopes=api,write_repository instead. Use the URL for the target instance rather than assuming the current GitLab.com route exists on an older self-managed server.
# Self-managed GitLab with separate API and SSH endpoints
glab auth login \
--hostname gitlab.company.com \
--ssh-hostname ssh.company.com
# Skip prompts and go straight to browser/OAuth auth
glab auth login --hostname gitlab.com --web
# Preconfigure multiple registry / dependency proxy domains during login
glab auth login \
--hostname gitlab.com \
--web \
--container-registry-domains "registry.gitlab.com,gitlab.com"
# Explicitly opt out of keyring storage (stores the token as plaintext)
glab auth login --hostname gitlab.company.com --insecure-storage \
--stdin < approved-token-file
On a normal workstation, glab auth login stores credentials in the operating system keyring by default when one is available: macOS Keychain, Windows Credential Manager, or Linux Secret Service. The old --use-keyring flag is deprecated because keyring storage is now the default. Re-running login migrates a credential previously stored as plaintext in the config file into the keyring.
Use --insecure-storage only when plaintext config-file storage is explicitly required and its risk is accepted. If no keyring backend is available, glab warns and falls back to the config file. In CI (GITLAB_CI or CI is set), glab defaults to config-file storage because keyrings are usually unavailable or ephemeral; prefer environment credentials rather than persisting a login there.
If a keyring is locked, unavailable, or denies access, glab reports the credential-read failure directly. Fix keyring access or re-authenticate instead of treating the resulting error as an invalid token.
glab checks whether refreshed OAuth credentials can be saved before it refreshes the token, and serializes credential writes across concurrent glab processes. If multiple agents or shells share one config directory, prefer separate config directories per actor for isolation, but do not add external file locks around glab itself.
In a sandbox such as Claude Code, glab must be allowed to write the directory from glab config path --dir, not only the config.yml file. glab writes a temporary file beside the config and then replaces the original. On snap installs, connect keyring access with sudo snap connect glab:password-manager-service if encrypted credential storage is required; otherwise glab auth login can fall back to plaintext config storage.
When re-authenticating interactively, glab preserves saved per-host values such as a custom API host, SSH host, and container-registry domains unless you explicitly override them with flags or prompts. Verify these values after re-authentication instead of deleting the config preemptively:
glab config get api_host --host gitlab.company.com
glab config get ssh_host --host gitlab.company.com
glab config get container_registry_domains --host gitlab.company.com
Non-interactive login also persists explicitly supplied --git-protocol and --api-protocol values in the host configuration. This applies to token/stdin and other prompt-free login paths, so automation can configure the protocols in the same login operation instead of requiring a later config edit. Verify the resulting host entry before relying on it:
glab auth login --hostname gitlab.company.com --stdin \
--git-protocol ssh --api-protocol https < approved-token-file
glab config get git_protocol --host gitlab.company.com
glab config get api_protocol --host gitlab.company.com
Keep token files outside version control and do not print their contents.
CI auto-login: GLAB_ENABLE_CI_AUTOLOGIN=true lets glab use CI_JOB_TOKEN in GitLab CI/CD without a stored login. GITLAB_TOKEN, GITLAB_ACCESS_TOKEN, and OAUTH_TOKEN still take precedence, so leave them unset when the intended credential is CI_JOB_TOKEN. Use explicit env tokens instead when a command needs a project, group, or personal access token.
If you need different agents to show up as different GitLab users, use distinct GitLab bot/service accounts. Multiple PATs on one GitLab user are useful for rotation or scope separation, but they do not create distinct visible identities.
Use the Actor identity for actor-authored GitLab comments, replies, approvals, and other writes. Use an agent identity only when the GitLab action is explicitly that agent's own work product. Pick the intended visible actor before the first write.
A good operational pattern is one env file per actor:
# ~/.config/openclaw/env/gitlab-reviewer.env
GITLAB_TOKEN=glpat-...
GITLAB_HOST=gitlab.com
Keep these env files outside version control, restrict their permissions (for example chmod 600), be mindful of backup exposure, and prefer least-privilege bot/service-account tokens. In a reused shell, clear stale GitLab auth vars first or start a fresh shell.
If the file uses plain KEY=value lines, load it with exported vars before running glab:
unset GITLAB_TOKEN GITLAB_ACCESS_TOKEN OAUTH_TOKEN GITLAB_HOST
set -a
source ~/.config/openclaw/env/gitlab-<actor>.env
set +a
Why this matters:
source does not necessarily export variables to child processesglab only sees env vars that are exportedglab cannot see the env token, it may silently fall back to shared stored auth in the active global config fileThat fallback/shared-auth behavior is convenient for humans, but in multi-agent automation it can cause the wrong GitLab account to post comments, create MRs, or approve work.
Run this immediately before any GitLab write, including glab mr note, review submission or approval, thread replies, and any glab api POST/PATCH/PUT/DELETE call:
glab auth status --hostname "$GITLAB_HOST"
glab api --hostname "$GITLAB_HOST" user
This assumes the target actor env file set GITLAB_HOST for the exact GitLab instance you intend to modify. Do not write until both commands clearly show the intended visible actor on that host.
If a comment or reply was posted under the wrong identity:
unset GITLAB_TOKEN GITLAB_ACCESS_TOKEN OAUTH_TOKEN GITLAB_HOST or start a fresh shell.set -a; source ...; set +a.glab auth status --hostname "$GITLAB_HOST" and glab api --hostname "$GITLAB_HOST" user.If the wrong-identity write changed state beyond a comment or reply, re-auth as above and then use the matching GitLab reversal for that write under the correct actor and host, such as unapproving an MR or issuing the compensating glab api --hostname "$GITLAB_HOST" mutation for the exact resource that was changed.
Logout from current:
glab auth logout
Login to new instance:
glab auth login --hostname gitlab.company.com
Verify:
glab auth status --hostname gitlab.company.com
Configure Docker helper:
glab auth configure-docker
Verify Docker can authenticate:
docker login registry.gitlab.com
Pull private images:
docker pull registry.gitlab.com/group/project/image:tag
configure-docker adds glab only for the configured GitLab registry domains.
It preserves unrelated Docker credential helpers and refuses to replace a
different helper already assigned to the same domain. If a domain has legacy
credentials from docker login, glab warns that the helper takes precedence;
after verifying helper-based access, use the exact suggested docker logout <domain> command to remove the shadowed entry. Back up and review
$DOCKER_CONFIG/config.json before repairing conflicts manually.
"401 Unauthorized" errors:
glab auth statusglab auth loginRe-login still looks stuck after changing auth method:
glab still appears to use stale stored credentials, run glab auth login again instead of assuming the config must be edited manually.glab auth status before retrying the failing command.Env-token auth failures:
GITLAB_TOKEN, GITLAB_ACCESS_TOKEN, or OAUTH_TOKEN is exported, it overrides stored credentials.GITLAB_TOKEN and GITLAB_ACCESS_TOKEN are treated as personal access tokens independently of a stored OAuth profile, so a temporary PAT does not inherit or refresh saved OAuth state.GLAB_IS_OAUTH2=true; otherwise glab sends the environment token as a personal access token. glab auth status reports this scheme mismatch after a 401.glab auth login and glab auth status warn when this precedence applies.type glab to distinguish a wrapper that intentionally injects a token (for example, a 1Password shell plugin alias) from a plain executable path. A wrapper can be expected and need no action; a plain path means the token came from the shell profile, current environment, or CI variables.glab auth status and glab api user before any GitLab write.set -a; source ...; set +a before retrying.Self-managed OAuth URL or refresh problems:
invalid_grant, re-run glab auth login; a revoked/expired OAuth grant or an earlier failed credential save can leave stored OAuth credentials stale.glab config path --dir and re-authenticate. Retrying the same stale token normally will not repair the saved credential.Multiple instances:
--hostname flag to specify instanceDocker authentication fails:
glab auth configure-dockercat ~/.docker/config.json"credHelpers": { "registry.gitlab.com": "glab-cli" }See references/commands.md for detailed flag documentation:
login - Authenticate with GitLab instancelogout - Log out of GitLab instancestatus - View authentication statusconfigure-docker - Configure Docker to use GitLab registrydocker-helper - Docker credential helperdpop-gen - Generate DPoP tokenInitial setup:
glab-config to set CLI defaultsglab-ssh-key for SSH key managementglab-gpg-key for commit signing setupRepository operations:
glab-repo for cloning repositoriesSearch for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer