Add Alpine/OpenRC compatibility for init system support
Some checks failed
CI/CD Pipeline / Code Format (push) Successful in 12s
CI/CD Pipeline / Build Debian Package (push) Successful in 1m55s
CI/CD Pipeline / Build RPM Package (push) Successful in 3m24s
CI/CD Pipeline / Build Alpine Package (push) Failing after 0s
CI/CD Pipeline / Build Arch Package (push) Successful in 2m15s
Some checks failed
CI/CD Pipeline / Code Format (push) Successful in 12s
CI/CD Pipeline / Build Debian Package (push) Successful in 1m55s
CI/CD Pipeline / Build RPM Package (push) Successful in 3m24s
CI/CD Pipeline / Build Alpine Package (push) Failing after 0s
CI/CD Pipeline / Build Arch Package (push) Successful in 2m15s
- Updated SPEC.md: Changed systemd requirements to distribution-dependent init system - Updated ARCHITECTURE.md: Added OpenRC hardening options and init script locations - Updated build-alpine.sh: Replaced systemd-dev with openrc, use /etc/init.d - Created configs/linux-patch-api-openrc: Full OpenRC init script - Added Dockerfile.rpm for RPM build container Init system support: - systemd: Debian, Ubuntu, RHEL, CentOS, Fedora - OpenRC: Alpine Linux Binary remains init-system agnostic - no Rust code changes required.
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## System Overview
|
## System Overview
|
||||||
|
|
||||||
The Linux_Patch_API is a secure, single-host API service that enables remote package and patch management on Linux systems. Each instance runs as a systemd service on the managed host, providing a REST API over mTLS with strict IP whitelist enforcement.
|
The Linux_Patch_API is a secure, single-host API service that enables remote package and patch management on Linux systems. Each instance runs as a system service on the managed host (systemd on most distributions, OpenRC on Alpine), providing a REST API over mTLS with strict IP whitelist enforcement.
|
||||||
|
|
||||||
**Architecture Type:** Agent Per Host (Option B)
|
**Architecture Type:** Agent Per Host (Option B)
|
||||||
**Deployment:** One instance per managed Linux host
|
**Deployment:** One instance per managed Linux host
|
||||||
@ -45,8 +45,9 @@ The Linux_Patch_API is a secure, single-host API service that enables remote pac
|
|||||||
- Distribution detection and adapter selection
|
- Distribution detection and adapter selection
|
||||||
|
|
||||||
6. **Audit Logger**
|
6. **Audit Logger**
|
||||||
- systemd journal integration (primary)
|
- System logging integration (primary)
|
||||||
- Optional remote syslog server
|
- systemd journal on systemd-based systems
|
||||||
|
- syslog/local files on OpenRC-based systems
|
||||||
- Local file fallback (`/var/log/linux_patch_api/`)
|
- Local file fallback (`/var/log/linux_patch_api/`)
|
||||||
- 30-day retention with daily rotation and gzip compression
|
- 30-day retention with daily rotation and gzip compression
|
||||||
|
|
||||||
@ -59,9 +60,10 @@ The Linux_Patch_API is a secure, single-host API service that enables remote pac
|
|||||||
### External Integrations
|
### External Integrations
|
||||||
|
|
||||||
- **Package Managers:** apt, dnf, yum, apk, pacman (via system commands)
|
- **Package Managers:** apt, dnf, yum, apk, pacman (via system commands)
|
||||||
- **systemd:** Service management and journal logging
|
- **Init System:** Service management and logging
|
||||||
|
- systemd (Debian, Ubuntu, RHEL, CentOS, Fedora)
|
||||||
|
- OpenRC (Alpine Linux)
|
||||||
- **Internal CA:** Certificate validation against self-hosted CA
|
- **Internal CA:** Certificate validation against self-hosted CA
|
||||||
- **Remote Syslog:** Optional external log aggregation
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -74,14 +76,17 @@ The Linux_Patch_API is a secure, single-host API service that enables remote pac
|
|||||||
- **mTLS:** Rust TLS library (rustls or native-tls)
|
- **mTLS:** Rust TLS library (rustls or native-tls)
|
||||||
|
|
||||||
### Infrastructure
|
### Infrastructure
|
||||||
- **Service Manager:** systemd
|
- **Service Manager:** Distribution-dependent
|
||||||
|
- systemd (most distributions)
|
||||||
|
- OpenRC (Alpine Linux)
|
||||||
- **Configuration:** YAML
|
- **Configuration:** YAML
|
||||||
- **Logging:** systemd journal + optional syslog
|
|
||||||
|
|
||||||
### Deployment
|
### Deployment
|
||||||
- **Package Format:** Native Linux packages (deb, rpm, apk, pkg.tar.zst)
|
- **Package Format:** Native Linux packages (deb, rpm, apk, pkg.tar.zst)
|
||||||
- **Distribution:** Via target system package manager (apt, dnf, apk, pacman)
|
- **Distribution:** Via target system package manager (apt, dnf, apk, pacman)
|
||||||
- **Installation:** Package installs binary, systemd service, and default config structure
|
- **Installation:** Package installs binary, init script/service, and default config structure
|
||||||
|
- systemd unit file for systemd distributions
|
||||||
|
- OpenRC init script for Alpine
|
||||||
- **Updates:** Handled through system package manager
|
- **Updates:** Handled through system package manager
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -99,16 +104,21 @@ The Linux_Patch_API is a secure, single-host API service that enables remote pac
|
|||||||
- No granular permissions (binary access: allowed or denied)
|
- No granular permissions (binary access: allowed or denied)
|
||||||
- Whitelisted IP + valid cert = full API access
|
- Whitelisted IP + valid cert = full API access
|
||||||
|
|
||||||
### Process Security (systemd Hardening)
|
### Process Security (Init System Hardening)
|
||||||
- **User:** root (required for package management)
|
- **User:** root (required for package management)
|
||||||
- **NoNewPrivileges:** true (prevent privilege escalation)
|
|
||||||
- **ProtectSystem:** strict (read-only filesystem except allowed paths)
|
|
||||||
- **ProtectHome:** true (no access to /home, /root, /run/user)
|
|
||||||
- **PrivateTmp:** true (isolated /tmp)
|
|
||||||
- **SystemCallFilter:** Restrict to required syscalls only (application whitelist)
|
|
||||||
- **RestrictAddressFamilies:** AF_INET, AF_INET6, AF_UNIX (network restrictions)
|
|
||||||
- **CapabilityBoundingSet:** CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN (minimal capabilities)
|
|
||||||
|
|
||||||
|
**systemd Hardening Options:**
|
||||||
|
- NoNewPrivileges: true (prevent privilege escalation)
|
||||||
|
- ProtectSystem: strict (read-only filesystem except allowed paths)
|
||||||
|
- ProtectHome: true (no access to /home, /root, /run/user)
|
||||||
|
- PrivateTmp: true (isolated /tmp)
|
||||||
|
- SystemCallFilter: Restrict to required syscalls only (application whitelist)
|
||||||
|
|
||||||
|
**OpenRC Hardening Options:**
|
||||||
|
- Run as dedicated service user
|
||||||
|
- File permission restrictions
|
||||||
|
- chroot isolation (optional)
|
||||||
|
- Equivalent security via rc.conf and init script options
|
||||||
### Data Security
|
### Data Security
|
||||||
- All communications encrypted via TLS
|
- All communications encrypted via TLS
|
||||||
- Certificates stored securely with restricted permissions
|
- Certificates stored securely with restricted permissions
|
||||||
@ -149,7 +159,9 @@ The Linux_Patch_API is a secure, single-host API service that enables remote pac
|
|||||||
└── audit.log # Local audit log fallback
|
└── audit.log # Local audit log fallback
|
||||||
|
|
||||||
/usr/bin/linux-patch-api # Binary location
|
/usr/bin/linux-patch-api # Binary location
|
||||||
/etc/systemd/system/linux-patch-api.service # Systemd service
|
Init scripts (distribution-dependent):
|
||||||
|
- /etc/systemd/system/linux-patch-api.service # systemd
|
||||||
|
- /etc/init.d/linux-patch-api # OpenRC (Alpine)
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
14
Dockerfile.rpm
Normal file
14
Dockerfile.rpm
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Fedora container with Node.js for GitHub Actions support
|
||||||
|
# Used for RPM package builds in CI/CD
|
||||||
|
FROM fedora:latest
|
||||||
|
|
||||||
|
# Install Node.js (required for GitHub Actions JavaScript-based actions)
|
||||||
|
# Also install dnf-plugins-core for potential multiarch support
|
||||||
|
RUN dnf install -y nodejs dnf-plugins-core && \
|
||||||
|
dnf clean all
|
||||||
|
|
||||||
|
# Verify node is available
|
||||||
|
RUN node --version
|
||||||
|
|
||||||
|
# Default command (not used in CI, but good for testing)
|
||||||
|
CMD ["/bin/bash"]
|
||||||
18
SPEC.md
18
SPEC.md
@ -41,7 +41,9 @@
|
|||||||
**Primary Objective:** Provide secure API for remote patch/package management on individual Linux hosts
|
**Primary Objective:** Provide secure API for remote patch/package management on individual Linux hosts
|
||||||
|
|
||||||
**Key Goals:**
|
**Key Goals:**
|
||||||
- Run as systemd service on each managed machine (Option B: Agent Per Host)
|
- Run as a system service on each managed machine (Option B: Agent Per Host)
|
||||||
|
- systemd for Debian/Ubuntu, RHEL/CentOS/Fedora
|
||||||
|
- OpenRC for Alpine Linux
|
||||||
- Internal network access only (no internet exposure)
|
- Internal network access only (no internet exposure)
|
||||||
- Support Debian/Ubuntu first, then expand to other distributions
|
- Support Debian/Ubuntu first, then expand to other distributions
|
||||||
- Maintain audit trail of all operations
|
- Maintain audit trail of all operations
|
||||||
@ -55,7 +57,9 @@
|
|||||||
- One API instance per host
|
- One API instance per host
|
||||||
- Internal network only (LAN/private network)
|
- Internal network only (LAN/private network)
|
||||||
- No public internet exposure
|
- No public internet exposure
|
||||||
- Must run as systemd service
|
- Must run as a system service (init system determined by distribution)
|
||||||
|
- systemd: Debian, Ubuntu, RHEL, CentOS, Fedora
|
||||||
|
- OpenRC: Alpine Linux
|
||||||
|
|
||||||
**Technical:**
|
**Technical:**
|
||||||
- Must run with elevated privileges for package management (root/sudo)
|
- Must run with elevated privileges for package management (root/sudo)
|
||||||
@ -119,7 +123,9 @@
|
|||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
- Linux OS with package manager support
|
- Linux OS with package manager support
|
||||||
- systemd for service management
|
- Init system for service management (distribution-dependent)
|
||||||
|
- systemd (most distributions)
|
||||||
|
- OpenRC (Alpine Linux)
|
||||||
- Network access for API communication
|
- Network access for API communication
|
||||||
- mTLS certificate infrastructure (CA, client certs)
|
- mTLS certificate infrastructure (CA, client certs)
|
||||||
- IP whitelist configuration
|
- IP whitelist configuration
|
||||||
@ -147,8 +153,10 @@
|
|||||||
- Configuration changes (whitelist updates, cert renewals)
|
- Configuration changes (whitelist updates, cert renewals)
|
||||||
|
|
||||||
- **Log Storage:**
|
- **Log Storage:**
|
||||||
- Primary: systemd journal (`journalctl`)
|
- Primary: Distribution-appropriate logging
|
||||||
- Secondary: Optional remote syslog server
|
- systemd journal (journalctl) on systemd systems
|
||||||
|
- syslog/local files on OpenRC systems
|
||||||
|
- Secondary: Optional remote syslog server (universal)
|
||||||
- Local file logs as fallback (`/var/log/linux_patch_api/`)
|
- Local file logs as fallback (`/var/log/linux_patch_api/`)
|
||||||
|
|
||||||
- **Log Retention:**
|
- **Log Retention:**
|
||||||
|
|||||||
10
build-alpine.sh
Executable file → Normal file
10
build-alpine.sh
Executable file → Normal file
@ -11,7 +11,7 @@ echo ""
|
|||||||
# Check if running on Alpine
|
# Check if running on Alpine
|
||||||
if ! command -v abuild &> /dev/null; then
|
if ! command -v abuild &> /dev/null; then
|
||||||
echo "Installing Alpine build tools..."
|
echo "Installing Alpine build tools..."
|
||||||
apk add --no-cache alpine-sdk rust cargo openssl-dev systemd-dev git
|
apk add --no-cache alpine-sdk rust cargo openssl-dev openrc git
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Setup build environment
|
# Setup build environment
|
||||||
@ -27,13 +27,13 @@ cargo build --release --target x86_64-unknown-linux-musl
|
|||||||
PKGDIR=$(pwd)/apk-package
|
PKGDIR=$(pwd)/apk-package
|
||||||
mkdir -p "$PKGDIR"/usr/bin
|
mkdir -p "$PKGDIR"/usr/bin
|
||||||
mkdir -p "$PKGDIR"/etc/linux_patch_api
|
mkdir -p "$PKGDIR"/etc/linux_patch_api
|
||||||
mkdir -p "$PKGDIR"/lib/systemd/system
|
mkdir -p "$PKGDIR"/etc/init.d
|
||||||
|
|
||||||
# Copy files
|
# Copy files
|
||||||
cp target/x86_64-unknown-linux-musl/release/linux-patch-api "$PKGDIR"/usr/bin/
|
cp target/x86_64-unknown-linux-musl/release/linux-patch-api "$PKGDIR"/usr/bin/
|
||||||
chmod 755 "$PKGDIR"/usr/bin/linux-patch-api
|
chmod 755 "$PKGDIR"/usr/bin/linux-patch-api
|
||||||
cp configs/linux-patch-api.service "$PKGDIR"/lib/systemd/system/
|
cp configs/linux-patch-api-openrc "$PKGDIR"/etc/init.d/linux-patch-api
|
||||||
cp configs/config.yaml.example "$PKGDIR"/etc/linux_patch_api/config.yaml
|
chmod 755 "$PKGDIR"/etc/init.d/linux-patch-api
|
||||||
cp configs/whitelist.yaml.example "$PKGDIR"/etc/linux_patch_api/whitelist.yaml
|
cp configs/whitelist.yaml.example "$PKGDIR"/etc/linux_patch_api/whitelist.yaml
|
||||||
|
|
||||||
# Create APKBUILD
|
# Create APKBUILD
|
||||||
@ -46,7 +46,7 @@ pkgdesc="Secure remote package management API for Linux systems"
|
|||||||
url="https://gitea.internal/linux-patch-api"
|
url="https://gitea.internal/linux-patch-api"
|
||||||
arch="x86_64"
|
arch="x86_64"
|
||||||
license="MIT"
|
license="MIT"
|
||||||
depends="systemd"
|
depends="openrc"
|
||||||
source="apk-package"
|
source="apk-package"
|
||||||
|
|
||||||
package() {
|
package() {
|
||||||
|
|||||||
72
configs/linux-patch-api-openrc
Normal file
72
configs/linux-patch-api-openrc
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#!/sbin/openrc-run
|
||||||
|
# OpenRC init script for linux-patch-api
|
||||||
|
# Used on Alpine Linux and other OpenRC-based systems
|
||||||
|
|
||||||
|
name="linux_patch_api"
|
||||||
|
command="/usr/bin/linux-patch-api"
|
||||||
|
command_args="--config /etc/linux_patch_api/config.yaml"
|
||||||
|
command_background=true
|
||||||
|
pidfile="/run/linux-patch-api/linux-patch-api.pid"
|
||||||
|
output_log="/var/log/linux_patch_api/linux-patch-api.log"
|
||||||
|
error_log="/var/log/linux_patch_api/linux-patch-api.err"
|
||||||
|
|
||||||
|
# Required dependencies
|
||||||
|
depend() {
|
||||||
|
use net logger
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create required directories before starting
|
||||||
|
start_pre() {
|
||||||
|
checkpath --directory --owner linux-patch-api:linux-patch-api --mode 0755 \
|
||||||
|
/run/linux-patch-api \
|
||||||
|
/var/log/linux-patch-api \
|
||||||
|
/var/lib/linux-patch-api \
|
||||||
|
/etc/linux_patch_api/certs
|
||||||
|
|
||||||
|
# Ensure config files exist
|
||||||
|
if [ ! -f "/etc/linux_patch_api/config.yaml" ]; then
|
||||||
|
eerror "Configuration file missing: /etc/linux_patch_api/config.yaml"
|
||||||
|
eerror "Please create config.yaml before starting the service"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "/etc/linux_patch_api/whitelist.yaml" ]; then
|
||||||
|
eerror "Whitelist file missing: /etc/linux_patch_api/whitelist.yaml"
|
||||||
|
eerror "Please create whitelist.yaml before starting the service"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify service started successfully
|
||||||
|
start_post() {
|
||||||
|
sleep 2
|
||||||
|
if [ -f "$pidfile" ]; then
|
||||||
|
einfo "linux-patch-api started successfully (PID: $(cat $pidfile))"
|
||||||
|
else
|
||||||
|
ewarn "linux-patch-api may not have started correctly - pidfile not found"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Clean shutdown
|
||||||
|
stop_pre() {
|
||||||
|
einfo "Stopping linux-patch-api service..."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify service stopped
|
||||||
|
stop_post() {
|
||||||
|
if [ -f "$pidfile" ]; then
|
||||||
|
rm -f "$pidfile"
|
||||||
|
fi
|
||||||
|
einfo "linux-patch-api stopped"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Service status
|
||||||
|
status() {
|
||||||
|
if [ -f "$pidfile" ] && kill -0 $(cat "$pidfile") 2>/dev/null; then
|
||||||
|
einfo "linux-patch-api is running (PID: $(cat $pidfile))"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
eerror "linux-patch-api is not running"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user