bug(python): OIDC refresh drops the gateway's oidc_scopes

Offen Anfängerfreundlich
#4,919 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@jyotir07 arbeitet bereits daran.

Seit 26.10.2026.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
84/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
authentication

Rechercherichtung

Beginne mit _OidcRefresher._refresh in python/openshell/sandbox.py und vergleiche dessen Tokenformat mit dem im Issue beschriebenen CLI-Aktualisierungspfad. Lies die Verarbeitung der Gateway-Metadaten in der Nähe und führe anschließend die gezielten Refresher-Tests in python/openshell/sandbox_test.py aus. Die Arbeit ist abgeschlossen, wenn die Tests zeigen, dass die Anfrage bei vorhandenem oidc_scopes durch Leerzeichen getrennte Werte enthält und unverändert bleibt, wenn es fehlt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

state:triage-needed
User Story

As a student building a personal project that creates and drives OpenShell sandboxes from the Python SDK (SandboxClient.from_active_cluster), I want the SDK to refresh my OIDC session the same way the CLI does, so that my scripts keep working after the access token expires without me running a CLI command to renew it.

I noticed the Python refresh behaving differently from the CLI while working on the project. Comparing the two refresh paths showed that the Python refresher never sends the gateway's oidc_scopes, and I then reproduced it with a unit test.

Problem Statement

_OidcRefresher._refresh in python/openshell/sandbox.py posts the refresh_token grant with only grant_type, refresh_token, and client_id. It never sends the gateway's oidc_scopes. The CLI does send them (ensure_valid_oidc_token_bundle → oidc_refresh_token(..., scopes)), and the docs say refresh uses "the OIDC scopes saved in the gateway metadata". The Python client-credentials provider in the same file already reads oidc_scopes / oidc_audience from metadata; only the refresh path omits them.

Impact / Why This Matters

With identity providers that require scope on the refresh grant, or that pick the token's resource from it (for example Microsoft Entra ID), the Python SDK's first automatic refresh fails or returns a token the gateway rejects. The same gateway works with the CLI. The current workaround is to run openshell gateway login or a CLI command before the token expires so the CLI rewrites oidc_token.json. That does not work for long-running Python processes.

Acceptance Criteria
  • When gateway metadata has oidc_scopes, the Python refresh request includes scope=<space-separated scopes>, matching the CLI.
  • Without oidc_scopes, the refresh request is unchanged.
  • A unit test covers both cases.
Reproduction Steps
  1. Register a gateway whose metadata.json has "auth_mode": "oidc" and "oidc_scopes": "openid api://openshell/.default", with an expired access token and a valid refresh token in oidc_token.json.
  2. Build the provider with _make_cluster_bearer_provider(gateway_dir, name) (the path SandboxClient.from_active_cluster uses) and call it once, with the refresher's httpx.Client bound to an httpx.MockTransport that records the token request.
  3. The posted form contains grant_type, refresh_token, and client_id, but no scope. The CLI's refresh for the same gateway sends scope=openid api://openshell/.default.
Suggested UX (if applicable)

No response

Environment
  • OpenShell: main @ c4688aa8
  • SDK: Python (python/openshell/sandbox.py, _OidcRefresher)
Logs
FAILED python/openshell/sandbox_test.py::test_refresher_sends_gateway_oidc_scopes
E   AssertionError: assert None == 'openid api://openshell/.default'
Vorherrschende Sprache
Rust
Sterne
20.6k
Forks
2k
Ø Merge
2 T. 14 Std.
Gemergte PRs (30 T.)
275

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus NVIDIA/OpenShell

Alle Issues in NVIDIA/OpenShell

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.