Skip to content

feat(BA-7364): deliver the login user id in the auth response - #13777

Open
jopemachine wants to merge 8 commits into
mainfrom
feature/BA-7364-auth-response-user-identity
Open

feat(BA-7364): deliver the login user id in the auth response#13777
jopemachine wants to merge 8 commits into
mainfrom
feature/BA-7364-auth-response-user-identity

Conversation

@jopemachine

@jopemachine jopemachine commented Aug 14, 2026

Copy link
Copy Markdown
Member

📚 Stacked PRs

This PR is part of a 5-PR stack. Merge in order:

  1. 👉 feat(BA-7364): deliver the login user id in the auth response #13777feat(BA-7364): deliver the login user id in the auth response ← you are here
  2. ⬇️ feat(BA-7365): key the rate limit counter by user id #13778feat(BA-7365): key the rate limit counter by user id
  3. ⬇️ feat(BA-7362): move the per-user API rate limit to the user resource policy #13779feat(BA-7362): move the per-user API rate limit to the user resource policy
  4. ⬇️ feat(BA-7363): publish the per-user rate limit to the shared Redis DB #13784feat(BA-7363): publish the per-user rate limit to the shared Redis DB
  5. ⬇️ feat(BA-7365): add a per-user rate limit middleware to the web server #13771feat(BA-7365): add a per-user rate limit middleware to the web server

Only the final tip (#13771) is guaranteed to build / pass CI; intermediate PRs are logical slices for reviewability.

Summary

  • Add a required user_id (UserID) field to AuthSuccessResponse, filled in the manager REST authorize handler, and store it in the web server session token in both login paths. The web server needs the login user's identity to key a per-user rate limit counter without asking the manager again.
  • Type the identifiers the auth result already carried: AuthorizationResult and AuthSuccessResponse now use UserID, AccessKey, SecretKey and UserRole instead of bare uuid.UUID / str.
  • Drop the dead or "" fallbacks on keypairs.secret_key, which is NOT NULL.

The rate limit value is deliberately not part of this response (see #13777 review): it is a resource policy value rather than part of who authenticated, and a session snapshot would go stale — the manager reads the policy per request, while a web server session would hold the login-time value for up to a week. The web server will read it from the shared rate limit Redis DB instead (BA-7363).

Resolves BA-7364.

`AuthSuccessResponse` carries the login user's id and the keypair rate
limit, and the web server stores both in the session token, so callers can
identify and throttle a login session without asking the manager again.
Both fields are optional to keep the wire format compatible with managers
that do not send them yet.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jopemachine
jopemachine requested a review from a team as a code owner August 14, 2026 05:57
Copilot AI balanced review requested due to automatic review settings August 14, 2026 05:57
@github-actions github-actions Bot added size:M 30~100 LoC comp:manager Related to Manager component comp:common Related to Common component comp:webserver Related to Web Server component labels Aug 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds user identity and keypair rate-limit metadata to successful authorization responses and persists them in web login sessions.

Changes:

  • Extends authorization DTOs and service results with user_id and rate_limit.
  • Stores both fields for password and token-based web logins.
  • Adds serialization, compatibility, service, and API tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/ai/backend/common/dto/manager/auth/types.py Adds optional response fields.
src/ai/backend/manager/data/auth/types.py Extends authorization result data.
src/ai/backend/manager/services/auth/service.py Returns the keypair rate limit.
src/ai/backend/manager/api/rest/auth/handler.py Exposes user ID and rate limit.
src/ai/backend/web/server.py Persists both fields in web sessions.
tests/unit/common/dto/manager/auth/test_auth_types.py Tests parsing and serialization.
tests/unit/manager/services/auth/test_authorize.py Tests service propagation.
tests/unit/manager/api/auth/test_handlers.py Tests API response fields.
changes/13777.feature.md Documents the feature.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

`AuthorizationResult` and `AuthSuccessResponse` carry `UserID`, `AccessKey`,
`SecretKey` and `UserRole` instead of bare `uuid.UUID` / `str`. The user id is
required on the wire: the manager always sends it, and a web server or SDK
newer than the manager it talks to is not a supported combination.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added size:L 100~500 LoC and removed size:M 30~100 LoC labels Aug 14, 2026
@jopemachine
jopemachine requested a balanced review from Copilot August 14, 2026 09:35
jopemachine and others added 2 commits August 14, 2026 18:36
…d fields

CI typechecks and runs the whole tree, so the response wrapper, both parse
cases, the handler fixture and the client-side authorize fixture all needed
the typed key values and the user id.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jopemachine
jopemachine force-pushed the feature/BA-7364-auth-response-user-identity branch from 1c8bb74 to b581df7 Compare August 14, 2026 09:37
@github-actions github-actions Bot added size:M 30~100 LoC and removed size:L 100~500 LoC labels Aug 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/ai/backend/web/server.py:772

  • The token-login path also turns a missing optional user ID into the literal string "None". Preserve the null value so sessions created against an older manager remain identifiable as lacking a user ID.
            "user_id": str(token.user_id),

src/ai/backend/common/dto/manager/auth/types.py:60

  • user_id is required here, so parse_auth_response() rejects successful responses from older managers that omit it. That contradicts the stated mixed-version wire compatibility; make it nullable with a default just like rate_limit.
    user_id: UserID

src/ai/backend/web/server.py:509

  • Once the advertised optional user_id is accepted, str(None) stores the literal string "None" rather than an absent ID. Downstream session consumers can then treat it as an ID and fail to parse it; preserve None in the session instead.

This issue also appears on line 772 of the same file.

                    "user_id": str(token.user_id),

jopemachine and others added 2 commits August 14, 2026 18:40
…r secret

`keypairs.secret_key` is NOT NULL, so the fallback could never be reached.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A missing field defaulting to null reads as unlimited, so an incomplete
payload would silently disable the limit. Null stays a valid value — it is
what an unset limit means — but it now has to be sent explicitly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jopemachine
jopemachine force-pushed the feature/BA-7364-auth-response-user-identity branch from bc83a6c to c3fdc55 Compare August 14, 2026 09:43
seedspirit
seedspirit previously approved these changes Aug 14, 2026
Comment thread src/ai/backend/common/dto/manager/auth/types.py Outdated
The limit is a resource policy value, not part of who authenticated, and a
session snapshot of it goes stale: the manager reads the policy per request
while a web server session would hold the login-time value for up to a week.
The web server will read it from the shared rate limit Redis DB instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@jopemachine jopemachine changed the title feat(BA-7364): deliver the user id and rate limit in the auth response feat(BA-7364): deliver the login user id in the auth response Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:common Related to Common component comp:manager Related to Manager component comp:webserver Related to Web Server component size:M 30~100 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants