Email the owner when a GPG key update adds a subkey or user ID
What does this MR do and why?
This MR builds on !265240 and merges after it. Until then it also carries that MR's commit, so the change to review is the last commit.
When an update of a GPG key adds a subkey or a user ID, this MR emails the owner "GPG key in your account was updated", as GitLab already does when a key is added, so that a change they did not make does not go unnoticed. The email names the key's fingerprint and the subkeys the update added. A revocation or a new expiration date sends nothing.
- Feature flag: the email is behind
updated_gpg_key_email(gitlab_com_derisk, off by default), becausedoc/development/emails.mdasks for a new mailer method to be wrapped in one. The update itself is not behind it. Rollout issue: #636223. - No changelog entry while the flag is off.
Gitlab::Gpg.merge_keynow also reports how many user IDs the merge added.- Docs: a history item and a flag note in "Update a GPG key".
How I tested it
Ruby 3.3.11 and PostgreSQL 17, without the GDK:
bundle exec rspec spec/services/repositories/gpg_keys/update_service_spec.rb spec/lib/gitlab/gpg_spec.rb: 70 examples, 0 failures.bundle exec rspec spec/mailers/emails/profile_spec.rb:142 spec/mailers/emails/profile_spec.rb:172 spec/services/notification_service_spec.rb:367: 21 examples, 0 failures.bundle exec rspec spec/mailers/previews_spec.rb -e gpg_key_email: 2 examples, 0 failures.- RuboCop, haml-lint,
gettext_extractor, markdownlint-cli2 and Vale on the changed files: clean.
With the code of !265240 alone, the email examples of the service spec, the new_user_ids examples, and all 11 new mailer and notification examples fail.
References
Related to #296977
- Builds on !265240.
- Rollout issue: #636223.
- Milestone: 19.6, as in the flag definition. I cannot set it myself.
Screenshots or screen recordings
The email, text part
The HTML part has the same text, with the fingerprints as code and "GPG keys" as a link.
Hi <name>!
A GPG key in your account was updated. The update added subkeys or user IDs to the key with this fingerprint:
Fingerprint: <fingerprint>
New subkeys:
- <subkey fingerprint>
If you did not update this key, revoke or remove it at <GPG keys URL>How to set up and validate locally
- Enable the flag in the Rails console:
Feature.enable(:updated_gpg_key_email). - Update a GPG key with a new subkey, as in the steps of !265240. The email arrives at
/rails/letter_opener. - Update it again with only a new expiration date (
g --quick-set-expire "$FPR" 2y). No email is sent.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.