syncstorage-rs

by christianhuth

Helm chartv8.2.2App 0.25.2Verified publisher

A Helm chart for deploying Mozilla's Firefox Sync Storage server to Kubernetes

About this chart

syncstorage-rs

A Helm chart for deploying Mozilla's Firefox Sync Storage server to Kubernetes

TL;DR;

helm repo add christianhuth https://charts.christianhuth.de
helm repo update
helm install my-release christianhuth/syncstorage-rs \
  --set syncstorage.masterKey.value='<random secret>' \
  --set syncstorage.config.publicUrl=https://sync.example.com

Or install it from the OCI registry:

helm install my-release oci://ghcr.io/christianhuth/helm-charts/syncstorage-rs \
  --set syncstorage.masterKey.value='<random secret>' \
  --set syncstorage.config.publicUrl=https://sync.example.com

Introduction

This chart bootstraps the Mozilla Firefox Sync Storage server on a Kubernetes cluster using the Helm package manager.

It uses the official images of Mozilla, one per database type: syncserver-mysql for MariaDB and MySQL (the default) and syncserver-postgres for PostgreSQL. Both images are only available for linux/amd64.

Prerequisites

  • Kubernetes 1.26+
  • The mariadb-operator if the bundled MariaDB databases are used (syncserver-db.enabled and tokenserver-db.enabled, the default)
  • The CloudNativePG operator if the bundled PostgreSQL database is used (postgresql.enabled: true)

Installing the mariadb-operator

The chart bundles the Syncserver and the Tokenserver database as custom resources of the mariadb-operator (via the upstream chart mariadb-cluster). The operator itself is not part of this chart, as it is installed once per Kubernetes cluster:

helm upgrade --install mariadb-operator-crds oci://ghcr.io/mariadb-operator/charts/mariadb-operator-crds --namespace mariadb-operator --create-namespace
helm upgrade --install mariadb-operator oci://ghcr.io/mariadb-operator/charts/mariadb-operator --namespace mariadb-operator --wait

Installing the CloudNativePG operator

With postgresql.enabled: true the chart bundles a PostgreSQL cluster as a custom resource of the CloudNativePG operator (via the upstream chart cnpg/cluster). The operator itself is not part of this chart, as it is installed once per Kubernetes cluster:

helm repo add cnpg https://cloudnative-pg.github.io/charts
helm repo update
helm upgrade --install cnpg cnpg/cloudnative-pg --namespace cnpg-system --create-namespace --wait

Installing the Chart

To install the chart with the release name my-release:

helm repo add christianhuth https://charts.christianhuth.de
helm repo update
helm install my-release christianhuth/syncstorage-rs \
  --set syncstorage.masterKey.value='<random secret>' \
  --set syncstorage.config.publicUrl=https://sync.example.com

The chart is also published as an OCI artifact which can be installed like this:

helm install my-release oci://ghcr.io/christianhuth/helm-charts/syncstorage-rs \
  --set syncstorage.masterKey.value='<random secret>' \
  --set syncstorage.config.publicUrl=https://sync.example.com

These commands deploy the Mozilla Firefox Sync Storage server on the Kubernetes cluster in the default configuration. The Values section lists the values that can be configured during installation.

Tip: List all releases using helm list

Uninstalling the Chart

To uninstall the my-release deployment:

helm uninstall my-release

The command removes all the Kubernetes components associated with the chart and deletes the release.

Configuring the Sync Server

Master key

syncstorage-rs derives the secrets signing its tokens from the master key, so the chart requires one. Instead of syncstorage.masterKey.value you can reference an existing Secret with the key master-key:

kubectl create secret generic syncstorage-master-key \
  --from-literal=master-key="$(openssl rand -hex 32)"
syncstorage:
  masterKey:
    existingSecret: syncstorage-master-key

Changing the master key invalidates the issued tokens, the clients then request new ones.

Public URL and Firefox

