运行 systemd 中没有 CAP_NET_RAW 的人(或动态用户)

Running nobody (or dynamic user) with CAP_NET_RAW in systemd

我想 运行 服务具有 cap_net_raw 功能,但不与文件系统 and/or 其他进程进行任何交互。我的程序将使用原始套接字和普通套接字(对于 API),stdout/err 用于日志记录,仅此而已。

我想编写 systemd.service 文件来执行此操作,但我无法为 DynamicUserUserCapabilityBoundingSet.[=17 生成正确的组合=]

我的(非工作)单位是这样的:

[Unit]
Description=my daemon (%I)
ConditionFileNotEmpty=/etc/daemon/%i.conf
Wants=network-online.target
BindsTo=daemon.target

[Service]
Type=simple
WorkingDirectory=/etc/daemon
EnvironmentFile=/etc/daemon/%i.conf
ExecStart=/usr/bin/daemon ${OPTIONS}
CapabilityBoundingSet=CAP_NET_RAW
ProtectSystem=true
ProtectHome=true
RestartSec=5s
Restart=on-failure
User=daemon-%i
Group=nobody
DynamicUser=true
[Install]
WantedBy=daemon.target

如何配置动态用户 'nobody' 和 CAP_NET_RAW

您还需要:

AmbientCapabilities=CAP_NET_RAW

this question about the difference between AmbientCapabilities and CapabilityBoundingSet, as well as the documentation