Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 583db2666a | |||
| f55cfbc7a1 | |||
| 0222b1677d | |||
| dda2fd3b0e | |||
| 3b3e129663 | |||
| 8acff754e8 | |||
| 4cac290502 | |||
| ec41091721 | |||
| 26f87ebc20 | |||
| a1a8eab41a |
35
.github/workflows/ci.yml
vendored
35
.github/workflows/ci.yml
vendored
@ -9,6 +9,7 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@ -19,7 +20,7 @@ jobs:
|
|||||||
name: Rust Format
|
name: Rust Format
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
with:
|
||||||
components: rustfmt
|
components: rustfmt
|
||||||
@ -30,7 +31,7 @@ jobs:
|
|||||||
name: Clippy
|
name: Clippy
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
with:
|
||||||
components: clippy
|
components: clippy
|
||||||
@ -43,7 +44,7 @@ jobs:
|
|||||||
name: Rust Tests
|
name: Rust Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
@ -54,7 +55,7 @@ jobs:
|
|||||||
name: Security Audit
|
name: Security Audit
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
- run: cargo install cargo-audit && cargo audit
|
- run: cargo install cargo-audit && cargo audit
|
||||||
|
|
||||||
@ -62,11 +63,11 @@ jobs:
|
|||||||
name: Secret scanning
|
name: Secret scanning
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Gitleaks
|
- name: Gitleaks
|
||||||
uses: gitleaks/gitleaks-action@v2
|
uses: gitleaks/gitleaks-action@v3
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
@ -74,9 +75,9 @@ jobs:
|
|||||||
name: Frontend Lint
|
name: Frontend Lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '20'
|
||||||
- name: Install & Lint
|
- name: Install & Lint
|
||||||
@ -87,7 +88,7 @@ jobs:
|
|||||||
needs: [rust-format, clippy, rust-test, security-audit, frontend-lint]
|
needs: [rust-format, clippy, rust-test, security-audit, frontend-lint]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Free disk space
|
- name: Free disk space
|
||||||
@ -103,7 +104,7 @@ jobs:
|
|||||||
- name: Strip binaries
|
- name: Strip binaries
|
||||||
run: strip target/release/pm-web target/release/pm-worker
|
run: strip target/release/pm-web target/release/pm-worker
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '20'
|
||||||
- name: Build frontend
|
- name: Build frontend
|
||||||
@ -125,7 +126,7 @@ jobs:
|
|||||||
echo "EOF" >> $GITHUB_OUTPUT
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
- name: Upload to GitHub Release
|
- name: Upload to GitHub Release
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v3
|
||||||
with:
|
with:
|
||||||
body: ${{ steps.release_notes.outputs.notes }}
|
body: ${{ steps.release_notes.outputs.notes }}
|
||||||
files: linux-patch-manager_*.deb
|
files: linux-patch-manager_*.deb
|
||||||
@ -137,16 +138,16 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v4
|
||||||
|
|
||||||
- name: Log in to GitHub Container Registry
|
- name: Log in to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v4
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
@ -154,7 +155,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Extract Docker metadata
|
- name: Extract Docker metadata
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v6
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/draco-lunaris/linux-patch-manager
|
images: ghcr.io/draco-lunaris/linux-patch-manager
|
||||||
tags: |
|
tags: |
|
||||||
@ -164,7 +165,7 @@ jobs:
|
|||||||
type=sha
|
type=sha
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
|
|||||||
@ -12,7 +12,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "1.1.7"
|
version = "1.1.12"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Echo <echo@moon-dragon.us>"]
|
authors = ["Echo <echo@moon-dragon.us>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@ -49,7 +49,8 @@ health_check_poll_interval_secs = 300
|
|||||||
# Maximum concurrent mTLS agent calls (Tokio Semaphore)
|
# Maximum concurrent mTLS agent calls (Tokio Semaphore)
|
||||||
max_concurrent_agent_calls = 64
|
max_concurrent_agent_calls = 64
|
||||||
|
|
||||||
# Worker heartbeat write interval (seconds)
|
# Worker heartbeat write interval (seconds). Default: 300 = 5 minutes
|
||||||
|
heartbeat_interval_secs = 300
|
||||||
|
|
||||||
# WS relay HTTP polling fallback interval (seconds). When WebSocket connection to
|
# WS relay HTTP polling fallback interval (seconds). When WebSocket connection to
|
||||||
# an agent fails, the relay falls back to polling the agent's HTTP API at this
|
# an agent fails, the relay falls back to polling the agent's HTTP API at this
|
||||||
|
|||||||
@ -101,7 +101,8 @@ pub struct WorkerConfig {
|
|||||||
pub health_check_poll_interval_secs: u64,
|
pub health_check_poll_interval_secs: u64,
|
||||||
/// Maximum concurrent agent calls
|
/// Maximum concurrent agent calls
|
||||||
pub max_concurrent_agent_calls: usize,
|
pub max_concurrent_agent_calls: usize,
|
||||||
/// Worker heartbeat interval in seconds
|
/// Worker heartbeat interval in seconds (default: 300 = 5 min)
|
||||||
|
#[serde(default = "default_heartbeat_interval")]
|
||||||
pub heartbeat_interval_secs: u64,
|
pub heartbeat_interval_secs: u64,
|
||||||
/// WS relay HTTP polling fallback interval in seconds (default: 10)
|
/// WS relay HTTP polling fallback interval in seconds (default: 10)
|
||||||
pub ws_relay_poll_interval_secs: u64,
|
pub ws_relay_poll_interval_secs: u64,
|
||||||
@ -255,6 +256,10 @@ fn default_health_check_poll_interval() -> u64 {
|
|||||||
300
|
300
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_heartbeat_interval() -> u64 {
|
||||||
|
300
|
||||||
|
}
|
||||||
|
|
||||||
fn default_sso_callback_url() -> String {
|
fn default_sso_callback_url() -> String {
|
||||||
"http://localhost:5173/auth/sso/callback".to_string()
|
"http://localhost:5173/auth/sso/callback".to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
30
debian/changelog
vendored
30
debian/changelog
vendored
@ -1,3 +1,33 @@
|
|||||||
|
linux-patch-manager (1.1.12-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* Release v1.1.12
|
||||||
|
|
||||||
|
-- git-echo <git-echo@moon-dragon.us> Tue, 09 Jun 2026 22:14:03 -0500
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
* Release v1.1.9
|
||||||
|
|
||||||
|
-- git-echo <git-echo@moon-dragon.us> Tue, 09 Jun 2026 13:05:59 -0500
|
||||||
|
|
||||||
|
linux-patch-manager (1.1.8-1) unstable; urgency=low
|
||||||
|
|
||||||
|
* Release v1.1.8
|
||||||
|
|
||||||
|
-- git-echo <git-echo@moon-dragon.us> Tue, 09 Jun 2026 11:47:58 -0500
|
||||||
|
|
||||||
linux-patch-manager (1.1.7-1) unstable; urgency=low
|
linux-patch-manager (1.1.7-1) unstable; urgency=low
|
||||||
|
|
||||||
* Release v1.1.7
|
* Release v1.1.7
|
||||||
|
|||||||
2
debian/control
vendored
2
debian/control
vendored
@ -1,5 +1,5 @@
|
|||||||
Package: linux-patch-manager
|
Package: linux-patch-manager
|
||||||
Version: 1.1.7-1
|
Version: 1.1.12-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
|
||||||
|
|||||||
296
debian/postinst
vendored
296
debian/postinst
vendored
@ -7,6 +7,9 @@ set -e
|
|||||||
# Fully automated: apt install ./linux-patch-manager_X.X.X-1_amd64.deb
|
# Fully automated: apt install ./linux-patch-manager_X.X.X-1_amd64.deb
|
||||||
# results in a running service with a printed admin password.
|
# results in a running service with a printed admin password.
|
||||||
# All steps are idempotent (safe to re-run on upgrade).
|
# All steps are idempotent (safe to re-run on upgrade).
|
||||||
|
#
|
||||||
|
# Migrations are handled by the application via sqlx on startup.
|
||||||
|
# This script only creates the database, user, and grants.
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
@ -22,7 +25,6 @@ error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
|
|||||||
DB_NAME="patch_manager"
|
DB_NAME="patch_manager"
|
||||||
DB_USER="patch_manager"
|
DB_USER="patch_manager"
|
||||||
CONFIG_DIR="/etc/patch-manager"
|
CONFIG_DIR="/etc/patch-manager"
|
||||||
MIGRATION_DIR="/usr/share/patch-manager/migrations"
|
|
||||||
ADMIN_PASSWORD_FILE="/etc/patch-manager/admin-password.txt"
|
ADMIN_PASSWORD_FILE="/etc/patch-manager/admin-password.txt"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -34,7 +36,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +91,7 @@ wait_for_postgresql() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# 4. Create PostgreSQL user and database (idempotent)
|
# 4. Create PostgreSQL user, database, and grants (idempotent)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
setup_database() {
|
setup_database() {
|
||||||
info "Setting up PostgreSQL database and user..."
|
info "Setting up PostgreSQL database and user..."
|
||||||
@ -107,7 +109,27 @@ setup_database() {
|
|||||||
# Store password for config generation
|
# Store password for config generation
|
||||||
echo "${db_password}" > /tmp/.pm-db-password-new
|
echo "${db_password}" > /tmp/.pm-db-password-new
|
||||||
else
|
else
|
||||||
info "PostgreSQL user '${DB_USER}' already exists, skipping creation."
|
info "PostgreSQL user '${DB_USER}' already exists."
|
||||||
|
# Recover the DB password: try from existing config, or generate new.
|
||||||
|
local config_file="${CONFIG_DIR}/config.toml"
|
||||||
|
local existing_pw=""
|
||||||
|
if [[ -f "${config_file}" ]]; then
|
||||||
|
# Extract password from URL: postgres://user:PASSWORD@host/db
|
||||||
|
# Use @localhost anchor so passwords containing @ are extracted correctly.
|
||||||
|
existing_pw=$(sed -n 's|^url = "postgres://[^:]*:\(.*\)@localhost.*"|\1|p' "${config_file}" | head -1)
|
||||||
|
fi
|
||||||
|
if [[ -n "${existing_pw}" && "${existing_pw}" != "CHANGEME" ]]; then
|
||||||
|
# Config has a real password — sync it to PostgreSQL so the app can connect.
|
||||||
|
psql_run -c "ALTER ROLE ${DB_USER} WITH PASSWORD '${existing_pw}';" 2>/dev/null || true
|
||||||
|
echo "${existing_pw}" > /tmp/.pm-db-password-new
|
||||||
|
info "Synced DB password from existing config to PostgreSQL."
|
||||||
|
else
|
||||||
|
# No config or CHANGEME — generate a fresh password and update PostgreSQL.
|
||||||
|
db_password=$(openssl rand -base64 32 | tr -dc 'A-Za-z0-9' | head -c 32)
|
||||||
|
psql_run -c "ALTER ROLE ${DB_USER} WITH PASSWORD '${db_password}';" 2>/dev/null || true
|
||||||
|
echo "${db_password}" > /tmp/.pm-db-password-new
|
||||||
|
info "Generated new DB password for existing user."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create database if not exists
|
# Create database if not exists
|
||||||
@ -120,84 +142,145 @@ setup_database() {
|
|||||||
info "Database '${DB_NAME}' already exists, skipping creation."
|
info "Database '${DB_NAME}' already exists, skipping creation."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Grant permissions (idempotent)
|
# Ensure pgcrypto extension is available (required by application migrations)
|
||||||
psql_run_db -c "GRANT USAGE 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
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# 5. Apply database migrations (idempotent)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
apply_migrations() {
|
|
||||||
info "Applying database migrations..."
|
|
||||||
|
|
||||||
# Ensure pgcrypto extension is available
|
|
||||||
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
|
# Grant full permissions so patch_manager owns and manages all objects
|
||||||
psql_run_db <<'MIGSQL'
|
psql_run_db -c "GRANT ALL PRIVILEGES ON SCHEMA public TO ${DB_USER};" 2>/dev/null || true
|
||||||
CREATE TABLE IF NOT EXISTS _migrations (
|
psql_run_db -c "GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER};" 2>/dev/null || true
|
||||||
id SERIAL PRIMARY KEY,
|
# If any future migration runs as postgres, ensure objects are still accessible by patch_manager
|
||||||
filename TEXT NOT NULL UNIQUE,
|
psql_run_db -c "ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO ${DB_USER};" 2>/dev/null || true
|
||||||
applied_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
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
|
||||||
MIGSQL
|
}
|
||||||
|
|
||||||
# Handle upgrade from pre-migration-tracking versions:
|
# ---------------------------------------------------------------------------
|
||||||
# If tables exist but _migrations is empty, mark all existing migrations as applied.
|
# 5. Write config.toml with DB URL
|
||||||
local migration_count
|
# ---------------------------------------------------------------------------
|
||||||
migration_count=$(psql_run_db -t -A -c "SELECT COUNT(*) FROM _migrations;" 2>/dev/null || echo "0")
|
# Handles three scenarios:
|
||||||
migration_count="${migration_count// /}"
|
# 1. No config file → create from example with real DB password
|
||||||
|
# 2. Config exists with CHANGEME → replace CHANGEME with real DB password
|
||||||
|
# 3. Config exists with real password → leave it alone (upgrade)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
write_config() {
|
||||||
|
local config_file="${CONFIG_DIR}/config.toml"
|
||||||
|
|
||||||
local tables_exist
|
# Resolve the DB password to use: from setup_database() or generate fresh.
|
||||||
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")
|
local db_password=""
|
||||||
tables_exist="${tables_exist// /}"
|
if [[ -f /tmp/.pm-db-password-new ]]; then
|
||||||
|
db_password=$(cat /tmp/.pm-db-password-new)
|
||||||
if [[ "${migration_count}" == "0" && "${tables_exist}" -gt 0 ]]; then
|
|
||||||
info "Existing database detected — marking all shipped migrations as already applied."
|
|
||||||
for sql_file in $(ls "${MIGRATION_DIR}"/*.sql 2>/dev/null | sort); do
|
|
||||||
local fname
|
|
||||||
fname=$(basename "${sql_file}")
|
|
||||||
psql_run_db -c "INSERT INTO _migrations (filename) VALUES ('${fname}') ON CONFLICT (filename) DO NOTHING;" 2>/dev/null || true
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Apply each migration in sorted order, skipping already-applied ones
|
if [[ -f "${config_file}" ]]; then
|
||||||
local applied=0
|
# Check if the config still has the CHANGEME placeholder
|
||||||
local skipped=0
|
if grep -q 'CHANGEME' "${config_file}"; then
|
||||||
for sql_file in $(ls "${MIGRATION_DIR}"/*.sql 2>/dev/null | sort); do
|
if [[ -z "${db_password}" ]]; then
|
||||||
local fname
|
# No password from setup_database() — generate a fresh one
|
||||||
fname=$(basename "${sql_file}")
|
db_password=$(openssl rand -base64 32 | tr -dc 'A-Za-z0-9' | head -c 32)
|
||||||
|
psql_run -c "ALTER ROLE ${DB_USER} WITH PASSWORD '${db_password}';" 2>/dev/null || true
|
||||||
local already_applied
|
fi
|
||||||
already_applied=$(psql_run_db -t -A -c "SELECT COUNT(*) FROM _migrations WHERE filename='${fname}';" 2>/dev/null || echo "0")
|
info "Replacing CHANGEME placeholder in existing config with real DB password."
|
||||||
already_applied="${already_applied// /}"
|
sed -i "s|postgres://patch_manager:CHANGEME@localhost/patch_manager|postgres://${DB_USER}:${db_password}@localhost/${DB_NAME}|" "${config_file}"
|
||||||
|
|
||||||
if [[ "${already_applied}" -gt 0 ]]; then
|
|
||||||
skipped=$((skipped + 1))
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
info " Applying migration: ${fname}"
|
|
||||||
if psql_run_db -f "${sql_file}"; then
|
|
||||||
psql_run_db -c "INSERT INTO _migrations (filename) VALUES ('${fname}');" 2>/dev/null || true
|
|
||||||
applied=$((applied + 1))
|
|
||||||
else
|
else
|
||||||
error " Failed to apply migration: ${fname}"
|
info "Config file ${config_file} already exists with a real password, leaving it unchanged."
|
||||||
return 1
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
if [[ "${applied}" -gt 0 ]]; then
|
|
||||||
info "Applied ${applied} new migration(s), skipped ${skipped} already applied."
|
|
||||||
else
|
else
|
||||||
info "All migrations up to date (${skipped} already applied)."
|
# No config file — create from example
|
||||||
|
if [[ -z "${db_password}" ]]; then
|
||||||
|
db_password=$(openssl rand -base64 32 | tr -dc 'A-Za-z0-9' | head -c 32)
|
||||||
|
psql_run -c "ALTER ROLE ${DB_USER} WITH PASSWORD '${db_password}';" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "Writing configuration file..."
|
||||||
|
cp /usr/share/patch-manager/config.example.toml "${config_file}"
|
||||||
|
sed -i "s|postgres://patch_manager:CHANGEME@localhost/patch_manager|postgres://${DB_USER}:${db_password}@localhost/${DB_NAME}|" "${config_file}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
chown patch-manager:patch-manager "${config_file}"
|
||||||
|
chmod 640 "${config_file}"
|
||||||
|
info "Configuration written to ${config_file}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# 6. Generate JWT keys (idempotent)
|
||||||
|
# Only generates if missing; regenerates verify.pem from signing.pem if lost.
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
generate_jwt_keys() {
|
||||||
|
if [[ ! -f "${CONFIG_DIR}/jwt/signing.pem" ]]; then
|
||||||
|
info "Generating Ed25519 JWT signing key..."
|
||||||
|
openssl genpkey -algorithm ed25519 -out "${CONFIG_DIR}/jwt/signing.pem" 2>/dev/null
|
||||||
|
openssl pkey -in "${CONFIG_DIR}/jwt/signing.pem" -pubout -out "${CONFIG_DIR}/jwt/verify.pem" 2>/dev/null
|
||||||
|
chown patch-manager:patch-manager "${CONFIG_DIR}/jwt/signing.pem" "${CONFIG_DIR}/jwt/verify.pem"
|
||||||
|
chmod 600 "${CONFIG_DIR}/jwt/signing.pem"
|
||||||
|
chmod 644 "${CONFIG_DIR}/jwt/verify.pem"
|
||||||
|
info "JWT keys generated."
|
||||||
|
elif [[ ! -f "${CONFIG_DIR}/jwt/verify.pem" ]]; then
|
||||||
|
info "Regenerating missing JWT verification key from existing signing key..."
|
||||||
|
openssl pkey -in "${CONFIG_DIR}/jwt/signing.pem" -pubout -out "${CONFIG_DIR}/jwt/verify.pem" 2>/dev/null
|
||||||
|
chown patch-manager:patch-manager "${CONFIG_DIR}/jwt/verify.pem"
|
||||||
|
chmod 644 "${CONFIG_DIR}/jwt/verify.pem"
|
||||||
|
info "JWT verification key regenerated."
|
||||||
|
else
|
||||||
|
info "JWT keys already exist, skipping."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# 6. Generate admin password and update database
|
# 7. Enable and start services
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
enable_and_start_services() {
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
# Enable the target (which pulls in web + worker)
|
||||||
|
systemctl enable patch-manager.target 2>/dev/null || true
|
||||||
|
|
||||||
|
# Enable individual services so they survive a reboot
|
||||||
|
systemctl enable patch-manager-web.service patch-manager-worker.service 2>/dev/null || true
|
||||||
|
|
||||||
|
# Start or restart services
|
||||||
|
if systemctl is-active --quiet patch-manager.target 2>/dev/null; then
|
||||||
|
info "Restarting patch-manager services (upgrade)..."
|
||||||
|
systemctl restart patch-manager.target 2>/dev/null || true
|
||||||
|
else
|
||||||
|
info "Starting patch-manager services..."
|
||||||
|
systemctl start patch-manager.target 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# 8. Wait for pm-web service to be healthy
|
||||||
|
# The application runs database migrations via sqlx on startup.
|
||||||
|
# We must wait for it to be ready before generating the admin password,
|
||||||
|
# since the users table won't exist until migrations complete.
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
wait_for_service_healthy() {
|
||||||
|
info "Waiting for pm-web service to become healthy (migrations run on startup)..."
|
||||||
|
local retries=30
|
||||||
|
local delay=1
|
||||||
|
local i
|
||||||
|
for ((i = 1; i <= retries; i++)); do
|
||||||
|
# Check if the service is active
|
||||||
|
if systemctl is-active --quiet patch-manager-web.service 2>/dev/null; then
|
||||||
|
# Service is active — try a health check on the HTTPS port
|
||||||
|
if curl -skf https://localhost:443/ >/dev/null 2>&1 || \
|
||||||
|
curl -skf https://localhost:8443/ >/dev/null 2>&1; then
|
||||||
|
info "pm-web is healthy."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
warn "pm-web not ready yet (attempt ${i}/${retries}), waiting ${delay}s..."
|
||||||
|
sleep "${delay}"
|
||||||
|
done
|
||||||
|
error "pm-web did not become healthy after $((retries * delay)) seconds."
|
||||||
|
error "Admin password generation may fail because the users table may not exist yet."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# 9. Generate admin password and update database
|
||||||
|
# Must run AFTER the service has started and run migrations,
|
||||||
|
# because the users table is created by sqlx migrations.
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
generate_admin_password() {
|
generate_admin_password() {
|
||||||
info "Generating admin password..."
|
info "Generating admin password..."
|
||||||
@ -248,77 +331,6 @@ generate_admin_password() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# 7. Write config.toml with DB URL (only if file doesn't exist)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
write_config() {
|
|
||||||
local config_file="${CONFIG_DIR}/config.toml"
|
|
||||||
|
|
||||||
if [[ -f "${config_file}" ]]; then
|
|
||||||
info "Config file ${config_file} already exists, not overwriting."
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
info "Writing configuration file..."
|
|
||||||
|
|
||||||
# Get the DB password — use the one we just generated if we created the user
|
|
||||||
local db_password=""
|
|
||||||
if [[ -f /tmp/.pm-db-password-new ]]; then
|
|
||||||
db_password=$(cat /tmp/.pm-db-password-new)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If we don't have a password (user already existed), generate a new one
|
|
||||||
# and update the PostgreSQL user so we can connect
|
|
||||||
if [[ -z "${db_password}" ]]; then
|
|
||||||
db_password=$(openssl rand -base64 32 | tr -dc 'A-Za-z0-9' | head -c 32)
|
|
||||||
psql_run -c "ALTER ROLE ${DB_USER} WITH PASSWORD '${db_password}';" 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Copy example config and set the DB URL
|
|
||||||
cp /usr/share/patch-manager/config.example.toml "${config_file}"
|
|
||||||
sed -i "s|postgres://patch_manager:CHANGEME@localhost/patch_manager|postgres://${DB_USER}:${db_password}@localhost/${DB_NAME}|" "${config_file}"
|
|
||||||
chown patch-manager:patch-manager "${config_file}"
|
|
||||||
chmod 640 "${config_file}"
|
|
||||||
|
|
||||||
info "Configuration written to ${config_file}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# 8. Generate JWT keys (idempotent)
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
generate_jwt_keys() {
|
|
||||||
if [[ ! -f "${CONFIG_DIR}/jwt/signing.pem" ]]; then
|
|
||||||
info "Generating Ed25519 JWT signing key..."
|
|
||||||
openssl genpkey -algorithm ed25519 -out "${CONFIG_DIR}/jwt/signing.pem" 2>/dev/null
|
|
||||||
openssl pkey -in "${CONFIG_DIR}/jwt/signing.pem" -pubout -out "${CONFIG_DIR}/jwt/verify.pem" 2>/dev/null
|
|
||||||
chown patch-manager:patch-manager "${CONFIG_DIR}/jwt/signing.pem" "${CONFIG_DIR}/jwt/verify.pem"
|
|
||||||
chmod 600 "${CONFIG_DIR}/jwt/signing.pem"
|
|
||||||
chmod 644 "${CONFIG_DIR}/jwt/verify.pem"
|
|
||||||
info "JWT keys generated."
|
|
||||||
else
|
|
||||||
info "JWT signing key already exists, skipping."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# 9. Enable and start services
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
enable_and_start_services() {
|
|
||||||
systemctl daemon-reload
|
|
||||||
|
|
||||||
# Enable the target (which pulls in web + worker)
|
|
||||||
systemctl enable patch-manager.target 2>/dev/null || true
|
|
||||||
|
|
||||||
# Start or restart services
|
|
||||||
if systemctl is-active --quiet patch-manager.target 2>/dev/null; then
|
|
||||||
info "Restarting patch-manager services (upgrade)..."
|
|
||||||
systemctl restart patch-manager.target 2>/dev/null || true
|
|
||||||
else
|
|
||||||
info "Starting patch-manager services..."
|
|
||||||
systemctl start patch-manager.target 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# 10. Install backup cron (idempotent)
|
# 10. Install backup cron (idempotent)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@ -338,11 +350,11 @@ case "$1" in
|
|||||||
create_directories
|
create_directories
|
||||||
wait_for_postgresql
|
wait_for_postgresql
|
||||||
setup_database
|
setup_database
|
||||||
apply_migrations
|
|
||||||
generate_admin_password
|
|
||||||
write_config
|
write_config
|
||||||
generate_jwt_keys
|
generate_jwt_keys
|
||||||
enable_and_start_services
|
enable_and_start_services
|
||||||
|
wait_for_service_healthy
|
||||||
|
generate_admin_password
|
||||||
install_backup_cron
|
install_backup_cron
|
||||||
|
|
||||||
# Clean up temp file
|
# Clean up temp file
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "patch-manager-ui",
|
"name": "patch-manager-ui",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.1.7",
|
"version": "1.1.12",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@ -12,31 +12,63 @@ CREATE EXTENSION IF NOT EXISTS "pg_trgm"; -- fuzzy text search on host names
|
|||||||
-- Enumerations
|
-- Enumerations
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TYPE user_role AS ENUM ('admin', 'operator');
|
DO $$ BEGIN
|
||||||
CREATE TYPE auth_provider AS ENUM ('local', 'azure_sso');
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'user_role') THEN
|
||||||
CREATE TYPE host_health_status AS ENUM ('pending', 'healthy', 'degraded', 'unreachable');
|
CREATE TYPE user_role AS ENUM ('admin', 'operator');
|
||||||
CREATE TYPE job_status AS ENUM ('queued', 'pending', 'running', 'succeeded', 'failed', 'cancelled');
|
END IF;
|
||||||
CREATE TYPE job_kind AS ENUM ('patch_apply', 'patch_remove', 'reboot', 'rollback');
|
END $$;
|
||||||
CREATE TYPE window_recurrence AS ENUM ('once', 'daily', 'weekly', 'monthly');
|
DO $$ BEGIN
|
||||||
CREATE TYPE cert_status AS ENUM ('active', 'revoked', 'expired');
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'auth_provider') THEN
|
||||||
CREATE TYPE audit_action AS ENUM (
|
CREATE TYPE auth_provider AS ENUM ('local', 'azure_sso');
|
||||||
'user_login', 'user_logout', 'user_login_failed',
|
END IF;
|
||||||
'user_created', 'user_deleted', 'user_updated',
|
END $$;
|
||||||
'host_registered', 'host_removed',
|
DO $$ BEGIN
|
||||||
'group_created', 'group_deleted',
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'host_health_status') THEN
|
||||||
'group_membership_changed',
|
CREATE TYPE host_health_status AS ENUM ('pending', 'healthy', 'degraded', 'unreachable');
|
||||||
'patch_job_created', 'patch_job_cancelled', 'patch_job_rollback',
|
END IF;
|
||||||
'maintenance_window_created', 'maintenance_window_updated', 'maintenance_window_deleted',
|
END $$;
|
||||||
'certificate_issued', 'certificate_renewed', 'certificate_revoked', 'certificate_downloaded',
|
DO $$ BEGIN
|
||||||
'config_changed',
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'job_status') THEN
|
||||||
'discovery_scan_started'
|
CREATE TYPE job_status AS ENUM ('queued', 'pending', 'running', 'succeeded', 'failed', 'cancelled');
|
||||||
);
|
END IF;
|
||||||
|
END $$;
|
||||||
|
DO $$ BEGIN
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'job_kind') THEN
|
||||||
|
CREATE TYPE job_kind AS ENUM ('patch_apply', 'patch_remove', 'reboot', 'rollback');
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
DO $$ BEGIN
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'window_recurrence') THEN
|
||||||
|
CREATE TYPE window_recurrence AS ENUM ('once', 'daily', 'weekly', 'monthly');
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
DO $$ BEGIN
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'cert_status') THEN
|
||||||
|
CREATE TYPE cert_status AS ENUM ('active', 'revoked', 'expired');
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
DO $$ BEGIN
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'audit_action') THEN
|
||||||
|
CREATE TYPE audit_action AS ENUM (
|
||||||
|
'user_login', 'user_logout', 'user_login_failed',
|
||||||
|
'user_created', 'user_deleted', 'user_updated',
|
||||||
|
'host_registered', 'host_removed',
|
||||||
|
'group_created', 'group_deleted',
|
||||||
|
'group_membership_changed',
|
||||||
|
'patch_job_created', 'patch_job_cancelled', 'patch_job_rollback',
|
||||||
|
'maintenance_window_created', 'maintenance_window_updated', 'maintenance_window_deleted',
|
||||||
|
'certificate_issued', 'certificate_renewed', 'certificate_revoked', 'certificate_downloaded',
|
||||||
|
'config_changed',
|
||||||
|
'discovery_scan_started'
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Groups (defined before users/hosts for FK ordering)
|
-- Groups (defined before users/hosts for FK ordering)
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE groups (
|
CREATE TABLE IF NOT EXISTS groups (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
name TEXT NOT NULL UNIQUE,
|
name TEXT NOT NULL UNIQUE,
|
||||||
description TEXT NOT NULL DEFAULT '',
|
description TEXT NOT NULL DEFAULT '',
|
||||||
@ -44,13 +76,13 @@ CREATE TABLE groups (
|
|||||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_groups_name ON groups (name);
|
CREATE INDEX IF NOT EXISTS idx_groups_name ON groups (name);
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Users
|
-- Users
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE users (
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
username TEXT NOT NULL UNIQUE,
|
username TEXT NOT NULL UNIQUE,
|
||||||
display_name TEXT NOT NULL DEFAULT '',
|
display_name TEXT NOT NULL DEFAULT '',
|
||||||
@ -73,28 +105,28 @@ CREATE TABLE users (
|
|||||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_users_email ON users (email);
|
CREATE INDEX IF NOT EXISTS idx_users_email ON users (email);
|
||||||
CREATE INDEX idx_users_azure_oid ON users (azure_oid) WHERE azure_oid IS NOT NULL;
|
CREATE INDEX IF NOT EXISTS idx_users_azure_oid ON users (azure_oid) WHERE azure_oid IS NOT NULL;
|
||||||
CREATE INDEX idx_users_role ON users (role);
|
CREATE INDEX IF NOT EXISTS idx_users_role ON users (role);
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- User <-> Group membership
|
-- User <-> Group membership
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE user_groups (
|
CREATE TABLE IF NOT EXISTS user_groups (
|
||||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
group_id UUID NOT NULL REFERENCES groups(id) ON DELETE CASCADE,
|
group_id UUID NOT NULL REFERENCES groups(id) ON DELETE CASCADE,
|
||||||
assigned_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
assigned_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
PRIMARY KEY (user_id, group_id)
|
PRIMARY KEY (user_id, group_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_user_groups_group ON user_groups (group_id);
|
CREATE INDEX IF NOT EXISTS idx_user_groups_group ON user_groups (group_id);
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Refresh Tokens
|
-- Refresh Tokens
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE refresh_tokens (
|
CREATE TABLE IF NOT EXISTS refresh_tokens (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
-- Stored as Argon2id hash of the opaque token bytes
|
-- Stored as Argon2id hash of the opaque token bytes
|
||||||
@ -109,14 +141,14 @@ CREATE TABLE refresh_tokens (
|
|||||||
ip_address INET
|
ip_address INET
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_refresh_tokens_user ON refresh_tokens (user_id);
|
CREATE INDEX IF NOT EXISTS idx_refresh_tokens_user ON refresh_tokens (user_id);
|
||||||
CREATE INDEX idx_refresh_tokens_expires ON refresh_tokens (expires_at) WHERE revoked = FALSE;
|
CREATE INDEX IF NOT EXISTS idx_refresh_tokens_expires ON refresh_tokens (expires_at) WHERE revoked = FALSE;
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Hosts
|
-- Hosts
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE hosts (
|
CREATE TABLE IF NOT EXISTS hosts (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
fqdn TEXT NOT NULL,
|
fqdn TEXT NOT NULL,
|
||||||
ip_address INET NOT NULL,
|
ip_address INET NOT NULL,
|
||||||
@ -136,28 +168,28 @@ CREATE TABLE hosts (
|
|||||||
CONSTRAINT hosts_fqdn_ip_unique UNIQUE (fqdn, ip_address)
|
CONSTRAINT hosts_fqdn_ip_unique UNIQUE (fqdn, ip_address)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_hosts_health_status ON hosts (health_status);
|
CREATE INDEX IF NOT EXISTS idx_hosts_health_status ON hosts (health_status);
|
||||||
CREATE INDEX idx_hosts_fqdn ON hosts USING gin (fqdn gin_trgm_ops);
|
CREATE INDEX IF NOT EXISTS idx_hosts_fqdn ON hosts USING gin (fqdn gin_trgm_ops);
|
||||||
CREATE INDEX idx_hosts_ip ON hosts (ip_address);
|
CREATE INDEX IF NOT EXISTS idx_hosts_ip ON hosts (ip_address);
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Host <-> Group membership
|
-- Host <-> Group membership
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE host_groups (
|
CREATE TABLE IF NOT EXISTS host_groups (
|
||||||
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
||||||
group_id UUID NOT NULL REFERENCES groups(id) ON DELETE CASCADE,
|
group_id UUID NOT NULL REFERENCES groups(id) ON DELETE CASCADE,
|
||||||
assigned_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
assigned_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
PRIMARY KEY (host_id, group_id)
|
PRIMARY KEY (host_id, group_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_host_groups_group ON host_groups (group_id);
|
CREATE INDEX IF NOT EXISTS idx_host_groups_group ON host_groups (group_id);
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Host Health Data (cached results from 5-min polls)
|
-- Host Health Data (cached results from 5-min polls)
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE host_health_data (
|
CREATE TABLE IF NOT EXISTS host_health_data (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
||||||
polled_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
polled_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
@ -166,14 +198,14 @@ CREATE TABLE host_health_data (
|
|||||||
payload JSONB NOT NULL DEFAULT '{}'
|
payload JSONB NOT NULL DEFAULT '{}'
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_host_health_host ON host_health_data (host_id, polled_at DESC);
|
CREATE INDEX IF NOT EXISTS idx_host_health_host ON host_health_data (host_id, polled_at DESC);
|
||||||
-- Retained for 30 days (pruned by worker)
|
-- Retained for 30 days (pruned by worker)
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Host Patch Data (cached results from 30-min polls)
|
-- Host Patch Data (cached results from 30-min polls)
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE host_patch_data (
|
CREATE TABLE IF NOT EXISTS host_patch_data (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
||||||
polled_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
polled_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
@ -184,14 +216,14 @@ CREATE TABLE host_patch_data (
|
|||||||
cve_count INTEGER NOT NULL DEFAULT 0
|
cve_count INTEGER NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_host_patch_host ON host_patch_data (host_id, polled_at DESC);
|
CREATE INDEX IF NOT EXISTS idx_host_patch_host ON host_patch_data (host_id, polled_at DESC);
|
||||||
-- Retained for 30 days (pruned by worker)
|
-- Retained for 30 days (pruned by worker)
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Maintenance Windows
|
-- Maintenance Windows
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE maintenance_windows (
|
CREATE TABLE IF NOT EXISTS maintenance_windows (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
||||||
label TEXT NOT NULL DEFAULT '',
|
label TEXT NOT NULL DEFAULT '',
|
||||||
@ -207,14 +239,14 @@ CREATE TABLE maintenance_windows (
|
|||||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_mw_host ON maintenance_windows (host_id);
|
CREATE INDEX IF NOT EXISTS idx_mw_host ON maintenance_windows (host_id);
|
||||||
CREATE INDEX idx_mw_start ON maintenance_windows (start_at) WHERE enabled = TRUE;
|
CREATE INDEX IF NOT EXISTS idx_mw_start ON maintenance_windows (start_at) WHERE enabled = TRUE;
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Patch Jobs
|
-- Patch Jobs
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE patch_jobs (
|
CREATE TABLE IF NOT EXISTS patch_jobs (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
kind job_kind NOT NULL DEFAULT 'patch_apply',
|
kind job_kind NOT NULL DEFAULT 'patch_apply',
|
||||||
status job_status NOT NULL DEFAULT 'queued',
|
status job_status NOT NULL DEFAULT 'queued',
|
||||||
@ -233,15 +265,15 @@ CREATE TABLE patch_jobs (
|
|||||||
completed_at TIMESTAMPTZ
|
completed_at TIMESTAMPTZ
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_patch_jobs_status ON patch_jobs (status);
|
CREATE INDEX IF NOT EXISTS idx_patch_jobs_status ON patch_jobs (status);
|
||||||
CREATE INDEX idx_patch_jobs_created ON patch_jobs (created_at DESC);
|
CREATE INDEX IF NOT EXISTS idx_patch_jobs_created ON patch_jobs (created_at DESC);
|
||||||
CREATE INDEX idx_patch_jobs_user ON patch_jobs (created_by_user_id);
|
CREATE INDEX IF NOT EXISTS idx_patch_jobs_user ON patch_jobs (created_by_user_id);
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Patch Job Hosts (per-host status within a batch job)
|
-- Patch Job Hosts (per-host status within a batch job)
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE patch_job_hosts (
|
CREATE TABLE IF NOT EXISTS patch_job_hosts (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
job_id UUID NOT NULL REFERENCES patch_jobs(id) ON DELETE CASCADE,
|
job_id UUID NOT NULL REFERENCES patch_jobs(id) ON DELETE CASCADE,
|
||||||
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
||||||
@ -257,15 +289,15 @@ CREATE TABLE patch_job_hosts (
|
|||||||
UNIQUE (job_id, host_id)
|
UNIQUE (job_id, host_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_pjh_job ON patch_job_hosts (job_id);
|
CREATE INDEX IF NOT EXISTS idx_pjh_job ON patch_job_hosts (job_id);
|
||||||
CREATE INDEX idx_pjh_host ON patch_job_hosts (host_id);
|
CREATE INDEX IF NOT EXISTS idx_pjh_host ON patch_job_hosts (host_id);
|
||||||
CREATE INDEX idx_pjh_status ON patch_job_hosts (status);
|
CREATE INDEX IF NOT EXISTS idx_pjh_status ON patch_job_hosts (status);
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Certificates
|
-- Certificates
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE certificates (
|
CREATE TABLE IF NOT EXISTS certificates (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
-- NULL = root CA cert
|
-- NULL = root CA cert
|
||||||
host_id UUID REFERENCES hosts(id) ON DELETE CASCADE,
|
host_id UUID REFERENCES hosts(id) ON DELETE CASCADE,
|
||||||
@ -279,15 +311,15 @@ CREATE TABLE certificates (
|
|||||||
cert_pem TEXT NOT NULL
|
cert_pem TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_certs_host ON certificates (host_id);
|
CREATE INDEX IF NOT EXISTS idx_certs_host ON certificates (host_id);
|
||||||
CREATE INDEX idx_certs_status ON certificates (status);
|
CREATE INDEX IF NOT EXISTS idx_certs_status ON certificates (status);
|
||||||
CREATE INDEX idx_certs_expires ON certificates (expires_at);
|
CREATE INDEX IF NOT EXISTS idx_certs_expires ON certificates (expires_at);
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Audit Log (tamper-evident, hash-chained)
|
-- Audit Log (tamper-evident, hash-chained)
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE audit_log (
|
CREATE TABLE IF NOT EXISTS audit_log (
|
||||||
id BIGSERIAL PRIMARY KEY,
|
id BIGSERIAL PRIMARY KEY,
|
||||||
action audit_action NOT NULL,
|
action audit_action NOT NULL,
|
||||||
actor_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
actor_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||||
@ -302,17 +334,17 @@ CREATE TABLE audit_log (
|
|||||||
row_hash TEXT NOT NULL DEFAULT ''
|
row_hash TEXT NOT NULL DEFAULT ''
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_audit_created ON audit_log (created_at DESC);
|
CREATE INDEX IF NOT EXISTS idx_audit_created ON audit_log (created_at DESC);
|
||||||
CREATE INDEX idx_audit_actor ON audit_log (actor_user_id);
|
CREATE INDEX IF NOT EXISTS idx_audit_actor ON audit_log (actor_user_id);
|
||||||
CREATE INDEX idx_audit_action ON audit_log (action);
|
CREATE INDEX IF NOT EXISTS idx_audit_action ON audit_log (action);
|
||||||
CREATE INDEX idx_audit_target ON audit_log (target_type, target_id);
|
CREATE INDEX IF NOT EXISTS idx_audit_target ON audit_log (target_type, target_id);
|
||||||
-- Retained for 6 months (pruned by worker)
|
-- Retained for 6 months (pruned by worker)
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Azure SSO Configuration
|
-- Azure SSO Configuration
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE azure_sso_config (
|
CREATE TABLE IF NOT EXISTS azure_sso_config (
|
||||||
id INTEGER PRIMARY KEY DEFAULT 1, -- singleton row
|
id INTEGER PRIMARY KEY DEFAULT 1, -- singleton row
|
||||||
enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
tenant_id TEXT NOT NULL DEFAULT '',
|
tenant_id TEXT NOT NULL DEFAULT '',
|
||||||
@ -329,7 +361,7 @@ CREATE TABLE azure_sso_config (
|
|||||||
-- System Configuration (key/value runtime settings)
|
-- System Configuration (key/value runtime settings)
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE system_config (
|
CREATE TABLE IF NOT EXISTS system_config (
|
||||||
key TEXT PRIMARY KEY,
|
key TEXT PRIMARY KEY,
|
||||||
value TEXT NOT NULL,
|
value TEXT NOT NULL,
|
||||||
description TEXT NOT NULL DEFAULT '',
|
description TEXT NOT NULL DEFAULT '',
|
||||||
@ -351,13 +383,14 @@ INSERT INTO system_config (key, value, description) VALUES
|
|||||||
('smtp_from', '', 'From address for notifications'),
|
('smtp_from', '', 'From address for notifications'),
|
||||||
('smtp_tls_mode', 'starttls', 'SMTP TLS mode: none, starttls, tls'),
|
('smtp_tls_mode', 'starttls', 'SMTP TLS mode: none, starttls, tls'),
|
||||||
('web_tls_strategy', 'internal_ca', 'Web UI TLS cert strategy: internal_ca or operator_supplied'),
|
('web_tls_strategy', 'internal_ca', 'Web UI TLS cert strategy: internal_ca or operator_supplied'),
|
||||||
('ip_whitelist', '[]', 'JSON array of allowed CIDR/IP strings; empty = allow all');
|
('ip_whitelist', '[]', 'JSON array of allowed CIDR/IP strings; empty = allow all')
|
||||||
|
ON CONFLICT (key) DO NOTHING;
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Worker Heartbeat
|
-- Worker Heartbeat
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE worker_heartbeat (
|
CREATE TABLE IF NOT EXISTS worker_heartbeat (
|
||||||
id INTEGER PRIMARY KEY DEFAULT 1, -- singleton row
|
id INTEGER PRIMARY KEY DEFAULT 1, -- singleton row
|
||||||
last_seen TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
last_seen TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||||
worker_version TEXT NOT NULL DEFAULT '',
|
worker_version TEXT NOT NULL DEFAULT '',
|
||||||
@ -368,7 +401,7 @@ CREATE TABLE worker_heartbeat (
|
|||||||
-- Discovery Results (transient; cleared before each scan)
|
-- Discovery Results (transient; cleared before each scan)
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE TABLE discovery_results (
|
CREATE TABLE IF NOT EXISTS discovery_results (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
scan_id UUID NOT NULL,
|
scan_id UUID NOT NULL,
|
||||||
ip_address INET NOT NULL,
|
ip_address INET NOT NULL,
|
||||||
@ -381,5 +414,5 @@ CREATE TABLE discovery_results (
|
|||||||
registered BOOLEAN NOT NULL DEFAULT FALSE
|
registered BOOLEAN NOT NULL DEFAULT FALSE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_discovery_scan ON discovery_results (scan_id);
|
CREATE INDEX IF NOT EXISTS idx_discovery_scan ON discovery_results (scan_id);
|
||||||
CREATE INDEX idx_discovery_ip ON discovery_results (ip_address);
|
CREATE INDEX IF NOT EXISTS idx_discovery_ip ON discovery_results (ip_address);
|
||||||
|
|||||||
@ -8,11 +8,11 @@
|
|||||||
|
|
||||||
-- When the retry engine should next attempt this host; NULL = not scheduled
|
-- When the retry engine should next attempt this host; NULL = not scheduled
|
||||||
ALTER TABLE patch_job_hosts
|
ALTER TABLE patch_job_hosts
|
||||||
ADD COLUMN retry_next_at TIMESTAMPTZ;
|
ADD COLUMN IF NOT EXISTS retry_next_at TIMESTAMPTZ;
|
||||||
|
|
||||||
-- Last failure reason captured by the worker for display in the UI
|
-- Last failure reason captured by the worker for display in the UI
|
||||||
ALTER TABLE patch_job_hosts
|
ALTER TABLE patch_job_hosts
|
||||||
ADD COLUMN last_error TEXT;
|
ADD COLUMN IF NOT EXISTS last_error TEXT;
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- pg_notify trigger: fires when an immediate job is inserted
|
-- pg_notify trigger: fires when an immediate job is inserted
|
||||||
@ -30,15 +30,21 @@ BEGIN
|
|||||||
END;
|
END;
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
CREATE TRIGGER trg_job_enqueued
|
DO $$ BEGIN
|
||||||
AFTER INSERT ON patch_jobs
|
IF NOT EXISTS (
|
||||||
FOR EACH ROW
|
SELECT 1 FROM pg_trigger WHERE tgname = 'trg_job_enqueued'
|
||||||
EXECUTE FUNCTION notify_job_enqueued();
|
) THEN
|
||||||
|
CREATE TRIGGER trg_job_enqueued
|
||||||
|
AFTER INSERT ON patch_jobs
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION notify_job_enqueued();
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
-- Index: efficiently find hosts due for retry
|
-- Index: efficiently find hosts due for retry
|
||||||
-- ============================================================
|
-- ============================================================
|
||||||
|
|
||||||
CREATE INDEX idx_pjh_retry
|
CREATE INDEX IF NOT EXISTS idx_pjh_retry
|
||||||
ON patch_job_hosts (retry_next_at)
|
ON patch_job_hosts (retry_next_at)
|
||||||
WHERE retry_next_at IS NOT NULL;
|
WHERE retry_next_at IS NOT NULL;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
-- Migration 007: Health check configuration and results
|
-- Migration 007: Health check configuration and results
|
||||||
|
|
||||||
-- Health checks configured per host (1-5 per host)
|
-- Health checks configured per host (1-5 per host)
|
||||||
CREATE TABLE host_health_checks (
|
CREATE TABLE IF NOT EXISTS host_health_checks (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE,
|
||||||
name VARCHAR(100) NOT NULL,
|
name VARCHAR(100) NOT NULL,
|
||||||
@ -27,10 +27,10 @@ CREATE TABLE host_health_checks (
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_health_checks_host ON host_health_checks (host_id);
|
CREATE INDEX IF NOT EXISTS idx_health_checks_host ON host_health_checks (host_id);
|
||||||
|
|
||||||
-- Health check poll results (4-day retention, pruned by worker)
|
-- Health check poll results (4-day retention, pruned by worker)
|
||||||
CREATE TABLE host_health_check_results (
|
CREATE TABLE IF NOT EXISTS host_health_check_results (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
check_id UUID NOT NULL REFERENCES host_health_checks(id) ON DELETE CASCADE,
|
check_id UUID NOT NULL REFERENCES host_health_checks(id) ON DELETE CASCADE,
|
||||||
healthy BOOLEAN NOT NULL,
|
healthy BOOLEAN NOT NULL,
|
||||||
@ -39,4 +39,4 @@ CREATE TABLE host_health_check_results (
|
|||||||
checked_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
checked_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_health_results_check ON host_health_check_results (check_id, checked_at DESC);
|
CREATE INDEX IF NOT EXISTS idx_health_results_check ON host_health_check_results (check_id, checked_at DESC);
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
-- FK with ON DELETE SET NULL: if target host deleted, revert to default.
|
-- FK with ON DELETE SET NULL: if target host deleted, revert to default.
|
||||||
|
|
||||||
ALTER TABLE host_health_checks
|
ALTER TABLE host_health_checks
|
||||||
ADD COLUMN target_host_id UUID REFERENCES hosts(id) ON DELETE SET NULL;
|
ADD COLUMN IF NOT EXISTS target_host_id UUID REFERENCES hosts(id) ON DELETE SET NULL;
|
||||||
|
|
||||||
CREATE INDEX idx_health_checks_target_host ON host_health_checks (target_host_id)
|
CREATE INDEX IF NOT EXISTS idx_health_checks_target_host ON host_health_checks (target_host_id)
|
||||||
WHERE target_host_id IS NOT NULL;
|
WHERE target_host_id IS NOT NULL;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
-- Migration: 016_enrollment_requests
|
-- Migration: 016_enrollment_requests
|
||||||
-- Description: Create enrollment_requests table for host self-enrollment
|
-- Description: Create enrollment_requests table for host self-enrollment
|
||||||
|
|
||||||
CREATE TABLE enrollment_requests (
|
CREATE TABLE IF NOT EXISTS enrollment_requests (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
machine_id TEXT NOT NULL UNIQUE,
|
machine_id TEXT NOT NULL UNIQUE,
|
||||||
fqdn TEXT NOT NULL,
|
fqdn TEXT NOT NULL,
|
||||||
@ -12,5 +12,5 @@ CREATE TABLE enrollment_requests (
|
|||||||
expires_at TIMESTAMPTZ NOT NULL DEFAULT NOW() + INTERVAL '24 hours'
|
expires_at TIMESTAMPTZ NOT NULL DEFAULT NOW() + INTERVAL '24 hours'
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX idx_enrollment_requests_token ON enrollment_requests (polling_token);
|
CREATE INDEX IF NOT EXISTS idx_enrollment_requests_token ON enrollment_requests (polling_token);
|
||||||
CREATE INDEX idx_enrollment_requests_expires ON enrollment_requests (expires_at);
|
CREATE INDEX IF NOT EXISTS idx_enrollment_requests_expires ON enrollment_requests (expires_at);
|
||||||
|
|||||||
@ -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.7"
|
VERSION="1.1.12"
|
||||||
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user