Skip to content

feat(core): add TenantContext middleware and active organization endpoint#1069

Merged
geoffjay merged 11 commits into
issue-215from
issue-216
Apr 16, 2026
Merged

feat(core): add TenantContext middleware and active organization endpoint#1069
geoffjay merged 11 commits into
issue-215from
issue-216

Conversation

@geoffjay
Copy link
Copy Markdown
Owner

@geoffjay geoffjay commented Apr 9, 2026

Adds multi-tenant request isolation infrastructure:

  • TenantContext extractor (middleware/tenant.rs) — resolves session → user → active org per-request; returns 401 for missing/expired sessions and 403 if no active organization is set. Designed to forward organization_id as X-Tenant-ID to downstream services.
  • PUT /users/me/active-organization (api/users.rs) — validates the requesting user is a member of the target org (403 if not), then updates active_organization_id. Returns the updated user profile without password_hash.
  • 4 endpoint tests: success, not-a-member (403), unauthenticated (401), cross-user org isolation

Closes #216

@geoffjay geoffjay added the review-agent Used to invoke a review by an agent tracking this label label Apr 9, 2026
…oint

Adds TenantContext extractor (session + active org required, 403 if no
active org) and PUT /users/me/active-organization endpoint with membership
validation. Also adds api/users.rs module with 4 endpoint tests.
Adds `agent auth register/login/logout/status` and `agent org list/create/switch`
commands communicating with the agentd-core service (port 17007). Session token
stored at ~/.config/agentd/session with 0600 permissions. Adds `dirs` dependency
for cross-platform config path resolution. Registers core service in status check.
Adds GET/PUT /api/v1/users/me, PUT /api/v1/users/me/password,
GET /api/v1/users/me/organizations, and full CRUD for organizations
with member management (add, remove, list). Enforces owner-only mutations,
last-owner protection, and clears active_organization_id on org deletion.
Adds update_email, update_password, and clear_active_organization_for_org
to UserStorage. 21 new endpoint tests covering auth and authorization checks.
Implements HTTP reverse proxy in crates/core that forwards /api/v1/{service}/*
requests to downstream agentd services with X-Tenant-ID and X-Request-ID header
injection. Includes concurrent health aggregation at /api/v1/health.
feat(core): add API gateway proxy for downstream service routing
feat(cli): add auth and org commands for core service
feat(core): add user and organization management API endpoints
@geoffjay geoffjay merged commit 0f82eb1 into issue-215 Apr 16, 2026
@geoffjay geoffjay deleted the issue-216 branch April 16, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-agent Used to invoke a review by an agent tracking this label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tenant ID middleware and active organization management

1 participant