Activer les connexions TLS¶
Transport Layer Security (TLS) ensures the communication between endpoints is encrypted.
This guide describes how to establish secure TLS SuperLink ↔ SuperNodes as well as User
↔ SuperLink connections. It also explains how to enable TLS on the internal Runtime API
connections used by SuperExec, ServerApp processes, and ClientApp processes.
Note
Ce guide s’appuie sur la mise en place de l’application Flower présentée dans le guide Exécuter Flower avec le Deployment Runtime et l’étend pour remplacer l’utilisation de --insecure au profit de TLS.
Astuce
Consultez l’exemple Flower Authentication pour un exemple complet autonome sur la mise en place de la sécurité TLS (et facultativement l’authentification des nœuds). Consultez le guide Authentifier les SuperNodes pour en savoir plus sur l’ajout d’une couche d’authentification aux connexions SuperLink ↔ SuperNode.
Certificats¶
Using TLS-enabled connections expects some certificates generated and passed when
launching the SuperLink, the SuperNodes and when a user (e.g. a data scientist that
wants to submit a Run) interacts with the federation via the flwr CLI. The same certificates can be used for local prototyping when
enabling TLS on internal Runtime API connections.
Nous avons préparé un script qui peut être utilisé pour générer de tels ensembles de certificats. Même si l’utilisation de ces derniers est acceptable pour la prototypage, nous vous recommandons de suivre les normes établies dans votre équipe/organisation et de générer les certificats et de les partager avec les parties correspondantes. Référez-vous à la section Générer des certificats TLS dans l’exemple lié en haut de ce guide.
# In the example directory, generate the certificates
$ python generate_creds.py
Cela générera les certificats TLS dans un nouveau répertoire certificates/. Copiez ce répertoire dans le répertoire de votre application (par exemple, un répertoire généré plus tôt via flwr new).
Avertissement
The approach for generating TLS certificates in the context of this example can serve as an inspiration and starting point, but it should not be used as a reference for production environments. Please refer to other sources regarding the issue of correctly generating certificates for production environments. For non-critical prototyping or research projects, it might be sufficient to use the self-signed certificates generated using the scripts mentioned in this guide. In production, do not reuse the same server certificate and private key for multiple services. A better practice is to use a unique key pair for each service, for example the SuperLink Fleet API, the SuperLink-hosted Runtime API, and each SuperNode-hosted Runtime API.
Lancement du SuperLink avec TLS¶
This section describes how to launch a SuperLink that works on TLS-enabled connections. The code snippet below assumes the certificates/ directory is in the same directory where you execute the command from. Edit the paths accordingly if that is not the case. When providing certificates for the Fleet API and Control API, the SuperLink expects a tuple of three certificates paths: CA certificate, server certificate and server private key. The same command can also provide AppIo-named certificates for the SuperLink’s Runtime API.
$ flower-superlink \
--ssl-ca-certfile certificates/ca.crt \
--ssl-certfile certificates/server.pem \
--ssl-keyfile certificates/server.key \
--appio-ssl-ca-certfile certificates/ca.crt \
--appio-ssl-certfile certificates/server.pem \
--appio-ssl-keyfile certificates/server.key
Comprendre la commande
--ssl-ca-certfile: Spécifiez l’emplacement du fichier de certificat CA dans votre fichier. Ce fichier est un certificat utilisé pour vérifier l’identité du SuperLink--ssl-certfile: Spécifiez l’emplacement du fichier de certificat TLS du SuperLink. Ce fichier est utilisé pour identifier le SuperLink et chiffrer les paquets transmis sur le réseau.--ssl-keyfile: Spécifiez l’emplacement du fichier de clé privée TLS du SuperLink. Ce fichier est utilisé pour déchiffrer les paquets transmis sur le réseau.--appio-ssl-ca-certfile: Specify the location of the CA certificate file used by SuperExec to verify the SuperLink’s Runtime API server certificate.--appio-ssl-certfile: Specify the location of the Runtime API server TLS certificate file. The certificate must include Subject Alternative Names (SANs) for the Runtime API address used by SuperExec. When using an IP address such as127.0.0.1, the certificate must include a matching IP SAN.--appio-ssl-keyfile: Specify the location of the Runtime API server TLS private key file.
Connexion des SuperNodes avec TLS¶
This section describes how to launch a SuperNode that works on TLS-enabled connections.
The code snippet below assumes the certificates/ directory is in the same directory
where you execute the command from. To secure the SuperNode ↔ SuperLink connection,
replace --insecure with --root-certificates. The same command can also provide
AppIo-named certificates for the SuperNode’s Runtime API.
$ flower-supernode \
--root-certificates certificates/ca.crt \
--appio-ssl-ca-certfile certificates/ca.crt \
--appio-ssl-certfile certificates/server.pem \
--appio-ssl-keyfile certificates/server.key \
--superlink 127.0.0.1:9092 \
--clientappio-api-address 127.0.0.1:9094 \
--node-config="partition-id=0 num-partitions=2"
Comprendre la commande
--root-certificates: Cela spécifie l’emplacement du fichier de certificat CA. Leca.crtfichier est utilisé pour vérifier l’identité de SuperLink.--appio-ssl-ca-certfile: Specify the location of the CA certificate file used by SuperExec to verify the SuperNode’s Runtime API server certificate.--appio-ssl-certfile: Specify the location of the Runtime API server TLS certificate file. The certificate must include Subject Alternative Names (SANs) for the Runtime API address used by SuperExec. When using an IP address such as127.0.0.1, the certificate must include a matching IP SAN.--appio-ssl-keyfile: Specify the location of the Runtime API server TLS private key file.
Suivez la même procédure, c’est-à-dire en remplaçant --insecure par --root-certificates, pour lancer le deuxième SuperNode.
$ flower-supernode \
--root-certificates certificates/ca.crt \
--appio-ssl-ca-certfile certificates/ca.crt \
--appio-ssl-certfile certificates/server.pem \
--appio-ssl-keyfile certificates/server.key \
--superlink 127.0.0.1:9092 \
--clientappio-api-address 127.0.0.1:9095 \
--node-config="partition-id=1 num-partitions=2"
À ce stade, vous avez réussi à lancer un SuperLink et deux SuperNodes avec des connexions TLS activées.
Note
The --appio-ssl-* Runtime API TLS options configure server-authenticated TLS.
They do not configure mutual TLS. The --appio-ssl-ca-certfile file is used by
SuperExec and app processes to verify the Runtime API server certificate, not as a
client certificate. If Runtime API TLS is not configured, internal Runtime API
connections remain unencrypted and should stay inside a trusted network.
TLS for Runtime API Connections in « Process » Isolation Mode¶
Pour plus de détails sur SuperExec, le mode d’isolement « process », et le mode d’isolement « subprocess », voir Communication réseau de Flower.
So far, we’ve been showing you how to enable TLS for Runtime API connections when using the default « subprocess » isolation mode. In this mode, SuperLink and SuperNode automatically start their SuperExecs with the correct Runtime API TLS options. However, if you want to run SuperExec separately in « process » isolation mode, you need to do a few things differently to enable TLS for the Runtime API connections.
First, we need to launch the SuperLink and SuperNode with --isolation=process and
with the Runtime API TLS options. This tells the SuperLink and SuperNode that the
SuperExecs will be launched separately, e.g. by an operator or orchestration system.
Next, in order for the SuperExecs to establish TLS connections to the Runtime APIs, we
need to provide the Runtime API TLS options when launching the SuperExecs. Below is an
example command to launch a SuperExec that can establish TLS connections to the Runtime
API hosted by the SuperLink:
$ flower-superexec \
--root-certificates certificates/ca.crt \
--appio-api-address 127.0.0.1:9091 \
--plugin-type serverapp
Comprendre la commande
--root-certificates: Specify the location of the CA certificate file. Theca.crtfile is used by SuperExec to verify the Runtime API server certificate.--appio-api-address: Specify the address of the Runtime API that SuperExec should connect to. In this example,127.0.0.1:9091is the SuperLink’s Runtime API.--plugin-type: Spécifiez le type de processus d’applications que SuperExec doit lancer. Utilisezserverapppour unServerAppSuperExec.
Next, use the same procedure for a ClientApp SuperExec, but pass the SuperNode’s
Runtime API address, e.g. 127.0.0.1:9094, and set --plugin-type clientapp.
Now your SuperLink-side SuperExec and SuperNode-side SuperExec can establish TLS connections to their respective Runtime APIs. When using « process » isolation mode, it is the responsibility of the process launcher (e.g. user or orchestrator) to launch the SuperExecs with the correct Runtime API TLS options. If you use an orchestration system to launch the SuperExecs, make sure to include the Runtime API TLS options in the commands or configuration used by your orchestration system.
Flower CLI avec TLS activé¶
Le Flower CLI (par exemple, la commande flwr run) est la façon dont un utilisateur (par exemple, un scientifique des données) peut interagir avec une fédération déployée. Les commandes Flower et CLI sont traitées par le SuperLink et donc, si elle a été configurée pour ne fonctionner que sur des connexions TLS, les requêtes envoyées par Flower CLI doivent faire usage d’un certificat TLS. Pour ce faire, remplacez le champ insecure = true dans votre fichier de configuration TOML Flower avec un nouveau champ qui lit le certificat:
[superlink.local-deployment]
address = "127.0.0.1:9093"
root-certificates = "/absolute/path/to/certificates/ca.crt"
Notez que le chemin vers le root-certificates est relatif à la racine du projet. Vous pouvez maintenant exécuter l’exemple en exécutant flwr run:
$ flwr run . local-deployment --stream
Astuce
Vous pouvez configurer votre profil local-deployment en tant que défaut afin de ne pas avoir à spécifier explicitement ce dernier dans chaque commande CLI Flower qui nécessite une connexion avec le SuperLink. Pour cela et plus d’informations sur la configuration de Flower, veuillez consulter le guide the Flower Configuration.
Conclusion¶
You should now have learned how to generate self-signed certificates using the given
script, start a TLS-enabled server and have two clients establish secure connections to
it. You should also have learned how to run your Flower project using flwr run with
TLS enabled and how to secure internal Runtime API connections. All other commands in
the Flower CLI will also be TLS-enabled.
Note
Veuillez consulter le Exécuter Flower à l’aide de Docker documentation pour apprendre à configurer une fédération où chaque composant s’exécute dans son propre conteneur Docker. Vous pouvez également utiliser TLS et d’autres fonctionnalités de sécurité dans Flower telles que l’implémentation d’un mécanisme d’authentification des SuperNodes.
Ressources supplémentaires¶
Ces sources supplémentaires peuvent être pertinentes si tu souhaites approfondir le sujet des certificats :