Skip to content

Commit 86911bb

Browse files
jopemachineclaude
andcommitted
refactor(BA-7364): drop the rate limit from the auth response
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>
1 parent c3fdc55 commit 86911bb

10 files changed

Lines changed: 1 addition & 15 deletions

File tree

changes/13777.feature.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Return the login user's id and rate limit from the authorization API, and keep both in the web server session.
1+
Return the login user's id from the authorization API and keep it in the web server session.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class AuthSuccessResponse(AuthResponse):
5858
status: str
5959
session_token: str
6060
user_id: UserID
61-
rate_limit: int | None
6261
type: AuthTokenType = AuthTokenType.KEYPAIR
6362

6463
def to_dict(self) -> dict[str, Any]:

src/ai/backend/manager/api/rest/auth/handler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ async def authorize(
169169
status=auth_result.status,
170170
session_token=auth_result.session_token,
171171
user_id=auth_result.user_id,
172-
rate_limit=auth_result.rate_limit,
173172
)
174173
resp = AuthorizeResponse(data=data)
175174
return APIResponse.build(HTTPStatus.OK, resp)

src/ai/backend/manager/data/auth/types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class AuthorizationResult:
2929
role: UserRole
3030
status: str
3131
session_token: str
32-
rate_limit: int | None
3332

3433

3534
@dataclass

src/ai/backend/manager/services/auth/service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,6 @@ async def _create_login_session(
416416
role=UserRole(user.role),
417417
status=user.status,
418418
session_token=session_result.session_token,
419-
# TODO: take this from the user resource policy instead of the keypair.
420-
rate_limit=keypair_row.rate_limit,
421419
),
422420
)
423421

src/ai/backend/web/server.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ async def _set_login_history(last_login_attempt: float, login_fail_count: float
507507
"role": token.role,
508508
"status": token.status,
509509
"user_id": str(token.user_id),
510-
"rate_limit": token.rate_limit,
511510
}
512511
public_return = {
513512
"access_key": token.access_key,
@@ -770,7 +769,6 @@ async def token_login_handler(request: web.Request) -> web.Response:
770769
"role": token.role,
771770
"status": token.status,
772771
"user_id": str(token.user_id),
773-
"rate_limit": token.rate_limit,
774772
}
775773
public_return = {
776774
"access_key": token.access_key,

tests/unit/client_v2/test_auth_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ async def test_authorize(self, sample_client_type_id: UUID) -> None:
8282
"status": "active",
8383
"session_token": "test_session_token",
8484
"user_id": "12345678-1234-5678-1234-567812345678",
85-
"rate_limit": None,
8685
"type": AuthTokenType.KEYPAIR,
8786
},
8887
}

tests/unit/common/dto/manager/auth/test_auth_response.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def test_authorize_response() -> None:
3434
status="active",
3535
session_token="test_session_token",
3636
user_id=UserID(uuid4()),
37-
rate_limit=None,
3837
type=AuthTokenType.KEYPAIR,
3938
)
4039
resp = AuthorizeResponse(data=data)

tests/unit/common/dto/manager/auth/test_auth_types.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def test_auth_success_response_creation() -> None:
4545
status="active",
4646
session_token="test_session_token",
4747
user_id=UserID(uuid4()),
48-
rate_limit=None,
4948
)
5049
assert resp.access_key == "AKTEST"
5150
assert resp.secret_key == "SKTEST"
@@ -63,7 +62,6 @@ def test_auth_success_response_to_dict() -> None:
6362
status="active",
6463
session_token="test_session_token",
6564
user_id=UserID(uuid4()),
66-
rate_limit=None,
6765
type=AuthTokenType.JWT,
6866
)
6967
d = resp.to_dict()
@@ -125,7 +123,6 @@ def test_parse_auth_response_success() -> None:
125123
"status": "active",
126124
"session_token": "test_token",
127125
"user_id": "12345678-1234-5678-1234-567812345678",
128-
"rate_limit": None,
129126
}
130127
result = parse_auth_response(data)
131128
assert isinstance(result, AuthSuccessResponse)
@@ -162,7 +159,6 @@ def test_parse_auth_response_explicit_success() -> None:
162159
"status": "active",
163160
"session_token": "test_token",
164161
"user_id": "12345678-1234-5678-1234-567812345678",
165-
"rate_limit": None,
166162
}
167163
result = parse_auth_response(data)
168164
assert isinstance(result, AuthSuccessResponse)

tests/unit/manager/api/auth/test_handlers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ def authorize_result(self) -> AuthorizeActionResult:
248248
role=UserRole.USER,
249249
status=UserStatus.ACTIVE,
250250
session_token="test_session_token",
251-
rate_limit=30000,
252251
),
253252
)
254253

0 commit comments

Comments
 (0)