-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(framework): Wire serverappio and clientappio auth interceptors #6796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
msheller
wants to merge
33
commits into
main
Choose a base branch
from
appio-authn/2-and-3-wire-serverappio-and-clientappio-auth-interceptors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
3ecefaf
PR 1 for appio-authn changes using tokens/interceptors
msheller 8c8aa0d
Reduced scope to ServerAppIo and fixed mypy pylint issues
msheller 466c1a2
Merge branch 'main' into appio-authn/1-shared-interceptor-foundation
msheller ade51e4
Apply suggestion from @panh99
panh99 cd6a276
Apply suggestion from @panh99
panh99 c666a09
Update framework/py/flwr/supercore/interceptors/appio_token_intercept…
msheller 92dbcd0
Update framework/py/flwr/supercore/interceptors/appio_token_intercept…
msheller 10d58a7
Merge branch 'main' into appio-authn/1-shared-interceptor-foundation
msheller d08b1b1
Fixed factory name
msheller c9d4bc0
Placed policy code into new auth module
msheller 079077c
Removed use of request token in interceptor
msheller a6c5f37
No longer relies on fixed list of methods for interceptor test
msheller 1021ae8
Merge branch 'main' into appio-authn/1-shared-interceptor-foundation
msheller 19dd511
Update policy.py
msheller dee3250
Update __init__.py
msheller ac98c4b
Merge branch 'main' into appio-authn/1-shared-interceptor-foundation
msheller 5cf4261
Initial draft
msheller 4630760
Merge branch 'main' into appio-authn/2-wire-serverappio-auth-interceptor
msheller 2a50444
Updated initial draft to include PR3 as well (ClientAppIo wiring)
msheller 9092eec
Disallow empty token in GrpcGrid init
msheller 9bbc1c7
Added tests recommended by Codex
msheller d862946
Initial draft of simulation wiring (client-side)
msheller eefd34d
Update to fix token lifecycle logic and force simulationio_connection…
msheller 8d6649e
Merge branch 'main' into appio-authn/2-and-3-wire-serverappio-and-cli…
msheller 3a8e941
Merge branch 'main' into appio-authn/2-and-3-wire-serverappio-and-cli…
msheller 9340dcb
Merge branch 'main' into appio-authn/2-and-3-wire-serverappio-and-cli…
msheller 0f95540
Merge branch 'main' into appio-authn/2-and-3-wire-serverappio-and-cli…
msheller 2d3bf9f
Added new run-type parameter to create_run calls
msheller 5049be1
Merge branch 'main' into appio-authn/2-and-3-wire-serverappio-and-cli…
msheller ab0975e
Added temporary test change to assist diagnosing CI failure
msheller a43fa90
Revert "Added temporary test change to assist diagnosing CI failure"
msheller cce72c9
Merge branch 'main' into appio-authn/2-and-3-wire-serverappio-and-cli…
msheller 8502bf1
Merge branch 'main' into appio-authn/2-and-3-wire-serverappio-and-cli…
msheller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
135 changes: 135 additions & 0 deletions
135
framework/py/flwr/server/superlink/serverappio/serverappio_auth_integration_test.py
This file contains hidden or 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,135 @@ | ||
| # Copyright 2026 Flower Labs GmbH. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ============================================================================== | ||
| """ServerAppIo auth interceptor integration tests.""" | ||
|
|
||
|
|
||
| import tempfile | ||
| import unittest | ||
|
|
||
| import grpc | ||
|
|
||
| from flwr.common import ConfigRecord | ||
| from flwr.common.constant import SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS, Status | ||
| from flwr.common.typing import RunStatus | ||
| from flwr.proto.appio_pb2 import ( # pylint: disable=E0611 | ||
| ListAppsToLaunchRequest, | ||
| ListAppsToLaunchResponse, | ||
| ) | ||
| from flwr.proto.serverappio_pb2 import ( # pylint: disable=E0611 | ||
| GetNodesRequest, | ||
| GetNodesResponse, | ||
| ) | ||
| from flwr.server.superlink.linkstate.linkstate_factory import LinkStateFactory | ||
| from flwr.server.superlink.serverappio.serverappio_grpc import run_serverappio_api_grpc | ||
| from flwr.supercore.constant import FLWR_IN_MEMORY_DB_NAME, NOOP_FEDERATION, RunType | ||
| from flwr.supercore.ffs import FfsFactory | ||
| from flwr.supercore.interceptors import APP_TOKEN_HEADER, AUTHENTICATION_FAILED_MESSAGE | ||
| from flwr.supercore.object_store import ObjectStoreFactory | ||
| from flwr.superlink.federation import NoOpFederationManager | ||
|
|
||
|
|
||
| class TestServerAppIoAuthIntegration(unittest.TestCase): | ||
| """Integration tests for ServerAppIo token-auth interceptor behavior.""" | ||
|
|
||
| def setUp(self) -> None: | ||
| """Start the ServerAppIo gRPC API without client-side auth helpers.""" | ||
| self.temp_dir = tempfile.TemporaryDirectory() # pylint: disable=R1732 | ||
| self.addCleanup(self.temp_dir.cleanup) | ||
|
|
||
| objectstore_factory = ObjectStoreFactory() | ||
| state_factory = LinkStateFactory( | ||
| FLWR_IN_MEMORY_DB_NAME, NoOpFederationManager(), objectstore_factory | ||
| ) | ||
| ffs_factory = FfsFactory(self.temp_dir.name) | ||
|
|
||
| self.state = state_factory.state() | ||
| node_id = self.state.create_node("mock_owner", "fake_name", b"pk", 30) | ||
| self.state.acknowledge_node_heartbeat(node_id, 1e3) | ||
|
|
||
| self._server: grpc.Server = run_serverappio_api_grpc( | ||
| SERVERAPPIO_API_DEFAULT_SERVER_ADDRESS, | ||
| state_factory, | ||
| ffs_factory, | ||
| objectstore_factory, | ||
| None, | ||
| ) | ||
|
|
||
| channel = grpc.insecure_channel("localhost:9091") | ||
| self._get_nodes = channel.unary_unary( | ||
| "/flwr.proto.ServerAppIo/GetNodes", | ||
| request_serializer=GetNodesRequest.SerializeToString, | ||
| response_deserializer=GetNodesResponse.FromString, | ||
| ) | ||
| self._list_apps_to_launch = channel.unary_unary( | ||
| "/flwr.proto.ServerAppIo/ListAppsToLaunch", | ||
| request_serializer=ListAppsToLaunchRequest.SerializeToString, | ||
| response_deserializer=ListAppsToLaunchResponse.FromString, | ||
| ) | ||
|
|
||
| def tearDown(self) -> None: | ||
| """Stop the gRPC API server.""" | ||
| self._server.stop(None) | ||
|
|
||
| def _create_running_run(self) -> int: | ||
| run_id = self.state.create_run( | ||
| "", "", "", {}, NOOP_FEDERATION, ConfigRecord(), "", RunType.SERVER_APP | ||
| ) | ||
| _ = self.state.update_run_status(run_id, RunStatus(Status.STARTING, "", "")) | ||
| _ = self.state.update_run_status(run_id, RunStatus(Status.RUNNING, "", "")) | ||
| return run_id | ||
|
|
||
| def test_get_nodes_denied_without_metadata_token(self) -> None: | ||
| """Protected RPC should deny requests missing metadata token.""" | ||
| run_id = self._create_running_run() | ||
|
|
||
| with self.assertRaises(grpc.RpcError) as err: | ||
| self._get_nodes.with_call(request=GetNodesRequest(run_id=run_id)) | ||
| assert err.exception.code() == grpc.StatusCode.UNAUTHENTICATED | ||
| assert err.exception.details() == AUTHENTICATION_FAILED_MESSAGE | ||
|
|
||
| def test_get_nodes_denied_with_invalid_metadata_token(self) -> None: | ||
| """Protected RPC should deny requests with invalid metadata token.""" | ||
| run_id = self._create_running_run() | ||
|
|
||
| with self.assertRaises(grpc.RpcError) as err: | ||
| self._get_nodes.with_call( | ||
| request=GetNodesRequest(run_id=run_id), | ||
| metadata=((APP_TOKEN_HEADER, "invalid-token"),), | ||
| ) | ||
| assert err.exception.code() == grpc.StatusCode.UNAUTHENTICATED | ||
| assert err.exception.details() == AUTHENTICATION_FAILED_MESSAGE | ||
|
|
||
| def test_get_nodes_allows_with_valid_metadata_token(self) -> None: | ||
| """Protected RPC should allow requests with a valid metadata token.""" | ||
| run_id = self._create_running_run() | ||
| token = self.state.create_token(run_id) | ||
| assert token is not None | ||
|
|
||
| response, call = self._get_nodes.with_call( | ||
| request=GetNodesRequest(run_id=run_id), | ||
| metadata=((APP_TOKEN_HEADER, token),), | ||
| ) | ||
|
|
||
| assert isinstance(response, GetNodesResponse) | ||
| assert call.code() == grpc.StatusCode.OK | ||
|
|
||
| def test_list_apps_to_launch_allows_without_metadata_token(self) -> None: | ||
| """No-auth RPC should be callable without metadata token.""" | ||
| response, call = self._list_apps_to_launch.with_call( | ||
| request=ListAppsToLaunchRequest() | ||
| ) | ||
|
|
||
| assert isinstance(response, ListAppsToLaunchResponse) | ||
| assert call.code() == grpc.StatusCode.OK |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.