Skip to content

feat(notify-expire-priv):增加查询权限到期提醒#3186

Open
RankRao wants to merge 5 commits into
hhyo:masterfrom
RankRao:feat-notify-expire-priv
Open

feat(notify-expire-priv):增加查询权限到期提醒#3186
RankRao wants to merge 5 commits into
hhyo:masterfrom
RankRao:feat-notify-expire-priv

Conversation

@RankRao
Copy link
Copy Markdown
Contributor

@RankRao RankRao commented May 19, 2026

权限优化:当前的查询权限最长为一年,考虑增加定时任务,在权限到期前3天,给管理员和对应的权限人,以邮件形式,发送权限到期提醒。

#2417

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4654c535b1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread sql_api/apps.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 98.55769% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.87%. Comparing base (52387b5) to head (f2278a3).

Files with missing lines Patch % Lines
sql/utils/tasks.py 33.33% 2 Missing ⚠️
sql_api/apps.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3186      +/-   ##
==========================================
+ Coverage   83.67%   83.87%   +0.20%     
==========================================
  Files         140      140              
  Lines       23431    23628     +197     
==========================================
+ Hits        19605    19819     +214     
+ Misses       3826     3809      -17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fa0f54fb4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread sql/query_privileges.py
Comment on lines +657 to +660
admin_emails = list(
Users.objects.filter(is_superuser=True, email__isnull=False)
.exclude(email="")
.values_list("email", flat=True)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Notify query managers, not only superusers

The repo treats users with sql.query_mgtpriv as query-permission managers (for example, the modify endpoint is gated by that permission), but this reminder builds the admin recipient list from is_superuser=True only. In deployments where resource-group/query admins are ordinary users with query_mgtpriv, expiring privileges will only CC superusers and the actual managers responsible for renewing/cleaning up those privileges will never be notified.

Useful? React with 👍 / 👎.

Comment thread sql/query_privileges.py
Comment on lines +674 to +676
if not user_email:
logger.warning(f"用户 {user_name} 未配置邮箱,跳过权限到期提醒")
continue
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Still notify admins when the owner lacks email

When an expiring privilege belongs to an account without an email address, this continue skips the entire reminder for that user's privileges, including the admin CC list that was already built above. For service/LDAP users or stale accounts without email, nobody is alerted before the permission expires even though the feature is meant to notify administrators as well as the permission holder.

Useful? React with 👍 / 👎.

Comment thread sql_api/apps.py
Comment on lines +15 to +16
if not Schedule.objects.filter(name="查询权限到期提醒").exists():
add_query_priv_expire_reminder_schedule()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Make schedule creation idempotent across workers

Because AppConfig.ready() runs in every Django process, multiple web/qcluster workers starting against a database that does not yet have this schedule can all pass the exists() check before any one creates it, and then each calls schedule(). Since the schedule name is only used as data here, that race leaves duplicate daily reminders and users/admins receive the same expiry email multiple times; create the row atomically or enforce a unique schedule before scheduling.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant