- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
",t};e.buildCustomizationMenuUi=t;function n(e){let t='
",t}function s(e){let n=e.filter.currentValue||e.filter.defaultValue,t='${e.filter.label}
`,e.filter.options.forEach(s=>{let o=s.id===n;t+=``}),t+="${e.filter.label}
`,t+=`App and API Protection for Go installation requirements can be abstract and the Go toolchain cross-compilation and CGO capabilities can make precise installation steps difficult to understand.
The goal of this guide is to provide a step-by-step guide to a working Dockerfile customized for your use case.
Many Dockerfiles found in this guide come from the appsec-go-test-app repository. To try it out, first clone the repository:
git clone https://github.com/DataDog/appsec-go-test-app.git
cd appsec-go-test-app
A list of Dockerfile
examples can be found in the examples/docker
directory.
Here is an example of it in its simplest form:
FROM golang:1 AS build
WORKDIR /app
COPY . .
RUN go install github.com/DataDog/orchestrion # Resolved from go.mod dependencies
RUN orchestrion go build -o=main .
FROM debian:bookworm
COPY --from=build /app/main /usr/local/bin
ENV DD_APPSEC_ENABLED=true
ENTRYPOINT [ "/usr/local/bin/main" ]
This is the simplest version of a working Dockerfile for a Datadog WAF-enabled Go application. If this is your first use of Orchestrion, note that this dockerfile requires you run orchestrion pin
beforehand and commit the resulting changes. See Getting Started for Go.
This Dockerfile is split into two stages:
DD_APPSEC_ENABLED
to true
to enable App and API Protection.This two-stage build process allows you to keep the final image small and free of unnecessary build tools while still ensuring that your application is instrumented correctly for App and API Protection.
The following sections show different Dockerfile scenarios, each with their specific considerations and complete examples.
Two main dimensions impact your Dockerfile choice for App and API Protection:
CGO_ENABLED
).These dimensions affect both build requirements and runtime compatibility. The Datadog WAF requires specific shared libraries (libc.so.6
and libpthread.so.0
) at runtime and the build approach varies depending on these choices. Those dependencies are required by all programs built with CGO enabled, so the Datadog WAF will work out-of-the-box on runtime environments that support such programs.
When CGO is disabled, however, Go usually produces a fully, statically linked binary that does not require these libraries. but this is not true when using the Datadog WAF. This is why, when CGO is disabled, the -tags=appsec
flag needs to be passed to enable the Datadog WAF.
This is the recommended approach for most users, using Debian/Ubuntu-based images:
FROM golang:1 AS build
WORKDIR /app
COPY . .
RUN go install github.com/DataDog/orchestrion
RUN orchestrion go build -o=main .
FROM ubuntu:noble
COPY --from=build /app/main /usr/local/bin
ENV DD_APPSEC_ENABLED=true
ENTRYPOINT [ "/usr/local/bin/main" ]
Key considerations:
If you need CGO but still want a lighter runtime image, build with a Debian-based image and run with Alpine:
FROM golang:1 AS build
WORKDIR /app
COPY . .
RUN go install github.com/DataDog/orchestrion
RUN orchestrion go build -o=main .
FROM alpine
COPY --from=build /app/main /usr/local/bin/main
RUN apk add libc6-compat
ENV DD_APPSEC_ENABLED=true
ENTRYPOINT [ "/usr/local/bin/main" ]
Key considerations:
appsec
build tag requiredapk add libc6-compat
adds symlinks where necessary for a glibc-built binary to work on AlpineFor minimal build and runtime size, using CGO disabled builds (the default on Alpine):
FROM golang:1-alpine AS build
WORKDIR /app
COPY . .
RUN go install github.com/DataDog/orchestrion
RUN orchestrion go build -tags=appsec -o=main .
FROM alpine
COPY --from=build /app/main /usr/local/bin/main
ENV DD_APPSEC_ENABLED=true
ENTRYPOINT [ "/usr/local/bin/main" ]
Key considerations:
-tags=appsec
flag when CGO is disabledFor ultra-minimal images when using CGO_ENABLED=0
:
FROM golang:1 AS build
WORKDIR /app
COPY . .
RUN go install github.com/DataDog/orchestrion
# Build with appsec tag for CGO-disabled builds
ENV CGO_ENABLED=0
RUN orchestrion go build -tags=appsec -o=main .
# Install ldd and extract shared libraries that are necessary at runtime
RUN apt update && apt install -y binutils
RUN ldd main | tr -s '[:blank:]' '\n' | grep '^/' | \
xargs -I % sh -c 'mkdir -p $(dirname libs%); cp % libs%;'
FROM scratch
COPY --from=build /app/libs /app/main /
ENV DD_APPSEC_ENABLED=true
ENTRYPOINT [ "/main" ]
Key considerations:
-tags=appsec
flag when CGO is disabledldd
command identifies all runtime dependenciesFor security-focused deployments using Google’s distroless images:
FROM golang:1 AS build
WORKDIR /app
COPY . .
RUN go install github.com/DataDog/orchestrion
ENV CGO_ENABLED=0
RUN orchestrion go build -tags=appsec -o=main .
# Install ldd and extract shared libraries
RUN apt update && apt install -y binutils
RUN ldd main | tr -s '[:blank:]' '\n' | grep '^/' | \
xargs -I % sh -c 'mkdir -p $(dirname libs%); cp % libs%;'
FROM gcr.io/distroless/base-debian12:nonroot
COPY --from=build /app/libs /app/main /
ENV DD_APPSEC_ENABLED=true
ENTRYPOINT [ "/main" ]
Key considerations:
For building applications targeting different architectures:
FROM golang:1 AS build
# Install cross-compilation toolchain
RUN apt-get update && apt-get install -y gcc-aarch64-linux-gnu
WORKDIR /app
COPY . .
RUN go install github.com/DataDog/orchestrion
# Cross-compile for ARM64
ENV CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc GOOS=linux GOARCH=arm64
RUN orchestrion go build -o=main .
FROM arm64v8/debian
COPY --from=build /app/main /usr/local/bin
ENV DD_APPSEC_ENABLED=true
ENTRYPOINT [ "/usr/local/bin/main" ]
Key considerations:
CC
, GOOS
, and GOARCH
environment variablesMost of these Dockerfiles are available in appsec-go-test-app, trying them out is very easy:
docker build -f ./examples/alpine/Dockerfile -t appsec-go-test-app .
docker run appsec-go-test-app
To verify that App and API Protection is working correctly:
To see App and API Protection threat detection in action, send known attack patterns to your application. For example, trigger the Security Scanner Detected rule by running a file that contains the following curl script:
for ((i=1;i<=250;i++));
do
# Target existing service’s routes
curl https://your-application-url/existing-route -A Arachni/v1.0;
# Target non existing service’s routes
curl https://your-application-url/non-existing-route -A Arachni/v1.0;
done
A few minutes after you enable your application and exercise it, threat information appears in the Application Trace and Signals Explorer in Datadog.