Prune login_activities older than 13 months (stored IPs and typed emails are kept forever)

未关闭 适合新手
#7,296 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@KoushikSagarr 已经在做这个了。

开始于 2026年11月8日。

  • #7357 来自 @KoushikSagarr —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
rails, ruby
领域
backend, database

调研方向

从 app/models/metrics_report.rb(active_users_by_type、ALLOWED_RANGES)开始,确认 12 个月的时间窗口,然后查看 lib/tasks/expire_case_contact_drafts.rake 了解 rake 任务的写法。新增 app/services/prune_login_activities_service.rb,对 LoginActivity 使用 in_batches.delete_all,时间窗口可配置且至少为 13 个月。完成标准是 spec/models/metrics_report_spec.rb 中的规范和新的服务规范全部通过,并且 rake 任务会输出被删除的记录数。

由索引模型根据 Issue 内容生成。

描述

Difficulty: Easy Good First Issue Help Wanted

Problem

login_activities (written by the authtrail gem on every Devise sign-in attempt) is never pruned. It's the second-largest table in production (~8 MB, behind only case_contacts), and every row holds personal data:

  • identity: the email that was typed, including failed attempts, which can be mistyped emails or other people's addresses
  • ip, user_agent, referrer
  • user_id, success, failure_reason, created_at

(Geocoding is off in config/initializers/authtrail.rb, so city/region/country/latitude/longitude are empty.)

Keeping this forever adds privacy risk without benefit. The only reader in the app is the all-CASA-admin Metrics page: "Monthly active users", MetricsReport#active_users_by_type in app/models/metrics_report.rb. Its widest range is 12 months (ALLOWED_RANGES = [3, 6, 12]).

Related: #7263 (PII in logs and Bugsnag).

Proposal

Keep 13 months of login activity (the 12-month metrics window plus the partial current month) and delete older rows daily.

  • A service, e.g. app/services/prune_login_activities_service.rb, that deletes LoginActivity.where(created_at: ...13.months.ago) with in_batches.delete_all so a large first run doesn't hold one long transaction. It returns the count deleted. Make the window configurable (LOGIN_ACTIVITY_RETENTION_MONTHS, default 13, minimum 13) so it can never cut into the metrics window.
  • A rake task rake prune_login_activities that calls it and prints the count. Follow the style of lib/tasks/expire_case_contact_drafts.rake.
  • Specs:
    • deletes rows older than the window
    • keeps rows inside it
    • refuses a window under 13 months
    • the Metrics page's 12-month monthly-active-users numbers are unchanged after pruning (spec/models/metrics_report_spec.rb)
  • Note in the PR description that a maintainer must add the task to Heroku Scheduler (daily).

Out of scope

Changing what authtrail records, e.g. not storing identity for failed attempts. That's worth a separate discussion under #7263.

Difficulty: beginner. One service, one rake task, specs.

主要语言
Ruby
星标
384
派生
558
平均合并
1 天 7 小时
30 天内合并 PR
63

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rubyforgood/casa 的其他 Issue

查看 rubyforgood/casa 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。