From d06a0e95608209c16e222bb7d6a7d6daf41ddb9c Mon Sep 17 00:00:00 2001 From: jafermarq Date: Fri, 11 Oct 2024 14:56:50 +0100 Subject: [PATCH 1/2] readme tweaks --- examples/flower-authentication/README.md | 86 ++++++++++++------------ 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/examples/flower-authentication/README.md b/examples/flower-authentication/README.md index 9e84d86379d..daf610b4981 100644 --- a/examples/flower-authentication/README.md +++ b/examples/flower-authentication/README.md @@ -21,58 +21,54 @@ git clone --depth=1 https://github.com/adap/flower.git _tmp && mv _tmp/examples/ This will create a new directory called `flower-authentication` with the following project structure: -```bash -$ tree . -. -├── certificate.conf # <-- configuration for OpenSSL -├── generate.sh # <-- generate certificates and keys -├── pyproject.toml # <-- project dependencies -├── client.py # <-- contains `ClientApp` -├── server.py # <-- contains `ServerApp` -└── task.py # <-- task-specific code (model, data) +```shell +flower-authentication +├── authexample +│ ├── __init__.py +│ ├── client_app.py # Defines your ClientApp +│ ├── server_app.py # Defines your ServerApp +│ └── task.py # Defines your model, training and data loading +├── pyproject.toml # Project metadata like dependencies and configs +├── certificate.conf # Configuration for OpenSSL +├── generate.sh # Generate certificates and keys +└── README.md ``` -## Install dependencies +### Install dependencies and project -Project dependencies (such as `torch` and `flwr`) are defined in `pyproject.toml`. You can install the dependencies by invoking `pip`: +Install the dependencies defined in `pyproject.toml` as well as the `authexample` package. -```shell -# From a new python environment, run: -pip install . +```bash +pip install -e . ``` -Then, to verify that everything works correctly you can run the following command: - -```shell -python3 -c "import flwr" -``` +## Generate public and private keys -If you don't see any errors you're good to go! +The `generate.sh` script by default generates certificates for creating a secure TLS connection +and three private and public key pairs for one server and two clients. -## Generate public and private keys +> \[!NOTE\] +> Note that this script should only be used for development purposes and not for creating production key pairs. ```bash ./generate.sh ``` -`generate.sh` is a script that (by default) generates certificates for creating a secure TLS connection -and three private and public key pairs for one server and two clients. You can generate more keys by specifying the number of client credentials that you wish to generate. The script also generates a CSV file that includes each of the generated (client) public keys. -⚠️ Note that this script should only be used for development purposes and not for creating production key pairs. - ```bash ./generate.sh {your_number_of_clients} ``` -## Start the long-running Flower server (SuperLink) +## Start the long-running Flower server-side (SuperLink+SuperExec) -To start a long-running Flower server (SuperLink) and enable authentication is very easy; all you need to do is type +Starting long-running Flower server-side components (SuperLink+SuperExec) and enable authentication is very easy; all you need to do is type `--auth-list-public-keys` containing file path to the known `client_public_keys.csv`, `--auth-superlink-private-key` containing file path to the SuperLink's private key `server_credentials`, and `--auth-superlink-public-key` containing file path to the SuperLink's public key `server_credentials.pub`. Notice that you can only enable authentication with a secure TLS connection. ```bash +# Launch the Superlink flower-superlink \ --ssl-ca-certfile certificates/ca.crt \ --ssl-certfile certificates/server.pem \ @@ -82,12 +78,26 @@ flower-superlink \ --auth-superlink-public-key keys/server_credentials.pub ``` -## Start the long-running Flower client (SuperNode) +Then launch the `SuperExec`: + +```bash +flower-superexec \ + --ssl-ca-certfile certificates/ca.crt \ + --ssl-certfile certificates/server.pem \ + --ssl-keyfile certificates/server.key \ + --executor-config '--executor-config 'root-certificates=\"certificates/ca.crt\"'' \ + --executor flwr.superexec.deployment:executor + +``` + +At this point your server-side is idling. First, let's connect two `SuperNodes`, and then we'll start a run. + +## Start the long-running Flower client-side (SuperNode) In a new terminal window, start the first long-running Flower client (SuperNode): ```bash -flower-supernode ./ \ +flower-supernode \ --root-certificates certificates/ca.crt \ --superlink 127.0.0.1:9092 \ --auth-supernode-private-key keys/client_credentials_1 \ @@ -98,7 +108,7 @@ flower-supernode ./ \ In yet another new terminal window, start the second long-running Flower client: ```bash -flower-supernode ./ \ +flower-supernode \ --root-certificates certificates/ca.crt \ --superlink 127.0.0.1:9092 \ --auth-supernode-private-key keys/client_credentials_2 \ @@ -111,20 +121,8 @@ above. Don't forget to specify the correct client private and public keys for ea ## Run the Flower App -With both the long-running server (SuperLink) and two clients (SuperNode) up and running, we can now start the SuperExec: - -```bash -flower-superexec \ - --ssl-ca-certfile certificates/ca.crt \ - --ssl-certfile certificates/server.pem \ - --ssl-keyfile certificates/server.key \ - --executor-config '--executor-config 'root-certificates=\"certificates/ca.crt\"'' \ - --executor flwr.superexec.deployment:executor - -``` - -Then, we run the `flwr run` command: +With both the long-running server-side (SuperLink+SuperExec) and two SuperNodes up and running, we can now start run. ```bash -flwr run . superexec +flwr run . my-federation ``` From 7ab3edf2d21575957fbba5a9ad0e3f0cc789663b Mon Sep 17 00:00:00 2001 From: jafermarq Date: Fri, 11 Oct 2024 16:50:31 +0100 Subject: [PATCH 2/2] tweak reame and pyproject.toml --- examples/flower-authentication/README.md | 16 ++++++++++------ examples/flower-authentication/pyproject.toml | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/flower-authentication/README.md b/examples/flower-authentication/README.md index daf610b4981..563454310bf 100644 --- a/examples/flower-authentication/README.md +++ b/examples/flower-authentication/README.md @@ -4,19 +4,22 @@ dataset: [CIFAR-10] framework: [torch, torchvision] --- -# Flower Authentication with PyTorch 🧪 +# Flower Federations with Authentication 🧪 -> 🧪 = This example covers experimental features that might change in future versions of Flower -> Please consult the regular PyTorch code examples ([quickstart](https://github.com/adap/flower/tree/main/examples/quickstart-pytorch), [advanced](https://github.com/adap/flower/tree/main/examples/advanced-pytorch)) to learn how to use Flower with PyTorch. +> \[!NOTE\] +> 🧪 = This example covers experimental features that might change in future versions of Flower. +> Please consult the regular PyTorch examples ([quickstart](https://github.com/adap/flower/tree/main/examples/quickstart-pytorch), [advanced](https://github.com/adap/flower/tree/main/examples/advanced-pytorch)) to learn how to use Flower with PyTorch. -The following steps describe how to start a long-running Flower server (SuperLink) and a long-running Flower client (SuperNode) with authentication enabled. +The following steps describe how to start a long-running Flower server (SuperLink+SuperExec) and a long-running Flower clients (SuperNode) with authentication enabled. The task is to train a simple CNN for image classification using PyTorch. ## Project Setup Start by cloning the example project. We prepared a single-line command that you can copy into your shell which will checkout the example for you: ```shell -git clone --depth=1 https://github.com/adap/flower.git _tmp && mv _tmp/examples/flower-authentication . && rm -rf _tmp && cd flower-authentication +git clone --depth=1 https://github.com/adap/flower.git _tmp \ + && mv _tmp/examples/flower-authentication . \ + && rm -rf _tmp && cd flower-authentication ``` This will create a new directory called `flower-authentication` with the following project structure: @@ -67,8 +70,9 @@ Starting long-running Flower server-side components (SuperLink+SuperExec) and en `--auth-list-public-keys` containing file path to the known `client_public_keys.csv`, `--auth-superlink-private-key` containing file path to the SuperLink's private key `server_credentials`, and `--auth-superlink-public-key` containing file path to the SuperLink's public key `server_credentials.pub`. Notice that you can only enable authentication with a secure TLS connection. +Let's first launche the `SuperLink`: + ```bash -# Launch the Superlink flower-superlink \ --ssl-ca-certfile certificates/ca.crt \ --ssl-certfile certificates/server.pem \ diff --git a/examples/flower-authentication/pyproject.toml b/examples/flower-authentication/pyproject.toml index af99f48a027..059ff4cc3b1 100644 --- a/examples/flower-authentication/pyproject.toml +++ b/examples/flower-authentication/pyproject.toml @@ -8,7 +8,7 @@ version = "1.0.0" description = "Federated Learning with PyTorch and authenticated Flower " license = "Apache-2.0" dependencies = [ - "flwr[simulation]>=1.11.0", + "flwr>=1.12.0", "flwr-datasets[vision]>=0.3.0", "torch==2.2.1", "torchvision==0.17.1", @@ -34,6 +34,6 @@ batch-size = 32 [tool.flwr.federations] default = "superexec" -[tool.flwr.federations.superexec] -address = "127.0.0.1:9093" +[tool.flwr.federations.my-federation] +address = "127.0.0.1:9093" # Address of the SuperExec root-certificates = "certificates/ca.crt"