Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OIDC: Sessions #15030

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft

OIDC: Sessions #15030

wants to merge 47 commits into from

Conversation

markylaing
Copy link
Contributor

This is for discussion and would add direct support for Entra ID and ADFS (#14174 #14175). It:

  • Adds logic to set a JWT as a cookie after successfully logging in (both via CLI and UI).
  • The JWT is signed using a key derived from the cluster-wide key (added in OIDC: Cluster-wide key and salt for cookie encryption #15011) using the session ID as a salt.
  • The session ID is saved both in the token itself ("sub" claim) and also in the metadata for the identity.
  • The identity metadata for OIDC identities now contains fields for the refresh token, for identity provider groups, and for a boolean to indicate if the session has been revoked. These are updated whenever a session times out.
  • Sessions can be revoked by session the session_terminated field in the identity metadata to true. I haven't implemented an API endpoint for this but it should be easy to do.
  • Adds a new config key oidc.session.lifetime, which determines the expiry of the JWTs issued by LXD.
  • Updates the OIDC Verifier to return an *api.IdentityInfo or error. This is set in the request context so that authorization can account for effective groups (LXD and IdP groups). The OIDC Verifier performs DB queries only when the user has authenticated.
  • Removes reliance on the identity cache for authorization. It is now used only for mTLS authentication.
  • Updates the Authenticate function in daemon.go to add an *api.IdentityInfo and *api.Certificate to the request context when appropriate. (Again, DB calls are made only when the caller has authenticated).
  • Updates the client and lxc/config to handle session cookies (and saves cookies on disk on exit).

Signed-off-by: Mark Laing <[email protected]>
Adds utils for managing a cluster wide secret and salt.

Signed-off-by: Mark Laing <[email protected]>
This function, in combination with `clusterSecretInternal`,
can be used to get a cluster-wide shared secret on demand.

Signed-off-by: Mark Laing <[email protected]>
We need to unset any previously configured value so that the joining
daemon will fetch the shared secret on the next call to
`(*Daemon).getClusterSecret`.

Signed-off-by: Mark Laing <[email protected]>
To do this, we need to delete the database entry first, then reset
the `(*Daemon).clusterSecretInternal` so that new ones are generated
when required. We only delete the database entries once, from the member
that received the request.

Signed-off-by: Mark Laing <[email protected]>
This change allows the verifier to perform OIDC discovery when
it is created (on config change). Users will get faster feedback
if their OIDC configuration is incorrect.

Signed-off-by: Mark Laing <[email protected]>
This PR changes the `relyingParty` field to a slice of relying parties
associated with the time at which they became outdated.

In /oidc/callback, we use any available relying party that can decrypt
the state cookie (and therefore complete the flow).

Relying parties are only kept around for 5 minutes.

Signed-off-by: Mark Laing <[email protected]>
Signed-off-by: Mark Laing <[email protected]>
@github-actions github-actions bot added Documentation Documentation needs updating API Changes to the REST API labels Feb 19, 2025
Expect an api.IdentityInfo and optional api.Certificate in request context.

Signed-off-by: Mark Laing <[email protected]>
The authenticate method now contains a handler to be called on successful
authentication for identities that should be present in the database.

It must be called when the authentication method is "cluster" to get the
context of the true caller.

Signed-off-by: Mark Laing <[email protected]>
This is in a few stages:
1. Check if there are any cookies for this URL.
  - If yes, do request.
  - If no, add Authorization: Bearer header. Preemptively
    add the token if present.
2. On failure, if we have an access token, try again with the
   access token using a *cloned* request. Not using a cloned
   request results in sending the invalid session cookie again.
   This is because the cookies aren't deleted from the request,
   they are only deleted from the cookie jar on the client.
3. If trying again fails or we don't have an access token, authenticate
   and try a third time.

Signed-off-by: Mark Laing <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Changes to the REST API Documentation Documentation needs updating
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant