Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 1 | # Matrix server (synapse). |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 2 | # This needs a secret provisioned, create with: |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 3 | # 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 Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 6 | # |
| 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 Dobrowolski | 3ea979d | 2019-05-23 16:11:52 +0200 | [diff] [blame] | 15 | # 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 Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 16 | # |
| 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 Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 19 | |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 20 | local kube = import "../../../kube/kube.libsonnet"; |
| 21 | local postgres = import "../../../kube/postgres.libsonnet"; |
Serge Bazanski | cdba291 | 2020-08-24 19:11:10 +0000 | [diff] [blame] | 22 | |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 23 | { |
| 24 | local app = self, |
| 25 | local cfg = app.cfg, |
| 26 | cfg:: { |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 27 | 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 Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 32 | storageClassName: "waw-hdd-redundant-3", |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 33 | |
Serge Bazanski | 5533ce9 | 2020-09-16 14:20:06 +0000 | [diff] [blame] | 34 | synapseImage: "matrixdotorg/synapse:v1.19.2", |
| 35 | riotImage: "vectorim/riot-web:v1.7.7", |
Sergiusz Bazanski | 735ac9c | 2020-07-17 12:10:42 +0200 | [diff] [blame] | 36 | casProxyImage: "registry.k0.hswaw.net/q3k/oauth2-cas-proxy:0.1.4", |
| 37 | appserviceIRCImage: "matrixdotorg/matrix-appservice-irc:release-0.17.1", |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 38 | # 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 Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 40 | }, |
| 41 | |
| 42 | metadata(component):: { |
Piotr Dobrowolski | 4b4231d | 2019-05-15 11:41:21 +0200 | [diff] [blame] | 43 | namespace: cfg.namespace, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 44 | labels: { |
| 45 | "app.kubernetes.io/name": "matrix", |
| 46 | "app.kubernetes.io/managed-by": "kubecfg", |
| 47 | "app.kubernetes.io/component": component, |
| 48 | }, |
| 49 | }, |
| 50 | |
Piotr Dobrowolski | 4b4231d | 2019-05-15 11:41:21 +0200 | [diff] [blame] | 51 | namespace: kube.Namespace(cfg.namespace), |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 52 | |
Serge Bazanski | c0c037a | 2020-08-23 01:24:03 +0000 | [diff] [blame] | 53 | postgres3: postgres { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 54 | cfg+: { |
| 55 | namespace: cfg.namespace, |
| 56 | appName: "synapse", |
| 57 | database: "synapse", |
| 58 | username: "synapse", |
Serge Bazanski | c0c037a | 2020-08-23 01:24:03 +0000 | [diff] [blame] | 59 | prefix: "waw3-", |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 60 | password: { secretKeyRef: { name: "synapse", key: "postgres_password" } }, |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 61 | storageClassName: cfg.storageClassName, |
Serge Bazanski | c0c037a | 2020-08-23 01:24:03 +0000 | [diff] [blame] | 62 | storageSize: "100Gi", |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 63 | }, |
| 64 | }, |
| 65 | |
Serge Bazanski | c0c037a | 2020-08-23 01:24:03 +0000 | [diff] [blame] | 66 | dataVolume: kube.PersistentVolumeClaim("synapse-data-waw3") { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 67 | metadata+: app.metadata("synapse-data"), |
| 68 | spec+: { |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 69 | storageClassName: cfg.storageClassName, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 70 | accessModes: [ "ReadWriteOnce" ], |
| 71 | resources: { |
| 72 | requests: { |
| 73 | storage: "50Gi", |
| 74 | }, |
| 75 | }, |
| 76 | }, |
| 77 | }, |
Piotr Dobrowolski | ffbb47c | 2019-05-16 12:18:39 +0200 | [diff] [blame] | 78 | |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 79 | synapseConfig: kube.ConfigMap("synapse") { |
| 80 | metadata+: app.metadata("synapse"), |
| 81 | data: { |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 82 | "homeserver.yaml": importstr "synapse/homeserver.yaml", |
| 83 | "log.config": importstr "synapse/log.config", |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 84 | }, |
| 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 Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 100 | BASE_URL: "https://%s" % [cfg.webDomain], |
| 101 | SERVICE_URL: "https://%s" % [cfg.webDomain], |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 102 | 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 Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 117 | synapseDeployment: kube.Deployment("synapse") { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 118 | metadata+: app.metadata("synapse"), |
| 119 | spec+: { |
| 120 | replicas: 1, |
| 121 | template+: { |
| 122 | spec+: { |
| 123 | volumes_: { |
| 124 | data: kube.PersistentVolumeClaimVolume(app.dataVolume), |
Piotr Dobrowolski | 8ebfc1d | 2020-03-03 21:01:18 +0100 | [diff] [blame] | 125 | config_template: kube.ConfigMapVolume(app.synapseConfig), |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 126 | } + { |
| 127 | [k]: { secret: { secretName: "appservice-%s-registration" % [k] } } |
| 128 | for k in std.objectFields(app.appservices) |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 129 | }, |
| 130 | containers_: { |
| 131 | web: kube.Container("synapse") { |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 132 | image: cfg.synapseImage, |
Piotr Dobrowolski | 8ebfc1d | 2020-03-03 21:01:18 +0100 | [diff] [blame] | 133 | command: ["/bin/sh", "-c", "/start.py migrate_config && exec /start.py"], |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 134 | ports_: { |
| 135 | http: { containerPort: 8008 }, |
Serge Bazanski | 1230ac3 | 2020-09-12 22:09:46 +0000 | [diff] [blame] | 136 | metrics: { containerPort: 9092 }, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 137 | }, |
| 138 | env_: { |
Piotr Dobrowolski | 8ebfc1d | 2020-03-03 21:01:18 +0100 | [diff] [blame] | 139 | SYNAPSE_CONFIG_DIR: "/config", |
Piotr Dobrowolski | eabbe8a | 2019-08-11 19:49:08 +0200 | [diff] [blame] | 140 | SYNAPSE_CONFIG_PATH: "/config/homeserver.yaml", |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 141 | |
Piotr Dobrowolski | 8ebfc1d | 2020-03-03 21:01:18 +0100 | [diff] [blame] | 142 | # These values are not used in a template, but |
| 143 | # are required by /start.py migrate_config |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 144 | SYNAPSE_SERVER_NAME: cfg.serverName, |
Piotr Dobrowolski | 8ebfc1d | 2020-03-03 21:01:18 +0100 | [diff] [blame] | 145 | 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 Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 150 | }, |
| 151 | volumeMounts_: { |
| 152 | data: { mountPath: "/data" }, |
Piotr Dobrowolski | 8ebfc1d | 2020-03-03 21:01:18 +0100 | [diff] [blame] | 153 | config_template: { |
| 154 | mountPath: "/conf/homeserver.yaml", |
| 155 | subPath: "homeserver.yaml", |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 156 | }, |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 157 | } + { |
| 158 | [k]: { mountPath: "/appservices/%s" % [k] } |
| 159 | for k in std.objectFields(app.appservices) |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 160 | }, |
| 161 | }, |
| 162 | }, |
| 163 | }, |
| 164 | }, |
| 165 | }, |
| 166 | }, |
| 167 | |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 168 | synapseSvc: kube.Service("synapse") { |
Piotr Dobrowolski | ffbb47c | 2019-05-16 12:18:39 +0200 | [diff] [blame] | 169 | metadata+: app.metadata("synapse"), |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 170 | target_pod:: app.synapseDeployment.spec.template, |
Piotr Dobrowolski | ffbb47c | 2019-05-16 12:18:39 +0200 | [diff] [blame] | 171 | }, |
| 172 | |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 173 | riotConfig: kube.ConfigMap("riot-web-config") { |
| 174 | metadata+: app.metadata("riot-web-config"), |
| 175 | data: { |
| 176 | "config.json": std.manifestJsonEx({ |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 177 | "default_hs_url": "https://%s" % [cfg.webDomain], |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 178 | "disable_custom_urls": false, |
| 179 | "disable_guests": false, |
| 180 | "disable_login_language_selector": false, |
Piotr Dobrowolski | 4b4231d | 2019-05-15 11:41:21 +0200 | [diff] [blame] | 181 | "disable_3pid_login": true, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 182 | "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 Dobrowolski | 4b4231d | 2019-05-15 11:41:21 +0200 | [diff] [blame] | 186 | |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 187 | "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 Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 197 | cfg.serverName, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 198 | ] |
| 199 | }, |
| 200 | "welcomeUserId": "@riot-bot:matrix.org", |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 201 | "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 Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 218 | web: kube.Container("riot-web") { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 219 | image: cfg.riotImage, |
| 220 | ports_: { |
| 221 | http: { containerPort: 80 }, |
| 222 | }, |
| 223 | volumeMounts_: { |
| 224 | config: { |
Piotr Dobrowolski | aca7e28 | 2020-03-21 22:14:38 +0100 | [diff] [blame] | 225 | mountPath: "/app/config.json", |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 226 | subPath: "config.json", |
| 227 | }, |
| 228 | }, |
| 229 | }, |
| 230 | }, |
| 231 | }, |
| 232 | }, |
| 233 | }, |
| 234 | }, |
| 235 | |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 236 | riotSvc: kube.Service("riot-web") { |
| 237 | metadata+: app.metadata("riot-web"), |
| 238 | target_pod:: app.riotDeployment.spec.template, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 239 | }, |
| 240 | |
Serge Bazanski | de62751 | 2020-08-24 21:17:55 +0000 | [diff] [blame] | 241 | // 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 Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 247 | appservices: {}, |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 248 | |
| 249 | ingress: kube.Ingress("matrix") { |
| 250 | metadata+: app.metadata("matrix") { |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 251 | 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 Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 260 | hosts: [cfg.webDomain], |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 261 | secretName: "synapse-tls", |
| 262 | }, |
| 263 | ], |
| 264 | rules: [ |
| 265 | { |
Serge Bazanski | 60076c7 | 2020-11-03 19:17:25 +0100 | [diff] [blame^] | 266 | host: cfg.webDomain, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 267 | http: { |
| 268 | paths: [ |
| 269 | { path: "/", backend: app.riotSvc.name_port }, |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 270 | { path: "/_matrix", backend: app.synapseSvc.name_port }, |
Piotr Dobrowolski | c39fb04 | 2019-05-17 09:13:56 +0200 | [diff] [blame] | 271 | { path: "/_cas", backend: app.casSvc.name_port }, |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 272 | ] |
| 273 | }, |
| 274 | } |
| 275 | ], |
| 276 | }, |
| 277 | }, |
Piotr Dobrowolski | fef4c12 | 2019-05-16 21:05:02 +0200 | [diff] [blame] | 278 | |
Piotr Dobrowolski | a222691 | 2019-05-14 18:49:29 +0200 | [diff] [blame] | 279 | } |