-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathconfigs.go
More file actions
516 lines (460 loc) · 10.8 KB
/
configs.go
File metadata and controls
516 lines (460 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
//go:build integration || interactive
package e2e
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"
"testing"
"github.com/efficientgo/core/testutil"
"github.com/efficientgo/e2e"
)
type testType string
const (
metrics testType = "metrics"
rules testType = "rules"
alerts testType = "alerts"
logs testType = "logs"
traces testType = "traces"
tracesTemplate testType = "tracesTemplate"
tracesTempo testType = "tracesTempo"
tenants testType = "tenants"
interactive testType = "interactive"
probes testType = "probes"
certsSharedDir = "certs"
configSharedDir = "config"
defaultTenantID = "1610b0c3-c509-4592-a256-a1871353dbfa"
mtlsTenantID = "845cdfd9-f936-443c-979c-2ee7dc91f646"
defaultTenantName = "test-oidc"
)
const tenantsYamlTpl = `
tenants:
- name: test-oidc
id: 1610b0c3-c509-4592-a256-a1871353dbfa
authenticator:
type: oidc
config:
clientID: test
clientSecret: ZXhhbXBsZS1hcHAtc2VjcmV0
issuerCAPath: %[1]s
issuerURL: https://%[2]s
redirectURL: https://%[7]s:8443/oidc/test-oidc/callback
usernameClaim: email
opa:
query: data.observatorium.allow
paths:
- %[3]s
- %[4]s
rateLimits:
- endpoint: "/api/metrics/v1/.+/api/v1/receive"
limit: 100
window: 1s
- endpoint: "/api/logs/v1/.*"
limit: 100
window: 1s
- name: another-tenant
id: 177ef09c-04e1-46c5-86f7-dc3250bfe869
oidc:
clientID: test
clientSecret: ZXhhbXBsZS1hcHAtc2VjcmV0
issuerCAPath: %[1]s
issuerURL: https://%[2]s
redirectURL: https://%[7]s:8443/oidc/another-tenant/callback
usernameClaim: email
opa:
query: data.observatorium.allow
paths:
- %[3]s
- %[4]s
- name: test-attacker
id: 066df98b-04e1-46c5-86f7-dc3250bfe869
oidc:
clientID: test
clientSecret: ZXhhbXBsZS1hcHAtc2VjcmV0
issuerCAPath: %[1]s
issuerURL: https://%[2]s
redirectURL: https://%[7]s:8443/oidc/test-attacker/callback
usernameClaim: email
opa:
query: data.observatorium.allow
paths:
- %[3]s
- %[4]s
- name: test-mtls
id: 845cdfd9-f936-443c-979c-2ee7dc91f646
mTLS:
caPath: %[5]s
opa:
url: http://%[6]s
rateLimits:
- endpoint: "/api/metrics/v1/.+/api/v1/receive"
limit: 1
window: 1s
- endpoint: "/api/logs/v1/.*"
limit: 1
window: 1s
- name: test-probes
id: 76480613-1952-48a0-8025-34307a07a822
oidc:
clientID: test
clientSecret: ZXhhbXBsZS1hcHAtc2VjcmV0
issuerCAPath: %[1]s
issuerURL: https://%[2]s
redirectURL: https://%[7]s:8443/oidc/test-probes/callback
usernameClaim: email
opa:
query: data.observatorium.allow
paths:
- %[3]s
- %[4]s
`
func createTenantsYAML(
t *testing.T,
e e2e.Environment,
issuerURL string,
opaURL string,
apiServiceHostname string,
) {
yamlContent := []byte(fmt.Sprintf(
tenantsYamlTpl,
filepath.Join(e.SharedDir(), certsSharedDir, "ca.pem"),
path.Join(issuerURL, "dex"),
filepath.Join(e.SharedDir(), configSharedDir, "observatorium.rego"),
filepath.Join(e.SharedDir(), configSharedDir, "rbac.yaml"),
filepath.Join(e.SharedDir(), certsSharedDir, "ca.pem"),
path.Join(opaURL, "v1/data/observatorium/allow"),
apiServiceHostname,
))
err := os.WriteFile(
filepath.Join(e.SharedDir(), configSharedDir, "tenants.yaml"),
yamlContent,
os.FileMode(0755),
)
testutil.Ok(t, err)
}
const dexYAMLTpl = `
issuer: https://%s:5556/dex
storage:
type: sqlite3
config:
file: /tmp/dex.db
web:
https: 0.0.0.0:5556
tlsCert: %s
tlsKey: %s
telemetry:
http: 0.0.0.0:5558
logger:
level: "debug"
oauth2:
passwordConnector: local
staticClients:
- id: test
name: test
secret: ZXhhbXBsZS1hcHAtc2VjcmV0
redirectURIs:
- https://%s:8443/oidc/test-oidc/callback
- https://%s:8443/oidc/another-tenant/callback
- https://%s:8443/oidc/test-probes/callback
enablePasswordDB: true
staticPasswords:
- email: "admin@example.com"
# bcrypt hash of the string "password"
hash: "$2a$10$2b2cU8CPhOTaGrs1HRQuAueS7JTT5ZHsHSzYiFPm1leZck7Mc8T4W"
username: "admin"
userID: "08a8684b-db88-4b73-90a9-3cd1661f5466"
`
func createDexYAML(
t *testing.T,
e e2e.Environment,
issuer string,
redirectURI string,
) {
yamlContent := []byte(fmt.Sprintf(
dexYAMLTpl,
issuer,
filepath.Join(e.SharedDir(), certsSharedDir, "dex.pem"),
filepath.Join(e.SharedDir(), certsSharedDir, "dex.key"),
redirectURI,
redirectURI,
redirectURI,
))
err := os.WriteFile(
filepath.Join(e.SharedDir(), configSharedDir, "dex.yaml"),
yamlContent,
os.FileMode(0755),
)
testutil.Ok(t, err)
}
const rulesYAMLTpl = `
type: S3
config:
bucket: %s
endpoint: %s
access_key: %s
insecure: true
secret_key: %s
`
func createRulesYAML(
t *testing.T,
e e2e.Environment,
bucket, endpoint, accessKey, secretKey string,
) {
yamlContent := []byte(fmt.Sprintf(
rulesYAMLTpl,
bucket,
endpoint,
accessKey,
secretKey,
))
err := os.WriteFile(
filepath.Join(e.SharedDir(), configSharedDir, "rules-objstore.yaml"),
yamlContent,
os.FileMode(0755),
)
testutil.Ok(t, err)
}
const otelConfigTpl = `
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
http:
endpoint: "0.0.0.0:4318"
exporters:
debug:
verbosity: detailed
otlp:
endpoint: %[1]s
tls:
insecure: true
service:
telemetry:
metrics:
readers:
- pull:
exporter:
prometheus:
host: 0.0.0.0
port: 8888
level: detailed
logs:
level: DEBUG
pipelines:
traces/grpc:
receivers: [otlp]
exporters: [debug,otlp]
`
// createOtelCollectorConfigYAML() creates YAML for an Open Telemetry collector inside the Observatorium API boundary.
func createOtelCollectorConfigYAML(
t *testing.T,
e e2e.Environment,
jaegerGRPCEndpoint string,
) {
// Warn if a YAML change introduced a tab character
if strings.ContainsRune(otelConfigTpl, '\t') {
t.Errorf("Tab in the YAML")
}
yamlContent := []byte(fmt.Sprintf(
otelConfigTpl,
jaegerGRPCEndpoint))
err := os.WriteFile(
filepath.Join(e.SharedDir(), configSharedDir, "collector.yaml"),
yamlContent,
os.FileMode(0644),
)
testutil.Ok(t, err)
}
// OTel trace collector that receives in HTTP w/o security, but exports in gRPC with security.
const otelForwardingConfigTpl = `
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
grpc:
endpoint: 0.0.0.0:4317
exporters:
debug:
verbosity: detailed
otlp:
endpoint: %[1]s
# auth:
# authenticator: oauth2client
tls:
insecure_skip_verify: true
compression: none
headers:
x-tenant: test-oidc
# (Use hard-coded auth header, because this forwarding collector
# is unable to do OIDC password grant)
authorization: bearer %[2]s
extensions:
health_check:
endpoint: 0.0.0.0:13133
zpages:
endpoint: 0.0.0.0:55679
service:
extensions: [health_check, zpages]
telemetry:
metrics:
readers:
- pull:
exporter:
prometheus:
host: 0.0.0.0
port: 8888
level: detailed
# extensions: [oauth2client]
pipelines:
traces:
receivers: [otlp]
exporters: [debug,otlp]
`
// createOtelForwardingCollectorConfigYAML() creates YAML for an Open Telemetry collector outside the
// Observatorium API boundary that forwards traces via GRPC to Observatorium.
func createOtelForwardingCollectorConfigYAML(
t *testing.T,
e e2e.Environment,
observatoriumGRPCEndpoint string,
dexToken string,
) {
// Warn if a YAML change introduced a tab character
if strings.ContainsRune(otelForwardingConfigTpl, '\t') {
t.Errorf("Tab in the YAML")
}
yamlContent := []byte(fmt.Sprintf(
otelForwardingConfigTpl,
observatoriumGRPCEndpoint,
dexToken))
err := os.WriteFile(
filepath.Join(e.SharedDir(), configSharedDir, "forwarding-collector.yaml"),
yamlContent,
os.FileMode(0644),
)
testutil.Ok(t, err)
}
const lokiYAMLTpl = `auth_enabled: true
server:
http_listen_port: 3100
common:
storage:
s3:
s3forcepathstyle: true
access_key_id: %[1]s
secret_access_key: %[2]s
endpoint: %[3]s
bucketnames: %[4]s
insecure: true
compactor:
working_directory: /tmp/loki/compactor
shared_store: s3
compaction_interval: 5m
distributor:
ring:
kvstore:
store: inmemory
ingester:
lifecycler:
address: 0.0.0.0
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 5m
chunk_retain_period: 30s
wal:
dir: /tmp/loki/ingester/wal
enabled: false
querier:
engine:
max_look_back_period: 5m
timeout: 3m
ruler:
storage:
type: s3
wal:
dir: /tmp/loki/ruler/wal
rule_path: /tmp/loki/
schema_config:
configs:
- from: 2019-01-01
store: boltdb-shipper
object_store: s3
schema: v12
index:
prefix: index_
period: 24h
storage_config:
boltdb_shipper:
active_index_directory: /tmp/loki/index
cache_location: /tmp/loki/index_cache
shared_store: s3
limits_config:
enforce_metric_name: false
reject_old_samples: false
`
func createLokiYAML(
t *testing.T,
e e2e.Environment,
accessId, accessKey, endpoint, bucket string,
) {
yamlContent := []byte(fmt.Sprintf(lokiYAMLTpl, accessId, accessKey, endpoint, bucket))
err := os.WriteFile(
filepath.Join(e.SharedDir(), configSharedDir, "loki.yml"),
yamlContent,
os.FileMode(0755),
)
testutil.Ok(t, err)
}
const tempoConfig = `
server:
http_listen_port: 3200
query_frontend:
search:
duration_slo: 5s
throughput_bytes_slo: 1.073741824e+09
trace_by_id:
duration_slo: 5s
distributor:
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
grpc:
endpoint: 0.0.0.0:4317
opencensus:
ingester:
max_block_duration: 5m # cut the headblock when this much time passes. this is being set for demo purposes and should probably be left alone normally
compactor:
compaction:
block_retention: 1h # overall Tempo trace retention. set for demo purposes
storage:
trace:
backend: local # backend configuration to use
wal:
path: /tmp/tempo/wal # where to store the the wal locally
local:
path: /tmp/tempo/blocks
`
// createTempoConfigYAML() creates YAML for Tempo inside the Observatorium API boundary.
func createTempoConfigYAML(
t *testing.T,
e e2e.Environment,
) {
// Warn if a YAML change introduced a tab character
if strings.ContainsRune(tempoConfig, '\t') {
t.Errorf("Tab in the YAML")
}
yamlContent := []byte(tempoConfig)
err := os.WriteFile(
filepath.Join(e.SharedDir(), configSharedDir, "tempo.yaml"),
yamlContent,
os.FileMode(0644),
)
testutil.Ok(t, err)
}