Fix RustFS secret bind paths in server installers #344

Merged
arnaud.dartois merged 2 commits from fix/install-rustfs-secret-compose-path into main 2026-11-12 18:02:31 +01:00
5 changed files with 66 additions and 8 deletions

No files matched your search

+2 -1
View File
@@ -350,6 +350,7 @@ if ($startCore) {
}
foreach ($service in $selected) {
$composeProjectDirectory = if ($service -eq 'backup') { $optionalDirectory } else { $destination }
switch ($service) {
'rustfs' {
$accessKeyPath = Join-Path $optionalSecretsDirectory 'rustfs_access_key'
@@ -379,7 +380,7 @@ foreach ($service in $selected) {
}
}
if ($startCore -and (Read-YesNo "Démarrer le service optionnel $service ?" 'o')) {
Invoke-DockerCompose @('--project-name', "heimdall-$service", '--env-file', $envPath,
Invoke-DockerCompose @('--project-directory', $composeProjectDirectory, '--project-name', "heimdall-$service", '--env-file', $envPath,
'-f', (Join-Path $optionalDirectory "docker-compose.$service.yml"), 'up', '-d')
} else {
Write-Host "Service $service préparé dans $optionalDirectory."
+6 -1
View File
@@ -296,6 +296,10 @@ if [[ "$(ask 'Démarrer PostgreSQL et Heimdall maintenant ?' 'o')" =~ ^([oO]|[oO
fi
for service in "${selected[@]}"; do
compose_project_directory="$destination"
if [[ "$service" == backup ]]; then
compose_project_directory="$destination/optional"
fi
case "$service" in
rustfs)
printf '%s' "heimdall$(openssl rand -hex 8)" > "$destination/optional/secrets/rustfs_access_key"
@@ -318,7 +322,8 @@ for service in "${selected[@]}"; do
;;
esac
if [[ "$start_core" == yes ]] && [[ "$(ask "Démarrer le service optionnel ${service} ?" 'o')" =~ ^([oO]|[oO][uU][iI]|[yY]|[yY][eE][sS])$ ]]; then
docker compose --project-name "heimdall-${service}" --env-file "$destination/.env" \
docker compose --project-directory "$compose_project_directory" --project-name "heimdall-${service}" \
--env-file "$destination/.env" \
-f "$destination/optional/docker-compose.${service}.yml" up -d
else
say "Service ${service} préparé dans $destination/optional/."
+12
View File
@@ -73,6 +73,18 @@ class PublicationWorkflowTests(unittest.TestCase):
self.assertNotIn('secrets.GITEA_TOKEN', workflow.split(' publish:\n', 1)[0])
class PowerShellInstallerTests(unittest.TestCase):
def test_optional_compose_commands_resolve_paths_from_install_root(self):
linux_installer = (REPO_ROOT/'install/install-server.sh').read_text()
windows_installer = (REPO_ROOT/'install/install-server.ps1').read_text()
self.assertIn('compose_project_directory="$destination"', linux_installer)
self.assertIn('compose_project_directory="$destination/optional"', linux_installer)
self.assertIn('docker compose --project-directory "$compose_project_directory"',
linux_installer)
self.assertIn("$composeProjectDirectory = if ($service -eq 'backup') { $optionalDirectory } else { $destination }",
windows_installer)
self.assertIn("Invoke-DockerCompose @('--project-directory', $composeProjectDirectory,",
windows_installer)
@unittest.skipUnless(shutil.which('pwsh'), 'PowerShell is not installed')
def test_server_installer_has_valid_powershell_syntax(self):
parser = "$tokens=$null; $errors=$null; [void][System.Management.Automation.Language.Parser]::ParseFile((Resolve-Path 'install/install-server.ps1'), [ref]$tokens, [ref]$errors); if ($errors.Count) { $errors | ForEach-Object { Write-Error $_.Message }; exit 1 }"
+3 -3
View File
@@ -5,13 +5,13 @@ description: Keep installer-managed RustFS and coturn Compose services aligned w
# Installer-managed optional services
The Linux and Windows server installers run optional Compose files with the installation root as the current directory. They save service secrets in `optional/secrets/` and pass the root `.env` for interpolation. Therefore, Compose secret `file:` entries must use `./optional/secrets/<name>`, not `./secrets/<name>` or paths relative to `optional/`.
The Linux and Windows server installers save service secrets in `<install-root>/optional/secrets/`, backup scripts in `<install-root>/optional/scripts/`, and pass the root `.env` for interpolation. Compose resolves relative paths from its project directory, which otherwise defaults to the directory containing the first `-f` file. RustFS and coturn Compose files reference `./optional/secrets/<name>`, so start them with `--project-directory <install-root>`. The backup Compose references `./scripts` and `./secrets/db_password`, so start it with `--project-directory <install-root>/optional`. Preserve these service-specific bases; applying the installation root to every optional Compose breaks the backup mounts.
## RustFS
- Keep `rustfs_access_key` and `rustfs_secret_key` file paths aligned with the generated files from both installers.
- Installers create these bind-mounted secret files as owner-only (`0600`), which the official RustFS process (`10001:10001`) cannot read directly. Keep a short root initializer, copy the files into the service's private tmpfs, `chown` the copies to UID/GID 10001, then drop to the `rustfs` account before executing the upstream entrypoint. Keep the root filesystem read-only and provide tmpfs only for runtime paths that RustFS writes (`/logs`, `/tmp`, and its secret copies).
- Verify Compose config from the install-root working directory and ensure Docker secrets are sourced from those files.
- Verify actual optional-service invocations use the right project directory: `<install-root>` for RustFS/coturn and `<install-root>/optional` for backup. Confirm normalized secret and script bind sources point to exact generated files/directories. A successful `config` without checking normalized source paths is insufficient because Compose can accept an unintended path that happens to exist.
- Keep the named data volume and shared `heimdall-net` behavior intact.
## coturn
@@ -26,4 +26,4 @@ The Linux and Windows server installers run optional Compose files with the inst
## Acceptance
Run `skills/optional-server-services/acceptance.sh`. It creates a uniquely named disposable Compose project, generated owner-only secrets, an isolated install root, unique listener and relay ports, then validates Compose using that root. It verifies RustFS `/health`, signs a real S3 bucket-creation request with the generated keys, and runs `turnutils_uclient` inside the Compose network with TURN REST credentials. This proves local container-network allocation only; it does not prove external firewall/NAT reachability. The trap tears down only that project and verifies its containers, volumes, and networks are absent. The recipe builds no local images and retains upstream images.
Run `skills/optional-server-services/acceptance.sh`. It creates a uniquely named disposable Compose project, generated owner-only secrets, an isolated install root, unique listener and relay ports, then validates Compose with each installer's explicit project directory. It asserts the normalized RustFS/coturn secret paths and backup secret/script bind sources exactly match the generated files before starting containers. It verifies RustFS `/health`, signs a real S3 bucket-creation request with the generated keys, and runs `turnutils_uclient` inside the Compose network with TURN REST credentials. This proves local container-network allocation only; it does not prove external firewall/NAT reachability. The trap tears down only that project and verifies its containers, volumes, and networks are absent. The recipe builds no local images and retains upstream images.
+43 -3
View File
@@ -7,13 +7,16 @@ project="heimdall-optional-services-${suffix}"
temp_dir=$(mktemp -d "${TMPDIR:-/tmp}/${project}.XXXXXX")
install_root="$temp_dir/install-root"
secret_dir="$install_root/optional/secrets"
backup_scripts_dir="$install_root/optional/scripts"
env_file="$temp_dir/acceptance.env"
override_file="$temp_dir/compose.override.yml"
turn_log="$temp_dir/turn-client.log"
rustfs_compose="$repo_root/docker/docker-compose.rustfs.yml"
coturn_compose="$repo_root/docker/docker-compose.coturn.yml"
backup_compose="$repo_root/docker/docker-compose.backup.yml"
backup_scripts=(backup.sh backup-protected-data.sh backup-rustfs.sh restore.sh restore-protected-data.sh)
local_image_tags=()
mkdir -p "$secret_dir"
mkdir -p "$secret_dir" "$backup_scripts_dir"
compose() {
docker compose --project-directory "$install_root" --env-file "$env_file" \
@@ -59,8 +62,11 @@ cleanup() {
done
rm -f -- "$env_file" "$override_file" "$turn_log" \
"$secret_dir/rustfs_access_key" "$secret_dir/rustfs_secret_key" \
"$secret_dir/coturn_secret" || cleanup_failed=1
rmdir -- "$secret_dir" "$install_root/optional" "$install_root" || cleanup_failed=1
"$secret_dir/coturn_secret" "$secret_dir/db_password" || cleanup_failed=1
for name in "${backup_scripts[@]}"; do
rm -f -- "$backup_scripts_dir/$name" || cleanup_failed=1
done
rmdir -- "$backup_scripts_dir" "$secret_dir" "$install_root/optional" "$install_root" || cleanup_failed=1
rmdir -- "$temp_dir" || cleanup_failed=1
if ((cleanup_failed)); then
printf 'Disposable optional-service cleanup failed for %s\n' "$project" >&2
@@ -116,6 +122,10 @@ coturn_username=acceptance
printf '%s' "$rustfs_access_key" > "$secret_dir/rustfs_access_key"
printf '%s' "$rustfs_secret_key" > "$secret_dir/rustfs_secret_key"
printf '%s' "$coturn_secret" > "$secret_dir/coturn_secret"
printf 'acceptance-db-password-%s' "$(od -An -N16 -tx1 /dev/urandom | tr -d ' \\n')" > "$secret_dir/db_password"
for name in "${backup_scripts[@]}"; do
cp "$repo_root/docker/scripts/$name" "$backup_scripts_dir/$name"
done
chmod 600 "$secret_dir"/*
cat > "$env_file" <<EOF
RUSTFS_API_PORT=$rustfs_api_port
@@ -129,6 +139,7 @@ COTURN_USERNAME=$coturn_username
RUSTFS_ACCESS_KEY=$rustfs_access_key
RUSTFS_SECRET_KEY=$rustfs_secret_key
ACCEPTANCE_NETWORK=${project}-heimdall-net
HEIMDALL_DATA_VOLUME=${project}-heimdall-data
EOF
chmod 600 "$env_file"
cat > "$override_file" <<'EOF'
@@ -155,6 +166,35 @@ EOF
printf 'Disposable project: %s\nLocal images built: none\n' "$project"
compose config --quiet
compose config --format json | INSTALL_ROOT="$install_root" python3 -c '
import json, os, sys
config = json.load(sys.stdin)
root = os.environ["INSTALL_ROOT"]
expected = {
"rustfs_access_key": os.path.join(root, "optional/secrets/rustfs_access_key"),
"rustfs_secret_key": os.path.join(root, "optional/secrets/rustfs_secret_key"),
"coturn_secret": os.path.join(root, "optional/secrets/coturn_secret"),
}
actual = {name: config["secrets"][name]["file"] for name in expected}
if actual != expected:
raise SystemExit("Compose secret bind mounts do not resolve under the installer root")
print("Verified RustFS and coturn secret bind mounts resolve under the installer root.")
'
docker compose --project-directory "$install_root/optional" --env-file "$env_file" \
-f "$backup_compose" --project-name "${project}-backup" config --format json |
BACKUP_PROJECT_DIRECTORY="$install_root/optional" python3 -c '
import json, os, sys
config = json.load(sys.stdin)
project_directory = os.environ["BACKUP_PROJECT_DIRECTORY"]
expected_secret = os.path.join(project_directory, "secrets/db_password")
expected_scripts = os.path.join(project_directory, "scripts")
actual_secret = config["secrets"]["db_password"]["file"]
scripts_mount = next((mount for mount in config["services"]["backup"]["volumes"]
if mount.get("target") == "/scripts"), None)
if actual_secret != expected_secret or scripts_mount is None or scripts_mount.get("source") != expected_scripts:
raise SystemExit("Backup secret or script bind mounts do not resolve under optional/")
print("Verified backup secret and scripts resolve under the installer optional directory.")
'
compose up -d rustfs coturn
base_url="http://127.0.0.1:$rustfs_api_port"