Skip to content

Phase 1 (backend): identity, teams & ownership#9

Merged
kosminus merged 1 commit into
mainfrom
claude/phase1-identity-auth
Jun 5, 2026
Merged

Phase 1 (backend): identity, teams & ownership#9
kosminus merged 1 commit into
mainfrom
claude/phase1-identity-auth

Conversation

@kosminus

@kosminus kosminus commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Implements the backend half of Phase 1 from planfull.md — the identity layer that gates the rest of the roadmap.

Decisions (confirmed)

  • Login: magic-link + local password; OIDC is a registered (unimplemented) provider seam.
  • Session: stateless HS256 JWT delivered as an HTTP-only cookie.
  • Build order: backend-first (this PR); frontend in a stacked follow-up.

What's included

  • Identity modelsOrganization, User, Team (= workspace), Membership (admin|editor|viewer), ApiKey. Single-tenant per deployment (isolation by workspace_id); organization_id carried on every core table so a future managed-SaaS fleet needs no migration.
  • Auth coreapp/core/security.py (PBKDF2 passwords, HS256 JWTs with a purpose claim, API-key gen/hash), app/core/auth.py (get_current_user → API key/Bearer/cookie, get_org_contextAuthContext, require_role, cookie helpers, DISABLE_AUTH dev escape hatch), and the pluggable app/core/auth_providers.py seam.
  • Services & endpointsauth_service, identity_service (incl. bootstrap_default_identity + system_context); routes /auth/*, /teams (+ members), /api-keys.
  • AuthZ wired through the stackconnection_service scopes by org+workspace and enforces role; metadata endpoints authorize via the connection cascade root (app/api/v1/deps.py); query/schema services, all endpoints, the MCP server, and startup auto-setup thread AuthContext. created_by/user_id promoted to real User FKs.
  • Migration 004 — nullable → seed default org/workspace/admin → backfill → NOT NULL, with (org_id, created_at) indexes and a full downgrade.

Verification

  • 98 unit tests pass (29 new: password/JWT/API-key crypto, provider registry, role hierarchy, 401 on protected routes).
  • Migration applies and reverses cleanly on a throwaway DB (down restores created_by).
  • End-to-end against a real DB: bootstrap, password login (wrong rejected), session-JWT roundtrip, viewer blocked from create, cross-workspace isolation (404), magic-link auto-provisioning a viewer.
  • ruff/mypy clean on new files.

Deploy note

Once migration 004 runs, auth is mandatory. The pre-auth frontend would 401, so docker-compose.yml sets DISABLE_AUTH=true as the bridge until the frontend PR lands.

🤖 Generated with Claude Code

Add the identity layer that gates the rest of the roadmap: real users,
teams/workspaces, roles, ownership, and audit FKs. Single-tenant per
deployment (isolation by workspace_id within an auto-created default org);
organization_id carried on every core table so a future managed-SaaS fleet
needs no migration.

Auth: magic-link + local password login issuing HS256 session JWTs delivered
as HTTP-only cookies; OIDC is a registered (unimplemented) provider seam;
DISABLE_AUTH escape hatch for local dev.

- Models: Organization, User, Team, Membership (admin|editor|viewer), ApiKey
- Core: security.py (PBKDF2 + JWT + API keys), auth.py (get_current_user /
  get_org_context / require_role + cookie helpers), auth_providers.py seam
- Services: auth_service (login/magic-link/register), identity_service
  (org/team/membership/api-key CRUD, bootstrap + system_context)
- Endpoints: /auth/*, /teams (+members), /api-keys
- AuthZ wired through connection_service, query/schema services, all metadata
  endpoints (via connection cascade root), the MCP server, and startup
  auto-setup (system context). created_by/user_id promoted to real User FKs.
- Migration 004: nullable -> seed default org/workspace/admin -> backfill ->
  NOT NULL, with (org_id, created_at) indexes and a full downgrade.
- Tests: password/JWT/API-key crypto, provider registry, role hierarchy,
  401 on protected routes (98 pass).
- docker-compose: DISABLE_AUTH=true bridge until the Phase 1 frontend lands.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kosminus kosminus merged commit 114426e into main Jun 5, 2026
2 checks passed
@kosminus kosminus deleted the claude/phase1-identity-auth branch June 5, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant