Repository navigation
fix: prevent expired sudo token reuse and failed sudo admin fallback across SDKs - #1806
Conversation
There was a problem hiding this comment.
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.
Typescript Tests 2 files 66 suites 1m 5s ⏱️ Results for commit 741a392. ♻️ This comment has been updated with latest results. |
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):
Scope
activeTokenbysudoIdinstead of_sudoToken.access_tokenpackages/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_sudoTokenwheneversudoIdis set, rather than checking whether_sudoToken.access_tokenis non-empty.POST /login/{id}(or token reset whilesudoIdis set) from silently falling back to an active admin_authTokenand reportingisAuthenticated() === true.Reset expired
_sudoTokenstate and authenticatePOST /login/{id}with_authToken_sudoTokeninsudoLogout()even whenisSudo()isfalse(for example after a 15-minute sudo token expires while the 60-minute API3 token is still active), and read_authTokendirectly when authenticatingPOST /login/{id}.sudoIdand reset_sudoTokeninlogout()when a sudo token has already expired so the session reverts cleanly to the API3 user without sending an unnecessaryDELETE /logout.python/looker_sdk/rtl/auth_session.py): Reset an expiredsudo_tokenduringlogout()and still log out an active API3 token whenlogout(full=True)is called aftersudo_tokenexpiry.Swift error propagation & C# repeated
Login(sudoId)fixswift/looker/rtl/authSession.swift): Replacetry? self.ok(response)+ force-unwrap (token!/sudoToken!) in_login()withtry self.ok(response)and propagate errors fromgetToken(), avoiding process crashes on auth errors.csharp/rtl/AuthSession.cs): FixLogin(string sudoId = null)so callingLogin("5")while"5"is already active refreshes sudo"5"instead of hitting theelsebranch (_login(null)) and dropping back to the admin API3 user.Testing
yarn jest packages/sdk-node/src/nodeSession.spec.ts packages/sdk-rtl/src,tsc --noEmit, andeslint./gradlew test&spotlessApplydotnet test(RTL unit tests)swiftcRTL unit test verificationpytest python/tests/rtl/test_auth_session.py&black --checkDeveloper Checklist
Fixes #1805