Private
Public Access
1
0

Compare commits

..

8 Commits

Author SHA1 Message Date
6ba708abb1 fix: remove all systemd capability restrictions blocking package management
Some checks failed
CI/CD Pipeline / Code Format (push) Successful in 1s
CI/CD Pipeline / Clippy Lints (push) Successful in 43s
CI/CD Pipeline / Unit Tests (push) Successful in 57s
CI/CD Pipeline / Security Audit (push) Successful in 5s
CI/CD Pipeline / Build Arch Package (push) Successful in 2m10s
CI/CD Pipeline / Build Alpine Package (push) Successful in 3m19s
CI/CD Pipeline / Build RPM Package (push) Successful in 3m2s
CI/CD Pipeline / Build Debian Package (push) Has started running
CI/CD Pipeline / Build Debian Package (Ubuntu 22.04) (push) Failing after 15m44s
- Remove CapabilityBoundingSet and AmbientCapabilities (apt needs full root capabilities)
- Remove ReadWritePaths (unnecessary without ProtectSystem=strict)
- Fix E2E test: properly FAIL on status=failed package operations
- Fix E2E test: require status=completed for install/update/remove lifecycle
- Update dpkg packaging service file to match configs/
- Bump version to 0.3.5
2026-05-03 04:13:50 +00:00
de7ec9905f fix: correct Cargo.toml version to 0.3.4
All checks were successful
CI/CD Pipeline / Code Format (push) Successful in 1s
CI/CD Pipeline / Clippy Lints (push) Successful in 53s
CI/CD Pipeline / Unit Tests (push) Successful in 1m39s
CI/CD Pipeline / Security Audit (push) Successful in 4s
CI/CD Pipeline / Build Debian Package (Ubuntu 22.04) (push) Successful in 1m52s
CI/CD Pipeline / Build Arch Package (push) Successful in 1m55s
CI/CD Pipeline / Build Alpine Package (push) Successful in 3m32s
CI/CD Pipeline / Build Debian Package (push) Successful in 2m27s
CI/CD Pipeline / Build RPM Package (push) Successful in 3m26s
2026-05-03 03:11:52 +00:00
508037d656 chore: bump version to 0.3.4 for clean CI build
Some checks failed
CI/CD Pipeline / Code Format (push) Successful in 3s
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Security Audit (push) Has been cancelled
CI/CD Pipeline / Build Debian Package (push) Has been cancelled
CI/CD Pipeline / Build Debian Package (Ubuntu 22.04) (push) Has been cancelled
CI/CD Pipeline / Build RPM Package (push) Has been cancelled
CI/CD Pipeline / Build Alpine Package (push) Has been cancelled
CI/CD Pipeline / Build Arch Package (push) Has been cancelled
CI/CD Pipeline / Clippy Lints (push) Has been cancelled
2026-05-03 03:11:41 +00:00
56de1d73e1 fix(ci): prevent recursive tag triggers and u2204 release duplication
Some checks failed
CI/CD Pipeline / Build RPM Package (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Security Audit (push) Has been cancelled
CI/CD Pipeline / Build Debian Package (push) Has been cancelled
CI/CD Pipeline / Build Debian Package (Ubuntu 22.04) (push) Has been cancelled
CI/CD Pipeline / Build Alpine Package (push) Has been cancelled
CI/CD Pipeline / Build Arch Package (push) Has been cancelled
CI/CD Pipeline / Code Format (push) Has been cancelled
CI/CD Pipeline / Clippy Lints (push) Has been cancelled
- Change tag trigger from v* to v*.*.* to prevent recursive CI runs
- Upload u2204 deb to same release tag (not creating -u2204 suffix)
- Rename u2204 deb filename to include u2204 for differentiation
2026-05-03 02:49:18 +00:00
157376af7e chore: bump version to 0.3.3 for dpkg and service fixes
Some checks failed
CI/CD Pipeline / Code Format (push) Successful in 2s
CI/CD Pipeline / Clippy Lints (push) Successful in 49s
CI/CD Pipeline / Unit Tests (push) Successful in 57s
CI/CD Pipeline / Security Audit (push) Successful in 4s
CI/CD Pipeline / Build Arch Package (push) Successful in 1m56s
CI/CD Pipeline / Build Debian Package (Ubuntu 22.04) (push) Successful in 1m58s
CI/CD Pipeline / Build Alpine Package (push) Successful in 3m27s
CI/CD Pipeline / Build RPM Package (push) Successful in 4m2s
CI/CD Pipeline / Build Debian Package (push) Has been cancelled
2026-05-03 02:35:32 +00:00
77e8ac2e65 fix: remove linux-patch-api user from dpkg scripts, change ownership to root
All checks were successful
CI/CD Pipeline / Code Format (push) Successful in 1s
CI/CD Pipeline / Clippy Lints (push) Successful in 46s
CI/CD Pipeline / Unit Tests (push) Successful in 58s
CI/CD Pipeline / Security Audit (push) Successful in 4s
CI/CD Pipeline / Build Arch Package (push) Successful in 1m55s
CI/CD Pipeline / Build Debian Package (Ubuntu 22.04) (push) Successful in 1m59s
CI/CD Pipeline / Build Alpine Package (push) Successful in 3m17s
CI/CD Pipeline / Build RPM Package (push) Successful in 3m42s
CI/CD Pipeline / Build Debian Package (push) Successful in 2m2s
- Remove user/group creation from preinst (service runs as root)
- Change directory ownership to root:root in preinst and postinst
- Remove user/group deletion from postrm
- Service runs as root, no dedicated user needed
2026-05-03 02:29:06 +00:00
9e42f32270 fix: remove sudo from apt commands and RestrictSUIDSGID from service
All checks were successful
CI/CD Pipeline / Code Format (push) Successful in 2s
CI/CD Pipeline / Clippy Lints (push) Successful in 1m17s
CI/CD Pipeline / Unit Tests (push) Successful in 56s
CI/CD Pipeline / Security Audit (push) Successful in 15s
CI/CD Pipeline / Build Debian Package (Ubuntu 22.04) (push) Successful in 1m57s
CI/CD Pipeline / Build Arch Package (push) Successful in 1m53s
CI/CD Pipeline / Build Alpine Package (push) Successful in 3m17s
CI/CD Pipeline / Build RPM Package (push) Successful in 3m36s
CI/CD Pipeline / Build Debian Package (push) Successful in 2m11s
- Remove sudo from apt command execution (service runs as root)
- Remove RestrictSUIDSGID from systemd service (blocks setuid for apt/dpkg)
- Remove NoNewPrivileges from systemd service (blocks sudo PERM_SUDOERS)
- Bump version to 0.3.2
2026-05-03 02:24:52 +00:00
2b35a143da fix: implement actual system reboot via shutdown/systemctl commands
All checks were successful
CI/CD Pipeline / Code Format (push) Successful in 2s
CI/CD Pipeline / Clippy Lints (push) Successful in 40s
CI/CD Pipeline / Unit Tests (push) Successful in 1m27s
CI/CD Pipeline / Security Audit (push) Successful in 4s
CI/CD Pipeline / Build Arch Package (push) Successful in 1m56s
CI/CD Pipeline / Build Debian Package (Ubuntu 22.04) (push) Successful in 2m32s
CI/CD Pipeline / Build Alpine Package (push) Successful in 3m25s
CI/CD Pipeline / Build RPM Package (push) Successful in 3m44s
CI/CD Pipeline / Build Debian Package (push) Successful in 3m0s
- Fix reboot_system() to use shutdown -r +N for delayed reboots
- Fix patches handler to call reboot_system() instead of just logging
- Add CAP_SYS_BOOT capability to systemd service for LXC reboot support
- Remove unused warn import from packages/mod.rs
- Bump version to 0.3.1
2026-05-03 01:37:22 +00:00
17 changed files with 172 additions and 145 deletions

Binary file not shown.

View File

@ -3,7 +3,7 @@ name: CI/CD Pipeline
"on":
push:
branches: [ master, develop ]
tags: [ 'v*' ]
tags: [ 'v*.*.*' ]
pull_request:
branches: [ master ]
@ -162,8 +162,14 @@ jobs:
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
FILE=$(ls ../linux-patch-api_*.deb 2>/dev/null | head -1)
# Rename deb to include u2204 in filename to avoid collision with main build
if [ -n "$FILE" ]; then
U2204_FILE="$(echo "$FILE" | sed 's/_amd64/_u2204_amd64/')"
mv "$FILE" "$U2204_FILE"
FILE="$U2204_FILE"
fi
chmod +x scripts/upload-release.sh
./scripts/upload-release.sh "${TAG_NAME}-u2204" "$FILE"
./scripts/upload-release.sh "$TAG_NAME" "$FILE"
build-rpm:
name: Build RPM Package

2
Cargo.lock generated
View File

@ -1859,7 +1859,7 @@ dependencies = [
[[package]]
name = "linux-patch-api"
version = "0.3.0"
version = "0.3.2"
dependencies = [
"actix",
"actix-rt",

View File

@ -1,6 +1,6 @@
[package]
name = "linux-patch-api"
version = "0.3.0"
version = "0.3.5"
edition = "2021"
authors = ["Echo <echo@moon-dragon.us>"]
description = "Secure remote package management API for Linux systems"

View File

@ -17,14 +17,17 @@ RuntimeDirectory=linux-patch-api
RuntimeDirectoryMode=0755
# Security hardening
NoNewPrivileges=true
# ProtectSystem removed - package management requires write access to /usr, /etc, /lib
# Network security provided by mTLS + IP whitelist
# NOTE: Package management requires extensive system access. The following
# restrictions have been removed because they block core functionality:
# - ProtectSystem=strict: Blocks writes to /usr, /etc, /lib where packages install
# - NoNewPrivileges: Blocks sudo/setuid which apt needs for _apt sandbox
# - RestrictSUIDSGID: Blocks setuid/setgid which apt needs for _apt sandbox
# - CapabilityBoundingSet: Drops capabilities that apt needs (SETUID, SETGID, CHOWN, etc.)
# - AmbientCapabilities: Same issue as CapabilityBoundingSet
# Network security is provided by mTLS + IP whitelist. The service runs as root
# and MUST be able to install/remove/update packages system-wide.
ProtectHome=true
# ReadWritePaths kept as documentation reference for apt/dpkg paths
ReadWritePaths=/var/lib/linux_patch_api /var/log/linux_patch_api /var/cache/apt /var/lib/apt /var/lib/dpkg /var/log/apt
PrivateTmp=true
PrivateDevices=true
ProtectHostname=true
ProtectClock=true
ProtectKernelTunables=true
@ -34,8 +37,6 @@ RestrictNamespaces=true
LockPersonality=true
MemoryDenyWriteExecute=false
RestrictRealtime=true
RestrictSUIDSGID=true
RemoveIPC=true
# System call filtering (whitelist approach)
SystemCallFilter=@system-service

59
debian/changelog vendored
View File

@ -1,24 +1,43 @@
linux-patch-api (0.3.0-1) unstable; urgency=low
linux-patch-api (0.3.5-1) unstable; urgency=low
* v0.3.0 beta release
* Fix List Jobs connection reset: Add client_disconnect_timeout (5s)
* Enforce TLS 1.3 only with builder_with_provider()
* Fix RwLock contention: Release read lock before sorting in list_jobs()
* Fix systemd service: Remove ProtectSystem=strict
* Fix systemd service: Change Type=notify to Type=simple
* Fix systemd service: Add DEBIAN_FRONTEND=noninteractive
* Add Ubuntu 22.04 CI build job
* Add apt-get -f install for broken runner deps
* Remove CapabilityBoundingSet and AmbientCapabilities - apt needs full root capabilities
* Remove ProtectSystem=strict, NoNewPrivileges, RestrictSUIDSGID - block core functionality
* Remove ReadWritePaths - unnecessary without ProtectSystem=strict
* Fix E2E test: properly FAIL on status=failed package operations
* Fix E2E test: require status=completed for install/update/remove lifecycle
* Update service file Type=notify -> Type=simple
* Add DEBIAN_FRONTEND=noninteractive environment variable
-- Echo <echo@moon-dragon.us> Sat, 02 May 2026 19:55:00 -0500
linux-patch-api (1.0.0-1) stable; urgency=medium
-- Echo <echo@moon-dragon.us> Sat, 03 May 2026 03:15:00 -0500
* Initial production release
* Secure mTLS-authenticated REST API for remote package management
* 15 API endpoints for package install/remove, patch application, system management
* Asynchronous job processing with WebSocket status streaming
* IP whitelist enforcement and comprehensive audit logging
* Systemd integration with security hardening
* Supports Debian 11/12, Ubuntu 20.04/22.04/24.04
linux-patch-api (0.3.4-1) unstable; urgency=low
-- Echo <echo@moon-dragon.us> Thu, 09 Apr 2026 18:57:12 -0500
* Fix CI workflow: prevent recursive tag triggers (v* -> v*.*.*)
* Fix CI workflow: upload u2204 deb to same release (no -u2204 suffix)
* Remove sudo from apt commands (service runs as root)
* Remove NoNewPrivileges and RestrictSUIDSGID from service file
* Update service file Type=notify -> Type=simple
* Add DEBIAN_FRONTEND=noninteractive environment variable
-- Echo <echo@moon-dragon.us> Fri, 02 May 2026 22:00:00 -0500
linux-patch-api (0.3.3-1) unstable; urgency=low
* Fix dpkg packaging: remove linux-patch-api user creation
* Change ownership to root:root in preinst/postinst scripts
* Bump version to 0.3.3
-- Echo <echo@moon-dragon.us> Fri, 02 May 2026 21:45:00 -0500
linux-patch-api (0.3.2-1) unstable; urgency=low
* Remove sudo from apt commands in source code
* Remove NoNewPrivileges=true from service file
* Remove RestrictSUIDSGID=true from service file
* Add DEBIAN_FRONTEND=noninteractive to service file
* Fix TLS 1.3 enforcement in mtls.rs
* Add client_disconnect_timeout to main.rs
* Optimize RwLock usage in jobs/manager.rs
* Bump version to 0.3.2
-- Echo <echo@moon-dragon.us> Fri, 02 May 2026 21:30:00 -0500

View File

@ -13,14 +13,14 @@ if [ "$1" = "configure" ]; then
echo "Creating default config.yaml..."
cp /etc/linux_patch_api/config.yaml.example /etc/linux_patch_api/config.yaml
chmod 640 /etc/linux_patch_api/config.yaml
chown linux-patch-api:linux-patch-api /etc/linux_patch_api/config.yaml
chown root:root /etc/linux_patch_api/config.yaml
fi
if [ ! -f "/etc/linux_patch_api/whitelist.yaml" ]; then
echo "Creating default whitelist.yaml..."
cp /etc/linux_patch_api/whitelist.yaml.example /etc/linux_patch_api/whitelist.yaml
chmod 640 /etc/linux_patch_api/whitelist.yaml
chown linux-patch-api:linux-patch-api /etc/linux_patch_api/whitelist.yaml
chown root:root /etc/linux_patch_api/whitelist.yaml
fi
# Reload systemd daemon to pick up new service file

View File

@ -39,18 +39,6 @@ if [ "$1" = "purge" ]; then
rm -rf /var/log/linux_patch_api
fi
# Remove system user
if getent passwd linux-patch-api > /dev/null 2>&1; then
echo "Removing user linux-patch-api..."
userdel linux-patch-api 2>/dev/null || true
fi
# Remove system group
if getent group linux-patch-api > /dev/null 2>&1; then
echo "Removing group linux-patch-api..."
groupdel linux-patch-api 2>/dev/null || true
fi
echo "linux-patch-api purged successfully"
fi

View File

@ -9,31 +9,14 @@ if [ -d "/etc/linux_patch_api" ]; then
echo "Detected existing installation - performing upgrade"
fi
# Create system user if it doesn't exist
if ! getent group linux-patch-api > /dev/null 2>&1; then
echo "Creating group linux-patch-api..."
groupadd --system linux-patch-api
fi
if ! getent passwd linux-patch-api > /dev/null 2>&1; then
echo "Creating user linux-patch-api..."
useradd --system \
--gid linux-patch-api \
--home-dir /var/lib/linux_patch_api \
--no-create-home \
--shell /usr/sbin/nologin \
--comment "Linux Patch API Service" \
linux-patch-api
fi
# Create required directories
mkdir -p /etc/linux_patch_api/certs
mkdir -p /var/lib/linux_patch_api
mkdir -p /var/log/linux_patch_api
# Set proper ownership
chown -R linux-patch-api:linux-patch-api /var/lib/linux_patch_api
chown -R linux-patch-api:linux-patch-api /var/log/linux_patch_api
# Set proper ownership (service runs as root)
chown -R root:root /var/lib/linux_patch_api
chown -R root:root /var/log/linux_patch_api
# Set secure permissions
chmod 750 /etc/linux_patch_api

View File

@ -5,7 +5,8 @@ After=network-online.target
Wants=network-online.target
[Service]
Type=notify
Type=simple
NotifyAccess=all
ExecStart=/usr/bin/linux-patch-api --config /etc/linux_patch_api/config.yaml
Restart=on-failure
RestartSec=5s
@ -16,12 +17,17 @@ RuntimeDirectory=linux-patch-api
RuntimeDirectoryMode=0755
# Security hardening
NoNewPrivileges=true
ProtectSystem=strict
# NOTE: Package management requires extensive system access. The following
# restrictions have been removed because they block core functionality:
# - ProtectSystem=strict: Blocks writes to /usr, /etc, /lib where packages install
# - NoNewPrivileges: Blocks sudo/setuid which apt needs for _apt sandbox
# - RestrictSUIDSGID: Blocks setuid/setgid which apt needs for _apt sandbox
# - CapabilityBoundingSet: Drops capabilities that apt needs (SETUID, SETGID, CHOWN, etc.)
# - AmbientCapabilities: Same issue as CapabilityBoundingSet
# Network security is provided by mTLS + IP whitelist. The service runs as root
# and MUST be able to install/remove/update packages system-wide.
ProtectHome=true
ReadWritePaths=/var/lib/linux_patch_api /var/log/linux_patch_api
PrivateTmp=true
PrivateDevices=true
ProtectHostname=true
ProtectClock=true
ProtectKernelTunables=true
@ -31,8 +37,6 @@ RestrictNamespaces=true
LockPersonality=true
MemoryDenyWriteExecute=false
RestrictRealtime=true
RestrictSUIDSGID=true
RemoveIPC=true
# System call filtering (whitelist approach)
SystemCallFilter=@system-service
@ -40,6 +44,7 @@ SystemCallErrorNumber=EPERM
# Environment
Environment="RUST_BACKTRACE=1"
Environment="DEBIAN_FRONTEND=noninteractive"
Environment="RUST_LOG=info"
# Logging

4
debian/postinst vendored
View File

@ -13,14 +13,14 @@ if [ "$1" = "configure" ]; then
echo "Creating default config.yaml..."
cp /etc/linux_patch_api/config.yaml.example /etc/linux_patch_api/config.yaml
chmod 640 /etc/linux_patch_api/config.yaml
chown linux-patch-api:linux-patch-api /etc/linux_patch_api/config.yaml
chown root:root /etc/linux_patch_api/config.yaml
fi
if [ ! -f "/etc/linux_patch_api/whitelist.yaml" ]; then
echo "Creating default whitelist.yaml..."
cp /etc/linux_patch_api/whitelist.yaml.example /etc/linux_patch_api/whitelist.yaml
chmod 640 /etc/linux_patch_api/whitelist.yaml
chown linux-patch-api:linux-patch-api /etc/linux_patch_api/whitelist.yaml
chown root:root /etc/linux_patch_api/whitelist.yaml
fi
# Reload systemd daemon to pick up new service file

12
debian/postrm vendored
View File

@ -39,18 +39,6 @@ if [ "$1" = "purge" ]; then
rm -rf /var/log/linux_patch_api
fi
# Remove system user
if getent passwd linux-patch-api > /dev/null 2>&1; then
echo "Removing user linux-patch-api..."
userdel linux-patch-api 2>/dev/null || true
fi
# Remove system group
if getent group linux-patch-api > /dev/null 2>&1; then
echo "Removing group linux-patch-api..."
groupdel linux-patch-api 2>/dev/null || true
fi
echo "linux-patch-api purged successfully"
fi

23
debian/preinst vendored
View File

@ -9,31 +9,14 @@ if [ -d "/etc/linux_patch_api" ]; then
echo "Detected existing installation - performing upgrade"
fi
# Create system user if it doesn't exist
if ! getent group linux-patch-api > /dev/null 2>&1; then
echo "Creating group linux-patch-api..."
groupadd --system linux-patch-api
fi
if ! getent passwd linux-patch-api > /dev/null 2>&1; then
echo "Creating user linux-patch-api..."
useradd --system \
--gid linux-patch-api \
--home-dir /var/lib/linux_patch_api \
--no-create-home \
--shell /usr/sbin/nologin \
--comment "Linux Patch API Service" \
linux-patch-api
fi
# Create required directories
mkdir -p /etc/linux_patch_api/certs
mkdir -p /var/lib/linux_patch_api
mkdir -p /var/log/linux_patch_api
# Set proper ownership
chown -R linux-patch-api:linux-patch-api /var/lib/linux_patch_api
chown -R linux-patch-api:linux-patch-api /var/log/linux_patch_api
# Set proper ownership (service runs as root)
chown -R root:root /var/lib/linux_patch_api
chown -R root:root /var/log/linux_patch_api
# Set secure permissions
chmod 750 /etc/linux_patch_api

View File

@ -139,7 +139,22 @@ pub async fn apply_patches(
),
)
.await;
// In production, would trigger actual reboot via system handler
// Trigger actual reboot via system handler
match backend_clone.reboot_system(request.reboot_delay_seconds) {
Ok(_) => {
let _ = job_manager_clone
.add_job_log(
&job_id_clone,
"Reboot command executed".to_string(),
)
.await;
}
Err(e) => {
let _ = job_manager_clone
.add_job_log(&job_id_clone, format!("Reboot failed: {}", e))
.await;
}
}
}
}
Err(e) => {

View File

@ -6,7 +6,7 @@
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use std::process::Command;
use tracing::{info, warn};
use tracing::info;
/// Package status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@ -98,18 +98,9 @@ impl AptBackend {
/// Run apt command and capture output
fn run_apt(&self, args: &[&str]) -> Result<String> {
// Use sudo for operations that modify packages (install, upgrade, remove, purge)
let needs_sudo = args.first().is_some_and(|&cmd| {
matches!(
cmd,
"install" | "upgrade" | "remove" | "purge" | "dist-upgrade" | "autoremove"
)
});
let (program, cmd_args): (&str, Vec<&str>) = if needs_sudo {
("sudo", ["apt"].iter().chain(args.iter()).copied().collect())
} else {
("apt", args.to_vec())
};
// Service runs as root - no sudo needed for apt commands
let program = "apt";
let cmd_args: Vec<&str> = args.to_vec();
let output = Command::new(program)
.args(&cmd_args)
@ -466,17 +457,27 @@ impl PackageManagerBackend for AptBackend {
fn reboot_system(&self, delay_seconds: u64) -> Result<()> {
if delay_seconds > 0 {
info!("Scheduling reboot in {} seconds", delay_seconds);
// In production, would use systemd shutdown scheduler
warn!("Delayed reboot not fully implemented - would use systemd in production");
// Use shutdown command for delayed reboot (converts seconds to minutes, minimum 1)
let delay_minutes = std::cmp::max(1u64, delay_seconds.div_ceil(60));
info!(
"Scheduling system reboot in {} minutes (requested {} seconds)",
delay_minutes, delay_seconds
);
Command::new("shutdown")
.args(["-r", &format!("+{}", delay_minutes)])
.status()
.context("Failed to schedule delayed reboot")?;
info!("System reboot scheduled in {} minutes", delay_minutes);
} else {
// Immediate reboot using systemctl
info!("Initiating immediate system reboot");
Command::new("systemctl")
.arg("reboot")
.status()
.context("Failed to execute reboot command")?;
info!("System reboot initiated");
}
Command::new("systemctl")
.arg("reboot")
.status()
.context("Failed to execute reboot command")?;
info!("System reboot initiated");
Ok(())
}
}

View File

@ -29,3 +29,45 @@
**Correction:** Always verify binary versions match before testing. Different BuildIDs mean different code.
**Rule:** Check binary versions (file size, BuildID, --version output) on all target systems before testing.
**Status:** Active
## 2026-05-02 - Always run cargo fmt AND cargo clippy locally before pushing
**Mistake:** Pushed code changes without running cargo fmt and cargo clippy locally, causing 8 CI iterations to fix formatting and lint errors.
**Correction:** Run `cargo fmt --all -- --check` and `cargo clippy --all-targets --all-features -- -D warnings` locally before every push.
**Rule:** ALWAYS run cargo fmt AND cargo clippy locally before pushing to Gitea. Fix all errors before pushing.
**Status:** Active
## 2026-05-02 - rustls 0.23 API: builder() vs builder_with_provider()
**Mistake:** Used ServerConfig::builder() which returns WantsVerifier state, then called with_protocol_versions() which requires WantsVersions state.
**Correction:** Use ServerConfig::builder_with_provider(Arc::new(aws_lc_rs::default_provider())) to get WantsVersions state. Also need aws_lc_rs feature in Cargo.toml.
**Rule:** In rustls 0.23, to set protocol versions, use builder_with_provider() not builder(). The builder() shortcut skips version negotiation.
**Status:** Active
## 2026-05-02 - apt broken deps block unrelated package installs
**Mistake:** CI failed because openssh-server on runner had version mismatch (13.16 server vs 13.15 client), blocking all apt-get install operations.
**Correction:** Add `sudo apt-get -f install -y` before `sudo apt-get install` in CI workflow to fix broken deps automatically.
**Rule:** Always add `apt-get -f install -y` before `apt-get install` in CI workflows. Runners may have broken apt state from partial upgrades.
**Status:** Active
## 2026-05-03 - NoNewPrivileges=true blocks sudo in systemd services
**Mistake:** Service used NoNewPrivileges=true which prevented sudo from working (PERM_SUDOERS: setresuid Operation not permitted).
**Correction:** Removed NoNewPrivileges=true from systemd service. The service runs as root and uses sudo for apt commands, which requires privilege escalation capabilities.
**Rule:** For package management services that use sudo, do not use NoNewPrivileges=true. mTLS + IP whitelist provides network security.
**Status:** Active
## 2026-05-03 - RestrictSUIDSGID=true blocks sudo in systemd services
**Mistake:** Service used RestrictSUIDSGID=true which prevented sudo from using setuid/setgid operations.
**Correction:** Removed RestrictSUIDSGID=true from systemd service. Package management requires setuid/setgid for apt/dpkg.
**Rule:** For package management services, do not use RestrictSUIDSGID=true. It blocks sudo and apt from working.
**Status:** Active
## 2026-05-03 - dpkg preinst creates linux-patch-api user causing permission issues
**Mistake:** dpkg preinst script creates a linux-patch-api system user and changes directory ownership, causing the service to crash with 'Permission denied' on log file creation.
**Correction:** Fix dpkg preinst to not create the linux-patch-api user or change directory ownership. Service runs as root and directories should be owned by root.
**Rule:** For services that run as root, do not create a dedicated system user in the dpkg preinst script. Keep all directory ownership as root:root.
**Status:** Active
## 2026-05-03 - Service runs as root, no sudo needed for apt commands
**Mistake:** Service used sudo to run apt commands even though it runs as root. This caused failures when systemd security restrictions blocked sudo.
**Correction:** Removed sudo from apt command execution in the source code. Service runs as root and can execute apt directly.
**Rule:** If a service runs as root, it does not need sudo to execute commands. Remove sudo from command execution.
**Status:** Active

View File

@ -298,8 +298,8 @@ def test_get_package_not_found(client: PatchAPIClient) -> str:
def test_install_package(client: PatchAPIClient) -> str:
"""POST /api/v1/packages - Install a safe test package (hello).
Note: Install may fail due to service permissions (NoNewPrivileges=true).
Both completed and failed are acceptable outcomes.
Verifies that the package installation completes successfully.
A failed status is a critical failure - the core function must work.
"""
payload = {
"packages": [{"name": TEST_PACKAGE, "version": None}],
@ -318,10 +318,7 @@ def test_install_package(client: PatchAPIClient) -> str:
# Poll job to completion
job_id = data["data"]["job_id"]
job = poll_job(client, job_id)
# Install may fail due to service permissions - both outcomes acceptable
if job["status"] == "failed":
return f"Install job completed with status=failed (may be permissions issue): job_id={job_id}, result={job.get('result', {})}"
assert job["status"] == "completed", f"Install job unexpected status: {job['status']}"
assert job["status"] == "completed", f"Install job failed: status={job['status']}, result={job.get('result', {})}"
return f"Installed {TEST_PACKAGE}: job_id={job_id}, status={job['status']}"
@ -336,15 +333,15 @@ def test_update_package(client: PatchAPIClient) -> str:
job_id = data["data"]["job_id"]
job = poll_job(client, job_id)
# Update may complete or fail (package already latest or not installed)
assert job["status"] in ["completed", "failed"], f"Unexpected job status: {job['status']}"
assert job["status"] == "completed", f"Update job failed: status={job['status']}, result={job.get('result', {})}"
return f"Updated {TEST_PACKAGE}: job_id={job_id}, status={job['status']}"
def test_remove_package(client: PatchAPIClient) -> str:
"""DELETE /api/v1/packages/{name} - Remove the test package.
Note: Remove may fail if package wasn't installed. Both outcomes acceptable.
Verifies that the package removal completes successfully.
A failed status is a critical failure - the core function must work.
"""
resp = client.delete(f"/api/v1/packages/{TEST_PACKAGE}")
assert resp.status_code == 202, f"Expected 202, got {resp.status_code}: {resp.text}"
@ -355,8 +352,7 @@ def test_remove_package(client: PatchAPIClient) -> str:
job_id = data["data"]["job_id"]
job = poll_job(client, job_id)
# Remove may fail if package wasn't installed
assert job["status"] in ["completed", "failed"], f"Remove job unexpected status: {job['status']}"
assert job["status"] == "completed", f"Remove job failed: status={job['status']}, result={job.get('result', {})}"
return f"Removed {TEST_PACKAGE}: job_id={job_id}, status={job['status']}"
@ -568,8 +564,8 @@ def test_wrong_cert_connection(client: PatchAPIClient) -> str:
def test_job_lifecycle(client: PatchAPIClient) -> str:
"""Full job lifecycle: install -> get job -> list jobs -> remove.
Accepts both completed and failed outcomes for install/remove
since service may have permission restrictions.
Verifies that install and remove both complete successfully.
A failed status is a critical failure - the core function must work.
"""
# Step 1: Install test package
payload = {
@ -589,7 +585,7 @@ def test_job_lifecycle(client: PatchAPIClient) -> str:
# Step 3: Poll to completion
job = poll_job(client, job_id)
assert job["status"] in ["completed", "failed"], f"Install job unexpected status: {job['status']}"
assert job["status"] == "completed", f"Install job failed: status={job['status']}, result={job.get('result', {})}"
# Step 4: Verify in job list
resp = client.get("/api/v1/jobs?limit=50", timeout=120)
@ -603,7 +599,7 @@ def test_job_lifecycle(client: PatchAPIClient) -> str:
assert resp.status_code == 202, f"Remove failed: HTTP {resp.status_code}"
remove_job_id = resp.json()["data"]["job_id"]
remove_job = poll_job(client, remove_job_id)
assert remove_job["status"] in ["completed", "failed"], f"Remove job unexpected status: {remove_job['status']}"
assert remove_job["status"] == "completed", f"Remove job failed: status={remove_job['status']}, result={remove_job.get('result', {})}"
return f"Full lifecycle OK: install job={job_id}, remove job={remove_job_id}"