Skip to content

Harden Steam sharing; bees for btrfs gaming machines, paused while gaming - #37

Open
andrewthomaslee wants to merge 1 commit into
mainfrom
steam-sharing-hardening
Open

andrewthomaslee wants to merge 1 commit into
mainfrom
steam-sharing-hardening

Conversation

@andrewthomaslee

Copy link
Copy Markdown
Member

Summary

Hardens Steam sharing (root-run scripts in users' folders), moves bees into the gaming module for every btrfs gaming machine, and keeps bees out of a running game's way.

 steam-copy-game (sudo)
-  runs as root, unsandboxed
+  re-execs as a transient unit: ProtectSystem=strict, writes only /home + dirOf libraryRoot,
+  caps CHOWN FOWNER DAC_OVERRIDE DAC_READ_SEARCH SETUID SETGID
   read installdir from the source user's appmanifest
+  refuse an installdir with "/" or "." / ".." (was: ../../etc copied/removed as root)
   place_copy
     root: mktemp + cp --reflink + chown
-    root: rm -rf dest; mv copy dest
+    receiving user (setpriv): rm -rf dest; mv copy dest
+  skip while steam-config-patcher@<to> runs (both write config.vdf)

 steam-shader-sync (timer)
+  same sandbox as a unit
-  libraries = every path in libraryfolders.vdf (user-editable)
+  libraries = Steam folder + <libraryRoot>/<user> only
-  biggest cache wins
+  biggest cache of the same buildid wins (no stale cache after an update)

 _steam-shader-record.py
+  vdf.VDFDict: duplicate keys survive; put()/drop() replace instead of append
+  receiver's previous config.vdf kept as config.vdf.steam-sharing.bak
 hostSpec.system.gaming
   steamSharing
+    libraryRoot = "/srv/steam/users"   # tmpfiles: <root>/<user> 0700
+  dedup
+    enable = steamSharing.enable && "/" is btrfs   # btrfsDedup.filesystems.root = fileSystems."/".device
+    pauseWhilePlaying = true   # systemctl freeze beesd@* while `reaper SteamLaunch AppId=` runs
 hostSpec.system.btrfsDedup.filesystems.<name>
+  memoryHighMB = 3072   # MemoryHigh: bees reclaims its own page cache
+services.btrfs.autoScrub.enable = mkDefault (any btrfs in fileSystems)

Docs: new Gaming page (documentation/docs/gaming.md, in the nav), README consumer note.

Evidence

  • nix flake check (incl. eval-all-enabled with gaming.dedup.enable): passes.
  • vm-test steam-sharing: passes, with new subtests:
    • a game folder that is a path is refused: manifest installdir = ../../../../../../../etc/secret → steam-copy-game --force fails, /etc/secret/key untouched, nothing in bob's library.
    • libraries outside libraryRoot are ignored: game listed only in /mnt/steam/elsewhere → "has no installed game 700".
    • steam-copy-game waits for steam-config-patcher, shader sync only shares within one build of a game, sandbox (ProtectSystem=strict) and tmpfiles-made libraries (<user>:700).
  • vm-test btrfs-dedup (local KVM): passes. New subtests: MemoryHigh = 3 GiB, btrfs-scrub@mnt-dedup.timer enabled, bees is frozen while a Steam game runs (log: a game is running: beesd@root.service paused … resumed 10 s after the fake reaper SteamLaunch AppId=100 exits), stopping the pause service never leaves bees frozen.
  • Heads-up, not from this PR: built on euc-hel-0, the existing dedup subtest timed out (bees hashes both files but finds no match within 600 s) both on this branch and with the old test file; locally the same subtest passes in ~32 s on this branch and on main. Run this test locally.

Before (live kamrui-h1): bees cgroup 24 GB page cache, zram swapping 1.5 GB; NVMe scheduler none ignores bees' idle I/O class.

Merge Danger

Door: two-way

Revert restores the old scripts and options. libraryRoot default /srv/steam/users makes tmpfiles create that folder on every steamSharing machine; existing libraries elsewhere (kamrui-h1's /mnt/steam/users/<user>) stop being used by the sharing tools until the machine moves to /srv/steam (external-systems/home, draft PR) or sets libraryRoot.

Blast Radius: gaming-machines

bees turns on by default for nixos too (btrfs root, gaming tag): 512 MB locked hash table, 3 GB memory ceiling, monthly scrub. Opt out per machine with hostSpec.system.gaming.dedup.enable = false.

Merge order: this first; the external-systems/home PR (draft) bumps modules after it merges. Do not merge until the owner approves.

🤖 Generated with Claude Code

…ming

steam-copy-game and steam-shader-sync run as root over folders users
control. Validate a game's installdir (a "../" path made root copy and,
with --force, remove system paths), use only the Steam folder and
<libraryRoot>/<user> as libraries, run both in a ProtectSystem=strict
sandbox, and let the receiving user do every replace and delete. Skip
users whose steam-config-patcher is writing config.vdf, keep duplicate
keys and a backup when rewriting it, and only share a shader cache
within one build of a game.

gaming.dedup turns bees on for the root filesystem of btrfs gaming
machines and freezes it while a Steam game runs: the idle I/O class does
nothing on NVMe ("none" scheduler). btrfs-dedup caps bees' memory with
MemoryHigh (its page cache pushed games into swap) and turns on a
monthly scrub. steamSharing.libraryRoot (default /srv/steam/users)
gets per-user libraries from tmpfiles. Docs: a Gaming page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant