fix: improve authentication and container reliability
- Update admin login logic to include email validation and optional fallback - Make Docker builds flexible for missing lockfiles - Standardize on 'node' user in web Dockerfile - Improve Nginx header forwarding for proxies - Add volume persistence and health dependency to compose file
This commit is contained in:
1 parent
1a1c19d7bb
commit
fa4516b078
5 files changed
+52
-25
No files matched your search
+22
-10
@@ -443,18 +443,30 @@ export async function verifyAdminCredentials(email: string, password: string) {
|
|||||||
const result = await pool.query(
|
const result = await pool.query(
|
||||||
`SELECT email, password_salt, password_hash
|
`SELECT email, password_salt, password_hash
|
||||||
FROM admin_users
|
FROM admin_users
|
||||||
WHERE email = $1`,
|
WHERE id = 1`,
|
||||||
[cleanEmail],
|
|
||||||
);
|
);
|
||||||
if (result.rowCount && result.rowCount > 0) {
|
if (result.rowCount && result.rowCount > 0) {
|
||||||
const admin = result.rows[0] as
|
const admin = result.rows[0] as {
|
||||||
| { email: string; password_salt: Buffer; password_hash: Buffer }
|
email: string;
|
||||||
| undefined;
|
password_salt: Buffer;
|
||||||
const salt = admin?.password_salt ?? Buffer.alloc(PASSWORD_SALT_BYTES);
|
password_hash: Buffer;
|
||||||
const expectedHash =
|
};
|
||||||
admin?.password_hash ?? Buffer.alloc(PASSWORD_HASH_BYTES);
|
const emailMatches = matchesSecret(
|
||||||
const actualHash = await derivePasswordHash(password, salt);
|
cleanEmail,
|
||||||
return Boolean(admin && timingSafeEqual(actualHash, expectedHash));
|
admin.email.trim().toLowerCase(),
|
||||||
|
);
|
||||||
|
const actualHash = await derivePasswordHash(
|
||||||
|
password,
|
||||||
|
admin.password_salt,
|
||||||
|
);
|
||||||
|
const passwordMatches = timingSafeEqual(
|
||||||
|
actualHash,
|
||||||
|
admin.password_hash,
|
||||||
|
);
|
||||||
|
return emailMatches && passwordMatches;
|
||||||
|
}
|
||||||
|
if (!process.env.DATASTACK_ADMIN_PASSWORD) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Database connection error, fall back to in-memory admin
|
// Database connection error, fall back to in-memory admin
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
FROM node:22-alpine AS dependencies
|
FROM node:22-alpine AS dependencies
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json* ./
|
||||||
RUN npm ci --omit=dev
|
RUN if [ -f package-lock.json ]; then npm ci --omit=dev; else npm install --omit=dev --no-audit --no-fund; fi
|
||||||
|
|
||||||
FROM node:22-alpine AS runner
|
FROM node:22-alpine AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
FROM node:22-alpine AS dependencies
|
FROM node:22-alpine AS dependencies
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json* ./
|
||||||
RUN npm ci
|
RUN if [ -f package-lock.json ]; then npm ci; else npm install --no-audit --no-fund; fi
|
||||||
|
|
||||||
FROM node:22-alpine AS builder
|
FROM node:22-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
@@ -16,13 +16,11 @@ ENV NODE_ENV=production
|
|||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
ENV HOSTNAME=0.0.0.0
|
ENV HOSTNAME=0.0.0.0
|
||||||
RUN addgroup -S -g 1001 nodejs \
|
COPY --from=builder --chown=node:node /app/public ./public
|
||||||
&& adduser -S -u 1001 -G nodejs nextjs
|
COPY --from=builder --chown=node:node /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
COPY --from=builder --chown=node:node /app/.next/static ./.next/static
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
||||||
RUN mkdir -p /app/storage/data \
|
RUN mkdir -p /app/storage/data \
|
||||||
&& chown -R nextjs:nodejs /app/storage
|
&& chown -R node:node /app/storage
|
||||||
USER nextjs
|
USER node
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
||||||
@@ -3,6 +3,16 @@ map $http_upgrade $connection_upgrade {
|
|||||||
'' close;
|
'' close;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
map $http_x_forwarded_proto $forwarded_proto {
|
||||||
|
default $http_x_forwarded_proto;
|
||||||
|
'' $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
map $http_x_forwarded_host $forwarded_host {
|
||||||
|
default $http_x_forwarded_host;
|
||||||
|
'' $host;
|
||||||
|
}
|
||||||
|
|
||||||
upstream nextjs_upstream {
|
upstream nextjs_upstream {
|
||||||
server web:3000;
|
server web:3000;
|
||||||
}
|
}
|
||||||
@@ -23,9 +33,10 @@ server {
|
|||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection $connection_upgrade;
|
proxy_set_header Connection $connection_upgrade;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Host $forwarded_host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
|
proxy_set_header X-Forwarded-Proto $forwarded_proto;
|
||||||
proxy_read_timeout 86400s;
|
proxy_read_timeout 86400s;
|
||||||
proxy_send_timeout 86400s;
|
proxy_send_timeout 86400s;
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
@@ -35,8 +46,9 @@ server {
|
|||||||
proxy_pass http://nextjs_upstream;
|
proxy_pass http://nextjs_upstream;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Host $forwarded_host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
|
proxy_set_header X-Forwarded-Proto $forwarded_proto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,14 +6,19 @@ services:
|
|||||||
dockerfile: docker/Dockerfile.web
|
dockerfile: docker/Dockerfile.web
|
||||||
expose:
|
expose:
|
||||||
- "3000"
|
- "3000"
|
||||||
|
volumes:
|
||||||
|
- datastack-data:/app/storage
|
||||||
environment:
|
environment:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
PORT: "3000"
|
PORT: "3000"
|
||||||
DATASTACK_JWT_SECRET: "${SERVICE_REALBASE64_64_JWT:?Coolify must generate SERVICE_REALBASE64_64_JWT}"
|
DATASTACK_JWT_SECRET: "${SERVICE_REALBASE64_64_JWT:?Coolify must generate SERVICE_REALBASE64_64_JWT}"
|
||||||
DATASTACK_ADMIN_EMAIL: "${DATASTACK_ADMIN_EMAIL:?Set DATASTACK_ADMIN_EMAIL in .env}"
|
DATASTACK_ADMIN_EMAIL: "${DATASTACK_ADMIN_EMAIL:-admin@datastack.dev}"
|
||||||
DATASTACK_ADMIN_SESSION_SECRET: "${SERVICE_REALBASE64_64_ADMINSESSION:?Coolify must generate SERVICE_REALBASE64_64_ADMINSESSION}"
|
DATASTACK_ADMIN_SESSION_SECRET: "${SERVICE_REALBASE64_64_ADMINSESSION:?Coolify must generate SERVICE_REALBASE64_64_ADMINSESSION}"
|
||||||
DATASTACK_ADMIN_SETUP_KEY: "${SERVICE_REALBASE64_64_ADMININSTALL:?Coolify must generate SERVICE_REALBASE64_64_ADMININSTALL}"
|
DATASTACK_ADMIN_SETUP_KEY: "${SERVICE_REALBASE64_64_ADMININSTALL:?Coolify must generate SERVICE_REALBASE64_64_ADMININSTALL}"
|
||||||
DATABASE_URL: "postgresql://datastack:${SERVICE_PASSWORD_64_POSTGRES:?Coolify must generate SERVICE_PASSWORD_64_POSTGRES}@postgres:5432/${SERVICE_HEX_32_DATABASENAME:?Coolify must generate SERVICE_HEX_32_DATABASENAME}"
|
DATABASE_URL: "postgresql://datastack:${SERVICE_PASSWORD_64_POSTGRES:?Coolify must generate SERVICE_PASSWORD_64_POSTGRES}@postgres:5432/${SERVICE_HEX_32_DATABASENAME:?Coolify must generate SERVICE_HEX_32_DATABASENAME}"
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test:
|
test:
|
||||||
@@ -85,7 +90,7 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 3
|
retries: 3
|
||||||
|
|
||||||
# Reserved for the planned metadata integration; not consumed by the current runtime.
|
# PostgreSQL stores the bootstrap admin credential and login throttle state in pgdata.
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16-alpine
|
image: postgres:16-alpine
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
Reference in new issue
Block a user