mirror of
https://github.com/hansjone/netx.git
synced 2026-10-16 05:20:44 +08:00
Harden auth scopes, SQL/WebCRT gates, and per-install JWT secrets.
Add capability RBAC, Alembic bootstrap, optional worker schedulers, and close public docs by default so lab installs stay usable without shared signing keys. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
cb8e0d23c5
commit
633a9d55bd
38 changed files with 1808 additions and 452 deletions
54
alembic/versions/20260802_scopes.py
Normal file
54
alembic/versions/20260802_scopes.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
"""Add app_user.scopes and api_token.scopes for capability RBAC.
|
||||
|
||||
Revision ID: 20260802_scopes
|
||||
Revises:
|
||||
Create Date: 2026-08-02
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20260802_scopes"
|
||||
down_revision: Union[str, Sequence[str], None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
dialect = bind.dialect.name
|
||||
# Idempotent adds for brownfield DBs that already ran startup ALTER TABLE.
|
||||
if dialect == "postgresql":
|
||||
op.execute("ALTER TABLE app_user ADD COLUMN IF NOT EXISTS scopes JSON DEFAULT '[]'")
|
||||
op.execute("ALTER TABLE api_token ADD COLUMN IF NOT EXISTS scopes JSON DEFAULT '[]'")
|
||||
else:
|
||||
insp = sa.inspect(bind)
|
||||
if "app_user" in insp.get_table_names():
|
||||
cols = {c["name"] for c in insp.get_columns("app_user")}
|
||||
if "scopes" not in cols:
|
||||
op.add_column("app_user", sa.Column("scopes", sa.JSON(), nullable=True))
|
||||
if "api_token" in insp.get_table_names():
|
||||
cols = {c["name"] for c in insp.get_columns("api_token")}
|
||||
if "scopes" not in cols:
|
||||
op.add_column("api_token", sa.Column("scopes", sa.JSON(), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
dialect = bind.dialect.name
|
||||
if dialect == "postgresql":
|
||||
op.execute("ALTER TABLE api_token DROP COLUMN IF EXISTS scopes")
|
||||
op.execute("ALTER TABLE app_user DROP COLUMN IF EXISTS scopes")
|
||||
else:
|
||||
try:
|
||||
op.drop_column("api_token", "scopes")
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
op.drop_column("app_user", "scopes")
|
||||
except Exception:
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue