Skip to content

Scaffolding: Federation gateway setup#299

Open
klpoland wants to merge 7 commits into
masterfrom
feature-kpoland-federation-gateway-scaffolding
Open

Scaffolding: Federation gateway setup#299
klpoland wants to merge 7 commits into
masterfrom
feature-kpoland-federation-gateway-scaffolding

Conversation

@klpoland

@klpoland klpoland commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Note

Medium Risk
Introduces a new internal export surface and changes global API-key auth/permissions; misconfiguration of CIDRs or operational flags could block sync or widen access, though export is off by default and sync keys are route-scoped.

Overview
Adds gateway-side federation scaffolding so a local federation-sync service can pull public metadata and react to changes, controlled by FEDERATION_ENABLED and related env settings (documented in example django.env).

Internal export API is registered under /api/.../federation/ with list/detail endpoints for public finalized datasets and public captures. Responses use new DatasetFederationSerializer / CaptureFederationSerializer payloads (including site_name from FEDERATION_SITE_NAME). Access requires a FederationSync API key, federation operational checks (sync health URL, Redis ping, presence of sync key), and client IP in FEDERATION_EXPORT_ALLOWED_CIDRS (defaults to private ranges).

Change notifications: post_save signals on datasets/captures publish created/updated/deleted events to Redis (FEDERATION_EVENTS_CHANNEL) when federation is operational and the record is (or ceases to be) exportable.

API key behavior: APIKeyAuthentication now sets request.auth to the UserAPIKey object. A global DisallowFederationSyncKey permission blocks sync keys from normal asset APIs; export routes use the inverse IsFederationSyncKey. New create_federation_sync_api_key management command and DB migration extend KeySources with federation_sync.

Also includes contract tests against sibling sds_federation Pydantic models, hardening/operational tests, and small dev-tool tweaks (fallow-cross-file-dupes.sh, create_test_files import paths).

Reviewed by Cursor Bugbot for commit 3393c0f. Bugbot is set up for automated code reviews on this repo. Configure here.

@klpoland klpoland self-assigned this Jun 19, 2026
@klpoland klpoland added feature New feature or request federation Federation related work (sync service, document storage, peer configuration, etc.) labels Jun 19, 2026
@semanticdiff-com

semanticdiff-com Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  gateway/sds_gateway/api_methods/views/dataset_endpoints.py  42% smaller
  gateway/sds_gateway/api_methods/tests/test_authenticate.py  26% smaller
  gateway/config/settings/base.py  7% smaller
  gateway/.envs/example/django.env Unsupported file format
  gateway/config/api_router.py  0% smaller
  gateway/pyproject.toml Unsupported file format
  gateway/scripts/fallow-cross-file-dupes.sh Unsupported file format
  gateway/sds_gateway/api_methods/apps.py  0% smaller
  gateway/sds_gateway/api_methods/authentication.py  0% smaller
  gateway/sds_gateway/api_methods/federation/__init__.py  0% smaller
  gateway/sds_gateway/api_methods/federation/availability.py  0% smaller
  gateway/sds_gateway/api_methods/federation/events.py  0% smaller
  gateway/sds_gateway/api_methods/federation/export_contract.py  0% smaller
  gateway/sds_gateway/api_methods/federation/permissions.py  0% smaller
  gateway/sds_gateway/api_methods/federation/signals.py  0% smaller
  gateway/sds_gateway/api_methods/helpers/compile_federated_data.py  0% smaller
  gateway/sds_gateway/api_methods/models.py  0% smaller
  gateway/sds_gateway/api_methods/permissions.py  0% smaller
  gateway/sds_gateway/api_methods/serializers/capture_serializers.py  0% smaller
  gateway/sds_gateway/api_methods/serializers/dataset_serializers.py  0% smaller
  gateway/sds_gateway/api_methods/tests/test_federation_export.py  0% smaller
  gateway/sds_gateway/api_methods/tests/test_federation_export_contract.py  0% smaller
  gateway/sds_gateway/api_methods/tests/test_federation_hardening.py  0% smaller
  gateway/sds_gateway/api_methods/views/capture_endpoints.py  0% smaller
  gateway/sds_gateway/api_methods/views/federation_endpoints.py  0% smaller
  gateway/sds_gateway/api_methods/views/file_endpoints.py  0% smaller
  gateway/sds_gateway/users/management/commands/create_federation_sync_api_key.py  0% smaller
  gateway/sds_gateway/users/management/commands/create_test_files.py  0% smaller
  gateway/sds_gateway/users/migrations/0012_alter_userapikey_source_federation_sync.py  0% smaller
  gateway/sds_gateway/users/migrations/max_migration.txt Unsupported file format
  gateway/sds_gateway/users/models.py  0% smaller

@klpoland klpoland changed the title gateway: federation export API, Redis events, sync API key Scaffolding: Federation gateway setup Jun 19, 2026
@klpoland klpoland added the gateway Gateway component label Jun 19, 2026
@klpoland

Copy link
Copy Markdown
Collaborator Author

Added some dedicated API endpoints, serializers, and signals for federation and configuration that defaults to disabling federation sync.

@klpoland klpoland force-pushed the feature-kpoland-federation-gateway-scaffolding branch 2 times, most recently from 9f94dfd to 83d51d0 Compare June 25, 2026 19:02
@klpoland klpoland marked this pull request as ready for review June 25, 2026 19:03
@klpoland klpoland requested a review from lucaspar June 25, 2026 19:03
Comment thread gateway/sds_gateway/api_methods/views/dataset_endpoints.py Outdated
Comment thread gateway/sds_gateway/api_methods/federation/availability.py
@klpoland klpoland force-pushed the feature-kpoland-federation-gateway-scaffolding branch from 83d51d0 to 4bbcbed Compare June 25, 2026 19:53
Comment thread gateway/.envs/example/django.env
Comment thread gateway/config/settings/base.py
Comment thread gateway/sds_gateway/api_methods/federation/events.py Outdated
Comment thread gateway/sds_gateway/api_methods/federation/export_contract.py Outdated
Comment thread gateway/sds_gateway/api_methods/federation/availability.py Outdated
@lucaspar lucaspar added the migrations Code changes that require data or schema migrations in the database. label Jun 25, 2026

# Create files
minio_client = MinioClient()
minio_client = get_minio_client()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test command calls missing upload method

Low Severity

This commit switches the dev command to get_minio_client(), which returns ObjectStoreFacade with MinIO-compatible methods like fput_object, but the upload loop still calls upload_file. That method is not defined on the facade or delegated MinIO client, so the command fails at runtime when uploading fixtures.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2c09fae. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3393c0f. Configure here.

user=user,
source=KeySources.FederationSync,
description="Federation sync service (export endpoints only)",
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command always rotates sync keys

Medium Severity

Each run of create_federation_sync_api_key deletes every existing FederationSync API key for the sync user before creating a new one. Re-running the command invalidates keys already configured in federation-sync without an explicit rotate flag.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3393c0f. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request federation Federation related work (sync service, document storage, peer configuration, etc.) gateway Gateway component migrations Code changes that require data or schema migrations in the database.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants