flwr-nightly 1.15.0.dev20250107__py3-none-any.whl → 1.15.0.dev20250112__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. flwr/cli/cli_user_auth_interceptor.py +6 -2
  2. flwr/cli/login/login.py +11 -4
  3. flwr/cli/utils.py +4 -4
  4. flwr/client/app.py +17 -9
  5. flwr/client/grpc_rere_client/client_interceptor.py +6 -0
  6. flwr/client/grpc_rere_client/grpc_adapter.py +16 -0
  7. flwr/common/auth_plugin/auth_plugin.py +33 -23
  8. flwr/common/constant.py +2 -0
  9. flwr/common/grpc.py +154 -3
  10. flwr/common/typing.py +20 -0
  11. flwr/proto/exec_pb2.py +12 -24
  12. flwr/proto/exec_pb2.pyi +27 -54
  13. flwr/proto/fleet_pb2.py +40 -27
  14. flwr/proto/fleet_pb2.pyi +84 -0
  15. flwr/proto/fleet_pb2_grpc.py +66 -0
  16. flwr/proto/fleet_pb2_grpc.pyi +20 -0
  17. flwr/server/app.py +53 -33
  18. flwr/server/superlink/driver/serverappio_grpc.py +1 -1
  19. flwr/server/superlink/driver/serverappio_servicer.py +22 -8
  20. flwr/server/superlink/fleet/grpc_bidi/grpc_server.py +2 -165
  21. flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +16 -0
  22. flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +2 -1
  23. flwr/server/superlink/linkstate/in_memory_linkstate.py +26 -22
  24. flwr/server/superlink/linkstate/linkstate.py +10 -4
  25. flwr/server/superlink/linkstate/sqlite_linkstate.py +50 -29
  26. flwr/server/superlink/simulation/simulationio_grpc.py +1 -1
  27. flwr/superexec/exec_grpc.py +1 -1
  28. flwr/superexec/exec_servicer.py +23 -2
  29. {flwr_nightly-1.15.0.dev20250107.dist-info → flwr_nightly-1.15.0.dev20250112.dist-info}/METADATA +4 -4
  30. {flwr_nightly-1.15.0.dev20250107.dist-info → flwr_nightly-1.15.0.dev20250112.dist-info}/RECORD +33 -33
  31. {flwr_nightly-1.15.0.dev20250107.dist-info → flwr_nightly-1.15.0.dev20250112.dist-info}/LICENSE +0 -0
  32. {flwr_nightly-1.15.0.dev20250107.dist-info → flwr_nightly-1.15.0.dev20250112.dist-info}/WHEEL +0 -0
  33. {flwr_nightly-1.15.0.dev20250107.dist-info → flwr_nightly-1.15.0.dev20250112.dist-info}/entry_points.txt +0 -0
@@ -54,8 +54,12 @@ class CliUserAuthInterceptor(
54
54
 
55
55
  response = continuation(details, request)
56
56
  if response.initial_metadata():
57
- retrieved_metadata = dict(response.initial_metadata())
58
- self.auth_plugin.store_tokens(retrieved_metadata)
57
+ credentials = self.auth_plugin.read_tokens_from_metadata(
58
+ response.initial_metadata()
59
+ )
60
+ # The metadata contains tokens only if they have been refreshed
61
+ if credentials is not None:
62
+ self.auth_plugin.store_tokens(credentials)
59
63
 
60
64
  return response
61
65
 
flwr/cli/login/login.py CHANGED
@@ -26,7 +26,7 @@ from flwr.cli.config_utils import (
26
26
  process_loaded_project_config,
27
27
  validate_federation_in_project_config,
28
28
  )
29
- from flwr.common.constant import AUTH_TYPE
29
+ from flwr.common.typing import UserAuthLoginDetails
30
30
  from flwr.proto.exec_pb2 import ( # pylint: disable=E0611
31
31
  GetLoginDetailsRequest,
32
32
  GetLoginDetailsResponse,
@@ -64,7 +64,7 @@ def login( # pylint: disable=R0914
64
64
  login_response: GetLoginDetailsResponse = stub.GetLoginDetails(login_request)
65
65
 
66
66
  # Get the auth plugin
67
- auth_type = login_response.login_details.get(AUTH_TYPE)
67
+ auth_type = login_response.auth_type
68
68
  auth_plugin = try_obtain_cli_auth_plugin(app, federation, auth_type)
69
69
  if auth_plugin is None:
70
70
  typer.secho(
@@ -75,7 +75,14 @@ def login( # pylint: disable=R0914
75
75
  raise typer.Exit(code=1)
76
76
 
77
77
  # Login
78
- auth_config = auth_plugin.login(dict(login_response.login_details), stub)
78
+ details = UserAuthLoginDetails(
79
+ auth_type=login_response.auth_type,
80
+ device_code=login_response.device_code,
81
+ verification_uri_complete=login_response.verification_uri_complete,
82
+ expires_in=login_response.expires_in,
83
+ interval=login_response.interval,
84
+ )
85
+ credentials = auth_plugin.login(details, stub)
79
86
 
80
87
  # Store the tokens
81
- auth_plugin.store_tokens(auth_config)
88
+ auth_plugin.store_tokens(credentials)
flwr/cli/utils.py CHANGED
@@ -223,19 +223,19 @@ def try_obtain_cli_auth_plugin(
223
223
  config_path = get_user_auth_config_path(root_dir, federation)
224
224
 
225
225
  # Load the config file if it exists
226
- config: dict[str, Any] = {}
226
+ json_file: dict[str, Any] = {}
227
227
  if config_path.exists():
228
228
  with config_path.open("r", encoding="utf-8") as file:
229
- config = json.load(file)
229
+ json_file = json.load(file)
230
230
  # This is the case when the user auth is not enabled
231
231
  elif auth_type is None:
232
232
  return None
233
233
 
234
234
  # Get the auth type from the config if not provided
235
235
  if auth_type is None:
236
- if AUTH_TYPE not in config:
236
+ if AUTH_TYPE not in json_file:
237
237
  return None
238
- auth_type = config[AUTH_TYPE]
238
+ auth_type = json_file[AUTH_TYPE]
239
239
 
240
240
  # Retrieve auth plugin class and instantiate it
241
241
  try:
flwr/client/app.py CHANGED
@@ -15,13 +15,14 @@
15
15
  """Flower client app."""
16
16
 
17
17
 
18
+ import multiprocessing
18
19
  import signal
19
- import subprocess
20
20
  import sys
21
21
  import time
22
22
  from contextlib import AbstractContextManager
23
23
  from dataclasses import dataclass
24
24
  from logging import ERROR, INFO, WARN
25
+ from os import urandom
25
26
  from pathlib import Path
26
27
  from typing import Callable, Optional, Union, cast
27
28
 
@@ -33,6 +34,7 @@ from flwr.cli.config_utils import get_fab_metadata
33
34
  from flwr.cli.install import install_from_fab
34
35
  from flwr.client.client import Client
35
36
  from flwr.client.client_app import ClientApp, LoadClientAppError
37
+ from flwr.client.clientapp.app import flwr_clientapp
36
38
  from flwr.client.nodestate.nodestate_factory import NodeStateFactory
37
39
  from flwr.client.typing import ClientFnExt
38
40
  from flwr.common import GRPC_MAX_MESSAGE_LENGTH, Context, EventType, Message, event
@@ -53,13 +55,12 @@ from flwr.common.constant import (
53
55
  TRANSPORT_TYPES,
54
56
  ErrorCode,
55
57
  )
58
+ from flwr.common.grpc import generic_create_grpc_server
56
59
  from flwr.common.logger import log, warn_deprecated_feature
57
60
  from flwr.common.message import Error
58
61
  from flwr.common.retry_invoker import RetryInvoker, RetryState, exponential
59
62
  from flwr.common.typing import Fab, Run, RunNotRunningException, UserConfig
60
63
  from flwr.proto.clientappio_pb2_grpc import add_ClientAppIoServicer_to_server
61
- from flwr.server.superlink.fleet.grpc_bidi.grpc_server import generic_create_grpc_server
62
- from flwr.server.superlink.linkstate.utils import generate_rand_int_from_bytes
63
64
 
64
65
  from .clientapp.clientappio_servicer import ClientAppInputs, ClientAppIoServicer
65
66
  from .grpc_adapter_client.connection import grpc_adapter
@@ -391,6 +392,7 @@ def start_client_internal(
391
392
  run_info_store: Optional[DeprecatedRunInfoStore] = None
392
393
  state_factory = NodeStateFactory()
393
394
  state = state_factory.state()
395
+ mp_spawn_context = multiprocessing.get_context("spawn")
394
396
 
395
397
  runs: dict[int, Run] = {}
396
398
 
@@ -513,7 +515,7 @@ def start_client_internal(
513
515
  # Docker container.
514
516
 
515
517
  # Generate SuperNode token
516
- token: int = generate_rand_int_from_bytes(RUN_ID_NUM_BYTES)
518
+ token = int.from_bytes(urandom(RUN_ID_NUM_BYTES), "little")
517
519
 
518
520
  # Mode 1: SuperNode starts ClientApp as subprocess
519
521
  start_subprocess = isolation == ISOLATION_MODE_SUBPROCESS
@@ -549,12 +551,13 @@ def start_client_internal(
549
551
  ]
550
552
  command.append("--insecure")
551
553
 
552
- subprocess.run(
553
- command,
554
- stdout=None,
555
- stderr=None,
556
- check=True,
554
+ proc = mp_spawn_context.Process(
555
+ target=_run_flwr_clientapp,
556
+ args=(command,),
557
+ daemon=True,
557
558
  )
559
+ proc.start()
560
+ proc.join()
558
561
  else:
559
562
  # Wait for output to become available
560
563
  while not clientappio_servicer.has_outputs():
@@ -826,6 +829,11 @@ class _AppStateTracker:
826
829
  signal.signal(signal.SIGTERM, signal_handler)
827
830
 
828
831
 
832
+ def _run_flwr_clientapp(args: list[str]) -> None:
833
+ sys.argv = args
834
+ flwr_clientapp()
835
+
836
+
829
837
  def run_clientappio_api_grpc(
830
838
  address: str,
831
839
  certificates: Optional[tuple[bytes, bytes, bytes]],
@@ -36,7 +36,9 @@ from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611
36
36
  CreateNodeRequest,
37
37
  DeleteNodeRequest,
38
38
  PingRequest,
39
+ PullMessagesRequest,
39
40
  PullTaskInsRequest,
41
+ PushMessagesRequest,
40
42
  PushTaskResRequest,
41
43
  )
42
44
  from flwr.proto.run_pb2 import GetRunRequest # pylint: disable=E0611
@@ -52,6 +54,8 @@ Request = Union[
52
54
  GetRunRequest,
53
55
  PingRequest,
54
56
  GetFabRequest,
57
+ PullMessagesRequest,
58
+ PushMessagesRequest,
55
59
  ]
56
60
 
57
61
 
@@ -129,6 +133,8 @@ class AuthenticateClientInterceptor(grpc.UnaryUnaryClientInterceptor): # type:
129
133
  GetRunRequest,
130
134
  PingRequest,
131
135
  GetFabRequest,
136
+ PullMessagesRequest,
137
+ PushMessagesRequest,
132
138
  ),
133
139
  ):
134
140
  if self.shared_secret is None:
@@ -40,8 +40,12 @@ from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611
40
40
  DeleteNodeResponse,
41
41
  PingRequest,
42
42
  PingResponse,
43
+ PullMessagesRequest,
44
+ PullMessagesResponse,
43
45
  PullTaskInsRequest,
44
46
  PullTaskInsResponse,
47
+ PushMessagesRequest,
48
+ PushMessagesResponse,
45
49
  PushTaskResRequest,
46
50
  PushTaskResResponse,
47
51
  )
@@ -132,12 +136,24 @@ class GrpcAdapter:
132
136
  """."""
133
137
  return self._send_and_receive(request, PullTaskInsResponse, **kwargs)
134
138
 
139
+ def PullMessages( # pylint: disable=C0103
140
+ self, request: PullMessagesRequest, **kwargs: Any
141
+ ) -> PullMessagesResponse:
142
+ """."""
143
+ return self._send_and_receive(request, PullMessagesResponse, **kwargs)
144
+
135
145
  def PushTaskRes( # pylint: disable=C0103
136
146
  self, request: PushTaskResRequest, **kwargs: Any
137
147
  ) -> PushTaskResResponse:
138
148
  """."""
139
149
  return self._send_and_receive(request, PushTaskResResponse, **kwargs)
140
150
 
151
+ def PushMessages( # pylint: disable=C0103
152
+ self, request: PushMessagesRequest, **kwargs: Any
153
+ ) -> PushMessagesResponse:
154
+ """."""
155
+ return self._send_and_receive(request, PushMessagesResponse, **kwargs)
156
+
141
157
  def GetRun( # pylint: disable=C0103
142
158
  self, request: GetRunRequest, **kwargs: Any
143
159
  ) -> GetRunResponse:
@@ -18,26 +18,31 @@
18
18
  from abc import ABC, abstractmethod
19
19
  from collections.abc import Sequence
20
20
  from pathlib import Path
21
- from typing import Any, Optional, Union
21
+ from typing import Optional, Union
22
22
 
23
23
  from flwr.proto.exec_pb2_grpc import ExecStub
24
24
 
25
+ from ..typing import UserAuthCredentials, UserAuthLoginDetails
26
+
25
27
 
26
28
  class ExecAuthPlugin(ABC):
27
29
  """Abstract Flower Auth Plugin class for ExecServicer.
28
30
 
29
31
  Parameters
30
32
  ----------
31
- config : dict[str, Any]
32
- The authentication configuration loaded from a YAML file.
33
+ user_auth_config_path : Path
34
+ Path to the YAML file containing the authentication configuration.
33
35
  """
34
36
 
35
37
  @abstractmethod
36
- def __init__(self, config: dict[str, Any]):
38
+ def __init__(
39
+ self,
40
+ user_auth_config_path: Path,
41
+ ):
37
42
  """Abstract constructor."""
38
43
 
39
44
  @abstractmethod
40
- def get_login_details(self) -> dict[str, str]:
45
+ def get_login_details(self) -> Optional[UserAuthLoginDetails]:
41
46
  """Get the login details."""
42
47
 
43
48
  @abstractmethod
@@ -47,7 +52,7 @@ class ExecAuthPlugin(ABC):
47
52
  """Validate authentication tokens in the provided metadata."""
48
53
 
49
54
  @abstractmethod
50
- def get_auth_tokens(self, auth_details: dict[str, str]) -> dict[str, str]:
55
+ def get_auth_tokens(self, device_code: str) -> Optional[UserAuthCredentials]:
51
56
  """Get authentication tokens."""
52
57
 
53
58
  @abstractmethod
@@ -62,50 +67,55 @@ class CliAuthPlugin(ABC):
62
67
 
63
68
  Parameters
64
69
  ----------
65
- user_auth_config_path : Path
66
- The path to the user's authentication configuration file.
70
+ credentials_path : Path
71
+ Path to the user's authentication credentials file.
67
72
  """
68
73
 
69
74
  @staticmethod
70
75
  @abstractmethod
71
76
  def login(
72
- login_details: dict[str, str],
77
+ login_details: UserAuthLoginDetails,
73
78
  exec_stub: ExecStub,
74
- ) -> dict[str, Any]:
75
- """Authenticate the user with the SuperLink.
79
+ ) -> UserAuthCredentials:
80
+ """Authenticate the user and retrieve authentication credentials.
76
81
 
77
82
  Parameters
78
83
  ----------
79
- login_details : dict[str, str]
80
- A dictionary containing the user's login details.
84
+ login_details : UserAuthLoginDetails
85
+ An object containing the user's login details.
81
86
  exec_stub : ExecStub
82
- An instance of `ExecStub` used for communication with the SuperLink.
87
+ A stub for executing RPC calls to the server.
83
88
 
84
89
  Returns
85
90
  -------
86
- user_auth_config : dict[str, Any]
87
- A dictionary containing the user's authentication configuration
88
- in JSON format.
91
+ UserAuthCredentials
92
+ The authentication credentials obtained after login.
89
93
  """
90
94
 
91
95
  @abstractmethod
92
- def __init__(self, user_auth_config_path: Path):
96
+ def __init__(self, credentials_path: Path):
93
97
  """Abstract constructor."""
94
98
 
95
99
  @abstractmethod
96
- def store_tokens(self, user_auth_config: dict[str, Any]) -> None:
97
- """Store authentication tokens from the provided user_auth_config.
100
+ def store_tokens(self, credentials: UserAuthCredentials) -> None:
101
+ """Store authentication tokens to the `credentials_path`.
98
102
 
99
- The configuration, including tokens, will be saved as a JSON file
100
- at `user_auth_config_path`.
103
+ The credentials, including tokens, will be saved as a JSON file
104
+ at `credentials_path`.
101
105
  """
102
106
 
103
107
  @abstractmethod
104
108
  def load_tokens(self) -> None:
105
- """Load authentication tokens from the user_auth_config_path."""
109
+ """Load authentication tokens from the `credentials_path`."""
106
110
 
107
111
  @abstractmethod
108
112
  def write_tokens_to_metadata(
109
113
  self, metadata: Sequence[tuple[str, Union[str, bytes]]]
110
114
  ) -> Sequence[tuple[str, Union[str, bytes]]]:
111
115
  """Write authentication tokens to the provided metadata."""
116
+
117
+ @abstractmethod
118
+ def read_tokens_from_metadata(
119
+ self, metadata: Sequence[tuple[str, Union[str, bytes]]]
120
+ ) -> Optional[UserAuthCredentials]:
121
+ """Read authentication tokens from the provided metadata."""
flwr/common/constant.py CHANGED
@@ -114,6 +114,8 @@ MAX_RETRY_DELAY = 20 # Maximum delay duration between two consecutive retries.
114
114
  # Constants for user authentication
115
115
  CREDENTIALS_DIR = ".credentials"
116
116
  AUTH_TYPE = "auth_type"
117
+ ACCESS_TOKEN_KEY = "access_token"
118
+ REFRESH_TOKEN_KEY = "refresh_token"
117
119
 
118
120
 
119
121
  class MessageType:
flwr/common/grpc.py CHANGED
@@ -15,16 +15,26 @@
15
15
  """Utility functions for gRPC."""
16
16
 
17
17
 
18
+ import concurrent.futures
19
+ import sys
18
20
  from collections.abc import Sequence
19
- from logging import DEBUG
20
- from typing import Optional
21
+ from logging import DEBUG, ERROR
22
+ from typing import Any, Callable, Optional
21
23
 
22
24
  import grpc
23
25
 
24
- from flwr.common.logger import log
26
+ from .address import is_port_in_use
27
+ from .logger import log
25
28
 
26
29
  GRPC_MAX_MESSAGE_LENGTH: int = 536_870_912 # == 512 * 1024 * 1024
27
30
 
31
+ INVALID_CERTIFICATES_ERR_MSG = """
32
+ When setting any of root_certificate, certificate, or private_key,
33
+ all of them need to be set.
34
+ """
35
+
36
+ AddServicerToServerFn = Callable[..., Any]
37
+
28
38
 
29
39
  def create_channel(
30
40
  server_address: str,
@@ -66,3 +76,144 @@ def create_channel(
66
76
  channel = grpc.intercept_channel(channel, interceptors)
67
77
 
68
78
  return channel
79
+
80
+
81
+ def valid_certificates(certificates: tuple[bytes, bytes, bytes]) -> bool:
82
+ """Validate certificates tuple."""
83
+ is_valid = (
84
+ all(isinstance(certificate, bytes) for certificate in certificates)
85
+ and len(certificates) == 3
86
+ )
87
+
88
+ if not is_valid:
89
+ log(ERROR, INVALID_CERTIFICATES_ERR_MSG)
90
+
91
+ return is_valid
92
+
93
+
94
+ def generic_create_grpc_server( # pylint: disable=too-many-arguments,R0917
95
+ servicer_and_add_fn: tuple[Any, AddServicerToServerFn],
96
+ server_address: str,
97
+ max_concurrent_workers: int = 1000,
98
+ max_message_length: int = GRPC_MAX_MESSAGE_LENGTH,
99
+ keepalive_time_ms: int = 210000,
100
+ certificates: Optional[tuple[bytes, bytes, bytes]] = None,
101
+ interceptors: Optional[Sequence[grpc.ServerInterceptor]] = None,
102
+ ) -> grpc.Server:
103
+ """Create a gRPC server with a single servicer.
104
+
105
+ Parameters
106
+ ----------
107
+ servicer_and_add_fn : tuple
108
+ A tuple holding a servicer implementation and a matching
109
+ add_Servicer_to_server function.
110
+ server_address : str
111
+ Server address in the form of HOST:PORT e.g. "[::]:8080"
112
+ max_concurrent_workers : int
113
+ Maximum number of clients the server can process before returning
114
+ RESOURCE_EXHAUSTED status (default: 1000)
115
+ max_message_length : int
116
+ Maximum message length that the server can send or receive.
117
+ Int valued in bytes. -1 means unlimited. (default: GRPC_MAX_MESSAGE_LENGTH)
118
+ keepalive_time_ms : int
119
+ Flower uses a default gRPC keepalive time of 210000ms (3 minutes 30 seconds)
120
+ because some cloud providers (for example, Azure) agressively clean up idle
121
+ TCP connections by terminating them after some time (4 minutes in the case
122
+ of Azure). Flower does not use application-level keepalive signals and relies
123
+ on the assumption that the transport layer will fail in cases where the
124
+ connection is no longer active. `keepalive_time_ms` can be used to customize
125
+ the keepalive interval for specific environments. The default Flower gRPC
126
+ keepalive of 210000 ms (3 minutes 30 seconds) ensures that Flower can keep
127
+ the long running streaming connection alive in most environments. The actual
128
+ gRPC default of this setting is 7200000 (2 hours), which results in dropped
129
+ connections in some cloud environments.
130
+
131
+ These settings are related to the issue described here:
132
+ - https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md
133
+ - https://github.com/grpc/grpc/blob/master/doc/keepalive.md
134
+ - https://grpc.io/docs/guides/performance/
135
+
136
+ Mobile Flower clients may choose to increase this value if their server
137
+ environment allows long-running idle TCP connections.
138
+ (default: 210000)
139
+ certificates : Tuple[bytes, bytes, bytes] (default: None)
140
+ Tuple containing root certificate, server certificate, and private key to
141
+ start a secure SSL-enabled server. The tuple is expected to have three bytes
142
+ elements in the following order:
143
+
144
+ * CA certificate.
145
+ * server certificate.
146
+ * server private key.
147
+ interceptors : Optional[Sequence[grpc.ServerInterceptor]] (default: None)
148
+ A list of gRPC interceptors.
149
+
150
+ Returns
151
+ -------
152
+ server : grpc.Server
153
+ A non-running instance of a gRPC server.
154
+ """
155
+ # Check if port is in use
156
+ if is_port_in_use(server_address):
157
+ sys.exit(f"Port in server address {server_address} is already in use.")
158
+
159
+ # Deconstruct tuple into servicer and function
160
+ servicer, add_servicer_to_server_fn = servicer_and_add_fn
161
+
162
+ # Possible options:
163
+ # https://github.com/grpc/grpc/blob/v1.43.x/include/grpc/impl/codegen/grpc_types.h
164
+ options = [
165
+ # Maximum number of concurrent incoming streams to allow on a http2
166
+ # connection. Int valued.
167
+ ("grpc.max_concurrent_streams", max(100, max_concurrent_workers)),
168
+ # Maximum message length that the channel can send.
169
+ # Int valued, bytes. -1 means unlimited.
170
+ ("grpc.max_send_message_length", max_message_length),
171
+ # Maximum message length that the channel can receive.
172
+ # Int valued, bytes. -1 means unlimited.
173
+ ("grpc.max_receive_message_length", max_message_length),
174
+ # The gRPC default for this setting is 7200000 (2 hours). Flower uses a
175
+ # customized default of 210000 (3 minutes and 30 seconds) to improve
176
+ # compatibility with popular cloud providers. Mobile Flower clients may
177
+ # choose to increase this value if their server environment allows
178
+ # long-running idle TCP connections.
179
+ ("grpc.keepalive_time_ms", keepalive_time_ms),
180
+ # Setting this to zero will allow sending unlimited keepalive pings in between
181
+ # sending actual data frames.
182
+ ("grpc.http2.max_pings_without_data", 0),
183
+ # Is it permissible to send keepalive pings from the client without
184
+ # any outstanding streams. More explanation here:
185
+ # https://github.com/adap/flower/pull/2197
186
+ ("grpc.keepalive_permit_without_calls", 0),
187
+ ]
188
+
189
+ server = grpc.server(
190
+ concurrent.futures.ThreadPoolExecutor(max_workers=max_concurrent_workers),
191
+ # Set the maximum number of concurrent RPCs this server will service before
192
+ # returning RESOURCE_EXHAUSTED status, or None to indicate no limit.
193
+ maximum_concurrent_rpcs=max_concurrent_workers,
194
+ options=options,
195
+ interceptors=interceptors,
196
+ )
197
+ add_servicer_to_server_fn(servicer, server)
198
+
199
+ if certificates is not None:
200
+ if not valid_certificates(certificates):
201
+ sys.exit(1)
202
+
203
+ root_certificate_b, certificate_b, private_key_b = certificates
204
+
205
+ server_credentials = grpc.ssl_server_credentials(
206
+ ((private_key_b, certificate_b),),
207
+ root_certificates=root_certificate_b,
208
+ # A boolean indicating whether or not to require clients to be
209
+ # authenticated. May only be True if root_certificates is not None.
210
+ # We are explicitly setting the current gRPC default to document
211
+ # the option. For further reference see:
212
+ # https://grpc.github.io/grpc/python/grpc.html#create-server-credentials
213
+ require_client_auth=False,
214
+ )
215
+ server.add_secure_port(server_address, server_credentials)
216
+ else:
217
+ server.add_insecure_port(server_address)
218
+
219
+ return server
flwr/common/typing.py CHANGED
@@ -266,3 +266,23 @@ class InvalidRunStatusException(BaseException):
266
266
  def __init__(self, message: str) -> None:
267
267
  super().__init__(message)
268
268
  self.message = message
269
+
270
+
271
+ # OIDC user authentication types
272
+ @dataclass
273
+ class UserAuthLoginDetails:
274
+ """User authentication login details."""
275
+
276
+ auth_type: str
277
+ device_code: str
278
+ verification_uri_complete: str
279
+ expires_in: int
280
+ interval: int
281
+
282
+
283
+ @dataclass
284
+ class UserAuthCredentials:
285
+ """User authentication tokens."""
286
+
287
+ access_token: str
288
+ refresh_token: str
flwr/proto/exec_pb2.py CHANGED
@@ -18,7 +18,7 @@ from flwr.proto import recordset_pb2 as flwr_dot_proto_dot_recordset__pb2
18
18
  from flwr.proto import run_pb2 as flwr_dot_proto_dot_run__pb2
19
19
 
20
20
 
21
- DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x15\x66lwr/proto/exec.proto\x12\nflwr.proto\x1a\x14\x66lwr/proto/fab.proto\x1a\x1a\x66lwr/proto/transport.proto\x1a\x1a\x66lwr/proto/recordset.proto\x1a\x14\x66lwr/proto/run.proto\"\xfb\x01\n\x0fStartRunRequest\x12\x1c\n\x03\x66\x61\x62\x18\x01 \x01(\x0b\x32\x0f.flwr.proto.Fab\x12H\n\x0foverride_config\x18\x02 \x03(\x0b\x32/.flwr.proto.StartRunRequest.OverrideConfigEntry\x12\x35\n\x12\x66\x65\x64\x65ration_options\x18\x03 \x01(\x0b\x32\x19.flwr.proto.ConfigsRecord\x1aI\n\x13OverrideConfigEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12!\n\x05value\x18\x02 \x01(\x0b\x32\x12.flwr.proto.Scalar:\x02\x38\x01\"2\n\x10StartRunResponse\x12\x13\n\x06run_id\x18\x01 \x01(\x04H\x00\x88\x01\x01\x42\t\n\x07_run_id\"<\n\x11StreamLogsRequest\x12\x0e\n\x06run_id\x18\x01 \x01(\x04\x12\x17\n\x0f\x61\x66ter_timestamp\x18\x02 \x01(\x01\"B\n\x12StreamLogsResponse\x12\x12\n\nlog_output\x18\x01 \x01(\t\x12\x18\n\x10latest_timestamp\x18\x02 \x01(\x01\"1\n\x0fListRunsRequest\x12\x13\n\x06run_id\x18\x01 \x01(\x04H\x00\x88\x01\x01\x42\t\n\x07_run_id\"\x9d\x01\n\x10ListRunsResponse\x12;\n\x08run_dict\x18\x01 \x03(\x0b\x32).flwr.proto.ListRunsResponse.RunDictEntry\x12\x0b\n\x03now\x18\x02 \x01(\t\x1a?\n\x0cRunDictEntry\x12\x0b\n\x03key\x18\x01 \x01(\x04\x12\x1e\n\x05value\x18\x02 \x01(\x0b\x32\x0f.flwr.proto.Run:\x02\x38\x01\"\x18\n\x16GetLoginDetailsRequest\"\x9c\x01\n\x17GetLoginDetailsResponse\x12L\n\rlogin_details\x18\x01 \x03(\x0b\x32\x35.flwr.proto.GetLoginDetailsResponse.LoginDetailsEntry\x1a\x33\n\x11LoginDetailsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x93\x01\n\x14GetAuthTokensRequest\x12G\n\x0c\x61uth_details\x18\x01 \x03(\x0b\x32\x31.flwr.proto.GetAuthTokensRequest.AuthDetailsEntry\x1a\x32\n\x10\x41uthDetailsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x92\x01\n\x15GetAuthTokensResponse\x12\x46\n\x0b\x61uth_tokens\x18\x01 \x03(\x0b\x32\x31.flwr.proto.GetAuthTokensResponse.AuthTokensEntry\x1a\x31\n\x0f\x41uthTokensEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\" \n\x0eStopRunRequest\x12\x0e\n\x06run_id\x18\x01 \x01(\x04\"\"\n\x0fStopRunResponse\x12\x0f\n\x07success\x18\x01 \x01(\x08\x32\xe5\x03\n\x04\x45xec\x12G\n\x08StartRun\x12\x1b.flwr.proto.StartRunRequest\x1a\x1c.flwr.proto.StartRunResponse\"\x00\x12\x44\n\x07StopRun\x12\x1a.flwr.proto.StopRunRequest\x1a\x1b.flwr.proto.StopRunResponse\"\x00\x12O\n\nStreamLogs\x12\x1d.flwr.proto.StreamLogsRequest\x1a\x1e.flwr.proto.StreamLogsResponse\"\x00\x30\x01\x12G\n\x08ListRuns\x12\x1b.flwr.proto.ListRunsRequest\x1a\x1c.flwr.proto.ListRunsResponse\"\x00\x12\\\n\x0fGetLoginDetails\x12\".flwr.proto.GetLoginDetailsRequest\x1a#.flwr.proto.GetLoginDetailsResponse\"\x00\x12V\n\rGetAuthTokens\x12 .flwr.proto.GetAuthTokensRequest\x1a!.flwr.proto.GetAuthTokensResponse\"\x00\x62\x06proto3')
21
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x15\x66lwr/proto/exec.proto\x12\nflwr.proto\x1a\x14\x66lwr/proto/fab.proto\x1a\x1a\x66lwr/proto/transport.proto\x1a\x1a\x66lwr/proto/recordset.proto\x1a\x14\x66lwr/proto/run.proto\"\xfb\x01\n\x0fStartRunRequest\x12\x1c\n\x03\x66\x61\x62\x18\x01 \x01(\x0b\x32\x0f.flwr.proto.Fab\x12H\n\x0foverride_config\x18\x02 \x03(\x0b\x32/.flwr.proto.StartRunRequest.OverrideConfigEntry\x12\x35\n\x12\x66\x65\x64\x65ration_options\x18\x03 \x01(\x0b\x32\x19.flwr.proto.ConfigsRecord\x1aI\n\x13OverrideConfigEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12!\n\x05value\x18\x02 \x01(\x0b\x32\x12.flwr.proto.Scalar:\x02\x38\x01\"2\n\x10StartRunResponse\x12\x13\n\x06run_id\x18\x01 \x01(\x04H\x00\x88\x01\x01\x42\t\n\x07_run_id\"<\n\x11StreamLogsRequest\x12\x0e\n\x06run_id\x18\x01 \x01(\x04\x12\x17\n\x0f\x61\x66ter_timestamp\x18\x02 \x01(\x01\"B\n\x12StreamLogsResponse\x12\x12\n\nlog_output\x18\x01 \x01(\t\x12\x18\n\x10latest_timestamp\x18\x02 \x01(\x01\"1\n\x0fListRunsRequest\x12\x13\n\x06run_id\x18\x01 \x01(\x04H\x00\x88\x01\x01\x42\t\n\x07_run_id\"\x9d\x01\n\x10ListRunsResponse\x12;\n\x08run_dict\x18\x01 \x03(\x0b\x32).flwr.proto.ListRunsResponse.RunDictEntry\x12\x0b\n\x03now\x18\x02 \x01(\t\x1a?\n\x0cRunDictEntry\x12\x0b\n\x03key\x18\x01 \x01(\x04\x12\x1e\n\x05value\x18\x02 \x01(\x0b\x32\x0f.flwr.proto.Run:\x02\x38\x01\"\x18\n\x16GetLoginDetailsRequest\"\x8a\x01\n\x17GetLoginDetailsResponse\x12\x11\n\tauth_type\x18\x01 \x01(\t\x12\x13\n\x0b\x64\x65vice_code\x18\x02 \x01(\t\x12!\n\x19verification_uri_complete\x18\x03 \x01(\t\x12\x12\n\nexpires_in\x18\x04 \x01(\x03\x12\x10\n\x08interval\x18\x05 \x01(\x03\"+\n\x14GetAuthTokensRequest\x12\x13\n\x0b\x64\x65vice_code\x18\x01 \x01(\t\"D\n\x15GetAuthTokensResponse\x12\x14\n\x0c\x61\x63\x63\x65ss_token\x18\x01 \x01(\t\x12\x15\n\rrefresh_token\x18\x02 \x01(\t\" \n\x0eStopRunRequest\x12\x0e\n\x06run_id\x18\x01 \x01(\x04\"\"\n\x0fStopRunResponse\x12\x0f\n\x07success\x18\x01 \x01(\x08\x32\xe5\x03\n\x04\x45xec\x12G\n\x08StartRun\x12\x1b.flwr.proto.StartRunRequest\x1a\x1c.flwr.proto.StartRunResponse\"\x00\x12\x44\n\x07StopRun\x12\x1a.flwr.proto.StopRunRequest\x1a\x1b.flwr.proto.StopRunResponse\"\x00\x12O\n\nStreamLogs\x12\x1d.flwr.proto.StreamLogsRequest\x1a\x1e.flwr.proto.StreamLogsResponse\"\x00\x30\x01\x12G\n\x08ListRuns\x12\x1b.flwr.proto.ListRunsRequest\x1a\x1c.flwr.proto.ListRunsResponse\"\x00\x12\\\n\x0fGetLoginDetails\x12\".flwr.proto.GetLoginDetailsRequest\x1a#.flwr.proto.GetLoginDetailsResponse\"\x00\x12V\n\rGetAuthTokens\x12 .flwr.proto.GetAuthTokensRequest\x1a!.flwr.proto.GetAuthTokensResponse\"\x00\x62\x06proto3')
22
22
 
23
23
  _globals = globals()
24
24
  _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
@@ -29,12 +29,6 @@ if _descriptor._USE_C_DESCRIPTORS == False:
29
29
  _globals['_STARTRUNREQUEST_OVERRIDECONFIGENTRY']._serialized_options = b'8\001'
30
30
  _globals['_LISTRUNSRESPONSE_RUNDICTENTRY']._options = None
31
31
  _globals['_LISTRUNSRESPONSE_RUNDICTENTRY']._serialized_options = b'8\001'
32
- _globals['_GETLOGINDETAILSRESPONSE_LOGINDETAILSENTRY']._options = None
33
- _globals['_GETLOGINDETAILSRESPONSE_LOGINDETAILSENTRY']._serialized_options = b'8\001'
34
- _globals['_GETAUTHTOKENSREQUEST_AUTHDETAILSENTRY']._options = None
35
- _globals['_GETAUTHTOKENSREQUEST_AUTHDETAILSENTRY']._serialized_options = b'8\001'
36
- _globals['_GETAUTHTOKENSRESPONSE_AUTHTOKENSENTRY']._options = None
37
- _globals['_GETAUTHTOKENSRESPONSE_AUTHTOKENSENTRY']._serialized_options = b'8\001'
38
32
  _globals['_STARTRUNREQUEST']._serialized_start=138
39
33
  _globals['_STARTRUNREQUEST']._serialized_end=389
40
34
  _globals['_STARTRUNREQUEST_OVERRIDECONFIGENTRY']._serialized_start=316
@@ -54,21 +48,15 @@ if _descriptor._USE_C_DESCRIPTORS == False:
54
48
  _globals['_GETLOGINDETAILSREQUEST']._serialized_start=784
55
49
  _globals['_GETLOGINDETAILSREQUEST']._serialized_end=808
56
50
  _globals['_GETLOGINDETAILSRESPONSE']._serialized_start=811
57
- _globals['_GETLOGINDETAILSRESPONSE']._serialized_end=967
58
- _globals['_GETLOGINDETAILSRESPONSE_LOGINDETAILSENTRY']._serialized_start=916
59
- _globals['_GETLOGINDETAILSRESPONSE_LOGINDETAILSENTRY']._serialized_end=967
60
- _globals['_GETAUTHTOKENSREQUEST']._serialized_start=970
61
- _globals['_GETAUTHTOKENSREQUEST']._serialized_end=1117
62
- _globals['_GETAUTHTOKENSREQUEST_AUTHDETAILSENTRY']._serialized_start=1067
63
- _globals['_GETAUTHTOKENSREQUEST_AUTHDETAILSENTRY']._serialized_end=1117
64
- _globals['_GETAUTHTOKENSRESPONSE']._serialized_start=1120
65
- _globals['_GETAUTHTOKENSRESPONSE']._serialized_end=1266
66
- _globals['_GETAUTHTOKENSRESPONSE_AUTHTOKENSENTRY']._serialized_start=1217
67
- _globals['_GETAUTHTOKENSRESPONSE_AUTHTOKENSENTRY']._serialized_end=1266
68
- _globals['_STOPRUNREQUEST']._serialized_start=1268
69
- _globals['_STOPRUNREQUEST']._serialized_end=1300
70
- _globals['_STOPRUNRESPONSE']._serialized_start=1302
71
- _globals['_STOPRUNRESPONSE']._serialized_end=1336
72
- _globals['_EXEC']._serialized_start=1339
73
- _globals['_EXEC']._serialized_end=1824
51
+ _globals['_GETLOGINDETAILSRESPONSE']._serialized_end=949
52
+ _globals['_GETAUTHTOKENSREQUEST']._serialized_start=951
53
+ _globals['_GETAUTHTOKENSREQUEST']._serialized_end=994
54
+ _globals['_GETAUTHTOKENSRESPONSE']._serialized_start=996
55
+ _globals['_GETAUTHTOKENSRESPONSE']._serialized_end=1064
56
+ _globals['_STOPRUNREQUEST']._serialized_start=1066
57
+ _globals['_STOPRUNREQUEST']._serialized_end=1098
58
+ _globals['_STOPRUNRESPONSE']._serialized_start=1100
59
+ _globals['_STOPRUNRESPONSE']._serialized_end=1134
60
+ _globals['_EXEC']._serialized_start=1137
61
+ _globals['_EXEC']._serialized_end=1622
74
62
  # @@protoc_insertion_point(module_scope)