Bach 운영 컨테이너 보안을 강화한다
백엔드는 내부 네트워크에만 두고 Docker 비밀 파일의 API 키를 프록시에서 주입한다. 프론트엔드는 루프백 포트 18102만 사용한다.
This commit is contained in:
@@ -22,6 +22,8 @@ FROM nginx:1.27-alpine
|
||||
|
||||
COPY --from=builder /app/frontend/dist /usr/share/nginx/html
|
||||
COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY frontend/docker-entrypoint.d/20-backend-api-key.sh /docker-entrypoint.d/20-backend-api-key.sh
|
||||
RUN chmod 755 /docker-entrypoint.d/20-backend-api-key.sh
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
secret_file="${BACKEND_API_KEY_FILE:-/run/secrets/backend_api_key}"
|
||||
if [ ! -r "$secret_file" ]; then
|
||||
echo "백엔드 인증 키 파일을 읽을 수 없습니다." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
backend_api_key="$(cat "$secret_file")"
|
||||
if [ -z "$backend_api_key" ]; then
|
||||
echo "백엔드 인증 키가 비어 있습니다." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
escaped_key="$(printf '%s' "$backend_api_key" | sed 's/[\\/&]/\\\\&/g')"
|
||||
sed -i "s/__BACKEND_API_KEY__/${escaped_key}/g" /etc/nginx/conf.d/default.conf
|
||||
@@ -34,6 +34,7 @@ server {
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-API-Key "__BACKEND_API_KEY__";
|
||||
# Sample / soundfont uploads can be large
|
||||
client_max_body_size 60M;
|
||||
# OMR + transcription can take a while
|
||||
|
||||
Reference in New Issue
Block a user