Skip to content

Bug 2099092 - Remove the obsolete api_key_only user preference now that the native REST API only accepts API keys, OAuth2 tokens, or cookie + api token - #2849

Open
dklawren wants to merge 1 commit into
mozilla:masterfrom
dklawren:2099092

Conversation

@dklawren

Copy link
Copy Markdown
Collaborator

Summary

Removes the api_key_only user preference ("Require API key authentication for API requests"). Every API endpoint now authenticates through the native Mojo login helper (Bugzilla/App/Plugin/Login.pm), which accepts only API keys, OAuth2 bearer tokens, or a login cookie plus Bugzilla_api_token. The username/password and login-token methods this preference blocked are no longer accepted anywhere, so the setting had no effect.

Follow-up of 2081819.

Changes

  • Bugzilla/Auth/Login/Cookie.pm and Bugzilla/Auth/Verify/DB.pm: drop the api_key_only checks, which can't be reached from the API, and the now unused invalid_auth_method error.
  • Bugzilla/Install.pm: remove the setting and add an OBSOLETE_SETTINGS list that update_settings() passes to remove_setting(), so checksetup deletes the existing setting, setting_value and profile_setting rows.
  • userprefs.cgi: remove the MFA prompt for turning the setting off (MfaSettings) and stop forcing it on when MFA is enabled.
  • MFA and settings preference templates, js/account.js, skins/standard/admin.css: remove the API key blurb and the settings-row MFA icon.
  • BMO group members report: remove the "(weakened)" marker and the api_key_only key from the JSON output.

Test plan

  • test_sanity passes (65 files, 18124 tests)
  • Run checksetup.pl on an existing database: the api_key_only rows are removed, and running it again is a no-op
  • Preferences > General Preferences: no API section, and saving other settings works without an MFA prompt
  • Enable TOTP 2FA: the confirm step no longer mentions API keys, and enrollment completes
  • page.cgi?id=group_members.html for a privileged group: the MFA column shows the method without "(weakened)"

References

…at the native REST API only accepts API keys, OAuth2 tokens, or cookie + api token

All API endpoints now authenticate through the native Mojo login helper,
which never consulted api_key_only and does not accept the
username/password or login-token methods the preference blocked. The
remaining checks in the legacy auth stack are unreachable from the API.

- Drop the api_key_only checks from Auth::Login::Cookie and
  Auth::Verify::DB, along with the now unused invalid_auth_method error.
- Remove the setting and delete existing rows via a new
  OBSOLETE_SETTINGS list processed by update_settings().
- Remove the MFA-gated save logic for the setting from userprefs.cgi
  and the related MFA page text, JS and CSS.
- Remove the "(weakened)" marker and api_key_only field from the BMO
  group members report.
Copilot AI balanced review requested due to automatic review settings November 30, 2026 03:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the removal of the obsolete api_key_only preference and its related authentication, MFA, and UI handling.

No open issues 🎉

What changed in this PR

Removes the obsolete api_key_only preference now that the native REST API enforces supported authentication methods independently of this setting.

Changes:

  • Deletes the preference and adds upgrade cleanup for stored settings and user choices.
  • Removes preference-dependent authentication checks and MFA handling.
  • Cleans up related UI text, styling, and group-report output.
File Description
userprefs.cgi Removes MFA verification for disabling the preference and forced activation during enrollment.
template/​en/​default/​global/​user-error.html.tmpl Removes the unused authentication-method error.
template/​en/​default/​global/​setting-descs.none.tmpl Removes the preference description.
template/​en/​default/​account/​prefs/​settings.html.tmpl Removes the preference’s MFA protection icon.
template/​en/​default/​account/​prefs/​mfa.html.tmpl Removes obsolete API-key guidance from MFA screens.
skins/​standard/​admin.css Removes the deleted MFA blurb’s selector.
js/​account.js Removes visibility handling for the deleted blurb.
extensions/​BMO/​template/​en/​default/​pages/​group_members.html.tmpl Removes the preference-dependent “weakened” MFA marker.
extensions/​BMO/​lib/​Reports/​Groups.pm Removes api_key_only from report JSON.
Bugzilla/​Install.pm Removes the setting definition and adds documented obsolete-setting cleanup.
Bugzilla/​Auth/​Verify/​DB.pm Removes the preference-dependent password authentication restriction.
Bugzilla/​Auth/​Login/​Cookie.pm Removes the preference-dependent cookie restriction and unused tracking variable.

Review effort: Balanced

@dklawren
dklawren requested review from Xzzz and cgsheeh November 30, 2026 03:29

@Xzzz Xzzz left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Checked nothing is left behind, checksetup cleanup works and can run safely and nothing else depends on what was removed.

=> All looks good to me, thanks Dave! :)

Just one small thing, out of the review: OBSOLETE_SETTINGS constant has only one entry, a direct remove_setting('api_key_only') (as BugModal does) would be enough ;)

Comment thread Bugzilla/Install.pm
}

foreach my $name (OBSOLETE_SETTINGS) {
remove_setting($name);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we deploy with old and new pods serving traffic at once? If checksetup deletes the setting rows while old code is still running, SaveMFAupdate on an old pod would call ->set('on') on an autovivified unblessed hash and die for anyone enrolling in MFA. Should we hold off on remove_setting until a later release, or is that window small enough not to matter?

Comment thread Bugzilla/Install.pm
use constant OBSOLETE_SETTINGS => (

# 2026-11-29 -- Bug 2099092
'api_key_only',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we add a test for OBSOLETE_SETTINGS (maybe alongside t/sqlite-memory.t), checking that update_settings() removes the setting, setting_value and profile_setting rows and that a second run is a no-op? The test plan says this was checked by hand, but it seems worth keeping as a regression test now that the list will grow.

}
$is_internal = 1;
}
elsif ($login_cookie && Bugzilla->usage_mode == USAGE_MODE_REST) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If no API request reaches Bugzilla::Auth::Login::Cookie anymore, aren't the rest of the i_am_webservice() branches here (Bugzilla_api_token, login_token, the invalid_cookies_or_token error) also dead? Should we file a follow-up to remove those too, so the next reader doesn't assume they still guard the API?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Well spotted! 👍 And I agree: nothing calls Bugzilla->login() in a REST usage context anymore, the Mojo login plugin does its own checks, so the i_am_webservice() branches in Cookie.pm are dead (and probably most of Bugzilla::Auth::Login::APIKey, which returns AUTH_NODATA outside of them).
As it fits the REST-to-Mojo cleanup (2057358), I can file the follow-up and work on it, if everyone agrees.

@@ -251,10 +251,6 @@ sub members_report {
$rh_user->{groups} = [$rh->{name}];
$rh_user->{lastseeon} = $member->last_seen_date;
$rh_user->{mfa} = $member->mfa;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The bug says consumers of the group members JSON output should be told that api_key_only is going away. Do we know who uses it (e.g. security/compliance scripts), and has anyone been contacted yet?

This branch has not been deployed

No deployments
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.

4 participants