Skip to content

πŸ›‘οΈ Sentinel: [LOW] a media-server switch's restore point stays 0600 - #372

Merged
Randomname653 merged 1 commit into
mainfrom
sentinel/rebind-snapshot-mode
Nov 28, 2026
Merged

Randomname653 merged 1 commit into
mainfrom
sentinel/rebind-snapshot-mode

Conversation

@Randomname653

Copy link
Copy Markdown
Owner

What & why

A Plex ⇄ Jellyfin switch (rebind.apply_plan) backs up the whole database to data/backups/rebind-*/curatarr.db before it re-keys anything. This copy is not the stripped nightly backup. It is the restore point, so it keeps every member's users.plex_token and the webhook secret. Its file mode didn't match that:

  • it was written with the process umask: 0644 in a 0755 folder (umask 022, the container default);
  • at the next start, _secure_db_files gave it the backups' mode. With BACKUP_GROUP_READABLE=true that is 0640, an option that is only safe because "the backups carry no tokens" (backup_modes() docstring, CHANGELOG).

Problem (evidence)

Two checks added to existing suites, run on untouched main:

test_rebind:        FAIL  the backup is 0600 in a 0700 folder (it carries the tokens) β€” ('0o100644', '0o40755')
test_backup_perms:  FAIL  ...and so does a switch's restore point: its tokens are not blanked β€” 0o640

Severity LOW: this needs a local account on the host, or membership in the app's group when the option is on, plus a completed switch. With that, the attacker can read members' Plex tokens. Nothing is reachable over the network.

Change

  • rebind.apply_plan: creates the rebind-* folder with mode 0o700 and runs os.chmod(snap, 0o600) after the snapshot passes its check.
  • connection._secure_db_files: database files under backups/rebind-*/ stay 0600. Every other backup still follows backup_modes().
  • The nightly backup, the cache snapshot and the undo/manifest logic are unchanged. The restore point still restores everything, tokens included.

Tests

  • test_rebind 41/1 β†’ 42/0
  • test_backup_perms 13/1 β†’ 14/0
  • test_media_switch and test_backup_retention are unchanged and green.
  • Battery: 356/357. The one failure is test_enrichment_status_perf.py, which fails the same way on untouched main in this sandbox (SQLite 3.45.1 picks another plan) and passes in CI.

Risk & edge cases

  • Windows: chmod only sets the read-only bit and mkdir(mode=) is ignored, so nothing changes there.
  • Folders from earlier switches keep their old folder mode. Their database files get 0600 at the next start.
  • relative_to(backups).parts[0] always has at least one part, because the path is inside backups.

Duplicate check

I searched open and closed PRs for rebind backup, rebind permissions, switch snapshot token and BACKUP_GROUP_READABLE (only #363 and #370 came up, neither covers this), the three agent journals, and git log -300 for rebind/backup changes. Main is at 3d9c8fd.

Checks

  • python tests/run_all.py is green (except the known sandbox perf suite above)
  • Behaviour changes come with a test that would have caught the old behaviour
  • No personal data, tokens or hardcoded local paths in the diff
  • Based on current main

Generated by Claude Code

The switch backs the whole database up under data/backups/rebind-*/
before it re-keys anything. That copy is not the stripped nightly one:
it keeps the members' Plex tokens, so it can restore the install as it
was. It was written with the process umask (0644 in a 0755 folder) and
the start-up pass then gave it the backups' mode, 0640 with
BACKUP_GROUP_READABLE, whose premise is that backups carry no tokens.

Now the folder is made 0700 and the copy chmod'ed 0600, and the start-up
pass keeps files under backups/rebind-* at 0600 like the live database.
The nightly backups keep following backup_modes().

test_rebind +1, test_backup_perms +1 (both fail without the change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014GBDVA6WTizC7z9Sp9S7Eg
@Randomname653 Randomname653 mentioned this pull request Nov 28, 2026
@Randomname653
Randomname653 merged commit 6399501 into main Nov 28, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants