Skip to content

Commit de1ab84

Browse files
committed
feat(oauth): use oauth to unify service-to-service authentication.
1 parent 29092f1 commit de1ab84

24 files changed

Lines changed: 652 additions & 204 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
*.swp
33
*.swo
44
.DS_Store
5+
.sisyphus
6+
__pycache__

charts/grafana/templates/_helpers.tmpl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ env:
2121
- name: DRYCC_VALKEY_URL
2222
value: "redis://:$(DRYCC_VALKEY_PASSWORD)@drycc-valkey:16379/2"
2323
{{- end }}
24-
- name: DRYCC_SERVICE_KEY
25-
valueFrom:
26-
secretKeyRef:
27-
name: controller-creds
28-
key: service-key
2924
- name: "DRYCC_CONTROLLER_URL"
3025
value: http://drycc-controller-api
3126
- name: "DRYCC_QUICKWIT_URL"
@@ -49,13 +44,20 @@ env:
4944
secretKeyRef:
5045
name: passport-creds
5146
key: drycc-passport-grafana-secret
47+
- name: DRYCC_PASSPORT_SCOPES
48+
valueFrom:
49+
secretKeyRef:
50+
name: passport-creds
51+
key: drycc-passport-grafana-scopes
5252
{{- else }}
5353
- name: DRYCC_PASSPORT_URL
5454
value: "{{ .Values.passportUrl }}"
5555
- name: DRYCC_PASSPORT_KEY
5656
value: "{{ .Values.passportKey }}"
5757
- name: DRYCC_PASSPORT_SECRET
5858
value: "{{ .Values.passportSecret }}"
59+
- name: DRYCC_PASSPORT_SCOPES
60+
value: "{{ .Values.passportScopes }}"
5961
{{- end }}
6062
- name: GF_DATABASE_TYPE
6163
value: postgres

charts/grafana/templates/grafana-configmap.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ data:
1515
}
1616
}
1717
:80 {
18+
# For security reasons, deny external access to internal endpoints.
19+
handle /proxy/* {
20+
respond "Not Found" 404
21+
}
22+
handle /alerts/* {
23+
respond "Not Found" 404
24+
}
25+
1826
handle /oauth2/* {
1927
reverse_proxy 127.0.0.1:4000
2028
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: batch/v1
2+
kind: CronJob
3+
metadata:
4+
name: grafana-oauth2-token-refresher
5+
labels:
6+
app: grafana
7+
component: token-refresher
8+
heritage: drycc
9+
spec:
10+
schedule: "0 2 * * *"
11+
concurrencyPolicy: Forbid
12+
successfulJobsHistoryLimit: 3
13+
failedJobsHistoryLimit: 3
14+
jobTemplate:
15+
spec:
16+
backoffLimit: 3
17+
template:
18+
metadata:
19+
labels:
20+
app: grafana
21+
component: token-refresher
22+
spec:
23+
restartPolicy: OnFailure
24+
containers:
25+
- name: token-refresher
26+
image: {{ .Values.imageRegistry }}/{{ .Values.imageOrg }}/grafana:{{ .Values.imageTag }}
27+
imagePullPolicy: {{ .Values.imagePullPolicy }}
28+
command: ["/usr/bin/env", "python3", "/usr/share/grafana/oauth2/credentials.py"]
29+
{{- include "grafana.envs" . | indent 12 }}

charts/grafana/templates/grafana-service.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ spec:
2525
port: 9094
2626
targetPort: alerting
2727
protocol: UDP
28-
- name: oauth2-tcp
29-
port: 4000
30-
targetPort: oauth2
31-
protocol: TCP
3228
- name: proxy-tcp
3329
port: 80
3430
targetPort: proxy

charts/grafana/templates/grafana-statefulset.yaml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ spec:
158158
done
159159
echo "Grafana is up and running."
160160
python3 oauth2/main.py \
161+
--bind 127.0.0.1 \
161162
--port 4000 \
162163
--client-id $(DRYCC_PASSPORT_KEY) \
163164
--client-secret $(DRYCC_PASSPORT_SECRET) \
@@ -167,32 +168,42 @@ spec:
167168
resources:
168169
{{- toYaml . | nindent 10 }}
169170
{{- end }}
170-
ports:
171-
- containerPort: 4000
172-
name: oauth2
173171
{{- include "grafana.envs" . | indent 8 }}
174172
{{- if not .Values.diagnosticMode.enabled }}
175173
livenessProbe:
176-
tcpSocket:
177-
port: oauth2
174+
exec:
175+
command:
176+
- curl
177+
- -fsS
178+
- -o
179+
- /dev/null
180+
- http://127.0.0.1:4000/oauth2/healthz
178181
initialDelaySeconds: 240
179182
periodSeconds: 10
180183
timeoutSeconds: 5
181184
failureThreshold: 6
182185
successThreshold: 1
183186
readinessProbe:
184-
httpGet:
185-
path: /oauth2/healthz
186-
port: oauth2
187+
exec:
188+
command:
189+
- curl
190+
- -fsS
191+
- -o
192+
- /dev/null
193+
- http://127.0.0.1:4000/oauth2/healthz
187194
initialDelaySeconds: 30
188195
periodSeconds: 10
189196
timeoutSeconds: 5
190197
failureThreshold: 6
191198
successThreshold: 1
192199
startupProbe:
193-
httpGet:
194-
path: /oauth2/healthz
195-
port: oauth2
200+
exec:
201+
command:
202+
- curl
203+
- -fsS
204+
- -o
205+
- /dev/null
206+
- http://127.0.0.1:4000/oauth2/healthz
196207
initialDelaySeconds: 30
197208
periodSeconds: 10
198209
timeoutSeconds: 5

charts/grafana/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ environment: {}
6464
valkeyUrl: ""
6565
## databaseUrl are will no longer use the built-in database component
6666
databaseUrl: ""
67-
# The passportUrl, passportKey and passportSecret are will no longer use the built-in passport component
67+
# The following parameters are used when passport.enabled is false
6868
passportUrl: ""
6969
passportKey: ""
7070
passportSecret: ""
71+
passportScopes: ""
7172
# victoriametricsUrl is will no longer use the built-in victoriametrics component
7273
victoriametricsUrl: ""
7374

rootfs/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM registry.drycc.cc/drycc/base:${CODENAME}
44
ARG DRYCC_UID=1001 \
55
DRYCC_GID=1001 \
66
DRYCC_HOME_DIR=/usr/share/grafana \
7-
GRAFANA_VERSION="12.4.2" \
7+
GRAFANA_VERSION="13.0.1" \
88
JQ_VERSION="1.7.1" \
99
CADDY_VERSION="2.11.2" \
1010
PYTHON_VERSION="3.14"

rootfs/usr/share/grafana/oauth2/alerting/pod_cpu.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
"isPaused": false,
7676
"notification_settings": {
77-
"receiver": "grafana-default-email"
77+
"receiver": "controller-alerts"
7878
},
7979
"folderUID": "drycc"
8080
}

rootfs/usr/share/grafana/oauth2/alerting/pod_memory.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
},
7676
"isPaused": false,
7777
"notification_settings": {
78-
"receiver": "grafana-default-email"
78+
"receiver": "controller-alerts"
7979
},
8080
"folderUID": "drycc"
8181
}

0 commit comments

Comments
 (0)