Skip to content

[SSO] Thread JWT groups and add sync diff logic#36308

Open
mtabebe wants to merge 1 commit intoMaterializeInc:mainfrom
mtabebe:ma/sso/jwt-groups
Open

[SSO] Thread JWT groups and add sync diff logic#36308
mtabebe wants to merge 1 commit intoMaterializeInc:mainfrom
mtabebe:ma/sso/jwt-groups

Conversation

@mtabebe
Copy link
Copy Markdown
Contributor

@mtabebe mtabebe commented Apr 29, 2026

Thread JWT group claims through the auth pipeline and add the core sync diff function:

  • Add groups: Option<Vec> to User, SessionConfig, ValidatedClaims, and AuthedUser so JWT group claims extracted during OIDC auth are available in handle_startup_inner. OIDC paths extract groups from ValidatedClaims; all non-OIDC paths pass groups: None.

  • Add sync_jwt_groups_diff function that computes Op::GrantRole and Op::RevokeRole operations by diffing current role memberships against JWT group claims. Only manages memberships granted by MZ_JWT_SYNC_ROLE_ID — manually-granted roles are never touched.

No behavioral change yet as nothing calls the sync function.

SQL-179 and SQL-180

Thread JWT group claims through the auth pipeline and add the core
sync diff function:

- Add groups: Option<Vec<String>> to User, SessionConfig,
ValidatedClaims, and AuthedUser so JWT group claims extracted during
OIDC auth are available in handle_startup_inner. OIDC paths extract
groups from ValidatedClaims; all non-OIDC paths pass groups: None.

- Add sync_jwt_groups_diff function that computes Op::GrantRole
and Op::RevokeRole operations by diffing current role memberships
against JWT group claims. Only manages memberships granted by
MZ_JWT_SYNC_ROLE_ID — manually-granted roles are never touched.

No behavioral change yet as nothing calls the sync function.
@mtabebe mtabebe force-pushed the ma/sso/jwt-groups branch from 2d9e694 to d312c26 Compare April 29, 2026 01:23
@mtabebe mtabebe requested a review from SangJunBak April 29, 2026 10:15
@mtabebe mtabebe marked this pull request as ready for review April 29, 2026 10:15
@mtabebe mtabebe requested a review from a team as a code owner April 29, 2026 10:15
/// - `member_id`: The user's role ID.
/// - `current_membership`: The user's current `RoleMembership.map`
/// (role_id → grantor_id).
/// - `target_role_ids`: Role IDs resolved from the JWT group names.
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.

Might be worth adding target_role_ids will be lowercase

pub fn compute_group_sync_diff(
member_id: RoleId,
current_membership: &BTreeMap<RoleId, RoleId>,
target_role_ids: &BTreeSet<RoleId>,
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.

One part that's confusing to me is how we'll get from String to RoleId.

Copy link
Copy Markdown
Contributor

@SangJunBak SangJunBak Apr 30, 2026

Choose a reason for hiding this comment

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

Like will we just have to search the current membership for roles that match the strings in groups outside of this function?

Copy link
Copy Markdown
Contributor

@SangJunBak SangJunBak left a comment

Choose a reason for hiding this comment

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

I did have a comment but I think the function and code makes sense!

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.

2 participants