You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/security/application_security/setup/go/dockerfile.md
+20-20Lines changed: 20 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -17,8 +17,8 @@ further_reading:
17
17
18
18
# Introduction
19
19
20
-
App and API Protection for Go installation requirements can be abstract and the Go toolchain
21
-
cross-compilation capabilities can make it hard to understand what has to be done precisely.
20
+
App and API Protection for Go installation requirements can be abstract. Moreover the Go toolchain
21
+
cross-compilation and CGO capabilities can make it hard to understand what has to be done precisely.
22
22
23
23
In these cases, a more precise way to materialize these examples like a Dockerfile can be interesting.
24
24
The goal of this guide is to be a step-by-step guide to a working Dockerfile, tailor-fitted for your usecase.
@@ -40,37 +40,35 @@ FROM golang:1 AS build
40
40
WORKDIR /app
41
41
COPY . .
42
42
43
-
RUN go install github.com/DataDog/orchestrion@latest && \
44
-
orchestrion pin
43
+
RUN go install github.com/DataDog/orchestrion # Resolved from go.mod dependencies
45
44
46
45
RUN orchestrion go build -o main .
47
46
48
-
FROMubuntu:noble
47
+
FROMdebian:bookworm
49
48
COPY --from=build /app/main /usr/local/bin
50
49
51
50
ENV DD_APPSEC_ENABLED=true
52
51
ENTRYPOINT [ "/usr/local/bin/main" ]
53
52
```
54
53
55
-
This constitutes the simplest version of a working Dockerfile for a Go application with Datadog's WAF enabled.
56
-
It would be better to run `orchestrion pin` ahead of time and commit it to your VCS for future builds, but this is not a strict requirement.
54
+
This constitutes the simplest version of a working Dockerfile for a Go application with Datadog's WAF enabled. If this is your first use of [Orchestrion][5]. This dockerfile requires to run `orchestrion pin` beforehand and commit the resulting changes for it to work. Please refer to our [Getting Started for Go][-]
57
55
58
56
This Dockerfile is split into two stages:
59
57
1. The build stage builds from an Debian image the Go application using the [Orchestrion][5] tool to instrument it with App and API Protection features.
60
58
2. The runtime stage copies the built application into a minimal Ubuntu image and sets the environment variable `DD_APPSEC_ENABLED` to `true` to enable App and API Protection.
61
59
62
-
This two-stage build process is beneficial because it allows you to keep the final image small and free of unnecessary build tools,
63
-
while still ensuring that your application is instrumented correctly for App and API Protection.
60
+
This two-stage build process is beneficial because it allows you to keep the final image small and free of unnecessary build tools.
61
+
While still ensuring that your application is instrumented correctly for App and API Protection.
64
62
65
63
The following sections show different Dockerfile scenarios, each with their specific considerations and complete examples.
66
64
67
65
## Dockerfile scenarios
68
66
69
67
Two main dimensions impact your Dockerfile choice for App and API Protection:
70
68
***libc implementation**: glibc (Debian/Ubuntu) or musl (Alpine)
71
-
***CGO**: enabled (default) or disabled (`CGO_ENABLED=0`)
69
+
***CGO**: enabled or disabled (with the env var `CGO_ENABLED`).
72
70
73
-
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. When CGO is enabled, those libraries will always be required so the Datadog WAF can be baked in without issue. But CGO being disabled is often synonymous with no shared library, which cannot be the case out-of-the-box for Datadog WAF. This is why, by default, when CGO is disabled, the `-tagsappsec` flag need to be passed.
71
+
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, which is why when CGO is disabled, the `-tags=appsec` flag needs to be passed in order for the Datadog WAF to be enabled.
74
72
75
73
### Standard glibc-based Dockerfile
76
74
@@ -82,7 +80,7 @@ FROM golang:1 AS build
82
80
WORKDIR /app
83
81
COPY . .
84
82
85
-
RUN go install github.com/DataDog/orchestrion@latest
83
+
RUN go install github.com/DataDog/orchestrion
86
84
RUN orchestrion go build -o main .
87
85
88
86
FROM ubuntu:noble
@@ -108,7 +106,7 @@ FROM golang:1 AS build
108
106
WORKDIR /app
109
107
COPY . .
110
108
111
-
RUN go install github.com/DataDog/orchestrion@latest
109
+
RUN go install github.com/DataDog/orchestrion
112
110
RUN orchestrion go build -o main .
113
111
114
112
FROM alpine
@@ -134,7 +132,7 @@ FROM golang:1-alpine AS build
134
132
WORKDIR /app
135
133
COPY . .
136
134
137
-
RUN go install github.com/DataDog/orchestrion@latest
135
+
RUN go install github.com/DataDog/orchestrion
138
136
RUN orchestrion go build -tags appsec -o main .
139
137
140
138
FROM alpine
@@ -157,7 +155,7 @@ FROM golang:1 AS build
157
155
WORKDIR /app
158
156
COPY . .
159
157
160
-
RUN go install github.com/DataDog/orchestrion@latest
158
+
RUN go install github.com/DataDog/orchestrion
161
159
162
160
# Build with appsec tag for CGO-disabled builds
163
161
ENV CGO_ENABLED=0
@@ -182,14 +180,14 @@ ENTRYPOINT [ "/main" ]
182
180
183
181
### Distroless Dockerfile
184
182
185
-
For security-focused deployments using Google's distroless images:
183
+
For security-focused deployments using [Google's distroless][7] images:
186
184
187
185
```dockerfile
188
186
FROM golang:1 AS build
189
187
WORKDIR /app
190
188
COPY . .
191
189
192
-
RUN go install github.com/DataDog/orchestrion@latest
0 commit comments