Store client credentials in a new system table#2983
Merged
Conversation
gefjon
reviewed
Jul 25, 2025
Contributor
gefjon
left a comment
There was a problem hiding this comment.
I am curious what the bug you alluded to during standup is.
gefjon
reviewed
Aug 6, 2025
Contributor
gefjon
left a comment
There was a problem hiding this comment.
This all looks reasonable at this stage.
gefjon
approved these changes
Sep 18, 2025
Contributor
gefjon
left a comment
There was a problem hiding this comment.
Please remove the commented-out code. Otherwise this looks good to me. I assume the Unity test suite failures are unrelated, but please verify that.
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.
Description of Changes
This adds a new system table to store the jwt payloads of connected clients. I'm planning to use this system table to expose client claims to modules in subsequent PRs.
The new table is called
st_connection_credentials. It is a private system table which stores a mapping fromconnection_idtojwt_payload. Note that a jwt payload is a json representation of the clients claims, not a fully signed token.The times when we need to insert and delete these rows closely mirrors that of the existing
st_clienttable, with 1.5 exceptions:st_clientuntil after theOnConnectreducer ran (even though it was in the same transaction). We wantst_connection_credentialsto be populated before calling the reducer, so that the reducer can use it get the credentials, so I made a change to insert tost_clientandst_connection_credentialsbefore calling the reducer.This also enforces uniqueness of connection ids. A duplicate connection id will now make the on-connect reducer fail (since it will violate uniqueness when trying to insert to
st_connection_credentials).Expected complexity level and risk
2.5
Adding a system table is a bit risky. This is almost rollback safe, with one annoying case that is worth calling out:
If a database is created with this system table, opening it with an older version of spacetimedb will only work if there is a snapshot of the database. If we try to load a table without a snapshot, replaying will fail on the first row for that table. This is because we don't write the table schema information to the commit log when creating a database. In practice, this is unlikely to be an issue, because new databases asynchronously trigger a snapshot immediately after creation.
Migrating existing databases will be fine. On startup this will detect that there is a missing system table, and add it in a way that writes it to the commit log. Since it is in the commit log, we can open the database with an older version and still understand the data for that table.
Testing
There are unit tests that cover opening a database created with an older version (which doesn't have this table).
I manually tested opening a migrated database with an older version of spacetimedb.