Skip to content

Commit a0881f5

Browse files
committed
Hardening the image
1. Resolve no write permission to running user for the copied resource, to make container immutable and reproducible Ref: https://sonarcloud.io/project/security_hotspots?id=OWASP_Nest&pullRequest=1323&issueStatuses=OPEN%2CCONFIRMED&sinceLeakPeriod=true&tab=code
1 parent 02e6924 commit a0881f5

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

frontend/docker/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ COPY --chmod=444 package.json pnpm-lock.yaml ./
1111
RUN pnpm install --ignore-scripts
1212

1313
COPY --chmod=444 .env next.config.ts postcss.config.js tailwind.config.js tsconfig.json ./
14-
COPY public public
15-
COPY src src
14+
COPY --chmod=555 public public
15+
COPY --chmod=555 src src
1616

1717
# Next.js collects completely anonymous telemetry data about general usage.
1818
# Learn more here: https://nextjs.org/telemetry
@@ -30,13 +30,15 @@ ENV NEXT_TELEMETRY_DISABLED=1
3030

3131
RUN addgroup --system --gid 1001 nodejs
3232
RUN adduser --system --uid 1001 nextjs
33-
34-
COPY --from=builder /app/public public
33+
# Copying files with root as owner, so that executing user cannot change the container i.e immutable and reproducible
34+
COPY --from=builder --chown=root:root --chmod=555 /app/public public
3535

3636
# Automatically leverage output traces to reduce image size
3737
# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
38-
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone .
39-
COPY --from=builder --chown=nextjs:nodejs /app/.next/static .next/static
38+
COPY --from=builder --chown=root:root --chmod=555 /app/.next/standalone .
39+
# Create (if not there ) cache directory and assign ownership to nextjs user with write permission, so that cahce can be stored
40+
RUN mkdir -p /app/.next/cache && chown -R nextjs:nodejs /app/.next/cache && chmod -R 755 /app/.next/cache
41+
COPY --from=builder --chown=root:root --chmod=555 /app/.next/static .next/static
4042

4143
USER nextjs
4244

0 commit comments

Comments
 (0)