大网数据广告活动
服务器运维问答

Why doesn't `systemd-run --user` enforce restrictions such as `ProtectSystem`?

· 52CE 我爱测

If I run this as root, it correctly prints touch: cannot touch '/tmp/test': Read-only file system .: systemd-run --pty --property=ProtectSystem=strict /bin/bash -c "touch /tmp/test" If I run it as myself, in my user's service man…

问题原文

原帖链接 · Graham King · CC BY-SA 3.0

If I run this as root, it correctly prints touch: cannot touch '/tmp/test': Read-only file system.:

systemd-run --pty --property=ProtectSystem=strict /bin/bash -c "touch /tmp/test"

If I run it as myself, in my user's service manager (--user), it no longer protects me, /tmp/test is created:

systemd-run --user --pty --property=ProtectSystem=strict /bin/bash -c "touch /tmp/test"

Why?

I think I'm missing a fundamental understanding of what "service manager" is in systemd. Systemd is going to be a big part of my (our) life, so I'd really like to understand it enough to be able to figure out the above. Is there a doc that explains this?

The context is I'm trying to sandbox an untrusted script (fetched via npm). Running systemd-run as root seems to be heading in the wrong direction, especially as our build system will use this. I could use firejail, but I already have systemd, and am familiar with the various sandboxing properties, so if at all possible I'd like to succeed with systemd-run.

Thanks!

已采纳解答

原帖链接 · Tollef Fog Heen · CC BY-SA 3.0

ProtectSystem and the other Protect* options use read-only bind mounts to enforce the protection. This is something a non-root user can't do, so you can't do this in a (non-root) user session, only in a system session.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-10-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。