rancher: Rancher 2.6.x: Unauthorized 401: must authenticate on Rancher API (/v3) when using scope
Rancher Server Setup
- Rancher version: 2.6.5
- Installation option (Docker install/Helm Chart): Docker Install
- Proxy/Cert Details: default / self-signed
Information about the Cluster
- Kubernetes version: 1.23.6
- Cluster Type (Local/Downstream): local
User Information
- What is the role of the user logged in? Admin (issue happens on all user roles)
Describe the bug
Accessing the Rancher 2 API (/v3) does not work when using API Keys with a scope. Being logged in to the UI, the API can be seen.
To Reproduce
- Click on user icon top-right corner
- Click on Account and API Keys
- Create API Key, select a specific cluster for scope (e.g. local)
- Use the token and secret to access the API
Result The API returns a 401.
$ curl -s -u token-p62nb:chcnszhxp6zqrbxwcz5z2r2w9jrftlvtwvzbsr88v4mk28kw4k5c2p https://rancher.example.com/v3/projects -k
{"type":"error","status":"401","message":"Unauthorized 401: must authenticate"}
Expected Result The API should work, even when using a cluster scope for the API key. Here’s the API access with a API Key without scope:
$ curl -s -u token-qb4ww:5h4p2znsjlbglkjx2l8vt7sbtnd49qszgh27jx6zgmqcp96dkl787z https://rancher.example.com/v3/projects -k
{"type":"collection","links":{"self":"https://rancher.example.com/v3/projects"},"createTypes ....
Screenshots

Additional context This may also be a limitation by design. But if that’s the case, what is the API supposed to do or which requests would actually work with a scope?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (2 by maintainers)
Apparently, you have to select NO scope, while generating API keys in rancher
While creating api, it gives this error if cluster is selected. Do not select cluster when creating api keys
Can someone please open this issue again as it’s clearly not resolved? @superseb maybe?
I confirm the issue still exist on rancher
v2.7.4.Can’t create working api token while having a scope (got 401 responses).
The issue still exists on Rancher:
v2.8.0Can’t create a working API token while having a scope.Returns,
confirmed in v2.8.5
Issue is still exists, fix is the same.
same issue on server v2.6.8 with cli v2.6.7