feat: implement package and cli tool for repairing oidc links (#26418)

This commit is contained in:
Steven Masley
2026-06-16 12:46:10 -07:00
committed by GitHub
parent b71bc31eec
commit 1d03e63f4f
19 changed files with 1116 additions and 1 deletions
+33
View File
@@ -113,3 +113,36 @@ WHERE
ELSE true
END
;
-- name: CountOIDCLinkedIDsByIssuer :many
-- Groups OIDC user links by their issuer prefix (the part before "||" in
-- linked_id) and returns a count for each. Empty linked_ids are reported
-- with an empty issuer_prefix. Used for analysis before resetting
-- mismatched links.
SELECT
(CASE
WHEN user_links.linked_id = '' THEN ''
ELSE split_part(user_links.linked_id, '||', 1)
END)::text AS issuer_prefix,
COUNT(*)::int AS count
FROM
user_links
INNER JOIN
users ON user_links.user_id = users.id
WHERE
user_links.login_type = 'oidc'
AND users.deleted = false
GROUP BY issuer_prefix;
-- name: UnlinkOIDCUsersByIssuerMismatch :execrows
-- Resets linked_id to '' for OIDC links where the linked_id is non-empty
-- and does not begin with the expected issuer prefix. This allows users to
-- re-authenticate under a new OIDC provider.
UPDATE user_links
SET linked_id = ''
FROM users
WHERE user_links.user_id = users.id
AND user_links.login_type = 'oidc'
AND user_links.linked_id != ''
AND NOT starts_with(user_links.linked_id, @expected_prefix)
AND users.deleted = false;