Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

syn2mas: Skip access tokens that don't have a device ID #2317

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/setup/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ Features that are provided to support this include:

- Ability to import existing password hashes from Synapse
- Ability to import existing sessions and devices
- Ability to import existing access tokens
- Ability to import existing access tokens linked to devices (ie not including short-lived admin puppeted access tokens)
- Ability to import existing upstream IdP subject ID mappings
- Provides a compatibility layer for legacy Matrix authentication

If
sandhose marked this conversation as resolved.
Show resolved Hide resolved
There will be tools to help with the migration process itself. But these aren't quite ready yet.

## Preparing for the migration
Expand Down
2 changes: 1 addition & 1 deletion tools/syn2mas/src/advisor.mts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export async function advisor(): Promise<void> {
);
if (accessTokensWithoutDeviceId > 0) {
error(
`Synapse database contains ${accessTokensWithoutDeviceId} access tokens without an associated device_id which aren't supported during migration`,
`Synapse database contains ${accessTokensWithoutDeviceId} access tokens without an associated device_id which will be skipped during migration`,
);
}

Expand Down
13 changes: 4 additions & 9 deletions tools/syn2mas/src/migrate.mts
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,11 @@ export async function migrate(): Promise<void> {
const synapseAccessTokens = await synapse
.select("*")
.from<SAccessToken>("access_tokens")
.where({ user_id: user.name });
.where({ user_id: user.name })
// Skip tokens without devices.
// These can be for example short-lived tokens created by puppeting a user over the Synapse admin API.
.whereNotNull("device_id");
for (const accessToken of synapseAccessTokens) {
if (!accessToken.device_id) {
warningsForUser += 1;
warn(
`Skipping access token ${accessToken.token} for user ${user.name} with no device_id`,
);
continue;
}

const tokenCreatedAt = accessToken.last_validated
? new Date(parseInt(`${accessToken.last_validated}`))
: masUser.created_at;
Expand Down
2 changes: 1 addition & 1 deletion tools/syn2mas/src/types/SAccessToken.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CREATE TABLE access_tokens (
export interface SAccessToken {
id: Id<SAccessToken>;
user_id: SynapseUserId;
device_id?: string;
device_id: string;
token: string;
valid_until_ms?: number;
puppets_user_id?: SynapseUserId;
Expand Down
Loading