On startup syncstorage-rs registers its public URL as storage node in the Tokenserver database, the clients sync against this URL. The chart takes syncstorage.config.publicUrl, or the first host of the Ingress (https if it is covered by TLS) or of the HTTPRoute (https). It must consist of the scheme and the host only, e.g. https://sync.example.com.

To use the server, open about:config in Firefox before logging in to your Mozilla account and set identity.sync.tokenserver.uri to https://sync.example.com/1.0/sync/1.5.

Limiting the number of users

By default everybody with a Mozilla account can use your server. There are two ways to restrict it:

  • syncstorage.config.allowNewUsers: false only lets accounts use the server that already synced with it. Leave it enabled until all your accounts synced once.

  • syncstorage.config.nodeCapacity is the maximum number of accounts the storage node accepts, e.g. 5. New accounts beyond it are rejected. syncstorage-rs only uses it when it creates the node, so set it before the first start or change it in the Tokenserver database later:

    UPDATE nodes SET capacity = 5, available = GREATEST(5 - current_load, 0) WHERE node = 'https://sync.example.com';
    

Mozilla accounts

By default the Tokenserver verifies the tokens of the clients against the production Mozilla accounts (syncstorage.config.fxa.emailDomain and syncstorage.config.fxa.oauthServerUrl). Change them only if you run your own Mozilla accounts server. All other settings of syncstorage-rs can be passed as environment variables with extraEnv, see the configuration reference.

Configuring the Databases

syncstorage-rs uses two databases: the Syncserver database (syncserver-db) and the Tokenserver database (tokenserver-db). Both have to be of the same type, either MariaDB/MySQL or PostgreSQL, matching the image (image.repository).

Bundled MariaDB with an existing Secret (recommended)

By default the chart bundles one MariaDB instance per database. Both are configured the same way, the examples below show the Syncserver database. Create a Secret containing the password of the database user:

kubectl create secret generic syncstorage-syncserver-db \
  --from-literal=password='<password>'

Reference the Secret in your values and disable the generation of a password:

syncserver-db:
  enabled: true
  mariadb:
    database: syncserver
    username: syncserver
    passwordSecretKeyRef:
      name: syncstorage-syncserver-db
      key: password
      generate: false

If no Secret is referenced, the operator generates a random password and stores it in the Secret <release>-syncserver-db-password. The connection URL used by syncstorage-rs is created by the operator in the Secret <release>-syncserver-db (key database-url), with the password URL-encoded.

Updating MariaDB

The image tags only pin the MariaDB release series (by default the long-term support release 12.3), so restarted instances get the latest patch version of the series. To upgrade to another release series (e.g. the next long-term support release), change the tag of <db>.mariadb.image. The operator rolls out the instances one by one and migrates the system schema (updateStrategy.mariadbAutoUpgradeEnabled). Downgrades to a previous release series are not supported by MariaDB, so take a backup before upgrading.

By default each database runs as a Galera cluster with 3 instances. All other settings (e.g. mariadb.replicas, mariadb.storage, backups) are passed to the upstream chart. See its values and the MariaDB API reference for all options.

Bundled PostgreSQL

The bundled PostgreSQL cluster hosts one database used by the Syncserver and the Tokenserver, like the setup of Mozilla. Disable the MariaDB instances and switch to the PostgreSQL image:

image:
  repository: mozilla-services/syncstorage-rs/syncserver-postgres

syncserver-db:
  enabled: false

tokenserver-db:
  enabled: false

postgresql:
  enabled: true

If no Secret is referenced, the operator generates the credentials of the database owner in the Secret <release>-postgresql-app. To use an existing Secret, create it with the type kubernetes.io/basic-auth. The username has to match postgresql.cluster.initdb.owner:

kubectl create secret generic syncstorage-database \
  --type=kubernetes.io/basic-auth \
  --from-literal=username=syncserver \
  --from-literal=password='<password>'
