Private
Public Access
1
0

Compare commits

...

4 Commits

Author SHA1 Message Date
f55cfbc7a1 chore: bump version to 1.1.11 (#67)
Some checks failed
CI Pipeline / Rust Format Check (push) Successful in 3s
CI Pipeline / Clippy Lints (push) Successful in 52s
CI Pipeline / Rust Unit Tests (push) Failing after 1m22s
CI Pipeline / Security Audit (push) Successful in 5s
CI Pipeline / Frontend Lint & Type Check (push) Successful in 15s
CI Pipeline / Build .deb & Release (push) Has been skipped
2026-06-09 16:06:40 -05:00
0222b1677d fix: run migrations as patch_manager, remove broken reassign_ownership (#66)
Some checks failed
CI Pipeline / Rust Format Check (push) Successful in 10s
CI Pipeline / Clippy Lints (push) Successful in 51s
CI Pipeline / Rust Unit Tests (push) Failing after 1m32s
CI Pipeline / Security Audit (push) Successful in 5s
CI Pipeline / Frontend Lint & Type Check (push) Successful in 15s
CI Pipeline / Build .deb & Release (push) Has been skipped
Root cause: postinst ran sqlx migrate as postgres (superuser), creating ALL
database objects owned by postgres. When pm-web connects as patch_manager, it
cannot ALTER TABLE during migrations because it does not own them. The
reassign_ownership() function never worked because REASSIGN OWNED BY postgres
TO patch_manager fails for superuser-owned objects.

Fix: Create the database owned by patch_manager (already done) and run all
migrations as patch_manager via PGPASSWORD auth. When all objects are owned by
patch_manager from the start, pm-web can ALTER them during upgrades.

Changes:
- Add psql_run_as_pm() helper that authenticates as patch_manager via PGPASSWORD
- Replace all psql_run_db calls in apply_migrations() with psql_run_as_pm
- Remove reassign_ownership() function entirely (it never worked)
- Remove reassign_ownership call from main()
- Add ALTER DEFAULT PRIVILEGES FOR ROLE postgres in setup_database() as safety
  net for any future migration that might run as postgres
- Upgrade GRANT USAGE/CREATE to GRANT ALL PRIVILEGES on schema public
- Keep pgcrypto extension creation as postgres (requires superuser)
- Renumber sections after removing reassign_ownership

Proven on live LPM system: service active, port 443 listening, all tables
owned by patch_manager.
2026-06-09 15:56:36 -05:00
dda2fd3b0e chore: bump version to 1.1.10 (#65)
Some checks failed
CI Pipeline / Rust Format Check (push) Successful in 3s
CI Pipeline / Clippy Lints (push) Successful in 51s
CI Pipeline / Rust Unit Tests (push) Failing after 1m52s
CI Pipeline / Security Audit (push) Successful in 4s
CI Pipeline / Frontend Lint & Type Check (push) Successful in 14s
CI Pipeline / Build .deb & Release (push) Has been skipped
2026-06-09 14:49:54 -05:00
3b3e129663 fix: reassign DB object ownership to patch_manager after migrations (#64)
The postinst script runs migrations as the postgres superuser, which
means all created tables, enum types, and sequences are owned by
postgres. When pm-web connects as patch_manager and tries to ALTER
tables during upgrades, it fails with 'must be owner of table groups'.

Add reassign_ownership() function that runs after apply_migrations()
and before systemctl start. This function:
- REASSIGN OWNED BY postgres TO patch_manager (tables, types, sequences)
- ALTER SCHEMA public OWNER TO patch_manager
- GRANT ALL PRIVILEGES on database, schema, tables, sequences, functions
- ALTER DEFAULT PRIVILEGES for future objects in public schema

Renumbered sections 6-10 to 6-12 to accommodate the new function.
2026-06-09 14:11:20 -05:00
6 changed files with 62 additions and 17 deletions

View File

@ -12,7 +12,7 @@ members = [
] ]
[workspace.package] [workspace.package]
version = "1.1.9" version = "1.1.11"
edition = "2021" edition = "2021"
authors = ["Echo <echo@moon-dragon.us>"] authors = ["Echo <echo@moon-dragon.us>"]
license = "MIT" license = "MIT"

12
debian/changelog vendored
View File

@ -1,3 +1,15 @@
linux-patch-manager (1.1.11-1) unstable; urgency=low
* Release v1.1.11
-- git-echo <git-echo@moon-dragon.us> Tue, 09 Jun 2026 15:57:10 -0500
linux-patch-manager (1.1.10-1) unstable; urgency=low
* Release v1.1.10
-- git-echo <git-echo@moon-dragon.us> Tue, 09 Jun 2026 14:11:31 -0500
linux-patch-manager (1.1.9-1) unstable; urgency=low linux-patch-manager (1.1.9-1) unstable; urgency=low
* Release v1.1.9 * Release v1.1.9

2
debian/control vendored
View File

@ -1,5 +1,5 @@
Package: linux-patch-manager Package: linux-patch-manager
Version: 1.1.9-1 Version: 1.1.11-1
Architecture: amd64 Architecture: amd64
Maintainer: Moon Dragon <echo@moon-dragon.us> Maintainer: Moon Dragon <echo@moon-dragon.us>
Installed-Size: 45000 Installed-Size: 45000

59
debian/postinst vendored
View File

@ -34,10 +34,16 @@ psql_run() {
} }
psql_run_db() { psql_run_db() {
# Run SQL against the patch_manager database # Run SQL against the patch_manager database as postgres superuser
sudo -u postgres psql -v ON_ERROR_STOP=1 -d "${DB_NAME}" "$@" 2>/dev/null sudo -u postgres psql -v ON_ERROR_STOP=1 -d "${DB_NAME}" "$@" 2>/dev/null
} }
psql_run_as_pm() {
# Run SQL against the patch_manager database as patch_manager user
# Requires PGPASSWORD to be set in the calling environment
PGPASSWORD="${PGPASSWORD}" psql -v ON_ERROR_STOP=1 -U "${DB_USER}" -h localhost -d "${DB_NAME}" "$@" 2>/dev/null
}
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# 1. Create service user (idempotent) # 1. Create service user (idempotent)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@ -140,23 +146,47 @@ setup_database() {
info "Database '${DB_NAME}' already exists, skipping creation." info "Database '${DB_NAME}' already exists, skipping creation."
fi fi
# Grant permissions (idempotent) # Grant full permissions so patch_manager owns and manages all objects
psql_run_db -c "GRANT USAGE ON SCHEMA public TO ${DB_USER};" 2>/dev/null || true psql_run_db -c "GRANT ALL PRIVILEGES ON SCHEMA public TO ${DB_USER};" 2>/dev/null || true
psql_run_db -c "GRANT CREATE ON SCHEMA public TO ${DB_USER};" 2>/dev/null || true
psql_run_db -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER};" 2>/dev/null || true psql_run_db -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER};" 2>/dev/null || true
# If any future migration runs as postgres, ensure objects are still accessible by patch_manager
psql_run_db -c "ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO ${DB_USER};" 2>/dev/null || true
psql_run_db -c "ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO ${DB_USER};" 2>/dev/null || true
psql_run_db -c "ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO ${DB_USER};" 2>/dev/null || true
} }
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# 5. Apply database migrations (idempotent) # 5. Apply database migrations (idempotent)
# Migrations run as patch_manager so all created objects are owned by
# patch_manager — this avoids the ownership conflicts that occur when
# postgres-owned objects need ALTER TABLE by a non-superuser.
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
apply_migrations() { apply_migrations() {
info "Applying database migrations..." info "Applying database migrations..."
# Ensure pgcrypto extension is available # Get the DB password for patch_manager authentication
local db_password=""
if [[ -f /tmp/.pm-db-password-new ]]; then
db_password=$(cat /tmp/.pm-db-password-new)
else
# Fallback: extract from config
local config_file="${CONFIG_DIR}/config.toml"
if [[ -f "${config_file}" ]]; then
db_password=$(sed -n 's|^url = "postgres://[^:]*:\(.*\)@localhost.*"|\1|p' "${config_file}" | head -1)
fi
if [[ -z "${db_password}" || "${db_password}" == "CHANGEME" ]]; then
error "Cannot determine DB password for migrations."
return 1
fi
fi
export PGPASSWORD="${db_password}"
# Ensure pgcrypto extension is available (requires superuser)
psql_run_db -c "CREATE EXTENSION IF NOT EXISTS pgcrypto;" 2>/dev/null || true psql_run_db -c "CREATE EXTENSION IF NOT EXISTS pgcrypto;" 2>/dev/null || true
# Create migration tracking table if not exists # Create migration tracking table if not exists (run as patch_manager)
psql_run_db <<'MIGSQL' psql_run_as_pm <<'MIGSQL'
CREATE TABLE IF NOT EXISTS _migrations ( CREATE TABLE IF NOT EXISTS _migrations (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
filename TEXT NOT NULL UNIQUE, filename TEXT NOT NULL UNIQUE,
@ -167,11 +197,11 @@ MIGSQL
# Handle upgrade from pre-migration-tracking versions: # Handle upgrade from pre-migration-tracking versions:
# If tables exist but _migrations is empty, mark all existing migrations as applied. # If tables exist but _migrations is empty, mark all existing migrations as applied.
local migration_count local migration_count
migration_count=$(psql_run_db -t -A -c "SELECT COUNT(*) FROM _migrations;" 2>/dev/null || echo "0") migration_count=$(psql_run_as_pm -t -A -c "SELECT COUNT(*) FROM _migrations;" 2>/dev/null || echo "0")
migration_count="${migration_count// /}" migration_count="${migration_count// /}"
local tables_exist local tables_exist
tables_exist=$(psql_run_db -t -A -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='public' AND table_name='users';" 2>/dev/null || echo "0") tables_exist=$(psql_run_as_pm -t -A -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='public' AND table_name='users';" 2>/dev/null || echo "0")
tables_exist="${tables_exist// /}" tables_exist="${tables_exist// /}"
if [[ "${migration_count}" == "0" && "${tables_exist}" -gt 0 ]]; then if [[ "${migration_count}" == "0" && "${tables_exist}" -gt 0 ]]; then
@ -179,7 +209,7 @@ MIGSQL
for sql_file in $(ls "${MIGRATION_DIR}"/*.sql 2>/dev/null | sort); do for sql_file in $(ls "${MIGRATION_DIR}"/*.sql 2>/dev/null | sort); do
local fname local fname
fname=$(basename "${sql_file}") fname=$(basename "${sql_file}")
psql_run_db -c "INSERT INTO _migrations (filename) VALUES ('${fname}') ON CONFLICT (filename) DO NOTHING;" 2>/dev/null || true psql_run_as_pm -c "INSERT INTO _migrations (filename) VALUES ('${fname}') ON CONFLICT (filename) DO NOTHING;" 2>/dev/null || true
done done
fi fi
@ -191,7 +221,7 @@ MIGSQL
fname=$(basename "${sql_file}") fname=$(basename "${sql_file}")
local already_applied local already_applied
already_applied=$(psql_run_db -t -A -c "SELECT COUNT(*) FROM _migrations WHERE filename='${fname}';" 2>/dev/null || echo "0") already_applied=$(psql_run_as_pm -t -A -c "SELECT COUNT(*) FROM _migrations WHERE filename='${fname}';" 2>/dev/null || echo "0")
already_applied="${already_applied// /}" already_applied="${already_applied// /}"
if [[ "${already_applied}" -gt 0 ]]; then if [[ "${already_applied}" -gt 0 ]]; then
@ -200,15 +230,18 @@ MIGSQL
fi fi
info " Applying migration: ${fname}" info " Applying migration: ${fname}"
if psql_run_db -f "${sql_file}"; then if psql_run_as_pm -f "${sql_file}"; then
psql_run_db -c "INSERT INTO _migrations (filename) VALUES ('${fname}');" 2>/dev/null || true psql_run_as_pm -c "INSERT INTO _migrations (filename) VALUES ('${fname}');" 2>/dev/null || true
applied=$((applied + 1)) applied=$((applied + 1))
else else
error " Failed to apply migration: ${fname}" error " Failed to apply migration: ${fname}"
unset PGPASSWORD
return 1 return 1
fi fi
done done
unset PGPASSWORD
if [[ "${applied}" -gt 0 ]]; then if [[ "${applied}" -gt 0 ]]; then
info "Applied ${applied} new migration(s), skipped ${skipped} already applied." info "Applied ${applied} new migration(s), skipped ${skipped} already applied."
else else

View File

@ -1,7 +1,7 @@
{ {
"name": "patch-manager-ui", "name": "patch-manager-ui",
"private": true, "private": true,
"version": "1.1.9", "version": "1.1.11",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@ -22,7 +22,7 @@ warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
error() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; } error() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; }
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VERSION="1.1.9" VERSION="1.1.11"
RELEASE="1" RELEASE="1"
PKG_NAME="linux-patch-manager" PKG_NAME="linux-patch-manager"
DEB_NAME="${PKG_NAME}_${VERSION}-${RELEASE}_amd64.deb" DEB_NAME="${PKG_NAME}_${VERSION}-${RELEASE}_amd64.deb"