-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,571 additions
and
628 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
.. _auth-label: | ||
|
||
Authentication and Authorization (RBAC) | ||
============================================= | ||
.. warning:: The FEDn RBAC system is an experimental feature and may change in the future. | ||
|
||
FEDn supports Role-Based Access Control (RBAC) for controlling access to the FEDn API and gRPC endpoints. The RBAC system is based on JSON Web Tokens (JWT) and is implemented using the `jwt` package. The JWT tokens are used to authenticate users and to control access to the FEDn API. | ||
There are two types of JWT tokens used in the FEDn RBAC system: | ||
- Access tokens: Used to authenticate users and to control access to the FEDn API. | ||
- Refresh tokens: Used to obtain new access tokens when the old ones expire. | ||
|
||
.. note:: Please note that the FEDn RBAC system is not enabled by default and does not issue JWT tokens. It is used to integrate with external authentication and authorization systems such as FEDn Studio. | ||
|
||
FEDn RBAC system is by default configured with four types of roles: | ||
- `admin`: Has full access to the FEDn API. This role is used to manage the FEDn network using the API client or the FEDn CLI. | ||
- `combiner`: Has access to the /add_combiner endpoint in the API. | ||
- `client`: Has access to the /add_client endpoint in the API and various gRPC endpoint to participate in federated learning sessions. | ||
|
||
A full list of the "roles to endpoint" mappings for gRPC can be found in the `fedn/network/grpc/auth.py`. For the API, the mappings are defined using custom decorators defined in `fedn/network/api/auth.py`. | ||
|
||
.. note:: The roles are handled by a custom claim in the JWT token called `role`. The claim is used to control access to the FEDn API and gRPC endpoints. | ||
|
||
To enable the FEDn RBAC system, you need to set the following environment variables in the controller and combiner: | ||
|
||
.. envvar:: FEDN_JWT_SECRET_KEY | ||
:type: str | ||
:required: yes | ||
:default: None | ||
:description: The secret key used for JWT token encryption. | ||
|
||
.. envvar:: FEDN_JWT_ALGORITHM | ||
:type: str | ||
:required: no | ||
:default: "HS256" | ||
:description: The algorithm used for JWT token encryption. | ||
|
||
.. envvar:: FEDN_AUTH_SCHEME | ||
:type: str | ||
:required: no | ||
:default: "Token" | ||
:description: The authentication scheme used in the FEDn API and gRPC interceptors. | ||
|
||
For further fexibility, you can also set the following environment variables: | ||
|
||
.. envvar:: FEDN_CUSTOM_URL_PREFIX | ||
:type: str | ||
:required: no | ||
:default: None | ||
:description: Add a custom URL prefix used in the FEDn API, such as /internal or /v1. | ||
|
||
.. envvar:: FEDN_AUTH_WHITELIST_URL | ||
:type: str | ||
:required: no | ||
:default: None | ||
:description: A URL patterns to the API that should be excluded from the FEDn RBAC system. For example /internal (to enable internal API calls). | ||
|
||
.. envvar:: FEDN_JWT_CUSTOM_CLAIM_KEY | ||
:type: str | ||
:required: no | ||
:default: None | ||
:description: The custom claim key used in the JWT token. | ||
|
||
.. envvar:: FEDN_JWT_CUSTOM_CLAIM_VALUE | ||
:type: str | ||
:required: no | ||
:default: None | ||
:description: The custom claim value used in the JWT token. | ||
|
||
|
||
For the client you need to set the following environment variables: | ||
|
||
.. envvar:: FEDN_JWT_ACCESS_TOKEN | ||
:type: str | ||
:required: yes | ||
:default: None | ||
:description: The access token used to authenticate the client to the FEDn API. | ||
|
||
.. envvar:: FEDN_JWT_REFRESH_TOKEN | ||
:type: str | ||
:required: no | ||
:default: None | ||
:description: The refresh token used to obtain new access tokens when the old ones expire. | ||
|
||
.. envvar:: FEDN_AUTH_SCHEME | ||
:type: str | ||
:required: no | ||
:default: "Token" | ||
:description: The authentication scheme used in the FEDn API and gRPC interceptors. | ||
|
||
You can also use `--token` flags in the FEDn CLI to set the access token. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Distributed Deployment | ||
=================================== | ||
|
||
This tutorial outlines the steps for deploying the FEDn framework over a **local network**, using a workstation as | ||
the host and different devices as clients. For general steps on how to run FEDn, see one of the quickstart tutorials. | ||
|
||
|
||
.. note:: | ||
For a secure and production-grade deployment solution over **public networks**, explore the FEDn Studio service at | ||
**studio.scaleoutsystems.com**. | ||
|
||
Alternatively follow this tutorial substituting the hosts local IP with your public IP, open the neccesary | ||
ports (see which ports are used in docker-compose.yaml), and ensure you have taken additional neccesary security | ||
precautions. | ||
|
||
Prerequisites | ||
------------- | ||
- `One host workstation and atleast one client device` | ||
- `Python 3.8, 3.9 or 3.10 <https://www.python.org/downloads>`__ | ||
- `Docker <https://docs.docker.com/get-docker>`__ | ||
- `Docker Compose <https://docs.docker.com/compose/install>`__ | ||
|
||
Launch a distributed FEDn Network | ||
------------- | ||
|
||
|
||
Start by noting your host's local IP address, used within your network. Discover it by running ifconfig on UNIX or | ||
ipconfig on Windows, typically listed under inet for Unix and IPv4 for Windows. | ||
|
||
Continue with following the standard procedure to initiate a FEDn network, for example using by docker-compose. | ||
Once the network is active, upload your compute package and seed (for comprehensive details, see the quickstart tutorials). | ||
|
||
|
||
Configuring and Attaching Clients | ||
------------- | ||
|
||
On your client device, continue with initializing your client. To connect to the host machine we need to ensure we are | ||
routing the correct DNS to our hosts local IP address. We can do this using the standard FEDn `client.yaml`: | ||
|
||
.. code-block:: | ||
network_id: fedn-network | ||
discover_host: api-server | ||
discover_port: 8092 | ||
We can then run using docker by adding the hosts in the docker run command: | ||
|
||
.. code-block:: | ||
docker run \ | ||
-v $PWD/client.yaml:<client.yaml file location> \ | ||
<potentiel data pointers> | ||
—add-host=api-server:<host local ip> \ | ||
—add-host=combiner:<host local ip> \ | ||
<image name> run client -in client.yaml --name client1 | ||
Alternatively updating the `/etc/hosts` file, appending the following lines for running naitively: | ||
|
||
.. code-block:: | ||
<host local ip> api-server | ||
<host local ip> combiner | ||
Start a training session | ||
------------- | ||
|
||
After connecting with your clients, you are ready to start training sessions from the host machine. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ data | |
*.npz | ||
*.tgz | ||
*.tar.gz | ||
*.log | ||
.async-simulation | ||
client.yaml |
Oops, something went wrong.