postgresql:
  enabled: true
  cluster:
    initdb:
      database: syncserver
      owner: syncserver
      secret:
        name: syncstorage-database

syncstorage-rs receives the password as part of its database URLs, so it must only contain URL-safe characters (A-Z, a-z, 0-9, -, ., _, ~). The image tag of postgresql.cluster.imageName only pins the major version, so restarted instances get the latest minor version. All other settings of the PostgreSQL cluster (e.g. postgresql.cluster.instances, postgresql.cluster.storage, backups) are passed to the upstream chart. See its values for all options.

External databases

syncserver-db:
  enabled: false

externalSyncserverDatabase:
  type: mysql
  hostname: mariadb.example.com
  port: 3306
  database: syncserver
  username: syncserver
  existingSecret: syncstorage-syncserver-db
  existingSecretPasswordKey: password

The Tokenserver database is configured the same way with tokenserver-db and externalTokenserverDatabase. For PostgreSQL set type: postgres on both and use the image mozilla-services/syncstorage-rs/syncserver-postgres, both may point to the same database. Instead of existingSecret you can set password, which lets the chart create the Secret. As the connection URL is assembled from the password, it must only contain URL-safe characters (A-Z, a-z, 0-9, -, ., _, ~).

Values

KeyTypeDefaultDescription
affinityobject{}Affinity settings for pod assignment
autoscaling.enabledboolfalse
autoscaling.maxReplicasint100
autoscaling.minReplicasint1
autoscaling.targetCPUUtilizationPercentageint80
deploymentStrategyobject{}Update strategy for the deployment
externalSyncserverDatabase.databasestring"syncserver"Name of the database to use
externalSyncserverDatabase.existingSecretstring""Name of an existing Secret containing the password of the user. The password must only contain URL-safe characters.
externalSyncserverDatabase.existingSecretPasswordKeystring"password"Key in the existing Secret containing the password of the user
externalSyncserverDatabase.hostnamestring""Hostname of the external Syncserver database. Used if neither syncserver-db.enabled nor postgresql.enabled is true.
externalSyncserverDatabase.passwordstring""Password of the user. Ignored if externalSyncserverDatabase.existingSecret is set. Must only contain URL-safe characters.
externalSyncserverDatabase.portstring""Port of the external Syncserver database. Defaults to 3306 for mysql and 5432 for postgres.
externalSyncserverDatabase.typestring"mysql"Type of the external Syncserver database: mysql (MariaDB or MySQL) or postgres. Has to match the type of the Tokenserver database and the image.
externalSyncserverDatabase.usernamestring"syncserver"Name of the user to use
externalTokenserverDatabase.databasestring"tokenserver"Name of the database to use
externalTokenserverDatabase.existingSecretstring""Name of an existing Secret containing the password of the user. The password must only contain URL-safe characters.
externalTokenserverDatabase.existingSecretPasswordKeystring"password"Key in the existing Secret containing the password of the user
externalTokenserverDatabase.hostnamestring""Hostname of the external Tokenserver database. Used if neither tokenserver-db.enabled nor postgresql.enabled is true. It may be the same database as the Syncserver database.
externalTokenserverDatabase.passwordstring""Password of the user. Ignored if externalTokenserverDatabase.existingSecret is set. Must only contain URL-safe characters.
externalTokenserverDatabase.portstring""Port of the external Tokenserver database. Defaults to 3306 for mysql and 5432 for postgres.
externalTokenserverDatabase.typestring"mysql"Type of the external Tokenserver database: mysql (MariaDB or MySQL) or postgres. Has to match the type of the Syncserver database and the image.
externalTokenserverDatabase.usernamestring"tokenserver"Name of the user to use
extraEnvlist[]additional environment variables to be added to the pods
fullnameOverridestring""String to fully override "syncstorage-rs.fullname"
image.pullPolicystring`

Deploy syncstorage-rs with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has syncstorage-rs 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 chartsyncstorage-rs is pinned at v8.2.2 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