Unable to use glab on staging.gitlab.com
Checklist
-
I'm using the latest version of the extension (Run glab --version
)- Extension version: 1.35.0
-
Operating system and version: macOS Sonoma 14.1.2 -
Gitlab.com or self-managed instance? staging.gitlab.com -
GitLab version (if self-managed) GitLab version here (Use the version
endpoint, like this: gitlab.my-company.com/api/v4/version) -
I have performed glab auth status
to check for authentication issues
Summary
I wanted to perform some automation script that are using glab
first on staging.gitlab.com, although I failed to authenticate to perform actions on staging properly.
Environment
- OS: Darwin 23.1.0 arm64
- SHELL: /opt/homebrew/bin/fish
- TERM: xterm-256color
- GLAB: glab version 1.35.0 (2023-11-01)⏎
Other:
Steps to reproduce
- Install
glab
- Run
glab auth login
. - Select self-hosted instance and then staging.gitlab.com as hostname and API hostname
- Use token to authenticate
-
glab
will respond with error
What is the current bug behavior?
cli
is still trying to check token using gitlab.com
API instead of staging.gitlab.com
API
⋊> ~ glab auth login 22:54:33
? What GitLab instance do you want to log into? GitLab Self-hosted Instance
? GitLab hostname: staging.gitlab.com
? API hostname: staging.gitlab.com
- Logging into staging.gitlab.com
? How would you like to login? Token
Tip: you can generate a Personal Access Token here https://staging.gitlab.com/-/profile/personal_access_tokens?scopes=api,write_repository
The minimum required scopes are 'api' and 'write_repository'.
? Paste your authentication token: **************************
? Choose default git protocol HTTPS
? Authenticate Git with your GitLab credentials? Yes
? Choose host API protocol HTTPS
- glab config set -h staging.gitlab.com git_protocol https
✓ Configured git protocol
- glab config set -h staging.gitlab.com api_protocol https
✓ Configured API protocol
error using api: GET https://gitlab.com/api/v4/user: 401 {message: 401 Unauthorized}
What is the expected correct behavior?
cli
should use staging.gitlab.com
to authenticate when user tries to run script on staging
Relevant logs and/or screenshots
Possible fixes
Most probably IsSelfHosted
func (https://gitlab.com/gitlab-org/cli/-/blob/main/pkg/glinstance/host.go#L60) returns false, when staging.gitlab.com
is used as host, because NormalizeHostname
for staging.gitlab.com
will return gitlab.com
.