Skip to content

refactor(auth): key session team resolution on canonical user_id - #6732

Open
jonpspri wants to merge 1 commit into
refactor/5889-rbac-user-idfrom
refactor/5890-team-user-id
Open

refactor(auth): key session team resolution on canonical user_id#6732
jonpspri wants to merge 1 commit into
refactor/5889-rbac-user-idfrom
refactor/5890-team-user-id

Conversation

@jonpspri

@jonpspri jonpspri commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

This PR keys session team resolution on the canonical user_id. resolve_session_teams derives the identity with get_user_id(payload) and passes it to _resolve_teams_from_db, _get_user_team_ids_sync, and the team-cache keys. A UUID session subject is an opaque reference, not an identity: it falls back to the e-mail argument, exactly like a missing identity. Phase-1 values are e-mail strings, so the EmailTeamMember.user_email queries, the DB-authority contract, and normalize_token_teams() are unchanged. _narrow_by_jwt_teams uses no identity and is unchanged. Docstrings state the new parameter meaning in auth.py and team_management_service.py.

Tested with:

  • uv run pytest tests/unit/mcpgateway/middleware/test_token_scoping.py::TestUserIdKeyedTeamResolution -q — failed first with the expected mode (spy received 'e@x.test' instead of 'u-1'), then 4 passed
  • uv run pytest tests -k "team or scoping" -q — 2475 passed, 73 skipped
  • uv run pytest tests/unit/mcpgateway/transports/test_streamablehttp_transport.py -q — 601 passed (call sites verified unchanged)
  • make ruff — all checks passed

Acceptance criteria of #5890 are met. Risk to existing users: none; phase-1 values are identical, including UUID-subject session tokens.

Stack: A.5 of epic #5884 (base: #6731).

Closes #5890

@jonpspri
jonpspri added this pull request to stack #6729 September 9, 2026 19:56
@jonpspri
jonpspri marked this pull request as ready for review September 9, 2026 19:56
@jonpspri
jonpspri force-pushed the refactor/5890-team-user-id branch from d079a73 to 9664afc Compare September 10, 2026 06:22
@jonpspri
jonpspri removed this pull request from stack #6729 September 12, 2026 08:50
@jonpspri
jonpspri force-pushed the refactor/5890-team-user-id branch from 9664afc to 175761f Compare September 12, 2026 09:07
@jonpspri
jonpspri added this pull request to stack #6798 September 12, 2026 09:08
@jonpspri
jonpspri force-pushed the refactor/5890-team-user-id branch from 175761f to 2e26964 Compare September 12, 2026 09:48
resolve_session_teams derives the identity with get_user_id(payload) and passes it to _resolve_teams_from_db, _get_user_team_ids_sync, and the team-cache keys. The e-mail argument stays the fallback for a missing identity and for a UUID session subject, which is an opaque reference and not an identity. Phase-1 values are e-mail strings, so the EmailTeamMember.user_email queries, the DB-authority contract, and normalize_token_teams() are unchanged. _narrow_by_jwt_teams uses no identity and is unchanged. Docstrings state the new parameter meaning.

Signed-off-by: Jonathan Springer <jps@s390x.com>
@jonpspri
jonpspri force-pushed the refactor/5890-team-user-id branch from 2e26964 to fd2032b Compare September 12, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Team resolution consumes canonical user_id

1 participant