Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

feat: Initial work refactoring noosphere-gateway to be generic over the spheres it manages. #698

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

jsantell
Copy link
Contributor

@jsantell jsantell commented Oct 25, 2023

  • trait ContextManager is provided to the gateway to access managed spheres' contexts.
  • SingleSphereContextManager implementation for existing orb gateway and tests.
  • All gateway routes now require X-SPHERE-IDENTITY header to specify the target sphere. Corresponding UCAN auth could apply to many spheres.
  • In addition to GatewayAuthority synthesized for authenticated routes, there's now GatewaySphereContext which provides access to the targeted gateway sphere.
  • Use TypedHeaders for parsing X-SPHERE-IDENTITY and UCAN headers into a proof chain. Note using the headers module, it should be the same version as axum in servers.
  • Worker tasks naively loop through all managed sphere contexts before waiting on some timer. Not scalable, and could result in long worker cycles, but good enough for now.

cargo test --features test-kubo,helpers passing locally

@jsantell jsantell force-pushed the mtg branch 7 times, most recently from 6a50daf to b599a96 Compare October 27, 2023 20:03
@jsantell
Copy link
Contributor Author

Updates:

  • Requests are now scoped by hostname e.g. did:key:abc.subconscious.cloud.
    • Some tests updated to properly set counterpart in gateways
    • SingleSphereContextManager always has available its one sphere context, and does not use whatever's in the hostname. This enables existing cluster gateways, and possibly misconfigured self-served gateways to continue functioning. The real counterpart identity is fetched from sphere storage to reflect truth.
    • TBD on what formatting we want for the DID subdomain e.g. did_key_abc or elide the DID type altogether abc.subconscious.cloud.
  • GatewayAuthority, in addition to handling auth, now contains the scoped sphere context. For unauthenticated requests (Did route), a GatewaySphereContext is used to access the sphere context. Rationale here is to not double up on processing on every request, and use one or the other in a route (with GatewayAuthority using an underlying GatewaySphereContext.
  • X-SPHERE-IDENTITY header removed.

@jsantell
Copy link
Contributor Author

Rebased on #685

Copy link
Contributor

github-actions bot commented Oct 31, 2023

Test flake analysis

status platform features toolchain
🟢 macos-13 test-kubo,headers,rocksdb stable
🟢 ubuntu-latest test-kubo,headers,rocksdb stable
🟢 ubuntu-latest test-kubo,headers nightly
🟡 macos-13 test-kubo,headers stable
🟡 ubuntu-latest test-kubo,headers stable
🟢 windows-latest test-kubo,headers stable

Flake summary for macos-13, test-kubo,headers, stable

     Summary [ 401.883s] 176 tests run: 176 passed (1 flaky), 1 skipped
   FLAKY 6/6 [  59.153s] noosphere::distributed_stress latency::clients_can_sync_when_there_is_a_lot_of_content

Flake summary for ubuntu-latest, test-kubo,headers, stable

     Summary [  45.391s] 176 tests run: 176 passed (1 flaky), 1 skipped
   FLAKY 2/6 [  16.842s] noosphere::distributed_stress multiplayer::orb_can_render_peers_in_the_sphere_address_book

@jsantell
Copy link
Contributor Author

jsantell commented Nov 1, 2023

rebased

@cdata
Copy link
Collaborator

cdata commented Nov 2, 2023

IIUC what you wrote here correctly:

GatewayAuthority, in addition to handling auth, now contains the scoped sphere context. For unauthenticated requests (Did route), a GatewaySphereContext is used to access the sphere context. Rationale here is to not double up on processing on every request, and use one or the other in a route (with GatewayAuthority using an underlying GatewaySphereContext.

This is actually a lot more expensive for the DID route, which currently is an unauthorized route that just response with a string:

Note that accessing a SphereContext effectively opens a database, and in a stateless world we face doing this on every request. This could lead to DoS by malicious clients hitting the DID route abusively.

@cdata
Copy link
Collaborator

cdata commented Nov 2, 2023

Can you speak a little bit about what this is building towards? Have you chosen a serverless function stack?

@jsantell
Copy link
Contributor Author

jsantell commented Nov 2, 2023

Can you speak a little bit about what this is building towards? Have you chosen a serverless function stack?

Step 1 is to genericize sphere context access in the gateway to share functionality between single-sphere gateways and a multi-tenant one, using the high-level start_gateway() function in noosphere-gateway. The minimum interface ContextManager supports this currently, with hand waving over .iter() for the worker threads. Landing this would let us begin continually integrating MTG progress in our cluster.

Step 2 involves more long term abstraction over how we want to extend the gateway. Using the high level start_gateway() doesn't provide extensions to the axum server/custom routing, nor worker configuration, but we can begin to sketch out a shared worker queue for all tasks, compatible with remote MQs, exporting axum routes, etc. -- none of this is needed yet to get a multi-tenant gateway up and running.

No opinions on serverless function stacks; the multi tenant gateway is designed to run as several instances operating over common data. Could become serverless functions if needed. Does not seem immediately relevant to spinning up multi-tenant gateways

This is actually a lot more expensive for the DID route, which currently is an unauthorized route that just response with a string:

We can add a more lightweight function in ContextManager for resolving the map from counterpart to sphere identity for this route; edit: all of our routes have the same weakness w/r/t accessing e.g. sphere state

@cdata
Copy link
Collaborator

cdata commented Nov 2, 2023

Does not seem immediately relevant to spinning up multi-tenant gateways

It's relevant insofar as we are writing Send + Sync bounds e.g., in ContextManaager. If we are generalizing without expressing an opinion at this point, I would like to make sure we aren't ruling out wasm32-wasi.

Copy link
Collaborator

@cdata cdata left a comment

Choose a reason for hiding this comment

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

This is a good first pass. I think some aspects need a bit of thought, but I'm excited about the direction it's going in.

rust/noosphere-cli/src/native/helpers/workspace.rs Outdated Show resolved Hide resolved
rust/noosphere-core/src/api/headers/ucan.rs Show resolved Hide resolved
rust/noosphere-core/src/api/headers/ucan.rs Outdated Show resolved Hide resolved
rust/noosphere-gateway/src/gateway.rs Outdated Show resolved Hide resolved
rust/noosphere-gateway/src/handlers/v0alpha1/did.rs Outdated Show resolved Hide resolved
rust/noosphere-gateway/src/middleware.rs Outdated Show resolved Hide resolved
rust/noosphere/tests/client_to_gateway.rs Show resolved Hide resolved
rust/noosphere/tests/client_to_gateway.rs Show resolved Hide resolved
rust/noosphere/tests/client_to_gateway.rs Show resolved Hide resolved
rust/noosphere/tests/client_to_gateway.rs Outdated Show resolved Hide resolved
@jsantell jsantell force-pushed the mtg branch 7 times, most recently from a57d8ec to 3119127 Compare November 7, 2023 21:57
@jsantell jsantell requested a review from cdata November 7, 2023 22:03
Copy link
Collaborator

@cdata cdata left a comment

Choose a reason for hiding this comment

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

Tentatively this looks like a candidate for merge, but let's talk F2F about some of my last comments!

rust/noosphere-gateway/src/extractors/scope.rs Outdated Show resolved Hide resolved
rust/noosphere-gateway/src/gateway.rs Show resolved Hide resolved
rust/noosphere-gateway/src/gateway_manager.rs Outdated Show resolved Hide resolved
rust/noosphere-gateway/src/handlers/v0alpha1/push.rs Outdated Show resolved Hide resolved
rust/noosphere-gateway/src/single_tenant.rs Outdated Show resolved Hide resolved
@jsantell jsantell force-pushed the mtg branch 5 times, most recently from 95313a0 to 40ece80 Compare November 13, 2023 22:37
@jsantell jsantell requested a review from cdata November 14, 2023 01:12
spheres it manages.

* Reconfigure setting up the gateway as a [Gateway] struct.
* Introduce [GatewayManager] to manage sphere context access and
  customization (e.g. counterpart extraction), functioning as the
  shared state throughout [axum].
* Introduce [SingleTenantGatewayManager] that implements
  [GatewayManager] for usage in orb.
* Isolate extractors.
Copy link
Collaborator

@cdata cdata left a comment

Choose a reason for hiding this comment

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

Great work on this!

@cdata cdata merged commit 92f0d8a into main Nov 14, 2023
22 checks passed
@cdata cdata deleted the mtg branch November 14, 2023 22:37
@github-actions github-actions bot mentioned this pull request Nov 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants