update
This commit is contained in:
@@ -9,6 +9,8 @@ readonly CONFIG_DIR="/etc/vps-agent"
|
||||
readonly CREDENTIAL_DIR="${CONFIG_DIR}/credentials"
|
||||
readonly STATE_DIR="/var/lib/vps-agent"
|
||||
readonly UNIT="/etc/systemd/system/vps-agent.service"
|
||||
readonly HELPER_SOCKET_UNIT="/etc/systemd/system/vps-agent-helper.socket"
|
||||
readonly HELPER_SERVICE_UNIT="/etc/systemd/system/vps-agent-helper@.service"
|
||||
readonly DEFAULT_RELEASES="https://gitea.hyperdog.dev/dizyaka/vps-control/releases"
|
||||
|
||||
VERSION="latest"
|
||||
@@ -137,6 +139,60 @@ RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
install -o root -g root -m 0644 /dev/null "$HELPER_SOCKET_UNIT"
|
||||
tee "$HELPER_SOCKET_UNIT" >/dev/null <<'EOF'
|
||||
[Unit]
|
||||
Description=VPS Control privileged helper socket
|
||||
[Socket]
|
||||
ListenStream=/run/vps-agent-helper/control.sock
|
||||
Accept=yes
|
||||
MaxConnections=1
|
||||
SocketUser=vps-agent
|
||||
SocketGroup=vps-agent
|
||||
SocketMode=0600
|
||||
DirectoryMode=0750
|
||||
RemoveOnStop=yes
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
EOF
|
||||
install -o root -g root -m 0644 /dev/null "$HELPER_SERVICE_UNIT"
|
||||
tee "$HELPER_SERVICE_UNIT" >/dev/null <<'EOF'
|
||||
[Unit]
|
||||
Description=VPS Control privileged helper request
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/vps-agent --privileged-helper --config /etc/vps-agent/config.toml
|
||||
StandardInput=socket
|
||||
StandardOutput=socket
|
||||
StandardError=journal
|
||||
User=root
|
||||
Group=root
|
||||
TimeoutStartSec=330
|
||||
UMask=0077
|
||||
PrivateTmp=true
|
||||
ProtectHome=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelLogs=true
|
||||
ProtectControlGroups=true
|
||||
ProtectClock=true
|
||||
ProtectHostname=true
|
||||
RestrictSUIDSGID=true
|
||||
LockPersonality=true
|
||||
RestrictRealtime=true
|
||||
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
|
||||
EOF
|
||||
}
|
||||
|
||||
install_helper_units() {
|
||||
local source_dir="$(cd "$(dirname "$0")" && pwd)/../agent/packaging"
|
||||
if [[ -f "$source_dir/vps-agent-helper.socket" && -f "$source_dir/vps-agent-helper@.service" ]]; then
|
||||
install -o root -g root -m 0644 "$source_dir/vps-agent-helper.socket" "$HELPER_SOCKET_UNIT"
|
||||
install -o root -g root -m 0644 "$source_dir/vps-agent-helper@.service" "$HELPER_SERVICE_UNIT"
|
||||
elif [[ ! -f "$HELPER_SOCKET_UNIT" || ! -f "$HELPER_SERVICE_UNIT" ]]; then
|
||||
die "helper unit templates are missing; use the packaged installer or install the units manually"
|
||||
fi
|
||||
}
|
||||
|
||||
create_config() {
|
||||
@@ -158,10 +214,21 @@ burst = 20.0
|
||||
command_timeout_seconds = 4
|
||||
[services]
|
||||
allowed = []
|
||||
inventory_limit = 512
|
||||
install_enabled = false
|
||||
install_timeout_seconds = 300
|
||||
packages = {}
|
||||
[firewall]
|
||||
management_enabled = false
|
||||
persistence_enabled = true
|
||||
allowed_interfaces = []
|
||||
allowed_sources = []
|
||||
allowed_ports = []
|
||||
rollback_timeout_seconds = 60
|
||||
max_snapshots = 5
|
||||
[fail2ban]
|
||||
management_enabled = false
|
||||
allowed_jails = ["sshd"]
|
||||
[logging]
|
||||
level = "info"
|
||||
[telemetry]
|
||||
@@ -223,8 +290,9 @@ do_install() {
|
||||
create_config
|
||||
create_token
|
||||
install_unit
|
||||
install_helper_units
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now vps-agent.service
|
||||
systemctl enable --now vps-agent-helper.socket vps-agent.service
|
||||
wait_healthy || die "agent failed to become healthy"
|
||||
systemctl status --no-pager vps-agent.service
|
||||
}
|
||||
@@ -239,6 +307,10 @@ do_update() {
|
||||
install -o root -g root -m 0755 "$downloaded" "$staged"
|
||||
install -o root -g root -m 0755 "$BINARY" "$PREVIOUS"
|
||||
mv -f -- "$staged" "$BINARY"
|
||||
install_unit
|
||||
install_helper_units
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now vps-agent-helper.socket
|
||||
systemctl restart vps-agent.service
|
||||
if ! wait_healthy; then
|
||||
info "health check failed; restoring previous binary"
|
||||
@@ -268,8 +340,18 @@ do_remove() {
|
||||
read -r -p "Permanently delete $CONFIG_DIR and credentials? [y/N] " answer
|
||||
[[ "$answer" == "y" || "$answer" == "Y" ]] || die "purge cancelled"
|
||||
fi
|
||||
systemctl disable --now vps-agent.service 2>/dev/null || true
|
||||
rm -f -- "$UNIT" "$BINARY" "$PREVIOUS"
|
||||
local pending transaction
|
||||
for pending in "$STATE_DIR"/firewall/pending-*.rules; do
|
||||
[[ -f "$pending" ]] || continue
|
||||
transaction="${pending##*/pending-}"
|
||||
transaction="${transaction%.rules}"
|
||||
[[ "$transaction" =~ ^[a-fA-F0-9]{16}$ ]] || die "invalid pending firewall transaction filename"
|
||||
"$BINARY" --firewall-rollback "$transaction" --config "$CONFIG_DIR/config.toml" \
|
||||
|| die "could not restore pending firewall transaction $transaction"
|
||||
systemctl stop "vps-agent-firewall-rollback-${transaction}.timer" 2>/dev/null || true
|
||||
done
|
||||
systemctl disable --now vps-agent.service vps-agent-helper.socket 2>/dev/null || true
|
||||
rm -f -- "$UNIT" "$HELPER_SOCKET_UNIT" "$HELPER_SERVICE_UNIT" "$BINARY" "$PREVIOUS"
|
||||
rm -rf -- "$STATE_DIR"
|
||||
systemctl daemon-reload
|
||||
if [[ "$PURGE" == true ]]; then
|
||||
|
||||
Reference in New Issue
Block a user