Inbox: intake and verified processing of follows (phase 2, step 4)
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 14s
CI / test (push) Successful in 1m57s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 14s
CI / test (push) Successful in 1m57s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
Intake (in the request, no network): size, content type and shape checks, blocked domains refused (403), duplicates acknowledged once, then stored and answered 202. Processing (federation.inbox worker task): - verify the HTTP signature with either scheme, as of when it arrived, using the cached key and refreshing the sender once on failure (key rotation); a deleted account's Delete still verifies from cache - the signer must be the activity's actor and the activity id must be on the actor's host - handlers: Follow (accept, or pending with manual approval; repeat follows re-accepted; blocked accounts rejected), Undo of a Follow (only by the same actor), Delete of an actor, Update of an actor; anything else recorded - items being processed are marked, retried on transient failures, re-queued if a worker dies, and pruned after 30 days Outgoing Accept/Reject/Block activities are stored with stable ids and queued per inbox for the delivery task (next step). Public activities are fetchable at /activities/<uuid>. Metrics for inbox activities and signature checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
c1a7dd0877
commit
f312c4b577
15 files changed
+1147
-60
No files matched your search
@@ -4,7 +4,7 @@ import json
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from scrobbler.federation import keys
|
||||
from scrobbler.federation import ids, keys
|
||||
from scrobbler.federation.net import Client, FetchError, Response
|
||||
from scrobbler.federation.protocol import signatures
|
||||
from scrobbler.federation.protocol.media import ACTIVITY_JSON, LD_JSON
|
||||
@@ -26,14 +26,6 @@ def client() -> Client:
|
||||
return existing
|
||||
|
||||
|
||||
def instance_key_id() -> str:
|
||||
return f"{current_app.extensions['federation'].base_url}/actor#main-key"
|
||||
|
||||
|
||||
def user_key_id(username: str) -> str:
|
||||
return f"{current_app.extensions['federation'].base_url}/users/{username}#main-key"
|
||||
|
||||
|
||||
def _signed_headers(method, url, headers, body, key_id, private_key, scheme) -> dict[str, str]:
|
||||
request = SignedRequest(method, url, headers, body)
|
||||
return {**headers, **signatures.sign(request, scheme, key_id, private_key)}
|
||||
@@ -47,7 +39,7 @@ def signed_get_json(url: str) -> dict:
|
||||
schemes = current_app.extensions["federation"].signature_schemes
|
||||
response = None
|
||||
for scheme in schemes:
|
||||
signed = _signed_headers("GET", url, headers, b"", instance_key_id(), private, scheme)
|
||||
signed = _signed_headers("GET", url, headers, b"", ids.instance_key_id(), private, scheme)
|
||||
response = client().request("GET", url, signed)
|
||||
if response.status != 401:
|
||||
break
|
||||
@@ -65,7 +57,7 @@ def signed_post(url: str, activity: dict, *, user_id: int, username: str) -> tup
|
||||
headers = {"Content-Type": LD_JSON, "Accept": ACTIVITY_JSON}
|
||||
response, used = None, ""
|
||||
for used in current_app.extensions["federation"].signature_schemes:
|
||||
signed = _signed_headers("POST", url, headers, body, user_key_id(username), private, used)
|
||||
signed = _signed_headers("POST", url, headers, body, ids.key_id(username), private, used)
|
||||
response = client().request("POST", url, signed, body)
|
||||
if response.status != 401:
|
||||
break
|
||||
|
||||
Reference in new issue
Block a user