feat(storage): add private file layer and isolate SeaweedFS on a storage network
This commit is contained in:
1 parent
f5b07e8f4d
commit
8378ad45b0
22 files changed
+1668
-40
No files matched your search
@@ -63,6 +63,8 @@ services:
|
||||
networks:
|
||||
- observability
|
||||
- app
|
||||
# SeaweedFS metrics listen only on the storage network.
|
||||
- storage
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
@@ -296,6 +298,9 @@ networks:
|
||||
app:
|
||||
name: ${APP_NETWORK:-app_default}
|
||||
external: true
|
||||
storage:
|
||||
name: ${APP_STORAGE_NETWORK:-${APP_PROJECT:-app}_storage}
|
||||
external: true
|
||||
observability:
|
||||
internal: true
|
||||
|
||||
|
||||
@@ -62,11 +62,30 @@ services:
|
||||
|
||||
seaweedfs:
|
||||
image: chrislusf/seaweedfs:latest
|
||||
# The storage network is the primary boundary: besides S3, mini serves
|
||||
# unauthenticated gRPC (master, filer, volume, S3), an admin server, and
|
||||
# HTTP APIs that ignore S3 credentials, so only the backend and the
|
||||
# monitoring Prometheus may join it. S3 requires the access key below;
|
||||
# -s3.iam=false only removes the IAM management API. As defense in depth,
|
||||
# each start sets fresh random JWT keys that never leave the container
|
||||
# (filer and volume HTTP requests need a token), and -whiteList limits
|
||||
# master and volume HTTP to in-container callers. "@" is the peer of the
|
||||
# local gRPC sockets that mini uses between its components.
|
||||
entrypoint:
|
||||
- /bin/sh
|
||||
- -ec
|
||||
- |
|
||||
for name in WEED_JWT_SIGNING_KEY WEED_JWT_SIGNING_READ_KEY WEED_JWT_FILER_SIGNING_KEY WEED_JWT_FILER_SIGNING_READ_KEY; do
|
||||
export "$$name=$$(head -c 32 /dev/urandom | base64)"
|
||||
done
|
||||
exec /entrypoint.sh "$$@"
|
||||
- seaweedfs
|
||||
command:
|
||||
- mini
|
||||
- -dir=/data
|
||||
- -ip=seaweedfs
|
||||
- -ip=127.0.0.1
|
||||
- -ip.bind=0.0.0.0
|
||||
- -whiteList=127.0.0.1,@
|
||||
- -webdav=false
|
||||
- -admin.ui=false
|
||||
- -s3.iam=false
|
||||
@@ -82,6 +101,8 @@ services:
|
||||
S3_BUCKET: ${SEAWEEDFS_BUCKET:?Set SEAWEEDFS_BUCKET in the root .env file}
|
||||
volumes:
|
||||
- seaweedfs_data:/data
|
||||
networks:
|
||||
- storage
|
||||
expose:
|
||||
- "8333"
|
||||
- "9327"
|
||||
@@ -215,6 +236,9 @@ services:
|
||||
condition: service_healthy
|
||||
seaweedfs:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- default
|
||||
- storage
|
||||
expose:
|
||||
- "8080"
|
||||
- "9090"
|
||||
@@ -278,3 +302,7 @@ volumes:
|
||||
networks:
|
||||
default:
|
||||
name: ${APP_NETWORK:-app_default}
|
||||
# Only SeaweedFS, the backend, and the monitoring Prometheus join it.
|
||||
storage:
|
||||
name: ${APP_STORAGE_NETWORK:-${APP_PROJECT:-app}_storage}
|
||||
internal: true
|
||||
@@ -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
@@ -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.'
|
||||
Reference in new issue
Block a user