Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Auth with token has reduced privilidges #94

Open
cobookman opened this issue Mar 5, 2024 · 1 comment
Open

Auth with token has reduced privilidges #94

cobookman opened this issue Mar 5, 2024 · 1 comment

Comments

@cobookman
Copy link

cobookman commented Mar 5, 2024

The usage of basic auth with API Key/user-tokens at least in my Service Sonar enterprise instance has reduced privileges even when associated to 'super admin' users. I noticed that by changing auth from Basic Auth to instead by Authorization Bearer Token headers, these auth issues went away.

Any issues if we change how user-tokens are authed from being Basic Auth to be instead bearer-token header.

if token:
_auth = HTTPBasicAuth(token, "")

Involves slight change to the codebase to be instead, something like:

if token:
    _session.headers.update({'Authorization': f'Bearer {token}'})
elif username and password:
    _session.auth = HTTPBasicAuth(username, password)
@ryanm101
Copy link

ryanm101 commented Jan 15, 2025

It's not quite that simple (i tried it) the following also fail but a direct requests call works.

# This fails 403 {"errors":[{"msg":"Insufficient privileges"}]}
sonar = SonarQubeClient(sonarqube_url=sonarqube_url)
#sonar.projects.default_headers.update(headers)
#sonar.auth.default_headers.update(headers)
sonar.session.headers.update(headers)
projects = sonar.projects.search_projects()
print(projects)


#this works
res = requests.get(f"{sonarqube_url}/api/components/search_projects?p=2&branch=master&ps=500", headers=headers)
print(res.json())

editing the init.py

        _session = requests.Session()
        _auth = None

        if token:
            _session.headers.update({"Authorization": f"Bearer {token}"})
        elif username and password:
            _auth = HTTPBasicAuth(username, password)

        _session.auth = _auth
sonar = SonarQubeClient(sonarqube_url=sonarqube_url, token=tk)
projects = sonar.projects.search_projects()
print(projects)

Looks like different endpoints for my server /api/projects vs /api/components

https://next.sonarqube.com/sonarqube/web_api/api/projects/search indicates this endpoint requires Admin

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants