Run a Connect

Run a Flaq Connect of your own: what it keeps and what it never sees, setting it up with Docker Compose, its console, running it behind a reverse proxy, and home accounts with email.

7 min read

Flaq Connect is a directory that helps the apps find servers without a domain of their own. Most servers never need their own: connect.flaq.dev is built in to every app, keeps no server's address and carries no messages. Run a Connect to depend on nobody else's, or for a community whose servers list on it. A server can list on several Connects at once, and apps ask each one. Connects never talk to each other.

What a Connect keeps, and what it never sees#

It keeps each listed server's signed record, which holds the server's id, key and name and no IP address; the names servers claimed; its settings and admins; and home accounts, if you turn them on. Apps check every record against the server's key, so no Connect can forge or redirect one.

It never sees a message, a file, a password, a sign-in or a token.

It does see metadata: which server ids exist, when each is online, and which app addresses ask for which server, and when. It holds a connected server's address in memory only, never in its database or logs, and its console never shows where a server or an app connects from.

What it needs#

  • A VPS with a public IPv4 address, and a host name with an A record only, such as connect.example.com. Connect relies on seeing each app's and server's real address, which Docker hides for IPv6 traffic unless its IPv6 support is set up, so leave out the AAAA record.
  • Open in the firewall: TCP 443 and UDP 443, and TCP 80 for the certificate.
  • Little else: a small VPS carries thousands of servers. Connect only exchanges a few small messages when an app first finds a server.

Set it up#

mkdir flaq-connect && cd flaq-connect
curl -O https://raw.githubusercontent.com/hyprlab/flaq/main/connect/docker-compose.yml
curl -o .env https://raw.githubusercontent.com/hyprlab/flaq/main/connect/.env.example
mkdir certs

Get the certificate as in Certificates, into certs/. Then fill in .env:

Variable
CONNECT_HOST Its host name. Invite links name it, and servers prove their keys to it by name, so choose it for good: changing it means every server listed there adding it again
CONNECT_OPERATOR, CONNECT_POLICY_URL Who runs it and its policy, shown on its home page and to anyone who asks (optional; the console can change them later)
CONNECT_DOWNLOAD_URL Where invite links send people without the app; Flaq's releases page by default

During the 1.0 beta, also set IMAGE_TAG=beta. Then start it and check it:

docker compose up -d
curl -s https://connect.example.com/.well-known/flaq    # {"kind":"connect",...}
docker compose logs connect                             # the link that makes the first admin

The console#

Connect's console is at https://connect.example.com/admin. It shows counts of what Connect did by the hour (apps let in or refused, punches), the servers listed, online or not, the names they go by, and its settings and admins. From it you remove a listing, which the server's gate sends again within minutes, block a server, so its record and names go and its gate is turned away, and suspend or release a name.

Nobody can sign in until the first admin exists. At its first start Connect writes a one-time link to its log, good for a day, which makes the first admin account: open it from docker compose logs connect. A restart before it is used writes a new one. More admins get links of their own from Settings, and anyone who can reach the machine can always make one:

docker exec flaq-connect flaq-connect admin link     # a one-time link that makes an admin
docker exec flaq-connect flaq-connect admin list     # the admins

That is also the way back in after a forgotten password: make a link, make a new account, and remove the old one in Settings.

Names#

Names are first come, first served, one per server on each Connect, and belong to the server's key. Suspend or release one in the console's Names, or from the command line:

docker exec flaq-connect flaq-connect names                 # every name, its server, its contact
docker exec flaq-connect flaq-connect names suspend NAME
docker exec flaq-connect flaq-connect names release NAME

A suspended name stops resolving and can't be claimed by anyone else; unsuspend gives it back. A name only leads to a server id, so a name that later points elsewhere never moves an account that already joined.

Behind a reverse proxy#

When a reverse proxy, such as Nginx Proxy Manager, already holds TCP 443 for other sites, it can carry Connect's HTTPS side too:

  1. In .env, set CONNECT_HTTPS_PORT to a free port, such as 8107, and run docker compose up -d.
  2. In the proxy, forward your Connect's host name to https://<machine>:8107. The scheme is https: Connect only speaks HTTPS, also to the proxy. Give the proxy host a Let's Encrypt certificate.
  3. On the router, forward UDP 443 straight to the machine running Connect. No HTTP proxy carries it: it is how servers keep their listing and how apps punch through.
  4. Give Connect the same certificate the proxy got, in certs/, and again after each renewal: servers and apps check it on the UDP side, where the proxy isn't in between.
  5. Set CONNECT_TRUST_PROXY=1 in .env. Connect then takes who is asking from the X-Forwarded-For the proxy adds, instead of the proxy's own address, for its limits on admissions and sign-in attempts.

Only behind the proxy

Set CONNECT_TRUST_PROXY=1 only when Connect's HTTPS port is reachable through the proxy alone, or anyone could claim any address.

Using it#

A server lists on it by adding connect.example.com under Connects on its console's Flaq Connect page; its invite links then lead there. An app needs nothing to follow an invite link, and finds servers by name alone on it once it is added under App settings > Flaq Connect.

Home accounts and email#

A Connect can also be a home for accounts, for people who don't belong to any one server: @ana@connect.example.com. It is off by default. Turn it on with the Home accounts switch on the console's Settings page, which takes effect at once. People then sign up and sign in there from the app, confirm their email address, and join servers that take accounts from your Connect. The console's Accounts page lists them, and an admin can delete one there. Sign-ups are limited per address.

For each account it keeps the handle and email address, a slow hash of the derived sign-in secret, the sealed key backup and server list, the current keys and the signed-in devices; never a password, a message, or which servers an account belongs to. Make an account describes it from the user's side.

Email#

Home accounts need a mail server, set on the Settings page under Email:

Field Meaning
Mail server, Port The SMTP server; the port defaults to 587
Security STARTTLS (the default), TLS for port 465, or none for a relay on the same machine
Username, Password Its sign-in, if it asks for one
Sender The From address, such as Flaq Connect <no-reply@connect.flaq.dev>

They are stored in the Connect's database and change without a restart. The Settings page sends a test message, and says what the mail server answered when one fails.

It sends three kinds of mail, each with a link that works once and for an hour: confirming an address, a forgotten password, and a new device signed in. Without a mail server it takes no sign-ups and sends no mail, though people already signed up keep signing in; the Overview says so until one is set.

Turning home accounts off stops sign-ups, sign-ins and passports, so within a day its accounts' sessions on member servers lapse. The accounts stay in the database, and turning it on again brings them back as they were.

Handles for servers listed by name#

The handles of servers listed by name, such as @ana@anas-place.connect.example.com, need a wildcard DNS record and a wildcard certificate: see Certificates.

Back it up#

Back up the connect-data volume, for its names, settings, admins and accounts. The records in it come back by themselves, since each server sends its own again every few minutes.