Skip to content

[M2.3c4b] Manage memberships and preserve the final owner - #90

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3c4b-membership-commands
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.3c4b-membership-commands

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Task

M2.3c4b, stacked on #89. Review in order; no automatic merge.

What changed and why

Add reauthenticated organization membership commands for existing verified accounts, explicit role changes and removal. Actor/subject account locks precede the organization lock; live authorization and owner count are then rechecked before writing. Administrators manage non-owners, owners manage ownership, and simultaneous departures cannot remove the final owner.

Membership changes and audits share the credential-invalidation transaction. Self-demotion returns a rotated session. Same-role requests preserve credential versions; removal cascades resource bindings. Directory candidates are rechecked after locking to reject changed email/active state. Unknown or unverified accounts are not invited by this slice.

Also add pure, closed organization/resource-role parsers with canonical-value tests. HTTP and administration screens follow in M2.3d/f.

How it was tested

  • Seven real restricted-PostgreSQL acceptance tests pass, covering administrator/owner restrictions, last-owner races, duplicate additions, self-demotion, invalid/stale/inactive inputs, directory races, cascading grants and rollback for every command.
  • Application coverage: 97% statements, 94% branches, 100% functions and lines.
  • All 94 domain and 103 API unit tests pass, with API/domain lint, typechecks and production builds.
  • The preceding full 177-test integration suite passed; CI runs the expanded suite and browser checks. Web, Go and protobuf checks passed earlier in the stack.
  • One local Nx native-runner process crashed; rerunning with its native command runner disabled completed successfully.

Security considerations

Only authorized organization administrators can resolve a membership candidate. Commands never receive password hashes and cannot move a membership across tenants. Role changes recheck current account versions under ordered locks; the database's deferred owner guard remains a second defense. Failed audits roll back membership and credential state together. No new dependency, shell invocation or secret exposure. CodeQL remains skipped by repository configuration; enabled security checks run in CI.

Checklist

  • M2.3c4b acceptance met; PLAN/SPEC updated
  • TDD role policy and real PostgreSQL command acceptance pass
  • Relevant lint, typechecks, unit tests and builds pass
  • Every membership mutation emits an atomic audit event
  • No secrets or generated artifacts edited manually

@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3c4a-privilege-change-locks branch from 9df2046 to 1c34e55 Compare November 5, 2026 14:48
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.3c4a-privilege-change-locks to main November 5, 2026 14:48
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.3c4b-membership-commands branch from e536f50 to 407dfb3 Compare November 5, 2026 14:50
@samuelmbabhazi
samuelmbabhazi merged commit 2490c84 into main Nov 5, 2026
2 of 11 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.3c4b-membership-commands branch November 5, 2026 14:51
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
## Task

M2.3c4c1, stacked on #90. Review in order; no automatic merge.

## What changed and why

Add audited project/environment role assignment and removal with fresh
password/MFA proof and ordered actor/subject locks. Assignment resolves
only an exact existing organization member by email after scope
authorization; it cannot add organization membership or grant ownership.
New/changed bindings require an active verified member. Removal also
works for disabled or subsequently promoted accounts.

Live scope checks honor explicit environment downgrades: a project
administrator downgraded in an environment cannot remove that
restriction themselves. Removing an override can restore inherited
rights, so removal invalidates credentials just like assignment.
Self-changes return a rotated session; unchanged/absent grants preserve
credential versions and audit proof confirmation.

## How it was tested

- Seven real restricted-PostgreSQL acceptance tests pass:
assignment/update/removal, idempotence, all administration scopes,
self-demotion, explicit overrides, wrong ancestry/recipients/roles,
duplicate concurrency, directory races and audit rollback.
- Application coverage: 98% statements, 97% branches, 100% functions and
lines.
- API lint, typechecks, 103 unit tests and production build pass.
- Parent PR #90 passed the full integration, browser,
generated-contract, Go and enabled security checks. CI runs the expanded
suite for this PR.

## Security considerations

Scope administrators do not receive a global account directory. Resource
ancestry and membership are rechecked under account/organization locks
before writing. Binding updates cannot change their tenant, parent
resource or membership. Audits and credential invalidation commit
together. No new dependency, shell invocation or credential exposure
path. CodeQL remains skipped by repository configuration.

## Checklist

- [x] M2.3c4c1 acceptance met; PLAN/SPEC updated
- [x] Local static checks, tests and build pass
- [x] Scope escalation, concurrency and rollback acceptance covered
- [x] Every grant mutation emits an atomic audit event
- [x] No secrets or generated artifacts edited manually
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
… enrollment errors (#109)

## Task

Review follow-ups for #90, #91 and #102, plus two rule-audit items. Refs
#22

## What changed

**No directory oracle (#90, #91)**
- `AccountMutationAuthority.confirmPassword()` checks the caller's
password without locks.
- `MembershipCommands.add` and `BindingCommands.assign` call it before
answering `resource_not_found` for an unknown address. An unknown
account and a wrong password now give the same 401, so these commands
cannot list the instance's verified accounts or an organization's
members. The success path still pays one Argon2id verification.

**Environment overrides (#91)**
- An administrator of a single environment can no longer create or
remove an environment override for a member who administers the whole
project. Before, the project admin could not undo such a restriction.
- Project admins and organization owners/admins are unaffected.

**Explicit response fields (#102)**
- `resourceDto` spread whole store rows into responses. It is replaced
by `organizationDto`, `projectDto`, `environmentDto`, `memberViewDto`
and `bindingViewDto`, which list every field. A future column cannot
reach session or bearer clients without a DTO change.
- The HTTP test asserts the exact key sets for project and environment
details.

**Rule audit items**
- The agent's enrollment error keeps its gRPC code (wrapped with `%w`)
and still drops the remote text. Its test fails without the fix
(`Unknown`).
- An `eslint-disable` gains its justification.
- SPEC: directory lookup ordering, the environment-override rule
(section 7), and bearer status codes (401 for bad tokens or token-less
routes, 403 for scope gaps checked before any lookup, so nothing leaks).

## How it was tested

- Local gate on the branch: lint, typecheck, unit tests and build for
all projects; go vet, go test and golangci-lint; no generated-code
drift; Semgrep and Prettier.
- New integration tests: same 401 for unknown and existing accounts on
membership add and binding assign; environment admin refused on a
project admin, owner allowed.
- CI is unavailable (account spending limit), so integration tests did
not run.

## Checklist

- [x] Local gate passes
- [x] Tests added
- [x] No new shell invocation and no new secret exposure path
- [x] Audit events unchanged (refused commands write nothing)
- [x] SPEC updated
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