synapse

by sudermanjr

Helm chartv1.1.5App v1.53.0

A Helm chart to deploy matrix synapse server. https://github.com/matrix-org/synapse

About this chart

synapse

A Helm chart to deploy matrix synapse server. https://github.com/matrix-org/synapse

Current chart version is 0.1.0

Source code can be found here

Generating values for keys

You can generate your own keys using the genKeys.sh script here.

./genKeys.sh <SERVER_NAME>

This will run a synapse docker container locally that generates an example config and all the keys.

Testing and development

If you have a local cluster (I use kind), then you can install a local version of the chart using a postgres container like so:

kubectl create ns synapse
helm upgrade --namespace synapse --install synapse . --set postgres.localDev.enabled=true --set postgres.init.enabled=true

This will create a postgres database, initialize the matrix database, and run the synapse server. You can then access it by port-forwarding:

kubectl -n synapse port-forward svc/synapse 8080:80

Then browse to [http://localhost:8080](http://localhost:8080] in your browser to see the startup page.

A Warning About Secrets

All secrets (including the server config) are stored as secrets as part of the chart. As of helm 3, all values passed in are also set as secrets. The issue then becomes twofold:

  1. You probably keep your values in git, unencrypted. You probably shouldn't in this case because they contain secrets.
  2. The secrets must be passed in from an insecure setting, such as your laptop.

I have done my best to balance the ease-of-use and the security when building this chart. There are however much better practices that could be used for handling the secrets for this server. I highly suggest reading more about that before running this in a "production" setting.

In the future, I will look at incorporating a Vault integration with this chart to make it easier to keep these keys in a safe place.

Chart Values

KeyTypeDefaultDescription
affinityobject{}
fullnameOverridestring""A template override for "fullname"
image.pullPolicystring"Always"The image pull policy for all containers. Recommend leaving this as Always
image.repositorystring"matrixdotorg/synapse"The docker image repository to use
image.tagstring""Overrides the image tag whose default is the chart appVersion.
imagePullSecretslist[]A list of pullsecrets to use everywhere
ingress.annotationsobject{"cert-manager.io/cluster-issuer":"letsencrypt-prod","kubernetes.io/ingress.class":"nginx-ingress"}Annotations to add to the synapse server ingress
ingress.enabledboolfalseIf true, creates an ingress for the synapse server
ingress.hostslist[{"host":"matrix.example.com","paths":["/"]}]A list of hosts and paths to use for the synapse ingress
ingress.tlslist[{"hosts":["matrix.example.com"],"secretName":"synapse-tls"}]A TLS block for the synapse server ingress
macaroonSecretKeystring"469535da278b1a340112b7190217efb8ba846476c9abb20e166e7cc4eaf8f413"The value for macaroon_secret_key
nameOverridestring""A template override for "name"
nodeSelectorobject{}A nodeSelector block to use on all pods in the chart
podAnnotationsobject{}Additional annotations to add to the synapse server pod
podSecurityContextobject{}The security context to add to the synapse server pod
postgres.cpMaxint10The cp_max setting in the synapse postgres config
postgres.cpMinint5The cp_min setting in the synapse postgres config
postgres.databasestring"matrix"The database name to use. Must be created, or use postgres.init
postgres.enabledbooltrueIf true, uses postgres as the database. If false, it is set to sqlite
postgres.hoststring"some-postgres.example.com"The host where your postgres server is located. Overriden if postgres.localDev.enabled is used
postgres.init.databasestring"defaultdb"The default database on the server. Used for connecting initially
postgres.init.enabledboolfalseIf true, a helm post-install hook will be used to initialize the database
postgres.init.image.repositorystring"quay.io/sudermanjr/utilities"The image to use for the init hook. Must include the psql utility
postgres.init.image.tagstring"latest"The tag to use for the init hook image
postgres.init.passwordstring"randomlongpasswordpleasechangeme"The password for the postgres.init.user
postgres.init.userstring"matrix"The username to use for initializing the database
postgres.localDev.enabledboolfalseIf true, will run a postgres container alongside the server for dev purposes
postgres.localDev.image.repositorystring"postgres"The image to use for the dev postgres container
postgres.localDev.image.tagint12THe version of the iamge to use for the dev postgres container
postgres.localDev.storageSizestring"1Gi"The size of the volume to attach for postgres data
postgres.passwordstring"randomlongpasswordpleasechangeme"The password for postgres.user
postgres.portstring"5432"The port of the postgres server. Overriden if postgres.localDev.enabled is used
postgres.userstring"matrix"The username for synapse to use when connecting to postgres
regSharedSecretstring"c681fdf2ca739edfe848e24ee93d0c51de7be836bd879c54bc57a007c96d3076"The value for registration_shared_secret
replicaCountint1The number of replicas to run. Currently only one is supported
reportStatsstring"no"Set to "yes" or "no", is set as SYNAPSE_REPORT_STATS
resourcesobject{}A resources block for the synapse server container
securityContextobject{"allowPrivilegeEscalation":true,"runAsNonRoot":false,"runAsUser":0}The security context to be used for the synapse server container. Currently this is required to run as root.
serverNamestring"matrix.example.com"The matrix server name to set in SYNAPSE_SERVER_NAME
service.portint80
service.typestring"ClusterIP"The service type to use for the synapse server
serviceAccount.annotationsobject{}Annotations to add to the service account
serviceAccount.createbooltrueSpecifies whether a service account should be created
serviceAccount.namestring""The name of the service account to use. If not set and create is true, a name is generated using the fullname template
signingKeyB64string"ZWQyNTUxOSBhX3JOcEogS0lDTHRqOVovL2lWMEZPbVpjR2tKSzArRDY1WFNvcHlJYlBmN3dvVytGNAo="The base64 encoded key to mount at /secrets/signing.key
storageClassstring"standard"The storage class to use for the persistent data volume mounted at /data. Also used for localDev postgres if enabled
storageSizestring"1Gi"The size of the persistent volume that is attached to the synapse server for /data
tolerationslist[]A list of tolerations to add to all pods in the chart

Deploy synapse with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has synapse on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartsynapse is pinned at v1.1.5 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply