feat(BA-4905): add LoginSecurityPolicy model, login_sessions table, and repository layer#9720
Open
HyeockJinKim wants to merge 6 commits intomainfrom
Open
feat(BA-4905): add LoginSecurityPolicy model, login_sessions table, and repository layer#9720HyeockJinKim wants to merge 6 commits intomainfrom
HyeockJinKim wants to merge 6 commits intomainfrom
Conversation
…ason enum - Add LoginSessionExpiryReason(StrEnum) with LOGOUT/EVICTED/EXPIRED values in data/login_session/types.py - Add LoginSessionData frozen dataclass in data/login_session/types.py - Add LoginSecurityPolicy(BaseModel) Pydantic model in models/login_session/types.py (placed in models/ per CLAUDE.md rules — data/ layer prohibits Pydantic imports) - Document deviation from plan in DEVIATION.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add PydanticColumn(LoginSecurityPolicy) to UserRow.login_security_policy (JSONB, nullable) - Add login_security_policy: dict[str, Any] | None field to UserData (default None) - Update UserRow.to_data() to serialize policy via model_dump() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…in_security_policy column - Create login_sessions table with id (UUID PK), user_uuid (FK users), session_token (unique), client_ip, created_at, expired_at, reason columns - Add index on login_sessions.user_uuid - Add login_security_policy JSONB column to users table - down_revision chains from ffcf0ed13a26 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add LOGIN_SESSION to EntityType enum and LOGIN_SESSION_REPOSITORY to LayerType
- Add to_dataclass() to LoginSessionRow for data layer conversion
- Create LoginSessionCacheSource: Valkey Sorted Set (ZADD/ZSCORE/ZCARD/ZPOPMIN/ZREM)
keyed by login_session:{user_uuid}; uses execute_command for sorted set ops
- Create LoginSessionDBSource: create_session, expire_session, list_active_sessions,
count_active_sessions via SQLAlchemy async
- Create LoginSessionRepository: cache-first reads with DB fallback, DB-first writes
with suppress_with_log for cache failures; includes evict_oldest_session
- Create LoginSessionService with create_session, expire_session, evict_oldest_session,
check_concurrency_limit; follows Action/ActionResult pattern
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
HyeockJinKim
commented
Mar 6, 2026
| container_uid: int | None = field(compare=False) | ||
| container_main_gid: int | None = field(compare=False) | ||
| container_gids: list[int] | None = field(compare=False) | ||
| login_security_policy: dict[str, Any] | None = field(default=None, compare=False) |
Collaborator
Author
There was a problem hiding this comment.
Avoid using dict. We recommend handling data through PydanticModel or dataclass.
Comment on lines
+242
to
+244
| login_security_policy: Mapped[LoginSecurityPolicy | None] = mapped_column( | ||
| "login_security_policy", PydanticColumn(LoginSecurityPolicy), nullable=True | ||
| ) |
Collaborator
Author
There was a problem hiding this comment.
Use the default value rather than leaving it optional.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LoginSecurityPolicyPydantic model withmax_concurrent_logins: int | Nonefield andlogin_security_policyJSONB column onUserRowLoginSessionRowORM model and Alembic migration for thelogin_sessionstable with proper FK, indexes, andLoginSessionExpiryReasonenumLoginSessionRepository(cache-first via Valkey Sorted Set + DB fallback) andLoginSessionService(create/expire/evict/check concurrency) following existing repository and service patternsTest plan
alembic upgrade headLoginSessionRepositoryZADD/ZSCORE/ZCARD/ZPOPMIN/ZREM operations work against ValkeyLoginSessionService.check_concurrency_limitenforcesmax_concurrent_loginscorrectlyResolves BA-4905