←back to thread

Against /Tmp

(dotat.at)
140 points todsacerdoti | 2 comments | | HN request time: 0s | source
Show context
jauntywundrkind ◴[] No.41913895[source]
Oh man, this sort of thing is part of what I love love love about systemd. It bakes in so many great isolation/sandboxing/privacy measures for units! From the article:

> There should be per-user temporary directories. In fact, on modern systems there are per-user temporary directories! But this solution came several decades too late.

> If you have per-user $TMPDIR then temporary filenames can safely be created using the simple mechanisms described in the mktemp(1) rationale or used by the old deprecated C functions. There’s no need to defend against an attacker who doesn’t have sufficient access to mount an attack! There’s no need for sticky directories because there aren’t any world-writable directories.

May I introduce you to PrivateTMP= ?

> PrivateTmp=¶

> Takes a boolean argument. If true, sets up a new file system namespace for the executed processes and mounts private /tmp/ and /var/tmp/ directories inside it that are not shared by processes outside of the namespace

https://www.freedesktop.org/software/systemd/man/latest/syst...

Notably you don't even need to change how programs work (no $TMPDIR necessary)! It creates a filesystem namespace for your process, such-that you see the normal fs, but with your own /tmp ! That way your program behaves regularly/as convention goes everywhere else, and existing programs you run can also benefit without re-writing!

I cannot emphasize enough how many excellent well integrated kick ass security features systemd gives you totally for free. DynamicUser= turns on PrivateTmp= by default and is an easy way to insure isolation, to prevent needing to hand-code & safely manage uid/gids yourself; I'd start there if you can.

There's so so so many great isolation features in this man page.

replies(2): >>41914119 #>>41915241 #
1. GoblinSlayer ◴[] No.41915241[source]
Happy debugging, yeah. FastCGI examples usually create sockets in /tmp, but nginx doesn't see them, go figure.
replies(1): >>41917272 #
2. jauntywundrkind ◴[] No.41917272[source]
A more canonical means would be to use the runtime directory. Explicitly setting a Runtime directory= for each would be appropriate.

I get your point. Yeah as a newbie flipping on random options listed under "sandbox" may be bad for you. But this hardly seems like a good dig against a well integrated unit process that has lots on tap to do the job very very well, in a succint manner.