-
Notifications
You must be signed in to change notification settings - Fork 325
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
Hash SCIM tokens #1240
Hash SCIM tokens #1240
Conversation
75ebe88
to
f374253
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 (some comments)
parser = string "sha512:" *> (ScimTokenHash <$> parser) | ||
|
||
instance ToByteString ScimTokenHash where | ||
builder (ScimTokenHash t) = BB.fromByteString "sha512:" <> builder t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a roundtrip test, like these?
(I admit that there are more gaps in the roundtrip test coverage, but we might as well start now to patch them...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(we can also do that in a separate PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added roundtrip test
services/spar/src/Spar/Data.hs
Outdated
where | ||
sel :: PrepQuery R (Identity ScimToken) ScimTokenRow | ||
let tokenHash = hashScimToken token | ||
mbRow <- retry x1 . query1 sel $ params Quorum (tokenHash, token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can return both hashed and unhashed in any order, if both are still in the DB (race condition).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found two things (both harmless). Integration tests pass locally.
That was wrong: the stray delete query risks a race condition where a token that should be available is already gone in unhashed from and not there yet in hashed form. Not very likely to materialize, but please fix it anyway. |
Co-authored-by: fisx <mf@zerobuzz.net>
Co-authored-by: fisx <mf@zerobuzz.net>
|
Currently SCIM tokens are persisted in plain text. Fixes https://github.com/zinfra/backend-issues/issues/1652
With this PR new SCIM tokens will only have their SHA512 hashes persisted.
Existing tokens (still persisted in plaintext) will remain valid, but will be re-persisted with their hash on every validation.
The columns
team_provisioning_by_token.token_
,team_provisioning_by_team.token_
which contained the plaintext token will be repurposed and also contain the hash value.To distinguish plaintext from hash values the hash values are prefixed with
sha512:
. In Haskell these two types are represented as the sum typeThis way all plaintext tokens which are regularly used should be converted to their hash. The remaining tokens should be converted via batch process or invalidated.