Deploy your own Client
You can deploy your own Federated Learning Net Client to participate in the Federated Learning Net network on almost any server or machine, including inside a virtual machine. This tutorial will guide you through the 5-10 minute process of deploying a Federated Learning Net Client on your own server or machine.
Prerequisites
- either Linux or MacOS. On Windows, you can use WSL2 with e.g. Ubuntu 22.04 or later.
- curl (for downloading the CLI installation shell script, you can delete it after the installation)
- docker
- docker compose
- at least 4 GB of RAM. This holds even for an empty client without data, as on startup the authentication service Keycloak uses a few GB.
- a server/machine that is at best running 24/7 so your data is always findable. You can read more why this is needed here
Furthermore, the client is accessed from the web browser via HTTP/HTTPS. If you want to access the Federated Learning Net Client also from another machine, you need to ensure HTTPS encryption or if this isn't possible use an ssh tunnel to connect to the FLNet Client.
If you only ever access the Federated Learning Net Client from the same machine you can skip this and
in the initialization just run the Federated Learning Net Client on 127.0.0.1 (localhost) and a chosen port,
accessing it from the browser on the same machine.
Deploying your Federated Learning Net Client
Please follow these steps to create, run and setup your Federated Learning Net Client in 5 to 15 minutes.
0. Prepare
First make sure the prerequisites are all installed!
Then, install the flnet CLI tool by running the following command:
curl -fsSL https://raw.githubusercontent.com/FedLearnNet/FL-Net-CLI/main/install.sh | sh
This will download the relevant binary for your system and place it in ~/.local/bin (Linux/Mac)
for non root users and /usr/local/bin as root.
Every Client needs an account in the Platform's Keycloak to join the network. Ask the Platform provider for the credentials and have them ready, as the next step asks for them.
We also recommend you first read relevant documentation:
- Welcome to understand the Network you're joining.
- Requests and Governance to understand how to manage access to your Client from the network.
- Securing access to the Client to understand how to secure access to your Client.
Lastly, the Client initialization script will ask you multiple questions to specify how the client should run. Please have the following information ready:
- Do you want to use SSL certificates (HTTPS)? If yes, do you have your own or do you want to generate self signed certificates? Hint: The flnet CLI can generate self signed certificates for you. Make sure you have the IP address of the machine available, this is set as the domain name in the certificate. Please read the Self signed certificates documentation before deploying.
- Which IP address and port should the Client bind to? Hint: chose localhost if you only access the Client from the same machine or via an SSH tunnel or use your own reverse proxy
- Which domain name should be used to access the Client? Hint: leave empty if you only access the Client from the same machine or via an SSH tunnel or use your own reverse proxy
1. Initializing the Client folder
Simply run the initialization command and follow the command line prompts:
flnet client init
This can be used to either to the initial setup, to reconfigure your client or to perform a fresh installation of the Client.
After running the installer, the flnet_client folder is ready to be used.
By default this is stored at ~/fl-net/clients/, use flnet client info to see the path of your client folder.
The install script will provide you with the next steps, but they are also listed here.
2. Running your created Client
To start the Client, run the following:
flnet client up
You can also run the underlying docker compose command yourself.
cd <path-to-client-folder>
docker compose up -d
The first start up might take upto a few minutes.
3. The initial setup of the Client
3.1 First login as the admin user to the KeyCloak Administration Console
The Client uses KeyCloak as the OIDC Provider for authentication.
There are two different so called Realms in it:
- The
FLNet-Clientrealm is used for the Client itself. It contains the users and groups that are used to access the Client. - The
Masterrealm is the administration realm of KeyCloak itself. It is used to manage the KeyCloak instance and theFLNet-Clientrealm.
First, you need to update the initial admin account created for you in the Master realm.
Please access the Client. If you gave a domain, use the domain name.
Otherwise use the given IP and port.
- Open the KeyCloak Administration Console at
<your-domain>/auth/admin/or<your-ip>:<your-port>/auth/admin/.
In case you missed the initial password given by the initialization script, the initial
username and password for the Master realm can be found in flnet_client/env/keycloak-secrets.env as KC_BOOTSTRAP_ADMIN_PASSWORD.
Use these credentials to log in.
Please immediately change the password, this can be done via the upper right corner under manage account. If going to the account management page causes an infinite reload glitch, you need to
- Go to the Clients page. This is found on the left navigation bar.
- Go to the account-console client by clicking on it's client id.
- In Web Origins, add a plus. This just allows the redirect URLs to also be origins of requests.
Please directly continue with creating a user for the Client.
3.2 Create a user for the Client via the KeyCloak Administration Console
The Federated Learning Net Client is initialized without any users in the FLNet-Client realm.
To create one:
- Follow the steps in the previous section to log in to the KeyCloak Administration Console.
- On the left navigation bar go to Manage Realms and choose the FLNet-Client realm.
- On the left navigation bar go to users and add a user.
Make sure to tick
Email verifiedor connect a SMTP server to the KeyCloak instance, see Keycloaks documentation. Alternatively you can deactivate that email verification is required.
Make sure the user is assigned to at least one group. Otherwise, the Client will refuse all operations for security reasons. For more information about the groups, click on groups. Alternatively, here is a description of the groups:
Admin: Members of the Admin group may see and edit anything, having full access.
Data-Access-Manager: Members of the Data-Access-Manager group may see all patient data, but cannot edit it or add new data. Furthermore, they can control access via the network in the form of queries or federated learning. They have access to all logs.
Data-Admin: Members of the Data-Admin group may read, edit and add patient data. Furthermore, they may see all logs related to the addition, updating or removal of patient data.
The Client is now ready to be used, simply visit it at the domain you chose (or IP:port) and use the user you just created.
3.3 Restricting access to the KeyCloak admin console
The KeyCloak Administration Console is available at <your-domain>/auth/admin/.
We recommend to restrict access to this console to only your own IP address.
You can do this by editing the nginx_keycloak_admin.conf file in the folder created by
the initialization script (~/fl-net/clients).
Further information
Updating an existing Client
Keycloak imports the FLNet-Client realm only on the first start, so realm changes of newer versions do not reach existing Clients automatically.
Since the backend-for-frontend login, the browser login runs through the local-learning-api client. Apply these changes once in the Keycloak admin console
(<your-domain>/auth/admin/, realm FLNet-Client, Clients → local-learning-api):
- Standard flow: enabled
- Valid redirect URIs:
<frontend-address>/local-learning-api/bff/login - Valid post logout redirect URIs:
<frontend-address>/ - Advanced → Proof Key for Code Exchange Code Challenge Method:
S256
<frontend-address> is the address the Client is reached at (DEPLOYED_ON_ADDRESS, e.g. https://clinic.example.org).
It is also passed to the local-learning-api as FLNET_BFF_FRONTEND_URL, from which the login callback is built.
The former option --platform-auth/--no-platform-auth and the env variable GLOBAL_KEYCLOAK_ENABLED were removed: a Platform login is mandatory.
Server availability 24/7
The Federated Learning Net allows discovery of data at any point in time. To also be able to discover your data, your machine needs to be connected. Therefore, we recommend running the server/machine that participates in the Federated Learning Net 24/7. The docker containers deployed are set to restart always unless manually stopped, so on server restart the client will automatically start again. If you still notice any issues after a server restart, please refer to the troubleshooting section below.
Securing your Client: Access to the Client from other machines
Access to the Federated Learning Net Client is via a webserver it deploys. If you are planning to access the Client only from the same machine where it is running there are no further setup steps needed,
you can use the machines browser and the address you configured, e.g. localhost:8250.
However if you want to access the node from another machine, you should either:
- Generate and use SSL certificates. If you don't use a domain but only an IP address, you need to perform some manual steps to make the default NGINX configuration work, refer to this section.
- Use an SSH tunnel and access the node via the tunnel
Generating SSL certificates
SSL certificates are the keys used for the encryption of traffic to/from the Federated Learning Net Client. The Federated Learning Net Client needs these keys to encrypt the traffic, using the NGINX reverse proxy shipped with the Client. If you use your own reverse proxy, refer to the advanced documentation on this. We recommend to use letsencrypt if you can fullfill the DNS challenges done by lets encrypt.
SSL certificates are usually bound to a domain, so please register a domain/subdomain first before continuing. The Federated Learning Net Client is then accessed via the browser and this domain.
Let's Encrypt certificates (server accessible from the internet)
We recommend using certbot. After installing certbot, run the following command, replacing
yourdomain.com with your own domain. This does NOT work with an IP address as domain.
sudo certbot certonly --standalone \
-d <yourdomain.com> \
--deploy-hook "docker exec fl-net-client-reverse-proxy-encrypted-1 nginx -s reload"
This will generate the SSL certificates as well as take care of renewal.
Please note that the deploy hook will initially fail as the Federated Learning Net Client has not been setup and
you might find error logs in the certbot logs. This is not an issue though as the
Federated Learning Net Client is setup in the next step.
Server not accessible from the internet
SSL certificate authorities usually verify your domain by sending a request to your server running the Federated Learning Net Client, e.g. it is behind a VPN or demilitarized zone. If your server is not reachable via the internet this is not possible. You have multiple options:
- Generate self signed certificates.
- Set up an entry in your domain that Let's Encrypt can use to verify your domain. This would be using the DNS-01 challenge. For automating the certification renewal, you need to check the API of your domain provider.
- Not generate SSL certificates at all and just use an SSH tunnel for encryption. For this you need to modify how the computer accessing the Federated Learning Net Client node behaves!
- Use your own CA Authority to sign the certificates. This completely depends on your own IT infrastructure, so we cannot provide additional help.
Self signed certificates
When you access the Federated Learning Net Client via the Browser a security warning will show, but traffic will be encrypted.
During flnet client init, set the domain either to the domain you setup or to the IP address and port the client will be accessed with (e.g. https://<your-ip>:<port>) and choose self-signed as SSL termination.
If no certificate exists yet, the CLI offers to create it at the end of the setup (this requires openssl). If you skipped that, generate it afterwards:
flnet client certs
The common name and subject alternative names of the certificate must match the domain you access the Client with.
The certificates are stored in your client folder under self_signed_certs/.
The NGINX of the Client is setup strictly and by default not set for self signed certificates.
Please go to the nginx https config file
nano FLNet_client/nginx_conf_HTTPS.conf
Comment out the following line:
add_header Strict-Transport-Security "max-age=31536000" always;
If you used an IP address as domain, please also follow the steps in the section about using an IP address for HTTPS. If you already started the Client, you need to run the following command for the Federated Learning Net Client to pick up the new certificates:
flnet client restart
Make sure to renew the certificates before they expire or to set a high expiracy date.
You can automatically renew them by running the same command again with the flags set correctly, please check flnet client certs --help for more information. This will overwrite the existing certificates and the reverse proxy of the Client needs to be restarted afterwards. The browser will show a security warning again, but traffic will be encrypted.
Example:
flnet client certs --no-input --force --cn <your-ip> --ip <your-ip> --days 365 \
&& flnet client restart reverse-proxy-encrypted
To run it automatically, e.g. monthly via crontab -e (cron needs the full path to flnet, see which flnet):
0 3 1 * * /path/to/flnet client certs --no-input --force --days 365 && /path/to/flnet client restart reverse-proxy-encrypted
If you run several Clients on this machine, add --name <client-name> to both commands.
Using an IP Address for HTTPS
If you are using an IP address as the domain using HTTPS, the default NGINX configuration is not set up for this, as it is somewhat unusual. NGINX cannot correctly find the right server block (the right configuration) for IP addresses.
The steps below reassign default_server to the SSL block so NGINX starts cleanly. Please perform the following manual steps:
- Go to the client directory:
cd FLNet_client - Open the file
nginx.confin a text editor. You need to comment out/remove the default server block at the end of the file. You can find it by searching forlisten 443 ssl default_server;. - Open the file
nginx_conf_HTTPS.confin a text editor. You need to add thedefault_serverflag to the listen directive. Changelisten 443 ssl;tolisten 443 ssl default_server;.
Using an SSH tunnel
If you prefer not to set up SSL certificates, you can run the Client on localhost and securely access it through an SSH tunnel. This approach encrypts the connection between your local machine and the server while keeping the Client bound to localhost only.
Steps to set up SSH tunneling:
- Deploy the Client to listen on
127.0.0.1(localhost) during the initialization step. You don't need any SSL certificates as the SSH tunnel we use here already encrypts traffic. - From your local machine accessing the Federated Learning Net Client, establish an SSH tunnel to your server:
# Replace 4444 with the port you configured during Client setup
# Replace user@your-server with your actual SSH credentials
ssh -L 4444:localhost:4444 user@your-server
This can also be setup in e.g. Putty. Please make sure that the port on the server and your machine align.
E.g. ssh -L 5555:localhost:4444 user@your-server will not work as the Client will think it is accessed from a non allowed source (the ports mismatch, gets accessed at host header localhost:5555 from your machine but expects localhost:4444)
- While the SSH connection is active, open your browser and navigate to
http://localhost:4444/
The Client will now be accessible on your local machine as if it were running locally, with all traffic securely encrypted through the SSH tunnel.
Advanced: Using your own reverse proxy
A reverse proxy handles all the traffic send to the Federated Learning Net Client, proxying it. Furthermore, the proxy is used for the encryption of this traffic.
The Federated Learning Net Client uses it's own NGINX reverse proxy. If you want to use your own reverse proxy, it simply needs to relay traffic to your chosen IP:Port where you want to run the Federated Learning Net Client. Please note that we use Server Sent Events (SSE), usually requiring special proxy configuration.
An example configuration for apache would be (Make sure to input your actual domain!):
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName <your-domain>
# Relay the traffic to where you deploy the client
Define CLIENT_EXPOSED_ADDRESS 127.0.0.1:8250
ProxyPass / http://${CLIENT_EXPOSED_ADDRESS}/
ProxyPassReverse / http://${CLIENT_EXPOSED_ADDRESS}/
# SSE Support
SetEnv proxy-sendchunked 1
# WebSocket support
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule ^/api/(.*) ws://${CLIENT_EXPOSED_ADDRESS}/api/$1 [P,L]
You then need to generate SSL certificates.
If your server is accessible from the internet
You can easily use certbots default certificate generation (Make sure to input your actual domain).
Use sudo certbot --apache -d <yourdomain.com>
for apache or sudo certbot --nginx -d <yourdomain.com> for nginx.
This will also automatically update the SSL certificates!
If your server is not accessible from the internet, e.g. it is behind a VPN or demilitarized zone Refer to the section on generating SSL certificates. While this is written for the Federated Learning Net Client NGINX reverse proxy, this is fundamentally the same with your own reverse proxy.
Limiting network traffic
Incoming network traffic
The Federated Learning Net Client is accessed through a web interface served by an nginx instance, which routes requests to either the static frontend or the API. Make sure the port you configured during initialization is reachable from any machine you want to access the Client from.
Outgoing network traffic
The Federated Learning Net Client needs to communicate with the Federated Learning Net Platform. Furthermore, it needs to be able to pull certain docker images to function. This leads to the following requirements for outgoing network traffic.
Always required (while the Client is running)
| Destination | Port | Used by | Purpose |
|---|---|---|---|
GLOBAL_DOMAIN from FLNet_Client/.env | 443 (https, wss) | the server and the Client containers | Platform API, the Client's permanent connection to the Platform, Tool images |
GLOBAL_DOMAIN from FLNet_Client/.env | GLOBAL_TCP_PORT from the same .env (tcp) | the Client containers | relay for federated learning |
| a DNS server | 53 | the server | name resolution, also for Docker |
an NTP server, e.g. pool.ntp.org | 123 (udp) | the server | correct time, otherwise issued authorization tokens might immediately expire |
The Client containers do not need any other destination. The GLOBAL_DOMAIN is the only host that must be reachable from the containers.
Required for installing and updating
These hosts are only contacted by the server itself, on port 443, when the flnet CLI is installed and when the Docker images are pulled (flnet client up on a new or updated Client).
They can be blocked again once all images are pulled, but are needed for every later update.
| Host | Purpose |
|---|---|
raw.githubusercontent.com | flnet CLI installation script |
github.com | flnet CLI download |
release-assets.githubusercontent.com | flnet CLI download (redirect target of github.com) |
ghcr.io | Federated Learning Net Client images |
pkg-containers.githubusercontent.com | Federated Learning Net Client image layers |
registry-1.docker.io | Docker Hub registry (PostgreSQL image) |
auth.docker.io | Docker Hub authentication |
production.cloudfront.docker.com | Docker Hub image layers |
quay.io | Red Hat registry (KeyCloak image) |
cdn01.quay.io | KeyCloak image layers |
cgr.dev | Chainguard registry (nginx reverse proxy image) |
9236a389bd48b984df91adc1bc924620.r2.cloudflarestorage.com | nginx reverse proxy image layers (Chainguard's storage) |
Please note:
- Whitelist host names, not paths. A firewall cannot see the path of an encrypted
httpsrequest, so e.g.ghcr.io/fedlearnnet/cannot be whitelisted on its own, onlyghcr.ioas a whole. - Whitelist host names, not IP addresses. Most of these hosts are served by content delivery networks whose IP addresses change frequently.
- Registries may serve image layers from other content delivery hosts depending on your location, e.g. Docker Hub also uses
production.cloudflare.docker.com. If an image pull fails, the error message names the blocked host. The Docker allow list covers further domains used by Docker itself. - KeyCloak tries to reach
config.liquibase.comon start up. This is not required and can stay blocked.
We strongly recommend to test deploying the Federated Learning Net Client after setting the network restrictions.
Troubleshooting
The Client is misbehaving after a server restart
Sometimes docker registers the shutdown of containers on shutdown as a manual stop and does not restart them on server restart.
- Try simply restarting the whole Client:
flnet client restart
- If the issues persist, investigate the logs of the containers in the following order:
reverse-proxy(this routes all traffic to the Client).local-learning-api(this is the main backend service of the Federated Learning Net Client)keycloak(this is the authentication service of the Federated Learning Net Client) If neither of these containers show any issues, check all further containers. Please contact the developers if issues persist and provide the logs of the containers if you cannot resolve the issues yourself or find a bug in the Federated Learning Net Client.
The Client is suddenly misbehabing towards the Platform
Please go to the Platform welcome page (the GLOBAL_DOMAIN from the Client's .env) and check if the Platform is reachable. Then please scroll down to the bottom of the page, there the Platforms version is shown. If the Platform is running a newer version than your Client, please update your Client to the same version as the Platform.