Create Debian package for beszel-agent (#497)

* Add Debian package to build

Signed-off-by: Daniel Lo Nigro <git@d.sb>

* Fix Lintian issues

Signed-off-by: Daniel Lo Nigro <git@d.sb>

* - Add prerm script to stop and disable service
- Add security/sandboxing options to systemd unit

Signed-off-by: Daniel Lo Nigro <git@d.sb>

---------

Signed-off-by: Daniel Lo Nigro <git@d.sb>
This commit is contained in:
Daniel Lo Nigro
2025-02-03 16:08:01 -08:00
committed by GitHub
parent 5a8e8c1512
commit e689f547ef
9 changed files with 172 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
[Unit]
Description=Beszel Agent Service
Wants=network-online.target
After=network-online.target
[Service]
Environment="PORT=45876"
# Port number can be overridden in beszel-agent.conf if needed
EnvironmentFile=/etc/beszel-agent.conf
ExecStart=/usr/bin/beszel-agent
User=beszel
Restart=on-failure
StateDirectory=beszel-agent
# Security/sandboxing settings
KeyringMode=private
LockPersonality=yes
NoNewPrivileges=yes
PrivateTmp=yes
ProtectClock=yes
ProtectHome=read-only
ProtectHostname=yes
ProtectKernel=yes
ProtectKernelLogs=yes
ProtectKernelTunables=yes
ProtectSystem=strict
RemoveIPC=yes
RestrictSUIDSGID=true
SystemCallArchitectures=native
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
. /usr/share/debconf/confmodule
db_version 2.0
db_input high beszel-agent/key || true
db_go

View File

@@ -0,0 +1,8 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Beszel
Upstream-Contact: henrygd <hank@henrygd.me>
Source: https://beszel.dev/
Files: *
Copyright: 2024 henrygd
License: MIT

View File

@@ -0,0 +1,11 @@
# No changelog in the repo at the moment. This would be good to fix
beszel-agent: no-changelog
# Current unable to fix these due to Goreleaser bug
# https://github.com/goreleaser/goreleaser/issues/5487
beszel-agent: no-debconf-config
beszel-agent: postinst-uses-db-input
# Needs to be fixed in Beszel build
beszel-agent: hardening-no-pie
beszel-agent: hardening-no-relro
# Maybe one day
beszel-agent: no-manual-page

View File

@@ -0,0 +1,49 @@
#!/bin/sh
set -e
[ "$1" = "configure" ] || exit 0
CONFIG_FILE=/etc/beszel-agent.conf
SERVICE=beszel-agent
SERVICE_USER=beszel
. /usr/share/debconf/confmodule
# This would normally be in the config control file, however this is currently
# broken in goreleaser. Temporarily do it here.
# https://github.com/goreleaser/goreleaser/issues/5487
db_version 2.0
db_input high beszel-agent/key || true
db_go
# Create group and user
if ! getent group "$SERVICE_USER" >/dev/null; then
echo "Creating $SERVICE_USER group"
addgroup --quiet --system "$SERVICE_USER"
fi
if ! getent passwd "$SERVICE_USER" >/dev/null; then
echo "Creating $SERVICE_USER user"
adduser --quiet --system "$SERVICE_USER" \
--ingroup "$SERVICE_USER" \
--no-create-home \
--home /nonexistent \
--gecos "System user for $SERVICE"
fi
# Create config file if it doesn't already exist
if [ ! -f "$CONFIG_FILE" ]; then
touch "$CONFIG_FILE"
chmod 0600 "$CONFIG_FILE"
chown "$SERVICE_USER":"$SERVICE_USER" "$CONFIG_FILE"
fi;
# Only add key to config if it's not already present
if ! grep -q "^KEY=" "$CONFIG_FILE"; then
db_get beszel-agent/key
echo "KEY=$RET" > "$CONFIG_FILE"
fi;
deb-systemd-helper enable "$SERVICE".service
systemctl daemon-reload
deb-systemd-invoke start "$SERVICE".service || echo "could not start $SERVICE.service!"

View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
if [ "$1" = "purge" ]; then
. /usr/share/debconf/confmodule
db_purge
rm /etc/beszel-agent.conf
fi

View File

@@ -0,0 +1,9 @@
#!/bin/sh
set -e
SERVICE=beszel-agent
deb-systemd-invoke stop "$SERVICE".service
if [ "$1" = "remove" ]; then
deb-systemd-helper purge "$SERVICE".service
fi

View File

@@ -0,0 +1,5 @@
Template: beszel-agent/key
Type: string
Description: SSH public key provided by beszel hub:
If you leave this blank, you will need to configure it in
/etc/beszel-agent.conf before starting Beszel.