From fc30a9c542d31d4d7e2f23cb18dae407bf28775c Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Mon, 9 Nov 2026 13:25:57 +0200 Subject: [PATCH 1/2] fix(auth): require re-authentication before minting a CLI access token - Send prompt=login in the authorization-code sign-in so Keycloak asks for the password even with a live SSO session (M4/W3). - Warn on the account page that the token works like a password for up to 180 days, and link to the Keycloak Applications page to remove signed-in computers (S5/A8). Clear the shown token when the page is left. - Record the minimum UI version (master after 8b17318) in the auth wiki for the M6 gate. --- docs/llm-wiki/08-auth-and-terms-flow.md | 2 +- .../pages/account-page/account-page.component.html | 14 ++++++++++++-- .../pages/account-page/account-page.component.ts | 9 +++++++-- src/app/pages/account-page/cli-token.spec.ts | 1 + src/app/pages/account-page/cli-token.ts | 3 +++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/docs/llm-wiki/08-auth-and-terms-flow.md b/docs/llm-wiki/08-auth-and-terms-flow.md index 270ae2698..5a6a7d906 100644 --- a/docs/llm-wiki/08-auth-and-terms-flow.md +++ b/docs/llm-wiki/08-auth-and-terms-flow.md @@ -40,7 +40,7 @@ Platform UI auth and JupyterHub auth are related but separate: 8. Hub sets its own session cookie (SameSite=Lax, Secure by default). Any valid Keycloak user for the Hub client is currently allowed (`allow_all = True`). 9. Before spawn, Hub injects the Keycloak access token into the notebook pod as `MIP_TOKEN`, refreshing via stored refresh tokens when needed. 10. Running notebooks can refresh `MIP_TOKEN` through Hub `/notebook/hub/api/platform-token` via the mip client transport. -11. Remote use (account page): shown when `GET /services/auth-config` answers (the backend has a public Keycloak client, `KEYCLOAK_CLI_CLIENT_ID`). "Create access token" runs an authorization-code sign-in with PKCE as that client (`scope=openid offline_access`, redirect back to `/account`, code exchanged by the browser, `cli-token.ts`) and shows the offline refresh token once; nothing stores it. Users paste it into `mip login --token` or `MIP_API_TOKEN`; the mip client renews access with Keycloak itself. The page also explains `mip login` (device flow). JupyterHub is not involved. +11. Remote use (account page): shown when `GET /services/auth-config` answers (the backend has a public Keycloak client, `KEYCLOAK_CLI_CLIENT_ID`). "Create access token" runs an authorization-code sign-in with PKCE as that client (`scope=openid offline_access`, `prompt=login` so Keycloak re-asks for the password even with a live SSO session (first present on master after commit 8b17318, 2026-11-06 — use that build or newer as the minimum UI version in the M6 gate), redirect back to `/account`, code exchanged by the browser, `cli-token.ts`) and shows the offline refresh token once; nothing stores it. Users paste it into `mip login --token` or `MIP_API_TOKEN`; the mip client renews access with Keycloak itself. The page also explains `mip login` (device flow). JupyterHub is not involved. Key files: `src/app/pages/notebook/hub-session.ts`, `hub-http.ts`, `jupyterhub-api.ts`, `nginx.conf.template`. diff --git a/src/app/pages/account-page/account-page.component.html b/src/app/pages/account-page/account-page.component.html index b20a6a364..a322ac66a 100644 --- a/src/app/pages/account-page/account-page.component.html +++ b/src/app/pages/account-page/account-page.component.html @@ -64,6 +64,13 @@

Use MIP from your own computer

No browser on that machine

+

+ This token works like your password for up to 180 days. Keep it only in + mip login --token; never put it in notebooks, .env files, + repositories or chat. Lost it or your computer? + . +

{{ tokenCopyStatus() }}

- Treat it like a password: it gives your full MIP data access for up to 6 months, until - it goes unused for 30 days, or until you run mip logout. + This token works like your password for up to 180 days. Keep it only in + mip login --token; never put it in notebooks, .env files, + repositories or chat. Lost it or your computer? + .

}

diff --git a/src/app/pages/account-page/account-page.component.ts b/src/app/pages/account-page/account-page.component.ts index c4507d124..945f78f27 100644 --- a/src/app/pages/account-page/account-page.component.ts +++ b/src/app/pages/account-page/account-page.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, computed, inject, signal, WritableSignal } from '@angular/core'; +import { ChangeDetectionStrategy, Component, OnDestroy, computed, inject, signal, WritableSignal } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; import { CommonModule, Location } from '@angular/common'; import { HttpClient } from '@angular/common/http'; @@ -14,7 +14,7 @@ import { AuthConfig, cliTokenSignInUrl, finishCliTokenSignIn, isSignInReturn } f styleUrl: './account-page.component.css', changeDetection: ChangeDetectionStrategy.OnPush }) -export class AccountPageComponent { +export class AccountPageComponent implements OnDestroy { public authService = inject(AuthService); private location = inject(Location); private http = inject(HttpClient); @@ -51,6 +51,11 @@ export class AccountPageComponent { } } + ngOnDestroy(): void { + // Drop the shown token right away; the signal is only ever held until the page is left. + this.cliToken.set(''); + } + async createToken(): Promise { const config = this.authConfig(); if (!config) return; diff --git a/src/app/pages/account-page/cli-token.spec.ts b/src/app/pages/account-page/cli-token.spec.ts index 7082a7ef0..9aeadeec7 100644 --- a/src/app/pages/account-page/cli-token.spec.ts +++ b/src/app/pages/account-page/cli-token.spec.ts @@ -26,6 +26,7 @@ describe('cli-token', () => { expect(url.searchParams.get('client_id')).toBe('mip-cli-handson'); expect(url.searchParams.get('response_type')).toBe('code'); expect(url.searchParams.get('scope')).toBe('openid offline_access'); + expect(url.searchParams.get('prompt')).toBe('login'); expect(url.searchParams.get('redirect_uri')).toBe(redirectUri); expect(url.searchParams.get('code_challenge_method')).toBe('S256'); expect(url.searchParams.get('code_challenge')).toMatch(/^[A-Za-z0-9_-]{43}$/); diff --git a/src/app/pages/account-page/cli-token.ts b/src/app/pages/account-page/cli-token.ts index 6c37444d1..8705d4856 100644 --- a/src/app/pages/account-page/cli-token.ts +++ b/src/app/pages/account-page/cli-token.ts @@ -41,6 +41,9 @@ export async function cliTokenSignInUrl(config: AuthConfig, redirectUri: string) client_id: config.clientId, response_type: 'code', scope: 'openid offline_access', + // Re-ask for the password even when the browser has a live SSO session, so a + // borrowed or stolen laptop cannot mint a token from the open session. + prompt: 'login', redirect_uri: redirectUri, state: pending.state, code_challenge: await codeChallenge(pending.verifier), From f4f78fa0dc35bff6a18a221988dc06aea7fe4e89 Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Mon, 9 Nov 2026 16:46:09 +0200 Subject: [PATCH 2/2] docs(account): keep lifetime rules by the shown token; 180 days everywhere Review feedback on PR #72: the warning paragraph was pasted twice and the under-token note lost the 30-day idle / mip logout rules; the footer mixed '6 months' with the new '180 days'. The guide above the button keeps the password warning once; the note under the token now states how the token ends (180 days, 30 days idle, mip logout) plus the Applications link. Specs now lock the destroy-clears-token behaviour, the warning copy, every Applications link, and prompt=login on the click path. --- .../account-page/account-page.component.html | 7 ++- .../account-page.component.spec.ts | 47 +++++++++++++++++-- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/app/pages/account-page/account-page.component.html b/src/app/pages/account-page/account-page.component.html index a322ac66a..48317ede1 100644 --- a/src/app/pages/account-page/account-page.component.html +++ b/src/app/pages/account-page/account-page.component.html @@ -90,9 +90,8 @@

No browser on that machine

{{ tokenCopyStatus() }}

- This token works like your password for up to 180 days. Keep it only in - mip login --token; never put it in notebooks, .env files, - repositories or chat. Lost it or your computer? + It lasts up to 180 days, or until it is unused for 30 days, or until you run + mip logout. Lost it or your computer? .

@@ -118,7 +117,7 @@

A browser on any device

import mip
 client = mip.Client.from_env()

- Each sign-in lasts at most 6 months, and ends after 30 days without use. To end it sooner, + Each sign-in lasts at most 180 days, and ends after 30 days without use. To end it sooner, run mip logout on that computer. Without that computer, remove "MIP command line" under Applications in your