Skip to content

[M2.3c2b1] Discover organizations through account-scoped row policies - #82

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3c2b1-organization-discovery
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3c2b1-organization-discovery

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Task

M2.3c2b1, stacked on #81 (feat/m2.3c2a-runtime-database-role).

What changed and why

Allow an authenticated account to discover its own organizations before selecting a tenant. SELECT-only RLS policies expose only its memberships and organization metadata, and only while the account is active and verified. Project/environment contents, role bindings and tenant writes remain inaccessible in discovery mode.

Add runAccountDiscovery with a transaction-local account setting. Tenant and account scopes are mutually exclusive, preserve same-scope nesting and clear both settings on exit. A caller cannot switch account or scope within an active transaction context. The identity must come from authentication, never a caller-selected account parameter.

Validation

  • Eight restricted-login PostgreSQL tests cover independent account discovery, disabled/pending/unknown accounts, private resource contents, write denial, nested-scope rejection, cleanup, current account status and immediate membership removal.
  • Existing restricted-role fixtures receive only the user columns needed by the account-status policy, preserving their lack of credential access.
  • All 136 PostgreSQL integration tests pass, including concurrent last-owner protection and pooled transaction isolation.
  • API lint, types, 103 unit tests and build pass. Workspace web/domain, Go and buf checks passed earlier in this session; their sources are unchanged.

Security considerations

No security-definer function or RLS bypass is added. Discovery does not expose other members, grant tenant write permissions or substitute for live application authorization. No tenant HTTP route is exposed by this slice; scoped repositories and authorization adapters follow. Account-status checks use existing identity columns. No dependency, application shell call, secret or new domain mutation is introduced.

Checklist

  • M2.3c2b1 acceptance and cross-account boundaries covered
  • PostgreSQL regression suite and API checks pass
  • SPEC and PLAN updated
  • No new application mutation requiring an audit event

@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3c2a-runtime-database-role branch from 840011a to 2fcc9a0 Compare November 5, 2026 12:46
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.3c2a-runtime-database-role to main November 5, 2026 12:46
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3c2b1-organization-discovery branch from 48a2075 to 85f7cf6 Compare November 5, 2026 12:46
@samuelmbabhazi
samuelmbabhazi merged commit beeea05 into main Nov 5, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.3c2b1-organization-discovery branch November 5, 2026 12:46
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
## Task

M2.3c2b2, stacked on #82 (`feat/m2.3c2b1-organization-discovery`).

## What changed and why

Resolve current active/verified membership, organization/project
ancestry, environment protection and role bindings before applying the
tenant policy. Reject unknown capabilities, invalid identifiers and
incomplete contexts before storage access. Ignore caller-supplied
role/protection metadata, use a shared canonical UUIDv7 validator and
return the same resource-not-found error for unavailable permissions and
resources.

All reads include organization filters inside the tenant unit of work.
Grant lookup is bounded to the unique project grant and the relevant
environment grant (or one environment grant for parent navigation). The
read-side module is independent of identity commands, preparing live
token authorization without a module dependency cycle.

## Validation

- Seven restricted-login PostgreSQL tests cover foreign/sibling resource
references, environment protection changes, explicit role downgrades,
environment-only grants, account disabling, membership removal,
malformed inputs and joining/rolling back the caller transaction.
- All 143 PostgreSQL integration tests pass. The final bounded grant
query also passes the targeted suite with 100% statement/branch/function
coverage across the new authorization service and repository.
- API/web/domain lint, types, tests and builds pass; final API
lint/types pass after query bounding. Go tests and buf lint passed
earlier in this session; their sources are unchanged.

## Security considerations

No permission cache, HTTP endpoint, token-authority switch or unaudited
mutation is introduced here. M2.3c3/c4 add audited commands and
serialize role changes with identity locks; M2.3d wires session/bearer
routes. Membership/account state and resource ancestry come only from
current database rows. No dependency, secret or application shell
invocation is added.

## Checklist

- [x] M2.3c2b2 acceptance and cross-resource boundaries covered
- [x] Restricted-login integration and application coverage checks pass
- [x] SPEC and PLAN updated
- [x] No new application mutation requiring an audit event
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant