-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Current State and Problem
- When a user accesses an MCP, we currently use the same access token for retrieving MCP details as we do for requests to the Onboarding API, assuming both use the same token.
- ✅ This is true in the DEV environment.
- ❌ However, in Staging and Canary, MCPs have a different client ID, which means they require a separate access token.
- This results in a 401 authentication error (was reported by @reshnm). The UI then assumes a new authentication flow is required and redirects the user.
Proposal
We need to manage separate tokens:
- One for the Onboarding API (currently stored in the
onboarding
cookie) - ✨ One (or more) for the MCP(s)
Currently, the frontend checks /api/auth/me
to determine if the user is authenticated with the Onboarding API. This is done by verifying if there is an access token in the cookie (fastify.get("/auth/me")
). If the token is missing, the login screen is displayed.
✨ Before accessing MCP resources, we should also check if the user is authenticated with the MCP API. This could be handled similarly by checking for an MCP-specific access token. If it is missing, the frontend should initiate the login process (or perhaps we can trigger the login automatically? 🤔).
The IdP details for the Onboarding API (such as endpoint and client ID) are provided via environment variables.
✨ To get the IdP details for accessing an MCP, we could retrieve the kubeconfig. The frontend already provides MCP details such as name, project, and workspace (via HTTP x-
header attributes), along with the Onboarding API access token (via cookie), so we can use this information.
✨ We can then initiate the OIDC flow to get an access token for the MCP. (This step could be skipped if the IdP and OIDC attributes are identical, as is currently the case in the DEV environment 🤔)
Cookies vs Session
- Currently, our BFF is stateless, and the Onboarding API token is stored in the
onboarding
cookie. - We could store each MCP’s token in its own cookie (or rather, store the combination of IdP and settings such as client ID 🤔). But dynamically registering cookies can be challenging (currently, the onboarding cookie is registered statically in
secure-session.js
). - Alternatively, we could store exactly two cookies: one for the Onboarding API and one for the MCP. However, this may cause issues when switching between MCPs or working with multiple MCPs in parallel.
→ It may be best to switch to sessions and store tokens in the backend.
(Switching to sessions has the additional benefit of allowing us to refresh access tokens in the BFF in the background, avoiding any possible race conditions.)
How this relates to Multiple IdPs
#143 disables the scenario of multiple IdPs. The approached outlined here, might work also in this multi-IdP scenario. 🤔 Needs further clarification
To Implement
- Switch from cookies to sessions
- Support different auth tokens for MCPs
- Support for live environments (Redis?)