diff --git a/src/py/flwr/client/app.py b/src/py/flwr/client/app.py index f92f4dd28174..b0c6a1cc002a 100644 --- a/src/py/flwr/client/app.py +++ b/src/py/flwr/client/app.py @@ -147,7 +147,7 @@ def start_client( client: Optional[Client] = None, grpc_max_message_length: int = GRPC_MAX_MESSAGE_LENGTH, root_certificates: Optional[Union[bytes, str]] = None, - use_grpc_certificates: bool = True, + use_grpc_certificates: bool = False, transport: Optional[str] = None, ) -> None: """Start a Flower client node which connects to a Flower server. @@ -176,10 +176,10 @@ class `flwr.client.Client` (default: None) The PEM-encoded root certificates as a byte string or a path string. If provided, a secure connection using the certificates will be established to an SSL-enabled Flower server. - use_grpc_certificates : bool (default: True) + use_grpc_certificates : bool (default: False) Enables HTTPS connection when True, using system certificates if `root_certificates` is None. Starts an insecure gRPC connection - when False, ignoring `root_certificates`. + if set to False and `root_certificates` is None. transport : Optional[str] (default: None) Configure the transport layer. Allowed values: - 'grpc-bidi': gRPC, bidirectional streaming @@ -188,6 +188,13 @@ class `flwr.client.Client` (default: None) Examples -------- + Starting a gRPC client with an insecure server connection: + + >>> start_client( + >>> server_address=localhost:8080, + >>> client_fn=client_fn, + >>> ) + Starting an SSL-enabled gRPC client using system certificates: >>> def client_fn(cid: str): @@ -196,6 +203,7 @@ class `flwr.client.Client` (default: None) >>> start_client( >>> server_address=localhost:8080, >>> client_fn=client_fn, + >>> use_grpc_certificates=True, >>> ) Starting an SSL-enabled gRPC client using provided certificates: @@ -207,14 +215,6 @@ class `flwr.client.Client` (default: None) >>> client_fn=client_fn, >>> root_certificates=Path("/crts/root.pem").read_bytes(), >>> ) - - Starting a gRPC client with an insecure server connection: - - >>> start_client( - >>> server_address=localhost:8080, - >>> client_fn=client_fn, - >>> use_grpc_certificates=False, - >>> ) """ event(EventType.START_CLIENT_ENTER) @@ -311,7 +311,7 @@ def start_numpy_client( client: NumPyClient, grpc_max_message_length: int = GRPC_MAX_MESSAGE_LENGTH, root_certificates: Optional[bytes] = None, - use_grpc_certificates: bool = True, + use_grpc_certificates: bool = False, transport: Optional[str] = None, ) -> None: """Start a Flower NumPyClient which connects to a gRPC server. @@ -335,10 +335,10 @@ def start_numpy_client( The PEM-encoded root certificates as a byte string or a path string. If provided, a secure connection using the certificates will be established to an SSL-enabled Flower server. - use_grpc_certificates : bool (default: True) + use_grpc_certificates : bool (default: False) Enables HTTPS connection when True, using system certificates if `root_certificates` is None. Starts an insecure gRPC connection - when False, ignoring `root_certificates`. + if set to False and `root_certificates` is None. transport : Optional[str] (default: None) Configure the transport layer. Allowed values: - 'grpc-bidi': gRPC, bidirectional streaming @@ -347,29 +347,29 @@ def start_numpy_client( Examples -------- - Starting an SSL-enabled gRPC client using system certificates: + Starting a gRPC client with an insecure server connection: >>> start_numpy_client( >>> server_address=localhost:8080, >>> client=FlowerClient(), >>> ) - Starting an SSL-enabled gRPC client using provided certificates: + Starting an SSL-enabled gRPC client using system certificates: - >>> from pathlib import Path - >>> >>> start_numpy_client( >>> server_address=localhost:8080, >>> client=FlowerClient(), - >>> root_certificates=Path("/crts/root.pem").read_bytes(), + >>> use_grpc_certificates=True, >>> ) - Starting a gRPC client with an insecure server connection: + Starting an SSL-enabled gRPC client using provided certificates: + >>> from pathlib import Path + >>> >>> start_numpy_client( >>> server_address=localhost:8080, >>> client=FlowerClient(), - >>> use_grpc_certificates=False, + >>> root_certificates=Path("/crts/root.pem").read_bytes(), >>> ) """ # warnings.warn( diff --git a/src/py/flwr/common/grpc.py b/src/py/flwr/common/grpc.py index a5e37c2f69b0..b5bceccbbccd 100644 --- a/src/py/flwr/common/grpc.py +++ b/src/py/flwr/common/grpc.py @@ -39,7 +39,7 @@ def create_channel( ("grpc.max_receive_message_length", max_message_length), ] - if use_grpc_certificates: + if use_grpc_certificates or root_certificates is not None: ssl_channel_credentials = grpc.ssl_channel_credentials(root_certificates) channel = grpc.secure_channel( server_address, ssl_channel_credentials, options=channel_options