Bind a worker's name and labels into its token; list and revoke tokens by jti

This commit is contained in:
2026-10-07 08:42:14 +02:00
parent 9ef7f90dd8
commit 953a983919
16 changed files with 470 additions and 38 deletions
@@ -0,0 +1,37 @@
"""worker_token
Every worker credential a superuser mints, by the `jti` it carries, so one can
be listed and revoked without rotating the key that signs them all.
Revision ID: b7d2e9c4a1f3
Revises: f8c3e5a91d27
Create Date: 2026-10-06
"""
import sqlalchemy as sa
import sqlmodel.sql.sqltypes
from alembic import op
# revision identifiers, used by Alembic.
revision = "b7d2e9c4a1f3"
down_revision = "f8c3e5a91d27"
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
"worker_token",
sa.Column("jti", sqlmodel.sql.sqltypes.AutoString(length=32), nullable=False),
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
sa.Column("labels", sa.JSON(), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
sa.Column("revoked_at", sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint("jti"),
)
def downgrade():
op.drop_table("worker_token")