1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2026-01-03 17:02:28 +03:00

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

These can't be migrated. They are likely enirely valid tokens created by puppeting a user via the Synapse admin api. Treating them as fatal errors will make it impossible to migrate any host that has ever used this admin API feature.
This commit is contained in:
Jason Robinson
2024-02-06 16:00:56 +02:00
committed by Quentin Gliech
parent 114c5fc33f
commit ff815c0333
3 changed files with 6 additions and 11 deletions

View File

@@ -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`,
);
}

View File

@@ -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;

View File

@@ -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;