feat(infra): add Bitwarden Secrets Manager injection for container secrets
Adds a bws-CLI build stage to the Dockerfile and a docker-entrypoint.sh that runs `bws run -- node server.js` when BWS_ACCESS_TOKEN is set, falling back to a plain `node server.js` start when it's not. Lets AWS Route 53 credentials (and any future BWS-managed secret) reach the container without ever being written to the committed .env file. Fixed during phase 24 verification: - The bws CLI config only set state_dir; bws 2.x requires server_base (or server_identity) even for the default Bitwarden cloud instance, which crash-looped the container on every start. Added server_base = "https://vault.bitwarden.com". - docker-compose.yml's app.environment block re-declared BWS_ACCESS_TOKEN/BWS_PROJECT_ID as ${VAR:-} substitutions, which resolve against the root .env (not .env.local) and silently overrode the real token with an empty string. Removed the redundant re-declaration — env_file: .env.local already injects them. Verified live: pulse-app rebuilt and restarted with both fixes, AWS credentials confirmed reaching the Node process via BWS injection. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
979554d4dc
commit
c155f56151
3 changed files with 43 additions and 1 deletions
27
Dockerfile
27
Dockerfile
|
|
@ -23,6 +23,17 @@ ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
# Download Bitwarden Secrets Manager CLI
|
||||||
|
FROM base AS bws
|
||||||
|
ARG BWS_VERSION=2.1.0
|
||||||
|
ARG BWS_ARCH=x86_64-unknown-linux-musl
|
||||||
|
RUN apk add --no-cache curl unzip
|
||||||
|
RUN curl -fsSL "https://github.com/bitwarden/sdk-sm/releases/download/bws-v${BWS_VERSION}/bws-${BWS_ARCH}-${BWS_VERSION}.zip" -o /tmp/bws.zip && \
|
||||||
|
mkdir -p /tmp/bws-extract && \
|
||||||
|
unzip -q /tmp/bws.zip -d /tmp/bws-extract && \
|
||||||
|
find /tmp/bws-extract -type f -name bws -exec chmod +x {} \; -exec cp {} /usr/local/bin/bws \; && \
|
||||||
|
/usr/local/bin/bws --version
|
||||||
|
|
||||||
# Production image, copy all the files and run next
|
# Production image, copy all the files and run next
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
@ -44,6 +55,20 @@ RUN chown nextjs:nodejs .next
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
# Copy Bitwarden Secrets Manager CLI and entrypoint
|
||||||
|
COPY --from=bws /usr/local/bin/bws /usr/local/bin/bws
|
||||||
|
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
|
||||||
|
RUN chmod +x /app/docker-entrypoint.sh
|
||||||
|
|
||||||
|
# bws config/state directory (writable by nextjs)
|
||||||
|
# server_base is required as of bws 2.x — the profile errors with
|
||||||
|
# "Profile has no `server_base` or `server_identity`" without it, even
|
||||||
|
# for the default Bitwarden cloud instance.
|
||||||
|
RUN mkdir -p /app/.config/bws && chown -R nextjs:nodejs /app/.config/bws && \
|
||||||
|
printf '[profiles.default]\nserver_base = "https://vault.bitwarden.com"\nstate_dir = "/app/.config/bws/state"\n' > /app/.config/bws/config && \
|
||||||
|
chown nextjs:nodejs /app/.config/bws/config
|
||||||
|
ENV BWS_CONFIG_FILE=/app/.config/bws/config
|
||||||
|
|
||||||
USER nextjs
|
USER nextjs
|
||||||
|
|
||||||
# Use custom port 3100 instead of 3000
|
# Use custom port 3100 instead of 3000
|
||||||
|
|
@ -52,4 +77,4 @@ EXPOSE 3100
|
||||||
ENV PORT 3100
|
ENV PORT 3100
|
||||||
ENV HOSTNAME "0.0.0.0"
|
ENV HOSTNAME "0.0.0.0"
|
||||||
|
|
||||||
CMD ["node", "server.js"]
|
CMD ["/app/docker-entrypoint.sh"]
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,13 @@ services:
|
||||||
POSTGRES_USER: ${POSTGRES_USER:-pulse_user}
|
POSTGRES_USER: ${POSTGRES_USER:-pulse_user}
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-your_secure_password_here_change_in_production}
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-your_secure_password_here_change_in_production}
|
||||||
DATABASE_URL: postgresql://${POSTGRES_USER:-pulse_user}:${POSTGRES_PASSWORD:-your_secure_password_here_change_in_production}@postgres:5432/${POSTGRES_DB:-pulse_autotask}
|
DATABASE_URL: postgresql://${POSTGRES_USER:-pulse_user}:${POSTGRES_PASSWORD:-your_secure_password_here_change_in_production}@postgres:5432/${POSTGRES_DB:-pulse_autotask}
|
||||||
|
|
||||||
|
# Bitwarden Secrets Manager (optional) — deliberately NOT re-declared here.
|
||||||
|
# env_file: .env.local already injects BWS_ACCESS_TOKEN/BWS_PROJECT_ID directly.
|
||||||
|
# Re-declaring them as ${VAR:-} substitutions resolves against the root .env /
|
||||||
|
# shell env (not .env.local), which clobbers the real value with an empty string
|
||||||
|
# when the var isn't also present in root .env — as it correctly isn't here,
|
||||||
|
# since BWS_ACCESS_TOKEN is a live secret that must never land in the committed .env.
|
||||||
depends_on:
|
depends_on:
|
||||||
redis:
|
redis:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|
|
||||||
10
docker-entrypoint.sh
Normal file
10
docker-entrypoint.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -n "${BWS_ACCESS_TOKEN:-}" ]; then
|
||||||
|
echo "Loading secrets from Bitwarden Secrets Manager..."
|
||||||
|
exec bws run ${BWS_PROJECT_ID:+--project-id "${BWS_PROJECT_ID}"} -- node server.js
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "BWS_ACCESS_TOKEN not set; starting without Bitwarden secrets."
|
||||||
|
exec node server.js
|
||||||
Loading…
Add table
Add a link
Reference in a new issue