-
Notifications
You must be signed in to change notification settings - Fork 3
/
hydra.yaml
438 lines (425 loc) · 11.4 KB
/
hydra.yaml
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
---
apiVersion: v1
kind: Namespace
metadata:
name: hydra
---
apiVersion: v1
kind: Secret
metadata:
name: hydra
namespace: hydra
type: Opaque
stringData:
DSN: memory
SECRETS_SYSTEM: youReallyNeedToChangeThis
SECRETS_COOKIE: youReallyNeedToChangeThis
OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT: youReallyNeedToChangeThis
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hydra
namespace: hydra
spec:
replicas: 1
selector:
matchLabels:
app: hydra
template:
metadata:
labels:
app: hydra
spec:
automountServiceAccountToken: false
initContainers:
- name: migrate
image: docker.io/oryd/hydra:v2.2.0
args:
- migrate
- sql
- -e
- --yes
envFrom:
- secretRef:
name: hydra
optional: false
resources:
requests:
cpu: 20m
memory: 32Mi
limits:
cpu: 100m
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 65534
runAsGroup: 65534
seccompProfile:
type: RuntimeDefault
capabilities:
drop:
- ALL
containers:
- name: hydra
image: docker.io/oryd/hydra:v2.2.0
args:
- serve
- all
- --dev
envFrom:
- secretRef:
name: hydra
optional: false
env:
- name: URLS_SELF_ISSUER
value: http://hydra.hydra.svc:4444
- name: URLS_SELF_ADMIN
value: http://hydra.hydra.svc:4445
- name: URLS_SELF_PUBLIC
value: http://hydra.docker.localhost
- name: URLS_CONSENT
value: http://consent.docker.localhost/consent
- name: URLS_LOGIN
value: http://consent.docker.localhost/login
- name: URLS_LOGOUT
value: http://consent.docker.localhost/logout
- name: STRATEGIES_ACCESS_TOKEN
value: jwt
- name: WEBFINGER_OIDC_DISCOVERY_TOKEN_URL
value: http://hydra.hydra.svc:4444/oauth2/token
- name: GOMAXPROCS
valueFrom:
resourceFieldRef:
resource: limits.cpu
- name: GOMEMLIMIT
valueFrom:
resourceFieldRef:
resource: limits.memory
ports:
- containerPort: 4444
name: public
protocol: TCP
- containerPort: 4445
name: admin
protocol: TCP
- containerPort: 5555
name: token
protocol: TCP
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 65534
runAsGroup: 65534
seccompProfile:
type: RuntimeDefault
capabilities:
drop:
- ALL
resources:
requests:
cpu: 250m
memory: 128Mi
limits:
cpu: 800m
memory: 392Mi
---
apiVersion: v1
kind: Service
metadata:
name: hydra
namespace: hydra
spec:
type: ClusterIP
ports:
- port: 4444
targetPort: public
name: public
- port: 4445
targetPort: admin
name: admin
- port: 5555
targetPort: token
name: token
selector:
app: hydra
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: hydra
namespace: hydra
spec:
entryPoints:
- web
routes:
- match: Host(`hydra.docker.localhost`)
kind: Rule
services:
- name: hydra
port: public
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: consent
namespace: hydra
spec:
replicas: 1
selector:
matchLabels:
app: consent
template:
metadata:
labels:
app: consent
spec:
automountServiceAccountToken: false
containers:
- name: consent
image: docker.io/jlevesy/hail-hydra:v0.0.1
args:
- -a
- http://hydra.hydra.svc:4445
- -b
- :3000
env:
- name: GOMAXPROCS
valueFrom:
resourceFieldRef:
resource: limits.cpu
- name: GOMEMLIMIT
valueFrom:
resourceFieldRef:
resource: limits.memory
ports:
- containerPort: 3000
name: consent
protocol: TCP
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 65534
runAsGroup: 65534
seccompProfile:
type: RuntimeDefault
capabilities:
drop:
- ALL
resources:
requests:
cpu: 25m
memory: 32Mi
limits:
cpu: 50m
memory: 64Mi
---
apiVersion: v1
kind: Service
metadata:
name: consent
namespace: hydra
spec:
type: ClusterIP
ports:
- port: 3000
targetPort: consent
name: consent
selector:
app: consent
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: consent
namespace: hydra
spec:
entryPoints:
- web
routes:
- match: Host(`consent.docker.localhost`)
kind: Rule
services:
- name: consent
port: consent
---
kind: ServiceAccount
apiVersion: v1
metadata:
name: create-hydra-clients
namespace: hydra
automountServiceAccountToken: false
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: create-hydra-clients
namespace: hydra
rules:
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: create-hydra-clients
namespace: hydra
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: create-hydra-clients
subjects:
- kind: ServiceAccount
name: create-hydra-clients
namespace: hydra
---
apiVersion: batch/v1
kind: Job
metadata:
name: create-hydra-clients
namespace: hydra
labels:
app: create-hydra-clients
spec:
template:
metadata:
labels:
app: create-hydra-clients
spec:
restartPolicy: OnFailure
serviceAccountName: create-hydra-clients
automountServiceAccountToken: true
initContainers:
- name: wait-for-hydra
image: "busybox:1.36"
imagePullPolicy: IfNotPresent
command: ['sh', '-c', "until nc -w 1 hydra.hydra.svc 4445; do echo waiting for hydra to start; sleep 5; done"]
resources:
limits:
cpu: 30m
memory: 50Mi
requests:
cpu: 20m
memory: 10Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 65532
seccompProfile:
type: RuntimeDefault
capabilities:
drop:
- NET_RAW
containers:
- image: docker.io/oryd/hydra:v2.2.0
name: bootstrap
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 100m
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile:
type: RuntimeDefault
capabilities:
drop:
- NET_RAW
command:
- sh
- -c
- |
set -e
hydra create oauth2-client \
--endpoint http://hydra.hydra.svc:4445 \
--name oauth-client \
--secret traefiklabs \
--grant-type client_credentials \
--audience https://traefik.io \
--token-endpoint-auth-method client_secret_post \
--format json > /data/oauth-client.json
hydra create oauth2-client \
--endpoint http://hydra.hydra.svc:4445 \
--name oauth-client-nologin \
--secret traefiklabs \
--grant-type client_credentials \
--audience https://traefik.io \
--format json > /data/oauth-client-nologin.json
hydra create oauth2-client \
--endpoint http://hydra.hydra.svc:4445 \
--name oidc-client \
--secret traefiklabs \
--grant-type authorization_code,refresh_token \
--response-type code,id_token \
--scope openid,offline \
--redirect-uri http://secure-applications.apigateway.docker.localhost/oidc/callback \
--post-logout-callback http://secure-applications.apigateway.docker.localhost/oidc/callback \
--format json > /data/oidc-client.json
hydra create oauth2-client \
--endpoint http://hydra.hydra.svc:4445 \
--name oidc-client-nologin \
--secret traefiklabs \
--grant-type authorization_code,refresh_token \
--response-type code,id_token \
--scope openid,offline \
--redirect-uri http://secure-applications.apigateway.docker.localhost/oidc-nologin/callback \
--post-logout-callback http://secure-applications.apigateway.docker.localhost/oidc/callback \
--format json > /data/oidc-client-nologin.json
hydra create jwks hydra.openid.id-token --alg RS256 --endpoint http://hydra.hydra.svc:4445
hydra create jwks hydra.jwt.access-token --alg RS256 --endpoint http://hydra.hydra.svc:4445
volumeMounts:
- mountPath: /data
name: data
- image: bitnami/kubectl:1.29-debian-12
name: create-secrets
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
cpu: 100m
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile:
type: RuntimeDefault
capabilities:
drop:
- NET_RAW
command:
- sh
- -c
- |
set -e
for client in oauth-client oauth-client-nologin oidc-client oidc-client-nologin; do
while true; do sleep 1; test -s /data/$client.json && break ; done
kubectl create secret -n apps generic $client \
--from-literal=client_id="$(cat /data/$client.json | jq -r '.client_id')" \
--from-literal=client_secret="$(cat /data/$client.json | jq -r '.client_secret')"
done
volumeMounts:
- mountPath: /data
name: data
volumes:
- name: data
emptyDir: {}