feat(m7.1): wire tenant claims, status enforcement, and db scoping helper #82
Reference in New Issue
Block a user
Delete Branch "feat/m7.1-tenant-claims"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Lays the platform-wide M7.1 multi-tenancy infrastructure on top of the existing Keycloak JWT signature validation.
Claimsstruct now decodestenant_id,tenant_slug,org_roles,products,plan,tenant_status, plussub/name/preferred_username.require_jwt_authbuilds acompliance_core::TenantContextfrom them and attaches it to request extensions. Missingtenant_id-> 401; missingtenant_status-> defaults to Trial with a warn-log.TenantContexttype in compliance-core. Single source of truth, re-exported alongsideOrgRoleandTenantStatus. TheOrgRoleenum is forward-compatible (#[serde(other)] Unknownvariant) so a new realm role doesn't 401 the world.TenantCtxAxum extractor. Handlers consume the context viaTenantCtx(ctx): TenantCtx. Returns 401 if the upstream middleware didn't insert one.require_tenant_statusmiddleware. Enforces §5c of PLATFORM_ARCHITECTURE.md: Active/Trial/Demo pass, Frozen returns 402 on non-GET/HEAD/OPTIONS, Archived returns 410 on every method.compliance_core::db::tenant_filterhelper. Returnsdoc! { "tenant_id": ... }.tenant_filter_mergecombines with extra conditions and refuses to let the caller override the tenant key.Per-collection wiring (adding
tenant_idto each model + threading the filter through everyfind/update_*/delete_*call across the 38 query call-sites) lands in a follow-up PR.Test plan
cargo fmt --all -- --checkcleancargo clippy --workspace --exclude compliance-dashboard -- -D warningsclean (matches baseline)cargo test -p compliance-core --lib— 7 tests pass (4 tenant, 3 db)cargo test -p compliance-agent --lib api::— 32 tests pass, including 6 new auth_middleware tests and 2 tenant_ctx testscargo test -p compliance-agent --test tenant_status_middleware— 6 integration tests pass (active / trial / demo / frozen / archived / no-context paths)tenant_statusclaim (separate ticket)View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.