blob: 300cf315dcf13d5577ae7a5cac9cd041b177e9db [file] [log] [blame]
Serge Bazanski60076c72020-11-03 19:17:25 +01001# Matrix server (synapse).
Piotr Dobrowolskia2226912019-05-14 18:49:29 +02002# This needs a secret provisioned, create with:
Serge Bazanski60076c72020-11-03 19:17:25 +01003# ns=matrix
4# kubectl -n $ns create secret generic synapse --from-literal=postgres_password=$(pwgen 24 1) --from-literal=macaroon_secret_key=$(pwgen 32 1) --from-literal=registration_shared_secret=$(pwgen 32 1)
5# kubectl -n $ns create secret generic oauth2-cas-proxy --from-literal=oauth2_secret=...
Serge Bazanskide627512020-08-24 21:17:55 +00006#
7# Sequencing appservices is fun. The appservice needs to run first (for
8# instance, via a bootstrap job), and on startup it will spit out a
9# registration file. This registration file then needs to be fed to synapse -
10# this is done via specialy named secrets (appservice-X-registration, for X key
11# in the appservices object).
12#
13# For appservice-irc instances, you can use this oneliner magic to get the
14# registration YAML from logs.
Piotr Dobrowolski3ea979d2019-05-23 16:11:52 +020015# kubectl -n matrix create secret generic appservice-irc-freenode-registration --from-file=registration.yaml=<(kubectl logs -n matrix $(kubectl get pods -n matrix --selector=job-name=appservice-irc-freenode-bootstrap --output=jsonpath='{.items[*].metadata.name}') | tail -n +4 | sed -r 's/(.*aliases:.*)/ group_id: "+freenode:hackerspace.pl"\n\1/')
Serge Bazanskide627512020-08-24 21:17:55 +000016#
17# For appservice-telegram instances, you can use this oneliner magic:
18# kubectl -n matrix create secret generic appservice-telegram-prod-registration --from-file=registration.yaml=<(kubectl -n matrix logs job/appservice-telegram-prod-bootstrap | grep -A 100 SNIPSNIP | grep -v SNIPSNIP)
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020019
Serge Bazanski60076c72020-11-03 19:17:25 +010020local kube = import "../../../kube/kube.libsonnet";
21local postgres = import "../../../kube/postgres.libsonnet";
Serge Bazanskicdba2912020-08-24 19:11:10 +000022
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020023{
24 local app = self,
25 local cfg = app.cfg,
26 cfg:: {
Serge Bazanski60076c72020-11-03 19:17:25 +010027 namespace: error "cfg.namespace must be set",
28 # webDomain is the domain name at which element will run
29 webDomain: error "cfg.webDomain must be set",
30 # serverName is the server part of the MXID this homeserver will cover
31 serverName: error "cfg.serverName must be set",
Serge Bazanskide627512020-08-24 21:17:55 +000032 storageClassName: "waw-hdd-redundant-3",
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +020033
Serge Bazanski5533ce92020-09-16 14:20:06 +000034 synapseImage: "matrixdotorg/synapse:v1.19.2",
35 riotImage: "vectorim/riot-web:v1.7.7",
Sergiusz Bazanski735ac9c2020-07-17 12:10:42 +020036 casProxyImage: "registry.k0.hswaw.net/q3k/oauth2-cas-proxy:0.1.4",
37 appserviceIRCImage: "matrixdotorg/matrix-appservice-irc:release-0.17.1",
Serge Bazanskide627512020-08-24 21:17:55 +000038 # That's v0.8.2 - we just don't trust that host to not re-tag images.
39 appserviceTelegramImage: "dock.mau.dev/tulir/mautrix-telegram@sha256:9e68eaa80c9e4a75d9a09ec92dc4898b12d48390e01efa4de40ce882a6f7e330"
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020040 },
41
42 metadata(component):: {
Piotr Dobrowolski4b4231d2019-05-15 11:41:21 +020043 namespace: cfg.namespace,
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020044 labels: {
45 "app.kubernetes.io/name": "matrix",
46 "app.kubernetes.io/managed-by": "kubecfg",
47 "app.kubernetes.io/component": component,
48 },
49 },
50
Piotr Dobrowolski4b4231d2019-05-15 11:41:21 +020051 namespace: kube.Namespace(cfg.namespace),
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020052
Serge Bazanskic0c037a2020-08-23 01:24:03 +000053 postgres3: postgres {
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020054 cfg+: {
55 namespace: cfg.namespace,
56 appName: "synapse",
57 database: "synapse",
58 username: "synapse",
Serge Bazanskic0c037a2020-08-23 01:24:03 +000059 prefix: "waw3-",
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020060 password: { secretKeyRef: { name: "synapse", key: "postgres_password" } },
Serge Bazanskide627512020-08-24 21:17:55 +000061 storageClassName: cfg.storageClassName,
Serge Bazanskic0c037a2020-08-23 01:24:03 +000062 storageSize: "100Gi",
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020063 },
64 },
65
Serge Bazanskic0c037a2020-08-23 01:24:03 +000066 dataVolume: kube.PersistentVolumeClaim("synapse-data-waw3") {
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020067 metadata+: app.metadata("synapse-data"),
68 spec+: {
Serge Bazanskide627512020-08-24 21:17:55 +000069 storageClassName: cfg.storageClassName,
Piotr Dobrowolskia2226912019-05-14 18:49:29 +020070 accessModes: [ "ReadWriteOnce" ],
71 resources: {
72 requests: {
73 storage: "50Gi",
74 },
75 },
76 },
77 },
Piotr Dobrowolskiffbb47c2019-05-16 12:18:39 +020078
Piotr Dobrowolskic39fb042019-05-17 09:13:56 +020079 synapseConfig: kube.ConfigMap("synapse") {
80 metadata+: app.metadata("synapse"),
81 data: {
Serge Bazanski60076c72020-11-03 19:17:25 +010082 "homeserver.yaml": importstr "synapse/homeserver.yaml",
83 "log.config": importstr "synapse/log.config",
Piotr Dobrowolskic39fb042019-05-17 09:13:56 +020084 },
85 },
86
87 casDeployment: kube.Deployment("oauth2-cas-proxy") {
88 metadata+: app.metadata("oauth2-cas-proxy"),
89 spec+: {
90 replicas: 1,
91 template+: {
92 spec+: {
93 containers_: {
94 proxy: kube.Container("oauth2-cas-proxy") {
95 image: cfg.casProxyImage,
96 ports_: {
97 http: { containerPort: 5000 },
98 },
99 env_: {
Serge Bazanski60076c72020-11-03 19:17:25 +0100100 BASE_URL: "https://%s" % [cfg.webDomain],
101 SERVICE_URL: "https://%s" % [cfg.webDomain],
Piotr Dobrowolskic39fb042019-05-17 09:13:56 +0200102 OAUTH2_CLIENT: "matrix",
103 OAUTH2_SECRET: { secretKeyRef: { name: "oauth2-cas-proxy", key: "oauth2_secret" } },
104 },
105 },
106 },
107 },
108 },
109 },
110 },
111
112 casSvc: kube.Service("oauth2-cas-proxy") {
113 metadata+: app.metadata("oauth2-cas-proxy"),
114 target_pod:: app.casDeployment.spec.template,
115 },
116
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200117 synapseDeployment: kube.Deployment("synapse") {
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200118 metadata+: app.metadata("synapse"),
119 spec+: {
120 replicas: 1,
121 template+: {
122 spec+: {
123 volumes_: {
124 data: kube.PersistentVolumeClaimVolume(app.dataVolume),
Piotr Dobrowolski8ebfc1d2020-03-03 21:01:18 +0100125 config_template: kube.ConfigMapVolume(app.synapseConfig),
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200126 } + {
127 [k]: { secret: { secretName: "appservice-%s-registration" % [k] } }
128 for k in std.objectFields(app.appservices)
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200129 },
130 containers_: {
131 web: kube.Container("synapse") {
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200132 image: cfg.synapseImage,
Piotr Dobrowolski8ebfc1d2020-03-03 21:01:18 +0100133 command: ["/bin/sh", "-c", "/start.py migrate_config && exec /start.py"],
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200134 ports_: {
135 http: { containerPort: 8008 },
Serge Bazanski1230ac32020-09-12 22:09:46 +0000136 metrics: { containerPort: 9092 },
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200137 },
138 env_: {
Piotr Dobrowolski8ebfc1d2020-03-03 21:01:18 +0100139 SYNAPSE_CONFIG_DIR: "/config",
Piotr Dobrowolskieabbe8a2019-08-11 19:49:08 +0200140 SYNAPSE_CONFIG_PATH: "/config/homeserver.yaml",
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200141
Piotr Dobrowolski8ebfc1d2020-03-03 21:01:18 +0100142 # These values are not used in a template, but
143 # are required by /start.py migrate_config
Serge Bazanski60076c72020-11-03 19:17:25 +0100144 SYNAPSE_SERVER_NAME: cfg.serverName,
Piotr Dobrowolski8ebfc1d2020-03-03 21:01:18 +0100145 SYNAPSE_REPORT_STATS: "no",
146
147 SYNAPSE_MACAROON_SECRET_KEY: { secretKeyRef: { name: "synapse", key: "macaroon_secret_key" } },
148 SYNAPSE_REGISTRATION_SHARED_SECRET: { secretKeyRef: { name: "synapse", key: "registration_shared_secret" } },
149 POSTGRES_PASSWORD: { secretKeyRef: { name: "synapse", key: "postgres_password" } },
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200150 },
151 volumeMounts_: {
152 data: { mountPath: "/data" },
Piotr Dobrowolski8ebfc1d2020-03-03 21:01:18 +0100153 config_template: {
154 mountPath: "/conf/homeserver.yaml",
155 subPath: "homeserver.yaml",
Piotr Dobrowolskic39fb042019-05-17 09:13:56 +0200156 },
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200157 } + {
158 [k]: { mountPath: "/appservices/%s" % [k] }
159 for k in std.objectFields(app.appservices)
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200160 },
161 },
162 },
163 },
164 },
165 },
166 },
167
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200168 synapseSvc: kube.Service("synapse") {
Piotr Dobrowolskiffbb47c2019-05-16 12:18:39 +0200169 metadata+: app.metadata("synapse"),
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200170 target_pod:: app.synapseDeployment.spec.template,
Piotr Dobrowolskiffbb47c2019-05-16 12:18:39 +0200171 },
172
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200173 riotConfig: kube.ConfigMap("riot-web-config") {
174 metadata+: app.metadata("riot-web-config"),
175 data: {
176 "config.json": std.manifestJsonEx({
Serge Bazanski60076c72020-11-03 19:17:25 +0100177 "default_hs_url": "https://%s" % [cfg.webDomain],
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200178 "disable_custom_urls": false,
179 "disable_guests": false,
180 "disable_login_language_selector": false,
Piotr Dobrowolski4b4231d2019-05-15 11:41:21 +0200181 "disable_3pid_login": true,
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200182 "brand": "Riot",
183 "integrations_ui_url": "https://scalar.vector.im/",
184 "integrations_rest_url": "https://scalar.vector.im/api",
185 "integrations_jitsi_widget_url": "https://scalar.vector.im/api/widgets/jitsi.html",
Piotr Dobrowolski4b4231d2019-05-15 11:41:21 +0200186
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200187 "bug_report_endpoint_url": "https://riot.im/bugreports/submit",
188 "features": {
189 "feature_groups": "labs",
190 "feature_pinning": "labs",
191 "feature_reactions": "labs"
192 },
193 "default_federate": true,
194 "default_theme": "light",
195 "roomDirectory": {
196 "servers": [
Serge Bazanski60076c72020-11-03 19:17:25 +0100197 cfg.serverName,
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200198 ]
199 },
200 "welcomeUserId": "@riot-bot:matrix.org",
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200201 "enable_presence_by_hs_url": {
202 "https://matrix.org": false
203 }
204 }, ""),
205 },
206 },
207
208 riotDeployment: kube.Deployment("riot-web") {
209 metadata+: app.metadata("riot-web"),
210 spec+: {
211 replicas: 1,
212 template+: {
213 spec+: {
214 volumes_: {
215 config: kube.ConfigMapVolume(app.riotConfig),
216 },
217 containers_: {
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200218 web: kube.Container("riot-web") {
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200219 image: cfg.riotImage,
220 ports_: {
221 http: { containerPort: 80 },
222 },
223 volumeMounts_: {
224 config: {
Piotr Dobrowolskiaca7e282020-03-21 22:14:38 +0100225 mountPath: "/app/config.json",
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200226 subPath: "config.json",
227 },
228 },
229 },
230 },
231 },
232 },
233 },
234 },
235
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200236 riotSvc: kube.Service("riot-web") {
237 metadata+: app.metadata("riot-web"),
238 target_pod:: app.riotDeployment.spec.template,
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200239 },
240
Serge Bazanskide627512020-08-24 21:17:55 +0000241 // Any appservice you add here will require an appservice-X-registration
242 // secret containing a registration.yaml file. Adding something to this
243 // dictionary will cause Synapse to not start until that secret is
244 // available - so change things carefully!
245 // If bootstrapping a new appservice, just keep it out of this dictionary
246 // until it spits you a registration YAML and you feed that to a secret.
Serge Bazanski60076c72020-11-03 19:17:25 +0100247 appservices: {},
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200248
249 ingress: kube.Ingress("matrix") {
250 metadata+: app.metadata("matrix") {
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200251 annotations+: {
252 "kubernetes.io/tls-acme": "true",
253 "certmanager.k8s.io/cluster-issuer": "letsencrypt-prod",
254 "nginx.ingress.kubernetes.io/proxy-body-size": "0",
255 },
256 },
257 spec+: {
258 tls: [
259 {
Serge Bazanski60076c72020-11-03 19:17:25 +0100260 hosts: [cfg.webDomain],
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200261 secretName: "synapse-tls",
262 },
263 ],
264 rules: [
265 {
Serge Bazanski60076c72020-11-03 19:17:25 +0100266 host: cfg.webDomain,
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200267 http: {
268 paths: [
269 { path: "/", backend: app.riotSvc.name_port },
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200270 { path: "/_matrix", backend: app.synapseSvc.name_port },
Piotr Dobrowolskic39fb042019-05-17 09:13:56 +0200271 { path: "/_cas", backend: app.casSvc.name_port },
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200272 ]
273 },
274 }
275 ],
276 },
277 },
Piotr Dobrowolskifef4c122019-05-16 21:05:02 +0200278
Piotr Dobrowolskia2226912019-05-14 18:49:29 +0200279}