Skip to content

Commit cd7a850

Browse files
authored
Add Docker and Kubernetes examples to DoS section (#5729)
1 parent ceecd0f commit cd7a850

File tree

3 files changed

+126
-4
lines changed

3 files changed

+126
-4
lines changed

content/en/docs/security/_index.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
title: Security
3+
cascade:
4+
collector_vers: 0.115.1
35
weight: 970
46
---
57

content/en/docs/security/config-best-practices.md

+123-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,129 @@ addresses so the network functions properly in dual-stack environments and
115115
applications, where both protocol versions are used.
116116
117117
If you are working in environments that have nonstandard networking setups, such
118-
as Docker or Kubernetes, see the
119-
[example configurations](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/security-best-practices.md#safeguards-against-denial-of-service-attacks)
120-
in our component developer documentation for ideas on how to bind your component
121-
endpoints.
118+
as Docker or Kubernetes, `localhost` might not work as expected. The following
119+
examples show setups for the OTLP receiver gRPC endpoint. Other Collector
120+
components might need similar configuration.
121+
122+
#### Docker
123+
124+
You can run the Collector in Docker by binding to the correct address. Here is a
125+
`config.yaml` configuration file for an OTLP exporter in Docker:
126+
127+
```yaml
128+
receivers:
129+
otlp:
130+
protocols:
131+
grpc:
132+
endpoint: my-hostname:4317 # Use the same hostname from your docker run command
133+
```
134+
135+
In your `docker run` command, use the `--hostname` argument to bind the
136+
Collector to the `my-hostname` address. You can access the Collector from
137+
outside that Docker network (for example, on a regular program running on the
138+
host) by connecting to `127.0.0.1:4567`. Here is an example `docker run`
139+
command:
140+
141+
```shell
142+
docker run --hostname my-hostname --name container-name -p 127.0.0.1:4567:4317 otel/opentelemetry-collector:{{% param collector_vers %}}
143+
```
144+
145+
#### Docker Compose
146+
147+
Similarly to plain Docker, you can run the Collector in Docker by binding to the
148+
correct address.
149+
150+
The Docker `compose.yaml` file:
151+
152+
```yaml
153+
services:
154+
otel-collector:
155+
image: otel/opentelemetry-collector-contrib:{{% param collector_vers %}}
156+
ports:
157+
- '4567:4317'
158+
```
159+
160+
The Collector `config.yaml` file:
161+
162+
```yaml
163+
receivers:
164+
otlp:
165+
protocols:
166+
grpc:
167+
endpoint: otel-collector:4317 # Use the service name from your Docker compose file
168+
```
169+
170+
You can connect to this Collector from another Docker container running in the
171+
same network by connecting to `otel-collector:4317`. You can access the
172+
Collector from outside that Docker network (for example, on a regular program
173+
running on the host) by connecting to `127.0.0.1:4567`.
174+
175+
#### Kubernetes
176+
177+
If you run the Collector as a `DaemonSet`, you can use a configuration like the
178+
following:
179+
180+
```yaml
181+
apiVersion: apps/v1
182+
kind: DaemonSet
183+
metadata:
184+
name: collector
185+
spec:
186+
selector:
187+
matchLabels:
188+
name: collector
189+
template:
190+
metadata:
191+
labels:
192+
name: collector
193+
spec:
194+
containers:
195+
- name: collector
196+
image: otel/opentelemetry-collector:{{% param collector_vers %}}
197+
ports:
198+
- containerPort: 4317
199+
hostPort: 4317
200+
protocol: TCP
201+
name: otlp-grpc
202+
- containerPort: 4318
203+
hostPort: 4318
204+
protocol: TCP
205+
name: otlp-http
206+
env:
207+
- name: MY_POD_IP
208+
valueFrom:
209+
fieldRef:
210+
fieldPath: status.podIP
211+
```
212+
213+
In this example, you use the
214+
[Kubernetes Downward API](https://kubernetes.io/docs/concepts/workloads/pods/downward-api/)
215+
to get your own Pod IP, then bind to that network interface. Then, we use the
216+
`hostPort` option to ensure that the Collector is exposed on the host. The
217+
Collector's config should look like this:
218+
219+
```yaml
220+
receivers:
221+
otlp:
222+
protocols:
223+
grpc:
224+
endpoint: ${env:MY_POD_IP}:4317
225+
http:
226+
endpoint: ${env:MY_POD_IP}:4318
227+
```
228+
229+
You can send OTLP data to this Collector from any Pod on the Node by accessing
230+
`${MY_HOST_IP}:4317` to send OTLP over gRPC and `${MY_HOST_IP}:4318` to send
231+
OTLP over HTTP, where `MY_HOST_IP` is the Node's IP address. You can get this IP
232+
from the Downward API:
233+
234+
```yaml
235+
env:
236+
- name: MY_HOST_IP
237+
valueFrom:
238+
fieldRef:
239+
fieldPath: status.hostIP
240+
```
122241

123242
### Scrub sensitive data
124243

scripts/auto-update/all-versions.sh

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function auto_update_versions() {
44
local cmd="./scripts/auto-update/version-in-file.sh"
55
local updates=(
66
"opentelemetry-collector-releases vers content/en/docs/collector/_index.md"
7+
"opentelemetry-collector-releases collector_vers content/en/docs/security/_index.md"
78
"opentelemetry-java otel content/en/docs/languages/java/_index.md"
89
"opentelemetry-java otel content/en/docs/zero-code/java/_index.md"
910
"opentelemetry-java-instrumentation instrumentation content/en/docs/languages/java/_index.md"

0 commit comments

Comments
 (0)