feat(api): CLI password reset with audit + session invalidation #704
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/cli-password-reset-admin"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What/Why
Operator-facing CLI password reset for the self-hosted recovery path. Spec 001 deferred email self-service reset; previously the only recovery was a manual, unaudited DB UPDATE. The old
resetPasswordAsSuperAdminservice method had zero callers and no session invalidation; replaced by an audited CLI flow.Design (per SE-approved plan)
MemoriesApiApplication.maindetects--reset-passwordbefore web boot and runs the flow in a slim Spring context (WebApplicationType.NONE) — only DataSource/JdbcTemplate/TransactionManager/Flyway/Jackson autoconfig + CoreBeans + LocalAuthService + AuditEventService. No Tomcat, no schedulers, no ApplicationRunners, no SecurityConfiguration. Component scan limited by TypeExcludeFilter to the two service classes.LocalAuthService.resetPasswordByEmail(email, newPassword)— normalizes email exactly like authenticate(), distinct unknown-email vs disabled-user errors, reuses existing hashPassword policy (>=12 chars), then in one @Transactional: password update + audit_events row (event_type=password_reset, actor_user_id=NULL, subject_type=user_account, details {actor:cli, target_email}) +DELETE FROM spring_session WHERE principal_name = :userId(FK cascade cleans attributes).resetPasswordAsSuperAdmindeleted.SessionPrincipalIndexConfigurationregisters a SingleIndexResolver on the JdbcIndexedSessionRepository mapping thememories.userIdsession attribute -> principal_name, so new sessions are indexed and invalidatable (V048 added the column, V049 widened it).--password-stdin) orMEMORIES_RESET_PASSWORDenv fallback (warned in docs); argv path rejected (shell-history leak); nothing echoed.Refs: specs/001-v1-baseline (ux-capability-matrix + open-questions updated), docs/adr/0056, docs/dev/cli-password-reset.md.
Test coverage
./gradlew :apps:api:test(full) and:apps:api:buildgreen locally. SecurityConfiguration file itself untouched (verified via git diff).Limitations
Notes
- LocalAuthService.resetPasswordByEmail: normalize email like authenticate(), distinct unknown-email vs disabled-user errors, hash+update+audit+session invalidation in one @Transactional - audit_events row: event_type=password_reset, actor_user_id=NULL, subject_type=user_account, details {actor:cli,target_email} - DELETE FROM spring_session WHERE principal_name=:userId (FK cascade) - remove dead resetPasswordAsSuperAdmin (zero callers) - SessionPrincipalIndexConfiguration: IndexResolver maps memories.userId session attr -> principal_name so new sessions are indexed/invalidatable - MemoriesApiApplication.main routes --reset-password to slim Spring context (WebApplicationType.NONE, no web/schedulers/runners/security) - PasswordResetCli: stdin or MEMORIES_RESET_PASSWORD password (never argv), exit codes 0/1/2/3/4/5 - bump version to 1.21.26