Prepare OpsProof database storage ownership
Homelab Main / validate (push) Failing after 1m43s Details
Homelab Main / running-update (push) Has been skipped Details
Homelab Main / debian-ops (push) Has been skipped Details

This commit is contained in:
juvenal.diaz 2026-12-04 15:18:40 -06:00
parent 193a44b1f1
commit c1f3cadb6f
3 changed files with 35 additions and 2 deletions

View File

@ -41,7 +41,9 @@ starter's pinned formatter, runs its frontend checks and build, runs the Go
feature tests against PostgreSQL, builds the binary, applies database
migrations, installs a hardened systemd unit, and verifies `/up`. Database
credentials are generated once and retained in the private OpsProof data
directory. It does not replace Debian's system Go.
directory. Jeannie resolves the database account's UID and GID from the image
before preparing the bind mount, so it does not depend on a host-specific
numeric account. It does not replace Debian's system Go.
## Security boundary

View File

@ -5688,6 +5688,8 @@ deploy_opsproof() {
local archive=""
local app_key=""
local postgres_password=""
local postgres_uid=""
local postgres_gid=""
local database_url=""
local elapsed=0
local node_major=""
@ -5726,7 +5728,7 @@ deploy_opsproof() {
return 1
fi
for required in curl docker git npm openssl sha256sum systemctl tar; do
for required in curl docker git npm openssl sha256sum stat systemctl tar; do
if ! command -v "${required}" >/dev/null 2>&1; then
echo "OpsProof deployment requires ${required} on Debian." >&2
return 1
@ -5746,6 +5748,23 @@ deploy_opsproof() {
"${install_dir}" "${install_dir}/releases" "${install_dir}/toolchains"
sudo install -d -m 0700 "${install_dir}/postgres"
if ! sudo docker image inspect "${postgres_image}" >/dev/null 2>&1; then
sudo docker pull "${postgres_image}"
fi
postgres_uid="$(sudo docker run --rm --entrypoint id "${postgres_image}" -u postgres)"
postgres_gid="$(sudo docker run --rm --entrypoint id "${postgres_image}" -g postgres)"
if ! [[ "${postgres_uid}" =~ ^[0-9]+$ && "${postgres_gid}" =~ ^[0-9]+$ ]]; then
echo "Could not resolve the PostgreSQL user identity from ${postgres_image}." >&2
return 1
fi
if [[ "$(stat -c '%u:%g' "${install_dir}/postgres")" != "${postgres_uid}:${postgres_gid}" ]]; then
if sudo docker container inspect "${postgres_container}" >/dev/null 2>&1; then
sudo docker stop "${postgres_container}" >/dev/null
fi
sudo chown -R "${postgres_uid}:${postgres_gid}" "${install_dir}/postgres"
fi
sudo chmod 0700 "${install_dir}/postgres"
if [[ -s "${database_env}" ]]; then
postgres_password="$(sed -n 's/^POSTGRES_PASSWORD=//p' "${database_env}" | head -n 1)"
fi

View File

@ -65,6 +65,18 @@ class OpsProofPipelineTests(unittest.TestCase):
)
self.assertIn('DATABASE_URL="${database_url}"', pipeline)
self.assertIn('"${release_dir}/opsproof" migrate --force', pipeline)
self.assertIn(
'postgres_uid="$(sudo docker run --rm --entrypoint id "${postgres_image}" -u postgres)"',
pipeline,
)
self.assertIn(
'sudo chown -R "${postgres_uid}:${postgres_gid}" "${install_dir}/postgres"',
pipeline,
)
self.assertLess(
pipeline.index('sudo chown -R "${postgres_uid}:${postgres_gid}"'),
pipeline.index('docker compose --env-file "${database_env}" up -d database'),
)
self.assertLess(
pipeline.index('docker compose --env-file "${database_env}" up -d database'),
pipeline.index("GOTOOLCHAIN=local go test ./..."),