fix(apiserver): refuse an identity purge that cannot finish - #5000
Open
rasty94 wants to merge 1 commit into
Open
fix(apiserver): refuse an identity purge that cannot finish#5000rasty94 wants to merge 1 commit into
rasty94 wants to merge 1 commit into
Conversation
DeleteUserIdentity cascades over several stores, and dex has no transaction across them. The password record is deleted near the end, and a password that comes from the config file cannot be deleted through the API at all. So purging a static user ends every session, revokes every refresh token, and then fails at the password step -- leaving the account standing, the user signed out everywhere, and no way to finish from the API. Check the one step that fails for a predictable reason before destroying anything, and refuse with a message that says what to do instead. Asking the question needs the static wrapper to answer it, which is what IsStaticPassword is for. The three static wrappers embed Storage as an interface, so they do not promote each other's methods and the answer would otherwise depend on which one happens to be outermost; each forwards the question inwards, and the test stacks them the way serve.go does. Signed-off-by: rasty94 <ajcomputerses@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
DeleteUserIdentitycan destroy half a user's data and then fail, with no way to finish the job from the API. This checks the step that predictably fails before anything is deleted.What this PR does / why we need it
The purge cascades over several stores — auth sessions, refresh tokens, offline sessions, the password record, the identity — and dex has no transaction across them. The password record is deleted near the end, and a password that comes from the config file cannot be deleted through the API at all.
So purging a static user today:
purge password: static passwords: read-only cannot delete password.The caller gets an error, but the account is still there, the user is signed out everywhere, and there is nothing they can do from the API to complete or undo it. For an endpoint whose documented purpose is a GDPR erasure, "half done and not repeatable" is the worst outcome available.
This checks first and refuses:
Special notes for your reviewer
Asking the question needs the static wrapper to answer it, hence
IsStaticPasswordonstaticPasswordsStorage. It is a type assertion in the apiserver rather than a method onstorage.Storage, because only the purge needs to ask, and only in order to refuse.The subtle part is the forwarding. The three static wrappers embed
Storageas an interface, so they do not promote each other's methods: a check that only works when the password wrapper is outermost passes its test and does nothing in a real dex, whereserve.gostacks clients → passwords → connectors. Each wrapper forwards the question inwards, and the test stacks them the same wayserve.godoes.The test asserts the session and the identity survive before it asserts the wording, so reverting the fix fails it on the defect rather than on the message.
Reordering the cascade to attempt the password first was the smaller diff, but it moves the partial state rather than removing it: a non-static user would then lose their password and keep their sessions, which is worse than the reverse.
storage/sqldoes not build on master right now (testing.(*B).Output requires go1.25, inpostgres_test.go); unrelated to this change.