

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Managing Secrets
incomplete
2: Injecting Secrets at Runtime
incomplete
3: Protecting Secrets
incomplete
4: Build Artifacts and Deployment Hygiene
incomplete
5: Limiting Build Context
incomplete
6: Source Code and Config Leaks
incomplete
7: Public File Leaks
incomplete
8: Server-Side Request Forgery
incomplete
9: Defending Against SSRF
incomplete
10: Open Redirects
incomplete
11: Risks of Dependencies
incomplete
12: Auditing Dependencies
incomplete
13: Dependency Maintenance
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
A production container should contain what the app needs to run and not much else. Extra tools and files increase image size and give an attacker more to work with.
This Dockerfile builds and runs a Go app in one image:
FROM golang:1.27.0-alpine
WORKDIR /app
COPY . .
RUN go build -o server ./cmd/server
CMD ["./server"]
It copies the entire build context and leaves the compiler, module cache, and source code in the production image. A multi-stage build can compile the binaries separately and copy only runtime artifacts into a smaller final stage:
FROM golang:1.27.0-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -o /out/server ./cmd/server
FROM alpine:3.22
WORKDIR /app
COPY --from=build /out/server ./server
USER 10001
CMD ["./server"]
The exact runtime files depend on the app. Explicitly copy only the binaries and assets production needs, and run the process as an unprivileged user.
Running as the unprivileged bearly user limits what a compromised process can do. The user still needs permission to perform Bearly Secure's ordinary runtime work.
Bearly Secure's production image contains the whole project and Go toolchain. Replace it with a narrow multi-stage image.
docker build -t bearly-secure .
docker run --rm --entrypoint id bearly-secure -u
Run and submit the CLI tests from the project root.