News for hackers. Stuff that matters.
Re:Show HN: Boulette - Protect you from yourself (even as ro... by dmd on Friday January 10, 2025 @10:53AM (#42656713)
What I really want is a way to get a read only root shell. I do a lot of work on a "traditional" multi-user unix host, where hundreds of scientists share a powerful computer. I often need to become root to look at files. I want to be able to do that without the ability to screw anything up.
Re:Show HN: Boulette - Protect you from yourself (even as ro... by jcalvinowens on Friday January 10, 2025 @11:19AM (#42656993)
If it's Linux, you can bind-mount the rootfs read-only and chroot into it:

    mahler ~ # mkdir /roroot
    mahler ~ # mount -o bind,ro / /roroot
    mahler ~ # chroot /roroot
    mahler / # passwd
    Enter new password: 
    Re-type new password: 
    passwd: Authentication token lock busy
    passwd: password unchanged
Re:Show HN: Boulette - Protect you from yourself (even as ro... by dmd on Friday January 10, 2025 @11:22AM (#42657023)
Oh, that's a good idea.
Re:Show HN: Boulette - Protect you from yourself (even as ro... by jeroenhd on Friday January 10, 2025 @11:23AM (#42657031)
I've used this command to achieve that in the past:

    sudo systemd-nspawn --directory=/ --read-only --ephemeral --volatile=yes
[systemd-nspawn](https://man7.org/linux/man-pages/man1/systemd-nspawn.1.html) would normally be used to run a command inside of a container (a directory), but in some modes you can specify the system root as the "container" path.

I believe this specific set of options relies on (BTRFS) file system snapshots for performance. It's possible that you can get it to work on non-BTRFS systems by providing another combination of command line variables, but the default setting is to copy the file system tree to a temporary path.

You can also pass parameters like --volatile=state (so you can write to /var) and --volatile=overlay (so you can "write" to state, but all changes are discarded after the container exits). --volatile=state is useful for extracting data from a temporary read-only system, --volatile=overlay is useful for running tools that crash if they run on a read-only filesystem.

Re:Show HN: Boulette - Protect you from yourself (even as ro... by ronsor on Friday January 10, 2025 @11:27AM (#42657095)
> I believe this specific set of options relies on (BTRFS) file system snapshots for performance. It's possible that you can get it to work on non-BTRFS systems by providing another combination of command line variables, but the default setting is to copy the file system tree to a temporary path.

You can use overlayfs + chroot.

Re:Show HN: Boulette - Protect you from yourself (even as ro... by ape4 on Friday January 10, 2025 @11:24AM (#42657055)
--read-only would be a nice option for `run0`
Re:Show HN: Boulette - Protect you from yourself (even as ro... by makemyworkforme on Friday January 10, 2025 @11:02AM (#42656805)
Can you create a group and set a sticky bit for ACLs for your root for the filesystem with read permissions for that group? That way all files created under the filesystem root will have read permissions for that user, but you cannot modify anything.
Re:Show HN: Boulette - Protect you from yourself (even as ro... by dmd on Friday January 10, 2025 @11:12AM (#42656925)
Not really, there are tons of different filesystems mounted from all over the place. It's a mess.
Re:Show HN: Boulette - Protect you from yourself (even as ro... by spease on Friday January 10, 2025 @11:14AM (#42656935)
Can you create a second read-only mount of root?

Maybe this would help:

https://serverfault.com/questions/136515/read-only-bind-moun...

Re:Show HN: Boulette - Protect you from yourself (even as ro... by dmd on Friday January 10, 2025 @11:17AM (#42656976)
But the point is I want my 'root' session to have no ability to do anything destructive.
Re:Show HN: Boulette - Protect you from yourself (even as ro... by dmd on Friday January 10, 2025 @11:22AM (#42657030)
Though as someone just suggested in another thread, chrooting into such a thing isn't a terrible idea. It certainly limits the damage I can do.
Re:Show HN: Boulette - Protect you from yourself (even as ro... by 6r17 on Friday January 10, 2025 @11:26AM (#42657075)
MicroOS has something in that spirit I think ? Maybe I'm wrong tough, don't even know if MicroOS is usable in host
Re:Show HN: Boulette - Protect you from yourself (even as ro... by rkeene2 on Friday January 10, 2025 @02:43PM (#42659320)
I've used seccomp in the past to create a read-only root.

I created a seccomp DSL to make this kind of stuff easier [0] (an example of dropping network access is at [1])

[0] https://chiselapp.com/user/rkeene/repository/bash-drop-netwo...

[1] https://chiselapp.com/user/rkeene/repository/bash-drop-netwo...