Skip to content

fix: prevent expired sudo token reuse and failed sudo admin fallback across SDKs - #1806

Merged
drstrangelooker merged 3 commits into
mainfrom
fix/sudo-token-expiry-and-escalation
Dec 2, 2026
Merged

drstrangelooker merged 3 commits into
mainfrom
fix/sudo-token-expiry-and-escalation

Conversation

@drstrangelooker

Copy link
Copy Markdown
Collaborator

Summary

Fixes sudo token renewal, revert, and failed-sudo privilege scoping across the Node, Swift, Kotlin, C#, and Python SDKs (follow-up from reviewing #1777):

  1. Scope activeToken by sudoId instead of _sudoToken.access_token

    • TypeScript / Node (packages/sdk-node/src/nodeSession.ts), Swift (swift/looker/rtl/authSession.swift), Kotlin (kotlin/src/main/com/looker/rtl/AuthSession.kt), and C# (csharp/rtl/AuthSession.cs): Return _sudoToken whenever sudoId is set, rather than checking whether _sudoToken.access_token is non-empty.
    • Prevents a failed POST /login/{id} (or token reset while sudoId is set) from silently falling back to an active admin _authToken and reporting isAuthenticated() === true.
  2. Reset expired _sudoToken state and authenticate POST /login/{id} with _authToken

    • TypeScript / Node, Swift, Kotlin, and C#: Reset _sudoToken in sudoLogout() even when isSudo() is false (for example after a 15-minute sudo token expires while the 60-minute API3 token is still active), and read _authToken directly when authenticating POST /login/{id}.
    • Clear sudoId and reset _sudoToken in logout() when a sudo token has already expired so the session reverts cleanly to the API3 user without sending an unnecessary DELETE /logout.
    • Python (python/looker_sdk/rtl/auth_session.py): Reset an expired sudo_token during logout() and still log out an active API3 token when logout(full=True) is called after sudo_token expiry.
  3. Swift error propagation & C# repeated Login(sudoId) fix

    • Swift (swift/looker/rtl/authSession.swift): Replace try? self.ok(response) + force-unwrap (token! / sudoToken!) in _login() with try self.ok(response) and propagate errors from getToken(), avoiding process crashes on auth errors.
    • C# (csharp/rtl/AuthSession.cs): Fix Login(string sudoId = null) so calling Login("5") while "5" is already active refreshes sudo "5" instead of hitting the else branch (_login(null)) and dropping back to the admin API3 user.

Testing

  • TypeScript / Node: yarn jest packages/sdk-node/src/nodeSession.spec.ts packages/sdk-rtl/src, tsc --noEmit, and eslint
  • Kotlin: ./gradlew test & spotlessApply
  • C#: dotnet test (RTL unit tests)
  • Swift: swiftc RTL unit test verification
  • Python: pytest python/tests/rtl/test_auth_session.py & black --check

Developer Checklist

  • Make sure to open an issue as a bug/issue before writing your code so we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Appropriate docs were updated (if necessary)

Fixes #1805

@drstrangelooker
drstrangelooker requested a review from a team as a code owner November 16, 2026 23:30

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the AuthSession class across multiple SDKs (C#, Kotlin, Node, Python, and Swift) to resolve issues with expired sudo token renewal, failed sudo logins, and logout behavior. Key changes include determining the active token based on sudoId rather than the presence of a sudo token, using the primary API token to authenticate sudo login requests, and clearing the sudo session locally without calling the server's logout endpoint if the sudo token has already expired. Feedback on the Kotlin implementation advises against calling invalidateTokens() because it unnecessarily clears Google IAP tokens, suggesting instead to reset only the Looker API and sudo tokens directly.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Python Tests

 11 files  ±0   11 suites  ±0   1m 45s ⏱️ +6s
173 tests +1  168 ✅ +1   5 💤 ±0  0 ❌ ±0 
977 runs  +6  949 ✅ +6  28 💤 ±0  0 ❌ ±0 

Results for commit 741a392. ± Comparison against base commit c0f4e06.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Typescript Tests

  2 files   66 suites   1m 5s ⏱️
256 tests 253 ✅ 3 💤 0 ❌
540 runs  534 ✅ 6 💤 0 ❌

Results for commit 741a392.

♻️ This comment has been updated with latest results.

@drstrangelooker
drstrangelooker merged commit 00cb3f3 into main Dec 2, 2026
14 checks passed
@drstrangelooker
drstrangelooker deleted the fix/sudo-token-expiry-and-escalation branch December 2, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sudo session renewal and failed sudo login use stale or admin tokens across Node, Swift, Kotlin, and C# SDKs

1 participant