feat(storage): add private file layer and isolate SeaweedFS on a storage network

This commit is contained in:
shira committed 2026-10-06 13:51:53 +03:00
1 parent f5b07e8f4d
commit 8378ad45b0
22 files changed
+1668 -40

No files matched your search

+7 -4
View File
@@ -21,6 +21,7 @@ spec_dir="${E2E_SPEC_DIR:-$frontend_dir/e2e}"
suffix=$(od -An -N4 -tx1 /dev/urandom | tr -d ' \n')
project="lincodex-e2e-$suffix"
network="${project}_default"
storage_network="${project}_storage"
env_file=""
started=0
@@ -61,7 +62,7 @@ done < <(env)
compose() {
env -i "${docker_env[@]}" \
APP_PROJECT="$project" APP_NETWORK="$network" \
APP_PROJECT="$project" APP_NETWORK="$network" APP_STORAGE_NETWORK="$storage_network" \
PLAYWRIGHT_VERSION="$declared" E2E_CI="${CI:-}" \
E2E_UID="$(id -u)" E2E_GID="$(id -g)" \
E2E_SPEC_DIR="$spec_dir" E2E_ARTIFACTS_DIR="$artifacts_dir" \
@@ -78,9 +79,11 @@ for volume in "${project}_postgres_data" "${project}_seaweedfs_data" "${project}
fail "Refusing to use existing E2E volume $volume."
fi
done
if docker network inspect "$network" >/dev/null 2>&1; then
fail "Refusing to use existing E2E network $network."
fi
for existing in "$network" "$storage_network"; do
if docker network inspect "$existing" >/dev/null 2>&1; then
fail "Refusing to use existing E2E network $existing."
fi
done
if [[ -n "$(docker ps -aq --filter "label=com.docker.compose.project=$project")" ]]; then
fail "Refusing to use existing Compose project $project."
fi
+41 -6
View File
@@ -8,12 +8,13 @@ project=lincodex-smoke
app_network="${project}_default"
port=18080
network="${project}_default"
storage_network="${project}_storage"
started=0
# The smoke stack sends no mail: it uses EMAIL_PROVIDER=disabled from
# .env.example and points mail links at its own loopback port.
compose() {
APP_PROJECT="$project" APP_NETWORK="$app_network" APP_HTTP_PORT="$port" \
APP_PROJECT="$project" APP_NETWORK="$app_network" APP_STORAGE_NETWORK="$storage_network" APP_HTTP_PORT="$port" \
APP_PUBLIC_URL="http://localhost:$port" docker compose \
--env-file "$env_file" \
-p "$project" \
@@ -27,10 +28,12 @@ for volume in "${project}_postgres_data" "${project}_seaweedfs_data" "${project}
exit 2
fi
done
if docker network inspect "$network" >/dev/null 2>&1; then
printf 'Refusing to use existing smoke network %s.\n' "$network" >&2
exit 2
fi
for existing in "$network" "$storage_network"; do
if docker network inspect "$existing" >/dev/null 2>&1; then
printf 'Refusing to use existing smoke network %s.\n' "$existing" >&2
exit 2
fi
done
for dockerfile in "$root/backend/Dockerfile" "$root/frontend/Dockerfile"; do
if [[ ! -f "$dockerfile" ]]; then
printf 'Missing required build file %s.\n' "$dockerfile" >&2
@@ -121,6 +124,38 @@ if [[ "$anonymous" != *"403 Forbidden"* ]]; then
printf 'SeaweedFS did not reject anonymous bucket access: %s\n' "$anonymous" >&2
exit 1
fi
# The storage network is the primary boundary. The frontend stands in for
# every other core container: it must neither resolve nor reach SeaweedFS, by
# name or by its storage address. A DNS or connection failure is a pass.
storage_address=$(docker inspect -f "{{(index .NetworkSettings.Networks \"$storage_network\").IPAddress}}" "$(compose ps -q seaweedfs)")
if [[ -z "$storage_address" ]]; then
printf 'SeaweedFS has no address on %s.\n' "$storage_network" >&2
exit 1
fi
for url in "http://seaweedfs:8333/" "http://$storage_address:8333/"; do
isolation=$(compose exec -T frontend wget -T 5 -S -O /dev/null "$url" 2>&1 || true)
if [[ "$isolation" == *"HTTP/"* ]]; then
printf 'The frontend reached SeaweedFS outside the storage network at %s: %s\n' "$url" "$isolation" >&2
exit 1
fi
done
# Defense in depth inside the storage network. Requests to the container's own
# storage address do not come from loopback, so they stand in for another
# member of that network; the filer, master, and volume HTTP APIs answer 401.
compose exec -T seaweedfs sh -ec '
expect_unauthorized() {
response=$(wget -S -O /dev/null "$1" 2>&1 || true)
case "$response" in
*"401 Unauthorized"*) ;;
*) printf "SeaweedFS %s did not return 401: %s\n" "$1" "$response" >&2; exit 1 ;;
esac
}
expect_unauthorized http://seaweedfs:8888/buckets/
expect_unauthorized http://seaweedfs:9333/dir/assign
fid=$(wget -q -O - http://127.0.0.1:9333/dir/assign | sed -n "s/.*\"fid\":\"\([^\"]*\)\".*/\1/p")
test -n "$fid"
expect_unauthorized "http://seaweedfs:9340/$fid"
'
compose stop seaweedfs
readiness=$(compose exec -T frontend wget -S -O /dev/null http://backend:8080/readyz 2>&1 || true)
if [[ "$readiness" != *"503 Service Unavailable"* ]]; then
@@ -130,4 +165,4 @@ fi
curl --fail --silent --show-error "http://127.0.0.1:$port/api/v1/healthz" >/dev/null
compose up -d --wait --wait-timeout 90 seaweedfs
wait_for_readiness
printf '%s\n' 'Technical smoke passed: frontend, API routing, PostgreSQL, Redis, SeaweedFS, dependency recovery, storage authentication, and the disabled mail transport.'
printf '%s\n' 'Technical smoke passed: frontend, API routing, PostgreSQL, Redis, SeaweedFS, dependency recovery, storage authentication and network isolation, and the disabled mail transport.'