feat: add optional swarm API key auth#1
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 770d0e7364
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await client.post(f"{config.tracker_url}/register", json=registration_data, headers=auth_headers()) | ||
| print(f"[{config.node_id}] 📡 Registered with tracker at {config.tracker_url}") |
There was a problem hiding this comment.
Check tracker registration response before declaring success
When SWARM_API_KEY is enabled and a node has a mismatched/missing key, /register returns 401, but this code logs a successful registration unconditionally because httpx does not raise on non-2xx responses unless raise_for_status() is called. In that configuration the node appears registered locally, but it never enters peers_db on the tracker, which breaks downstream peer discovery and forwarding while hiding the real auth failure.
Useful? React with 👍 / 👎.
Summary
rtmalikian/llm-swarmREADME, changelog, Python services, Docker config, tests, and dependency list.README/docs TODOs reviewed
The README includes several roadmap TODOs. I chose the bounded security item:
[x] Security Hardening: Implement Swarm-wide API Keys for tracker and node-to-node authentication via SWARM_API_KEY.Skipped broader items for this run because they are larger architectural efforts: libp2p/Noise/TLS, tensor validation/checksums, tensor compression, dynamic slicing, GUI, and geographic routing.
Security probing performed
python3 -m pip_audit -r requirements.txt, butpip_auditis not installed in the local environment.Improvement made
When
SWARM_API_KEYis set:/register,/heartbeat,/peers,/coverage,/find_peer) requireAuthorization: Bearer <SWARM_API_KEY>./process_layerscalls require the same bearer token.When
SWARM_API_KEYis unset, the existing unauthenticated local-development behavior is preserved.Files changed
auth_utils.py— shared auth dependency and outgoing auth header helper.tracker.py— protects tracker control-plane endpoints.swarm_node.py— protects layer processing and sends auth headers to tracker/peers.docker-compose.yml— propagatesSWARM_API_KEYto tracker and node containers.tests/test_api_key_auth.py— regression coverage for auth behavior.README.md— usage/security docs and roadmap checkbox update.CHANGELOG.md— Unreleased security entry.Verification
pytest tests/test_api_key_auth.py -q— passed (3 tests).pytest -q— passed (3 tests; existing FastAPIon_eventdeprecation warnings only).python3 -m py_compile auth_utils.py tracker.py swarm_node.py launch_leader.py slice_model.py slice_qwen.py test_mesh.py tests/test_api_key_auth.py— passed.python3 -m pip_audit -r requirements.txt— not run successfully becausepip_auditis unavailable locally.Notes / limitations
/v1/chat/completionsentry endpoint remains public unless deployed behind the authenticated node-to-node path or external access controls; this PR focuses on the specific tracker/node-to-node TODO.