You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(backup): carry live credentials only onto the same account - #5394
Related issue: N/A
Validation tasks: none
Other clients: N/A (no client-visible change)
A full restore could carry a live account's credentials onto a different account that had come to share its id. That covers its API keys, external sign-in links, notification destinations and watch-provider connections. It took two full restores, the second from a backup older than an account made between them, plus an account in that backup that had never been used. This change carries a live credential only onto the same account, and stops a full restore from handing out account ids the live server already used.
A full restore keeps the live server's credentials, less those whose account is not in the restored data or has more authority there (carriedOwners). It found "the account" by id alone. But the restored data brings back the backup's account id sequence, so a new account on the live server can get an id that another account holds in a later backup. The authority comparison refused most such pairs, because a profile only the backup has counts as wider. An account that never had a profile slipped through. The stricter-switch carry matched an account by id and name, so a live "disabled" could land on another account with the same name.
Approach
A live account and a restored one are the same account when both the id and the creation time (users.created_at) agree. carriedOwners keeps only those, so every carried table follows. The condition is one SQL fragment, sameAccount, over a same_accounts table the carry builds, in the new internal/backup/credentials_accounts.go.
The creation time is a timestamptz that only its column default writes, and pg_dump copies it at full precision. The test checks that it comes back unchanged. Accounts made by invitation, sign-in provider or admin all take the default.
The stricter account switches (accountKey) also match on the creation time, written in UTC.
After the carry, the restored account id sequence follows the live server's sequence, so it moves past every id the live server handed out, not only the ids of its surviving accounts. This runs only when the restore carries from a live server of the same deployment. For a backup of another deployment nothing is carried, and the sequence stays as the backup has it.
A live credential whose account is a different account in the backup is dropped and listed with the other dropped credentials. That message now also says "is another account there with the same id".
Validation
New Postgres test, TestFullRestoreCarriesCredentialsOnlyOntoTheSameAccountDB, which runs real backups and full restores in three cases: an account never used in the backup, one with a profile, and a disabled live account that shares the name. On main it fails in 5 of 5 runs: the live API key and sign-in link land on the backup's account, the disabled switch carries to it, and the next account reuses a live id. On this branch it passes in 5 of 5 runs. A second test covers the sequence on its own: after a full restore, the next account takes an id above every one the live server's sequence handed out, including when that account is deleted or the same backup is restored again.
Whole internal/backup package, run alone against a migrated database with pg_dump and pg_restore available: all 164 top-level tests pass and none skip. Three existing carry tests that set up one account on two databases now give both rows the same creation time.
gofmt, go build ./..., go vet, go mod tidy -diff, make lint-changed, make lint-router-recovery, make verify-local-paths and make verify-size-ratchet all pass.
An independent review ran these, in its own checkout:
At the head (532193f42a): both new tests; the sequence case staged by hand, with the newest live account deleted and either no account or one older account left; and an ordinary restore onto the same server with the live session in three time zones, which carried the API key, the sign-in link and the disabled switch each time.
At the commit before the sequence change (a69771ad0f) only, not again at the head: the whole internal/backup package, and a backup taken by the first build that had backups, restored by this build after the live database was migrated forward. That restore carried the key, the link and the disabled switch, with the creation time unchanged to the microsecond.
Also at a69771ad0f: removing the sequence step, the same-account condition in carriedOwners, or the creation time in accountKey each fails a case of the first test.
CI on the head commit is the deciding run for the package, lint and contract checks.
Steps, build and trimmed test output for main and for this branch. Nothing visible changes.
Risks
A live credential whose account is a different account in the backup is now dropped where it used to be carried. The owner sees it in the restore output's "Dropped … whose owner is not in the backup, is another account there with the same id, …" line. That person signs in again and creates the key or link again, on the account the restore actually gives them. On a full restore from the same deployment every account in both databases is the same row, so nothing else changes. An account whose creation time differs between the two would be treated as a different account and lose its carried credentials. Nothing in Silo writes that column after an account is created.
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or how I checked a change nobody sees.
AI Disclosure
Harness: T3 Code (Claude Code)
Tool(s): Claude Code, GitHub CLI
Model(s): claude-opus-5-5
Involvement: Fully AI-generated; human verification is pending before merge
Adversarial review: an independent review ran before merge; what it ran is under Validation
Restrict credential carry to same-account matches and advance restored account ID sequence
Credential carry in PGLoader.CarryCredentials now only carries live credentials onto an account whose restored ID and created_at both match the live account, classified via a same_accounts temporary table (credentials.go, credentials_accounts.go)
Stricter-flag account matching in accountKey now includes the UTC creation timestamp at microsecond precision, not just the username-or-email fallback (credentials_stricter.go)
After a carry, advanceAccountIDs moves the restored account ID sequence past the highest live ID used, while keeping a higher restored position or restored user ID. This prevents new accounts from reusing an ID previously held by a different live account
Adds PostgreSQL tests for full restores where a live account reuses a backup account's ID, plus sequence checks across deleted accounts and repeated restores (carry_same_account_postgres_test.go); both tests are added to db-contracts.txt
Behavioral Change: credentials belonging to a live account that only matches by ID (not creation time) are no longer carried and are reported as dropped; check carriedOwners, sameAccounts, and Dropped field semantics in credentials.go if you depend on prior carry behavior
…account
Two accounts can hold one id once a full restore has moved the account
id sequence back. This test builds that history through real backups and
full restores and checks that the live account's API key, sign-in link
and disabled switch stay off the backup's account, and that a new
account does not take an id the live server used. It fails on main.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A full restore kept a live account's credentials wherever the restored
data had an account with its id. A full restore also puts the account id
sequence back, so an account created on the live server since could hold
an id that another account has in a later backup, and its API keys,
sign-in links and destinations were carried onto that account.
The carry now pairs a live account with a restored one only when the id
and the creation time agree (same_accounts, sameAccount); a live
credential of any other account is dropped and reported. The stricter
account switches match on the creation time as well. After the carry
the account id sequence moves past every id the live server used.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
These tests stand up one account on a live and a restored database. The
carry now also compares when the account was created, so both rows get
one creation time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves sameAccount and the live account reads into credentials_accounts.go,
keeps credentials.go under the size limit, and splits the restore test's
checks into a helper.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.
Reviewing changes in Silo
Include the related issue, expected behavior, and validation steps in the PR description.
For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
Follow this repository's AGENTS.md and CONTRIBUTING.md.
Request another review with @kody start-review in a PR comment.
React with 👍 or 👎 to give feedback on individual suggestions.
Review settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
⚠️ 4 Kody Rule(s) were not evaluated
These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:
Preserve optional store capabilities through production wrappers
Detach mandatory cleanup from request cancellation and bound its lifetime
Preserve durable media identity and share identity-evidence precedence
Bound decoder throughput trades and share direct-play eligibility
No actionable comments were generated in the recent review.
Walkthrough
The restore flow matches live and restored accounts by ID and creation time before carrying credentials. It also advances the restored account ID sequence and adds PostgreSQL coverage for full restores.
Live account data includes IDs and creation times. Account keys include creation time, and a temporary table records live and restored accounts that match on both fields.
Credential carry and ID sequence internal/backup/credentials.go, internal/backup/credentials_accounts.go
Credential carry filters live account IDs through the matching-account set. The dropped-credentials report includes ID collisions with different restored accounts. The restore also advances the account ID sequence.
PostgreSQL tests cover full-restore credential carry, account state, and subsequent ID allocation. Existing test fixtures now use matching creation times, and the new tests are listed as database contracts.
Restores now carry live credentials only onto the same account (matched by ID and creation time) and keep the account ID sequence ahead of IDs already issued. No concrete merge-blocking risk was found. Owners may need to sign in again after a restore that drops credentials.
Security architecture risk: Low · up to 53219
The change reduces the risk of attaching live credentials to the wrong account. A restore can now stop before cutover if its database role cannot read the live account ID sequence. The live database remains in place, but recovery may be delayed until that access is corrected.
Retained concerns
Low · reliability · inferred: Same-deployment full restore now requires the restore role to read the live users sequence directly. A role that passed the prior restore checks and could read account and credential rows, but lacks SELECT on that sequence, can pass preflight and fail only after the backup has been loaded into staging. The failure stops cutover and preserves the live database, but can delay recovery.
Security review details
Security Blast Radius
observed — The ownership change applies to live account-owned credentials carried into the staged replacement database, including API keys and external sign-in links. The restore still withholds the live account-bound carry source when the backup is from another deployment.
Trust Boundaries and Controls
observed — Full restore takes the restore lock and checks for other live database clients before carry and again after closing the live database to new connections. The checks support the requirement to stop live writers; the restore lock does not itself exclude normal database clients.
Hardening Proposals
proposed — Check the live sequence read privilege before loading staging for a same-deployment restore. If access is missing, report the specific permission needed so operators can correct it before retrying without broadening the restore role unnecessarily.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(backup): carry live credentials only onto the same account" matches the main change: the restore now carries live credentials only onto an account whose ID and creation time both match.…
Description check
The description explains the problem (credentials carried onto a different account sharing an ID), the approach (same-account matching by ID and users.created_at, sequence advancement, stricter accoun…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "fix(backup): carry live credentials only onto the same account" matches the main change: the restore now carries live credentials only onto an account whose ID and creation time both match. It is specific and concise, and a teammate scanning history would understand the primary change.
Full details: Description check
Explanation
The description explains the problem (credentials carried onto a different account sharing an ID), the approach (same-account matching by ID and users.created_at, sequence advancement, stricter account key change), validation, and risks. It lines up with the changeset files and objectives.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 51ec33b8-1fe7-4839-9421-2fc3715d2f76
Commits
Reviewing files that changed from the base of the PR and between a69771a and 532193f.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
advanceAccountIDs moved the restored sequence past the highest live
account that still existed. An id handed to an account deleted since, or
the position an earlier restore of the same backup reached, could be
given out again. It now reads the live sequence's position in the live
snapshot and moves the restored sequence past the greatest of that, the
highest live account, the restored accounts and the restored sequence,
also when the live server has no accounts left.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.
Reviewing changes in Silo
Include the related issue, expected behavior, and validation steps in the PR description.
For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
Follow this repository's AGENTS.md and CONTRIBUTING.md.
Request another review with @kody start-review in a PR comment.
React with 👍 or 👎 to give feedback on individual suggestions.
Review settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
⚠️ 4 Kody Rule(s) were not evaluated
These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:
Preserve optional store capabilities through production wrappers
Detach mandatory cleanup from request cancellation and bound its lifetime
Preserve durable media identity and share identity-evidence precedence
Bound decoder throughput trades and share direct-play eligibility
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
bugSomething isn't workinggoPull requests that update go codeimpact: securityAuth, privacy, or permission boundarypriority: P0Fix/merge first: data-loss, security, or widespread breakagesize/L200–499 added + deleted lines (all files); change volume, not priority.
1 participant
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.
Problem
Related issue: N/A
Validation tasks: none
Other clients: N/A (no client-visible change)
A full restore could carry a live account's credentials onto a different account that had come to share its id. That covers its API keys, external sign-in links, notification destinations and watch-provider connections. It took two full restores, the second from a backup older than an account made between them, plus an account in that backup that had never been used. This change carries a live credential only onto the same account, and stops a full restore from handing out account ids the live server already used.
A full restore keeps the live server's credentials, less those whose account is not in the restored data or has more authority there (
carriedOwners). It found "the account" by id alone. But the restored data brings back the backup's account id sequence, so a new account on the live server can get an id that another account holds in a later backup. The authority comparison refused most such pairs, because a profile only the backup has counts as wider. An account that never had a profile slipped through. The stricter-switch carry matched an account by id and name, so a live "disabled" could land on another account with the same name.Approach
users.created_at) agree.carriedOwnerskeeps only those, so every carried table follows. The condition is one SQL fragment,sameAccount, over asame_accountstable the carry builds, in the newinternal/backup/credentials_accounts.go.timestamptzthat only its column default writes, andpg_dumpcopies it at full precision. The test checks that it comes back unchanged. Accounts made by invitation, sign-in provider or admin all take the default.accountKey) also match on the creation time, written in UTC.Validation
TestFullRestoreCarriesCredentialsOnlyOntoTheSameAccountDB, which runs real backups and full restores in three cases: an account never used in the backup, one with a profile, and a disabled live account that shares the name. Onmainit fails in 5 of 5 runs: the live API key and sign-in link land on the backup's account, the disabled switch carries to it, and the next account reuses a live id. On this branch it passes in 5 of 5 runs. A second test covers the sequence on its own: after a full restore, the next account takes an id above every one the live server's sequence handed out, including when that account is deleted or the same backup is restored again.internal/backuppackage, run alone against a migrated database withpg_dumpandpg_restoreavailable: all 164 top-level tests pass and none skip. Three existing carry tests that set up one account on two databases now give both rows the same creation time.gofmt,go build ./...,go vet,go mod tidy -diff,make lint-changed,make lint-router-recovery,make verify-local-pathsandmake verify-size-ratchetall pass.532193f42a): both new tests; the sequence case staged by hand, with the newest live account deleted and either no account or one older account left; and an ordinary restore onto the same server with the live session in three time zones, which carried the API key, the sign-in link and the disabled switch each time.a69771ad0f) only, not again at the head: the wholeinternal/backuppackage, and a backup taken by the first build that had backups, restored by this build after the live database was migrated forward. That restore carried the key, the link and the disabled switch, with the creation time unchanged to the microsecond.a69771ad0f: removing the sequence step, the same-account condition incarriedOwners, or the creation time inaccountKeyeach fails a case of the first test.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-5394/
Steps, build and trimmed test output for
mainand for this branch. Nothing visible changes.Risks
A live credential whose account is a different account in the backup is now dropped where it used to be carried. The owner sees it in the restore output's "Dropped … whose owner is not in the backup, is another account there with the same id, …" line. That person signs in again and creates the key or link again, on the account the restore actually gives them. On a full restore from the same deployment every account in both databases is the same row, so nothing else changes. An account whose creation time differs between the two would be treated as a different account and lose its carried credentials. Nothing in Silo writes that column after an account is created.
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Restrict credential carry to same-account matches and advance restored account ID sequence
PGLoader.CarryCredentialsnow only carries live credentials onto an account whose restored ID andcreated_atboth match the live account, classified via asame_accountstemporary table (credentials.go, credentials_accounts.go)accountKeynow includes the UTC creation timestamp at microsecond precision, not just the username-or-email fallback (credentials_stricter.go)advanceAccountIDsmoves the restored account ID sequence past the highest live ID used, while keeping a higher restored position or restored user ID. This prevents new accounts from reusing an ID previously held by a different live accountcarriedOwners,sameAccounts, andDroppedfield semantics incredentials.goif you depend on prior carry behaviorMacroscope summarized 532193f.