Federation data and actor keys (phase 1, step 1)
- federation_settings (per user; off, followers-only, not discoverable by default) and federation_keys (RSA-2048; NULL user = instance actor), on the federation migration branch - Private keys encrypted at rest with Fernet, keyed by HKDF-SHA256 from FEDERATION_KEY_SECRET (now required, 32+ chars, never printed) - Keys are created when a user first enables sharing and never regenerated; sharing.shared_user() treats unknown and non-sharing users identically - One flask-smorest Api per app (get_api(app)), so apps with and without federation never share an OpenAPI spec - Test fixtures for a second, federation-enabled app on the same DB 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
00ad8e9e6d
commit
98c65547f3
12 files changed
+513
-5
No files matched your search
@@ -0,0 +1,48 @@
|
||||
"""Federation's own tables. All prefixed federation_; the only link to the core schema
|
||||
is a foreign key to users. Migrations live on the `federation` Alembic branch."""
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, LargeBinary, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from scrobbler.extensions import db
|
||||
|
||||
VISIBILITIES = ("followers", "unlisted", "public")
|
||||
|
||||
|
||||
def utcnow() -> datetime:
|
||||
return datetime.now(UTC)
|
||||
|
||||
|
||||
class FederationSettings(db.Model):
|
||||
__tablename__ = "federation_settings"
|
||||
|
||||
user_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="CASCADE"), primary_key=True
|
||||
)
|
||||
enabled: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
visibility: Mapped[str] = mapped_column(String(16), default="followers")
|
||||
manually_approves_followers: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
discoverable: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
indexable: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
display_name: Mapped[str | None] = mapped_column(String(100))
|
||||
bio: Mapped[str | None] = mapped_column(Text)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), default=utcnow, onupdate=utcnow
|
||||
)
|
||||
|
||||
|
||||
class FederationKey(db.Model):
|
||||
"""An actor's RSA key pair. user_id is NULL for the instance actor."""
|
||||
|
||||
__tablename__ = "federation_keys"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
user_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="CASCADE"), unique=True
|
||||
)
|
||||
public_key_pem: Mapped[str] = mapped_column(Text)
|
||||
private_key_encrypted: Mapped[bytes] = mapped_column(LargeBinary)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utcnow)
|
||||
Reference in new issue
Block a user