feat(install): bundled PostgreSQL has no network and is reached by Unix socket; print an AppArmor profile instead of disabling the userns restriction
This commit is contained in:
1 parent
4247f6c96d
commit
6cb184404a
8 files changed
+77
-30
No files matched your search
@@ -350,7 +350,7 @@ jobs:
|
||||
for cmd in $(jq -r '.required_topology.units[]' release.json); do
|
||||
cp "dist/$cmd" "$name/"
|
||||
done
|
||||
cp deployments/INSTRUCTIONS.md CHANGELOG.md docker-compose.yml "$name/"
|
||||
cp deployments/INSTRUCTIONS.md CHANGELOG.md "$name/"
|
||||
cp scripts/archie-update-* "$name/"
|
||||
digest='${{ needs.build-and-push.outputs.agent_digest }}'
|
||||
test -n "$digest"
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ release's per-component sections are labelled beneath its heading.
|
||||
- `archied setup` asks for the PostgreSQL URL. Left blank, it uses the bundled Compose database with a generated password stored in `~/.config/archie/env` as `PGPASSWORD`, not in `config.toml`.
|
||||
- The bundled PostgreSQL listens on 127.0.0.1 only. A database created before this release keeps its old `archie` password; enter its URL at setup or recreate the volume.
|
||||
- The release zip carries `docker-compose.yml`.
|
||||
- Extensions need unprivileged user namespaces. On Ubuntu 23.10 and later run `sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0` or extensions fail to start.
|
||||
- Extensions need unprivileged user namespaces, which Ubuntu 23.10 and later restrict. Allow them for the Archie binaries with an AppArmor profile; from the next release the installer prints it. Do not disable the restriction system-wide.
|
||||
- fix(app): assign the temp-file close result on the error path
|
||||
- fix(webhook): set a ReadHeaderTimeout on the forge webhook receivers
|
||||
- fix(forge): refuse a review line number that does not fit an int
|
||||
|
||||
@@ -117,8 +117,9 @@ or a hosted provider API key.
|
||||
checkout instead. Re-run `archied setup` at any time to change the answers.
|
||||
|
||||
Extensions run in an unprivileged user namespace. Ubuntu 23.10 and later
|
||||
block these by default; allow them with
|
||||
`sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0`.
|
||||
block these by default; on such a host the installer prints an AppArmor
|
||||
profile that allows them for the Archie binaries only, to install with
|
||||
`sudo`.
|
||||
|
||||
2. **Check it is up.**
|
||||
|
||||
|
||||
+1
-3
@@ -25,9 +25,7 @@ services:
|
||||
image: postgres:18
|
||||
environment:
|
||||
POSTGRES_USER: archie
|
||||
# archied setup generates PGPASSWORD into ~/.config/archie/env; the fallback is
|
||||
# the dev password deployments/dev.toml uses.
|
||||
POSTGRES_PASSWORD: ${PGPASSWORD:-archie}
|
||||
POSTGRES_PASSWORD: archie
|
||||
POSTGRES_DB: archie
|
||||
# postgres:18 moved its default PGDATA under a versioned path; pin the
|
||||
# classic location so the named volume keeps working across image updates.
|
||||
|
||||
+59
-18
@@ -89,8 +89,8 @@ fi
|
||||
|
||||
mkdir -p "${ARCHIE_CONFIG_DIR}" "${ARCHIE_DATA_DIR}" "${ARCHIE_BIN_DIR}"
|
||||
|
||||
# 2. Binaries. STAGE ends up holding the binaries, release.json, the updater
|
||||
# scripts and docker-compose.yml, whichever way they were obtained.
|
||||
# 2. Binaries. STAGE ends up holding the binaries, release.json and the
|
||||
# updater scripts, whichever way they were obtained.
|
||||
TMP="$(mktemp -d)"
|
||||
trap 'rm -rf "${TMP}"' EXIT
|
||||
|
||||
@@ -111,7 +111,7 @@ if [ "${FROM_SOURCE}" = true ]; then
|
||||
for cmd in $(jq -er '.required_topology.units | join(" ")' "${SRC_DIR}/release.json"); do
|
||||
(cd "${SRC_DIR}" && go build -ldflags "${LDFLAGS}" -o "${STAGE}/${cmd}" "./cmd/${cmd}")
|
||||
done
|
||||
cp "${SRC_DIR}/release.json" "${SRC_DIR}/docker-compose.yml" "${SRC_DIR}"/scripts/archie-update-* "${STAGE}/"
|
||||
cp "${SRC_DIR}/release.json" "${SRC_DIR}"/scripts/archie-update-* "${STAGE}/"
|
||||
else
|
||||
if [ -z "${VERSION}" ]; then
|
||||
tag="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p')"
|
||||
@@ -138,7 +138,6 @@ for cmd in ${TOPOLOGY_UNITS}; do
|
||||
install -m755 "${STAGE}/${cmd}" "${ARCHIE_BIN_DIR}/${cmd}"
|
||||
done
|
||||
install -m755 "${STAGE}"/archie-update-* "${ARCHIE_BIN_DIR}/"
|
||||
install -m644 "${STAGE}/docker-compose.yml" "${ARCHIE_DATA_DIR}/docker-compose.yml"
|
||||
echo " Installed ${TOPOLOGY_UNITS} and the updater to ${ARCHIE_BIN_DIR}/"
|
||||
|
||||
# 3. Configuration. archied setup asks every question and writes config.toml
|
||||
@@ -161,24 +160,66 @@ else
|
||||
echo " [SKIP] ${ARCHIE_CONFIG_DIR}/config.toml already exists. Re-run 'archied setup' to change it."
|
||||
fi
|
||||
|
||||
# 4. PostgreSQL. Every service fails closed without it. The default database_url is
|
||||
# the Compose postgres service, so start it when the config still uses it.
|
||||
if ! grep -qE '@127\.0\.0\.1:5432/archie' "${ARCHIE_CONFIG_DIR}/config.toml"; then
|
||||
# 4. PostgreSQL. Every service fails closed without it. The bundled database
|
||||
# has no network at all: the services reach it through its Unix socket,
|
||||
# mounted at PG_SOCKET_DIR, so it publishes no port and cannot collide with
|
||||
# another PostgreSQL. Its password is the PGPASSWORD setup generated.
|
||||
PG_SOCKET_DIR="${ARCHIE_DATA_DIR}/postgres"
|
||||
PG_COMPOSE="${ARCHIE_DATA_DIR}/postgres.yml"
|
||||
if ! grep -qF "host=${PG_SOCKET_DIR}" "${ARCHIE_CONFIG_DIR}/config.toml"; then
|
||||
echo " [OK] Using the PostgreSQL server named by database_url."
|
||||
elif command -v docker &>/dev/null && [ -f "${ARCHIE_DATA_DIR}/docker-compose.yml" ]; then
|
||||
echo "==> Starting PostgreSQL 18 (docker compose up -d postgres)..."
|
||||
touch "${ENV_FILE}" && chmod 600 "${ENV_FILE}"
|
||||
if ! docker compose --env-file "${ENV_FILE}" -f "${ARCHIE_DATA_DIR}/docker-compose.yml" up -d postgres; then
|
||||
# Started without their database the services only crash-loop, and if
|
||||
# something else holds 5432 they hit the wrong server.
|
||||
elif ! command -v docker &>/dev/null; then
|
||||
echo " [WARN] Docker not found: the bundled PostgreSQL needs it. Install Docker, or run 'archied setup' with your own PostgreSQL 18 URL." >&2
|
||||
AUTO_START=false
|
||||
else
|
||||
echo "==> Starting the bundled PostgreSQL 18..."
|
||||
mkdir -p "${PG_SOCKET_DIR}"
|
||||
cat >"${PG_COMPOSE}" <<'EOF'
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:18
|
||||
network_mode: none
|
||||
environment:
|
||||
POSTGRES_USER: archie
|
||||
POSTGRES_PASSWORD: ${PGPASSWORD:-}
|
||||
POSTGRES_DB: archie
|
||||
POSTGRES_INITDB_ARGS: --auth-local=scram-sha-256
|
||||
PGDATA: /var/lib/postgresql/data/pgdata
|
||||
volumes:
|
||||
- pg_data:/var/lib/postgresql/data
|
||||
# :z relabels the directory for SELinux hosts.
|
||||
- ./postgres:/var/run/postgresql:z
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U archie -d archie"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
volumes:
|
||||
pg_data:
|
||||
EOF
|
||||
if ! docker compose -p archie --env-file "${ENV_FILE}" -f "${PG_COMPOSE}" up -d --wait; then
|
||||
echo " [WARN] The bundled PostgreSQL did not start, so the services are installed but not started." >&2
|
||||
echo " If another PostgreSQL holds port 5432, run 'archied setup' and enter its URL, then:" >&2
|
||||
echo " systemctl --user enable --now ${TOPOLOGY_UNITS}" >&2
|
||||
echo " Check: docker compose -p archie -f ${PG_COMPOSE} logs" >&2
|
||||
AUTO_START=false
|
||||
fi
|
||||
else
|
||||
echo " [WARN] Docker not found: point database_url in ${ARCHIE_CONFIG_DIR}/config.toml at a PostgreSQL 18 server before starting the services."
|
||||
AUTO_START=false
|
||||
fi
|
||||
|
||||
# Extensions run in an unprivileged user namespace. Ubuntu 23.10+ forbids
|
||||
# those unless an AppArmor profile allows them, and only root can add one, so
|
||||
# print the profile that allows it for these binaries alone.
|
||||
if [ "$(cat /proc/sys/kernel/apparmor_restrict_unprivileged_userns 2>/dev/null)" = 1 ]; then
|
||||
echo " [WARN] This host restricts user namespaces, so extensions will not start until you run:" >&2
|
||||
cat >&2 <<EOF
|
||||
sudo tee /etc/apparmor.d/archie >/dev/null <<'PROFILE'
|
||||
abi <abi/4.0>,
|
||||
include <tunables/global>
|
||||
profile archie ${ARCHIE_BIN_DIR}/archie{d,-*} flags=(unconfined) {
|
||||
userns,
|
||||
}
|
||||
PROFILE
|
||||
sudo apparmor_parser -r /etc/apparmor.d/archie
|
||||
EOF
|
||||
fi
|
||||
|
||||
# 5. Systemd user service setup & linger configuration
|
||||
|
||||
@@ -161,6 +161,12 @@ func DefaultWorkDir() string {
|
||||
return filepath.Join(xdgDataHome(), "archie", "work")
|
||||
}
|
||||
|
||||
// DefaultPostgresSocketDir is where the bundled PostgreSQL's Unix socket is
|
||||
// mounted on the host.
|
||||
func DefaultPostgresSocketDir() string {
|
||||
return filepath.Join(xdgDataHome(), "archie", "postgres")
|
||||
}
|
||||
|
||||
// DefaultConfigDir returns the directory archie's configuration lives in:
|
||||
// $XDG_CONFIG_HOME/archie, or ~/.config/archie. It is the base every
|
||||
// config-home-derived path is built on. It is not the -config source
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration/tomlwrite"
|
||||
)
|
||||
|
||||
@@ -144,9 +145,9 @@ func RunParams(ctx context.Context, p Prompter, discovery ModelDiscovery, secret
|
||||
}
|
||||
|
||||
// stepDatabase returns the PostgreSQL URL. A blank answer on a fresh install
|
||||
// means the bundled Compose database with a generated password. The password
|
||||
// goes only to the env file as PGPASSWORD, which pgx and Compose both read, so
|
||||
// config.toml holds no secret.
|
||||
// means the bundled database: no network, reached through its Unix socket, with
|
||||
// a generated password that goes only to the env file as PGPASSWORD, which pgx
|
||||
// and Compose both read, so config.toml holds no secret.
|
||||
func stepDatabase(ctx context.Context, p Prompter, secrets SecretSink, existing, param string) (string, error) {
|
||||
if strings.TrimSpace(param) != "" {
|
||||
return param, nil
|
||||
@@ -170,5 +171,5 @@ func stepDatabase(ctx context.Context, p Prompter, secrets SecretSink, existing,
|
||||
if err := secrets.Put("env", "PGPASSWORD", password); err != nil {
|
||||
return "", fmt.Errorf("setup: store database password: %w", err)
|
||||
}
|
||||
return "postgres://archie@127.0.0.1:5432/archie?sslmode=disable", nil
|
||||
return "postgres://archie@/archie?host=" + configuration.DefaultPostgresSocketDir(), nil
|
||||
}
|
||||
+1
-1
@@ -93,7 +93,7 @@ archied_dirs() {
|
||||
printf '%s\n' "cmd/archied" "Dockerfile.archied" "cmd/archie-ui" "internal/app/archieui" \
|
||||
"Taskfile.yml" ".github/workflows/deploy.yml" "install.sh" \
|
||||
"scripts/archie-update-install" "scripts/archie-update-check" \
|
||||
"scripts/archie-update-watchdog" "deployments/INSTRUCTIONS.md" "docker-compose.yml"
|
||||
"scripts/archie-update-watchdog" "deployments/INSTRUCTIONS.md"
|
||||
}
|
||||
|
||||
# The UI Service ships with the archied release on purpose (archie-ui shares
|
||||
|
||||
Reference in new issue
Block a user