Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ else
exit 1
fi

# The service user the unit below runs as, created before the download and the
# registration, so a host where this fails keeps the agent it already runs and
# spends no registration key. OpenRC has no equivalent and Alpine ships no
# useradd, which is why this is confined to systemd.
if [ "$INIT" = systemd ]; then
id -u monitor-agent >/dev/null 2>&1 ||
useradd --system --no-create-home --shell /usr/sbin/nologin monitor-agent ||
{ echo "cannot create the system user monitor-agent" >&2; exit 1; }
fi

case "$(uname -m)" in
x86_64 | amd64) ARCH=x86_64 ;;
aarch64 | arm64) ARCH=aarch64 ;;
Expand Down Expand Up @@ -236,8 +246,14 @@ EnvironmentFile=$ENV_FILE
ExecStart=$BIN --interval $INTERVAL${INSECURE:+ --insecure}
Restart=always
RestartSec=5
DynamicUser=yes
# A fixed user rather than DynamicUser=: when the mount namespace cannot be
# created, as in an LXC container without nesting, systemd skips ProtectSystem=
# and the other mount sandboxing for a unit with a static User=, but refuses to
# start one with DynamicUser= and exits 226/NAMESPACE. DynamicUser= also implied
# RestrictSUIDSGID=, which is therefore stated below.
User=monitor-agent
NoNewPrivileges=yes
RestrictSUIDSGID=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
Expand Down