Sovrain
  1. Documentation
  2. Self-hosting

How-to guide

Run the image behind your own proxy

Run the Sovrain image in your own compose file or in Kubernetes, behind a reverse proxy you already have, and make it trust your company's CA.

This guide runs the Sovrain image in a setup of your own, such as your own compose file or Kubernetes, behind a reverse proxy you already run. The proxy answers HTTPS for Sovrain’s names and passes the requests on. For a server where Sovrain and Caddy are all there is, the compose file of the release does all of this: Run Sovrain on your server.

Before you start

  • The image. releases.sovrain.app/sovrain:1.0.0-rc.1, for amd64 and arm64. It runs the selfhost profile, listens on port 8080 with plain HTTP and keeps its data in the volume /data. Tags: Image tags.
  • Two DNS names that point at your proxy: the sign-up address, here auth.example.com, and your organization’s address one level below it, here acme.auth.example.com.
  • Certificates for both names in your proxy.
  • A mail account that sends over SMTP on port 465 with TLS; see Configure outgoing mail.

Run the container

  1. Write the configuration as an environment file, here sovrain.env, readable only by you:

    cat > sovrain.env <<EOF
    IDP_BASE_URL=https://auth.example.com
    IDP_MEK=$(openssl rand -base64 32)
    IDP_CSRF_SECRET=$(openssl rand -base64 32)
    IDP_SMTP_HOST=smtp.example.com
    IDP_SMTP_USERNAME=sovrain@example.com
    IDP_SMTP_PASSWORD=change-me
    EOF
    chmod 600 sovrain.env
    

    In Kubernetes, put the same values in a Secret. IDP_MEK is the master key; create it once and keep a copy in your password manager. Without it, nobody can read the data again.

  2. Start the container with a volume for /data. Publish port 8080 only where your proxy reaches it, never to the internet; here, on the server’s loopback address:

    docker volume create sovrain-data
    docker run -d --name sovrain --restart unless-stopped \
      -p 127.0.0.1:8080:8080 \
      -v sovrain-data:/data \
      --env-file sovrain.env \
      --health-cmd 'curl -fsS http://localhost:8080/ready || exit 1' \
      releases.sovrain.app/sovrain:1.0.0-rc.1
    
  3. Check that it is ready:

    curl -s http://127.0.0.1:8080/ready
    

It answers {"ready":true}.

Set up the proxy

Your proxy serves HTTPS on both names and passes every request to Sovrain’s port 8080. Sovrain needs three things from it:

  • The original Host header. Sovrain tells the sign-up address from the organization’s address by it.
  • X-Forwarded-For set to the client’s address. Sovrain takes the first address in this header as the client, for rate limits and for the activity Sovrain records. Configure the proxy to replace the header, not to add to one the client sent.
  • HTTPS on both names. Sovrain marks its cookies Secure and builds its links with https://, from IDP_BASE_URL.

With Caddy, which sets X-Forwarded-For itself:

auth.example.com, acme.auth.example.com {
	reverse_proxy 127.0.0.1:8080
}

With nginx:

server {
    listen 443 ssl;
    http2 on;
    server_name auth.example.com acme.auth.example.com;
    ssl_certificate     /etc/ssl/sovrain/fullchain.pem;
    ssl_certificate_key /etc/ssl/sovrain/privkey.pem;
    client_max_body_size 0;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
    }
}

client_max_body_size 0 lifts nginx’s limit of 1 MB per request: attachments in the password manager and imports of an organization are larger, and Sovrain sets its own limits.

Open https://auth.example.com/register. The form Create a new organization opens over HTTPS.

Create your organization

Create the first organization with the short name of your second DNS name, as in Run Sovrain on your server. After that, sign-up closes and more people join by invitation. The 30-day trial has started; before it ends, activate a license.

Other situations

If Sovrain must trust your company’s CA

Sovrain checks the daily license check’s connection to releases.sovrain.app against the CAs of the image. When your network passes HTTPS through a company proxy that presents certificates from your own CA, build an image that trusts it:

FROM releases.sovrain.app/sovrain:1.0.0-rc.1
COPY company-ca.crt /usr/local/share/ca-certificates/
RUN update-ca-certificates

Run that image in place of the release’s, and build it again for each new release. The mail server is checked against Sovrain’s own list of public CAs instead; see Configure outgoing mail.

If you run it in Kubernetes

  • Run one replica, with a deployment strategy that stops the old pod before it starts the new one (Recreate). Only one Sovrain may use a data volume at a time.
  • Mount a persistent volume at /data.
  • Use GET /ready on port 8080 as the readiness probe.
  • Give the ingress both names, and make it pass Host and set X-Forwarded-For as above.

Keep in mind

  • Sovrain sends no Strict-Transport-Security header. Add it in your proxy if you want browsers to remember HTTPS.
  • Back up the volume and the environment file: Back up Sovrain.
  • Every variable the image reads: Server configuration.