Skip to content

ProtectHome=true does not work in systemd --user mode #25014

@Hi-Angel

Description

@Hi-Angel

systemd version the issue has been seen with

250

Used distribution

No response

Linux kernel version used

5.19.15-lqx1.0.fc36.x86_64

CPU architectures issue was seen on

x86_64

Component

systemd

Expected behaviour you didn't see

Either permission denied errors or lack of content in the output for /home and /run/user

Unexpected behaviour you saw

ls shows content of /home and /run/user

Steps to reproduce the problem

ProtectHome option is described by manual as:

Takes a boolean argument[…]. If true, the directories /home/, /root, and /run/user are made inaccessible and empty for processes invoked by this unit.[…]

For testing purposes I needed to run some graphical app but deny it any possible access to my HOME dir (which may be used together with setting HOME to an arbitrary dir, but is orthogonal to that). So I created a service that makes use of ProtectHome=true which I expected to do exactly that. To my dismay, the option simply doesn't work.

Steps to reproduce In terms of terminal commands:

$ cat ~/.config/systemd/user/test.service
[Unit]
Description=Test unit

[Service]
Type=oneshot
ExecStart=/usr/bin/ls /home/ /run/user/
ProtectHome=true

[Install]
WantedBy=multi-user.target
$ systemctl --user daemon-reload
$ systemctl --user start test
$ systemctl --user status test
○ test.service - Test unit
     Loaded: loaded (/home/konstantin/.config/systemd/user/test.service; disabled; vendor preset: disabled)
     Active: inactive (dead)

окт 15 13:56:55 fedora systemd[3399]: Starting test.service - Test unit...
окт 15 13:56:55 fedora ls[21097]: /home/:
окт 15 13:56:55 fedora ls[21097]: konstantin
окт 15 13:56:55 fedora ls[21097]: /run/user/:
окт 15 13:56:55 fedora ls[21097]: 0
окт 15 13:56:55 fedora ls[21097]: 1000
окт 15 13:56:55 fedora systemd[3399]: Finished test.service - Test unit.

Additional program output to the terminal or log subsystem illustrating the issue

окт 15 13:56:55 fedora systemd[3399]: Starting test.service - Test unit...
окт 15 13:56:55 fedora ls[21097]: /home/:
окт 15 13:56:55 fedora ls[21097]: konstantin
окт 15 13:56:55 fedora ls[21097]: /run/user/:
окт 15 13:56:55 fedora ls[21097]: 0
окт 15 13:56:55 fedora ls[21097]: 1000
окт 15 13:56:55 fedora systemd[3399]: Finished test.service - Test unit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions