Skip to content

Commit 719ab97

Browse files
committed
move secrets to k8 secrets, add logs from tier-2
1 parent 0a16647 commit 719ab97

5 files changed

Lines changed: 140 additions & 13 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
# environment file with secret password
2424
**/.env
2525

26+
# local kubectl secrets (copy from showroom/kubectl/secrets.example.yaml)
27+
showroom/kubectl/secrets.local.yaml
28+
showroom/kubectl/secrets.env
29+
showroom/kubectl/htpasswd.secret
30+
2631
# potentially generated file
2732
/src/file-sink/received-logs.txt
2833

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Preferred: use secrets.env (see secrets.env.example) and run:
2+
# task secrets:apply
3+
# or: ./kubectl/apply-secrets.sh (Linux/macOS/Git Bash)
4+
# or: ./kubectl/apply-secrets.ps1 (Windows PowerShell)
5+
#
6+
# Secrets are applied with kubectl create secret ... | kubectl apply (nothing committed).
7+
#
8+
# Cross-check with tier-1.yaml / tier-2.yaml:
9+
# - tier-1 init: secret dice-java-openbao-token key token
10+
# - tier-1 otel sidecar: secret otel-otlp-client-auth keys username, password -> OTEL_OTLP_EXPORTER_*
11+
# - tier-2 otel: secret otel-otlp-ingest-htpasswd key htpasswd -> file /etc/otelcol-secrets/htpasswd
12+
# The htpasswd line MUST authenticate the same user/password as otel-otlp-client-auth (tier-1 exporter).
13+
# - tier-2 otel OpenSearch: secret opensearch-credentials keys username, password -> OPENSEARCH_*
14+
#
15+
# Legacy (optional): copy this file to secrets.local.yaml (gitignored), replace REPLACE_ME, then:
16+
# kubectl apply -f secrets.local.yaml
17+
---
18+
apiVersion: v1
19+
kind: Secret
20+
metadata:
21+
name: dice-java-openbao-token
22+
namespace: tier-1
23+
type: Opaque
24+
stringData:
25+
token: REPLACE_ME
26+
---
27+
apiVersion: v1
28+
kind: Secret
29+
metadata:
30+
name: otel-otlp-client-auth
31+
namespace: tier-1
32+
type: Opaque
33+
stringData:
34+
username: REPLACE_ME
35+
password: REPLACE_ME
36+
---
37+
apiVersion: v1
38+
kind: Secret
39+
metadata:
40+
name: otel-otlp-ingest-htpasswd
41+
namespace: tier-2
42+
type: Opaque
43+
stringData:
44+
htpasswd: |
45+
REPLACE_ME_USERNAME:REPLACE_ME_PASSWORD_OR_BCRYPT_HASH
46+
---
47+
apiVersion: v1
48+
kind: Secret
49+
metadata:
50+
name: opensearch-credentials
51+
namespace: tier-2
52+
type: Opaque
53+
stringData:
54+
username: REPLACE_ME
55+
password: REPLACE_ME

showroom/kubectl/tier-1.yaml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# - Deployment with 3 replicas
33
# - Each pod runs the application container and an otelcol sidecar
44
# - ConfigMap contains the otelcol config
5+
#
6+
# Apply namespace secrets before this manifest: task secrets:apply (kubectl/secrets.env), or see secrets.example.yaml.
7+
# dice-java-openbao-token (key: token)
8+
# otel-otlp-client-auth (keys: username, password) — must match tier-2 otel-otlp-ingest-htpasswd line
59

610
apiVersion: v1
711
kind: ConfigMap
@@ -12,10 +16,8 @@ data:
1216
extensions:
1317
basicauth/client:
1418
client_auth:
15-
# TEST-ONLY: plaintext credentials in a ConfigMap are NOT production-ready.
16-
# For production use a Kubernetes Secret and/or external secret store, and rotate credentials.
17-
username: "##########"
18-
password: "##########"
19+
username: ${env:OTEL_OTLP_EXPORTER_USERNAME}
20+
password: ${env:OTEL_OTLP_EXPORTER_PASSWORD}
1921
2022
receivers:
2123
otlp:
@@ -26,6 +28,11 @@ data:
2628
endpoint: 0.0.0.0:4318
2729
2830
processors:
31+
transform/fixlogtime:
32+
log_statements:
33+
- context: log
34+
statements:
35+
- set(time_unix_nano, observed_time_unix_nano) where time_unix_nano == 0
2936
certificatehash:
3037
hash_algorithm: SHA256
3138
sign_content: body
@@ -52,7 +59,7 @@ data:
5259
pipelines:
5360
logs:
5461
receivers: [otlp]
55-
processors: [certificatehash, batch]
62+
processors: [transform/fixlogtime, certificatehash, batch]
5663
exporters: [otlphttp, debug]
5764
metrics:
5865
receivers: [otlp]
@@ -154,7 +161,10 @@ spec:
154161
- name: OPENBAO_CERT_PATH
155162
value: "kv/data/secret"
156163
- name: OPENBAO_TOKEN
157-
value: "##########"
164+
valueFrom:
165+
secretKeyRef:
166+
name: dice-java-openbao-token
167+
key: token
158168
volumeMounts:
159169
- name: dice-java-certs
160170
mountPath: /etc/dice-java/certs
@@ -203,6 +213,17 @@ spec:
203213
imagePullPolicy: IfNotPresent
204214
args:
205215
- "--config=/etc/otelcol-contrib/config.yaml"
216+
env:
217+
- name: OTEL_OTLP_EXPORTER_USERNAME
218+
valueFrom:
219+
secretKeyRef:
220+
name: otel-otlp-client-auth
221+
key: username
222+
- name: OTEL_OTLP_EXPORTER_PASSWORD
223+
valueFrom:
224+
secretKeyRef:
225+
name: otel-otlp-client-auth
226+
key: password
206227
ports:
207228
- name: otlp-grpc
208229
containerPort: 4317

showroom/kubectl/tier-2.yaml

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# ServiceAccount for the OTel Collector Agent
2+
# Apply namespace secrets before this manifest: task secrets:apply (kubectl/secrets.env), or see secrets.example.yaml.
3+
# otel-otlp-ingest-htpasswd (key: htpasswd) -> /etc/otelcol-secrets/htpasswd
4+
# opensearch-credentials (keys: username, password) -> OPENSEARCH_USERNAME / OPENSEARCH_PASSWORD
25
apiVersion: v1
36
kind: ServiceAccount
47
metadata:
@@ -19,11 +22,7 @@ data:
1922
endpoint: ${env:MY_POD_IP}:13133
2023
basicauth/server:
2124
htpasswd:
22-
inline: |
23-
# TEST-ONLY: plaintext htpasswd entries are NOT production-ready.
24-
# For production generate a bcrypt htpasswd line (e.g. `htpasswd -nbBC 10 USER PASS`)
25-
# and store it in a Kubernetes Secret (or external secret store).
26-
##########:##########
25+
file: /etc/otelcol-secrets/htpasswd
2726
basicauth/client:
2827
client_auth:
2928
username: ${env:OPENSEARCH_USERNAME}
@@ -40,8 +39,20 @@ data:
4039
endpoint: 0.0.0.0:4318
4140
auth:
4241
authenticator: basicauth/server
42+
filelog/tier2:
43+
include:
44+
- /var/log/pods/tier-2_*/*/*.log
45+
start_at: end
46+
include_file_path: true
47+
operators:
48+
- type: container
4349
4450
processors:
51+
transform/fixlogtime:
52+
log_statements:
53+
- context: log
54+
statements:
55+
- set(time_unix_nano, observed_time_unix_nano) where time_unix_nano == 0
4556
certificatelogverify:
4657
hash_algorithm: SHA256
4758
sign_content: body
@@ -69,6 +80,18 @@ data:
6980
sending_queue:
7081
enabled: true
7182
storage: file_storage
83+
opensearch/tier2self:
84+
http:
85+
endpoint: https://opensearch-cluster-master.tier-3.svc.cluster.local:9200
86+
tls:
87+
insecure_skip_verify: true
88+
auth:
89+
authenticator: basicauth/client
90+
logs_index: otel-logs-tier2
91+
traces_index: otel-traces
92+
sending_queue:
93+
enabled: true
94+
storage: file_storage
7295
debug/logs:
7396
verbosity: detailed
7497
debug/metrics:
@@ -79,8 +102,12 @@ data:
79102
pipelines:
80103
logs:
81104
receivers: [otlp]
82-
processors: [certificatelogverify, batch]
105+
processors: [transform/fixlogtime, certificatelogverify, batch]
83106
exporters: [opensearch, debug/logs]
107+
logs/tier2self:
108+
receivers: [filelog/tier2]
109+
processors: [transform/fixlogtime, batch]
110+
exporters: [opensearch/tier2self]
84111
metrics:
85112
receivers: [otlp]
86113
processors: [batch]
@@ -182,13 +209,19 @@ spec:
182209
cpu: 200m
183210
requests:
184211
memory: 128Mi
185-
cpu: 100m
212+
cpu: 50m
186213
volumeMounts:
187214
- name: config
188215
mountPath: /etc/otelcol-contrib
189216
readOnly: true
190217
- name: storage
191218
mountPath: /var/lib/otelcol/storage
219+
- name: pod-logs
220+
mountPath: /var/log/pods
221+
readOnly: true
222+
- name: otlp-ingest-htpasswd
223+
mountPath: /etc/otelcol-secrets
224+
readOnly: true
192225
livenessProbe:
193226
httpGet:
194227
path: /
@@ -219,6 +252,14 @@ spec:
219252
hostPath:
220253
path: /var/lib/otelcol/storage
221254
type: DirectoryOrCreate
255+
- name: otlp-ingest-htpasswd
256+
secret:
257+
secretName: otel-otlp-ingest-htpasswd
258+
defaultMode: 288
259+
- name: pod-logs
260+
hostPath:
261+
path: /var/log/pods
262+
type: Directory
222263
---
223264
# Service for the OTel Collector Agent
224265
apiVersion: v1

showroom/taskfile.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ includes:
3434
desc: Install and manage the sample application (dice-java).
3535
taskfile: ./tasks/tier-1.yaml
3636

37+
secrets:
38+
desc: Apply workload secrets from kubectl/secrets.env.
39+
taskfile: ./tasks/secrets.yaml
40+
3741
tasks:
3842
default:
3943
desc: Create and start local kubernetes cluster and install otel-demo.
@@ -52,6 +56,7 @@ tasks:
5256
cmds:
5357
- task: garden:set-kubeconfig
5458
- task: cluster:install
59+
- task: secrets:apply
5560
- task: monitoring:install
5661
- task: otelcol-agent:install
5762
- task: dice:install

0 commit comments

Comments
 (0)