feat(access): blocked workspace members are refused (portal#74) #471

Merged
sharang merged 1 commits from feat/blocked-members into main 2026-10-05 22:21:21 +00:00
Owner

portal#74 follow-up, handed over by the platform session: Prüfwerk enforces blocked workspace members. Stage only.

Background

  • Since portal#82 / tenant-registry#64, IT admins and staff can block members per workspace. The registry records this as the user attribute org_blocked.
  • It does not disable the Keycloak user. Until now, a blocked member could get back into Prüfwerk after signing in again.

Change

  • Agent: entitlement check with user_id
    • require_entitlement sends the person's Keycloak sub as user_id in the existing POST /v1/internal/entitlements/check.
    • The registry answers allowed:false, reason:"member_blocked" for a blocked member.
    • The agent then refuses with 403 {"error":"MEMBER_BLOCKED"}.
    • The cache key is now (tenant, addon, user), still ≤ 60 s.
  • Which tokens are checked: only person tokens.
    • Support takes its own path (get_tenant), so no block check, as before.
    • Service tokens (platform API, runner) have no tenant context at that point.
  • On errors:
    • The registry itself lets the user in when its block lookup fails (entitlements.go: "member block check failed; allowing").
    • Older registries ignore the unknown field.
    • An unreachable registry still refuses with 503 entitlement_unavailable as before. That is the entitlement check failing closed (MVP-1.2); the block check adds nothing to it.
  • GET /api/v1/access: only answers once authentication, entitlement and role checks let the caller through. It's for the dashboard.
  • Dashboard:
    • check_auth asks /api/v1/access once per page load, except for support.
    • On MEMBER_BLOCKED the app shows only the "Zugang gesperrt" page: "Ihr Zugang zu diesem Arbeitsbereich ist gesperrt oder wurde entfernt. Wenden Sie sich an die IT-Administration Ihres Unternehmens…" (DE/EN), with buttons back to the portal and to sign out.
    • If the agent can't be reached, it doesn't count as a block, and the agent still refuses every request itself.
    • AuthInfo gains member_blocked.

Tests

  • tests/member_blocked.rs (fake registry plus Mongo, through the real middleware):
    • blocked → 403 MEMBER_BLOCKED;
    • another member → 200, and the registry received user_id = their sub;
    • support context → 200 without an entitlement call;
    • registry unreachable → 503 entitlement_unavailable, unchanged.
  • Dashboard: only_the_blocked_refusal_counts_as_a_block.
  • fmt and clippy with the CI flags (core, agent, both dashboard feature sets). Tests: agent lib 618, dashboard 82, core 107, plus tenant_status_middleware and git_source.

To test on stage

  1. In the portal, as IT admin, block a test user in the workspace.
  2. Sign in to Prüfwerk as that user: the "Zugang gesperrt" page; API calls → 403 MEMBER_BLOCKED. Allow up to 60 s for the cache.
  3. Unblock: access works again after ≤ 60 s.
  4. Support access (staff) into the same workspace is unaffected.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

portal#74 follow-up, handed over by the platform session: **Prüfwerk enforces blocked workspace members.** Stage only. ## Background - Since portal#82 / tenant-registry#64, IT admins and staff can block members per workspace. The registry records this as the user attribute `org_blocked`. - It does **not** disable the Keycloak user. Until now, a blocked member could get back into Prüfwerk after signing in again. ## Change - **Agent: entitlement check with `user_id`** - `require_entitlement` sends the person's Keycloak `sub` as `user_id` in the existing `POST /v1/internal/entitlements/check`. - The registry answers `allowed:false, reason:"member_blocked"` for a blocked member. - The agent then refuses with **403 `{"error":"MEMBER_BLOCKED"}`**. - The cache key is now `(tenant, addon, user)`, still ≤ 60 s. - **Which tokens are checked:** only person tokens. - Support takes its own path (`get_tenant`), so no block check, as before. - Service tokens (platform API, runner) have no tenant context at that point. - **On errors:** - The registry itself lets the user in when its block lookup fails (`entitlements.go`: "member block check failed; allowing"). - Older registries ignore the unknown field. - An **unreachable registry** still refuses with **503 `entitlement_unavailable`** as before. That is the entitlement check failing closed (MVP-1.2); the block check adds nothing to it. - **`GET /api/v1/access`:** only answers once authentication, entitlement and role checks let the caller through. It's for the dashboard. - **Dashboard:** - `check_auth` asks `/api/v1/access` once per page load, except for support. - On `MEMBER_BLOCKED` the app shows only the **"Zugang gesperrt"** page: "Ihr Zugang zu diesem Arbeitsbereich ist gesperrt oder wurde entfernt. Wenden Sie sich an die IT-Administration Ihres Unternehmens…" (DE/EN), with buttons back to the portal and to sign out. - If the agent can't be reached, it doesn't count as a block, and the agent still refuses every request itself. - `AuthInfo` gains `member_blocked`. ## Tests - **`tests/member_blocked.rs`** (fake registry plus Mongo, through the real middleware): - blocked → 403 `MEMBER_BLOCKED`; - another member → 200, and the registry received `user_id` = their sub; - support context → 200 **without** an entitlement call; - registry unreachable → 503 `entitlement_unavailable`, unchanged. - Dashboard: `only_the_blocked_refusal_counts_as_a_block`. - fmt and clippy with the CI flags (core, agent, both dashboard feature sets). Tests: agent lib 618, dashboard 82, core 107, plus `tenant_status_middleware` and `git_source`. ## To test on stage 1. In the portal, as IT admin, block a test user in the workspace. 2. Sign in to Prüfwerk as that user: the **"Zugang gesperrt"** page; API calls → 403 `MEMBER_BLOCKED`. Allow up to 60 s for the cache. 3. Unblock: access works again after ≤ 60 s. 4. Support access (staff) into the same workspace is unaffected. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-05 22:11:44 +00:00
feat(access): blocked workspace members are refused (portal#74)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 8m42s
3abb32b65c
Since portal#82 / tenant-registry#64 an IT admin or staff can block a
member per workspace; the registry records it, never disables the
Keycloak user, and Prüfwerk let a blocked member back in after a new
login.

- The entitlement check now sends the person's Keycloak `sub` as
  `user_id`; the registry answers `allowed: false, reason:
  member_blocked` for a blocked member, and the agent refuses with
  403 {"error":"MEMBER_BLOCKED"}. Cached per tenant and user for up to
  60 s, like the entitlement answer. Only person tokens are checked:
  support takes its own path, and service tokens (platform API, runner)
  carry no tenant context there. The registry allows when its own block
  lookup fails; an unreachable registry is still refused as before
  (entitlement fails closed).
- GET /api/v1/access: answered only past authentication, entitlement
  and role checks, for the dashboard's sign-in check.
- Dashboard: check_auth asks it once per page load (not for support)
  and a blocked member sees only "Zugang gesperrt" ("Ihr Zugang zu
  diesem Arbeitsbereich ist gesperrt oder wurde entfernt…"), with the
  way back to the portal and sign-out. AuthInfo gains member_blocked.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 0e7a138cd4 into main 2026-10-05 22:21:21 +00:00
Sign in to join this conversation.