Files
Amir Zarrinkafsh 7edaaf3b56 fix(oidc): handle concurrent creation of the user opaque identifier (#13296)
`GenerateOpaqueUserID` loaded the opaque identifier for a user and
sector and inserted a new one when none existed, with nothing guarding
the gap between the two. Two first time authorizations for the same user
and sector which arrived together both found no identifier, and the
second insert failed on the unique constraint over `service`,
`sector_id` and `username`, which ended its authorization with
`ErrSubjectCouldNotLookup`. The `OIDCConformance` suite hits this
whenever its plans authorize `john` in the same instant, which shows up
as `duplicate key value violates unique constraint
"user_opaque_identifier_service_sector_id_username_key"` in the
PostgreSQL log.

When the insert fails on a unique constraint the identifier which won is
now loaded and returned, so every request resolves the same subject.
`storage.IsUniqueConstraintViolation` recognizes the violation on
SQLite, MySQL and PostgreSQL.

Signed-off-by: Amir Zarrinkafsh <3339418+nightah@users.noreply.github.com>
2026-09-29 03:48:52 +00:00
..