Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions Bugzilla/Auth/Login/Cookie.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sub get_login_info {
my ($self) = @_;
my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
my ($user_id, $login_cookie, $is_internal);
my ($user_id, $login_cookie);

$login_cookie = $cgi->cookie("Bugzilla_logincookie");
$user_id = $cgi->cookie("Bugzilla_login");
Expand Down Expand Up @@ -68,7 +68,6 @@ sub get_login_info {
Bugzilla->check_rate_limit('token_mismatch');
ThrowUserError('auth_invalid_token', {token => $api_token});
}
$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.


Expand Down Expand Up @@ -100,15 +99,6 @@ sub get_login_info {
# If the cookie is valid, return a valid username.
if (defined $db_cookie && secure_compare($cookie_hash, $db_cookie)) {

# forbid logging in with a cookie if only api-keys are allowed
if (i_am_webservice() && !$is_internal) {
my $user = Bugzilla::User->new({id => $user_id, cache => 1});
if ($user->settings->{api_key_only}->{value} eq 'on') {
Bugzilla->check_rate_limit('token_mismatch');
ThrowUserError('invalid_cookies_or_token');
}
}

# If we logged in successfully, then update the lastused
# time on the login cookie
$dbh->do(
Expand Down
8 changes: 0 additions & 8 deletions Bugzilla/Auth/Verify/DB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ sub check_credentials {
$user->update();
}

if (i_am_webservice() && $user->settings->{api_key_only}->{value} eq 'on') {

# api-key verification happens in Auth/Login/APIKey
# token verification happens in Auth/Login/Cookie
# if we get here from an api call then we must be using user/pass
return {failure => AUTH_ERROR, user_error => 'invalid_auth_method',};
}

return $login_data;
}

Expand Down
26 changes: 19 additions & 7 deletions Bugzilla/Install.pm
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,6 @@ sub SETTINGS {
default => 'on',
category => 'Reviews and Needinfo'
},
{
name => 'api_key_only',
options => ['on', 'off'],
default => 'off',
category => 'API'
},
{
name => 'autosize_comments',
options => ['on', 'off'],
Expand All @@ -217,6 +211,14 @@ sub SETTINGS {
];
}

# Settings that used to be defined in SETTINGS and must be deleted, along
# with any user choices for them, from existing installations.
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.

);

use constant SYSTEM_GROUPS => (
{name => 'admin', description => 'Administrators'},
{name => 'tweakparams', description => 'Can change Parameters'},
Expand Down Expand Up @@ -319,6 +321,10 @@ sub update_settings {
foreach my $params (@settings) {
add_setting($params);
}

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?

}
}

sub update_system_groups {
Expand Down Expand Up @@ -590,6 +596,11 @@ issues after the database is completely set up and configured.

Contains information about Settings, used by L</update_settings()>.

=item C<OBSOLETE_SETTINGS>

Names of Settings that are no longer used. L</update_settings()> deletes
them, along with any user choices for them.

=back

=head1 SUBROUTINES
Expand All @@ -598,7 +609,8 @@ Contains information about Settings, used by L</update_settings()>.

=item C<update_settings()>

Description: Adds and updates Settings for users.
Description: Adds and updates Settings for users, and removes any
listed in L</OBSOLETE_SETTINGS>.

Params: none

Expand Down
4 changes: 0 additions & 4 deletions extensions/BMO/lib/Reports/Groups.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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?

$rh_user->{api_key_only}
= $member->settings->{api_key_only}->{value} eq 'on'
? JSON::true
: JSON::false;
}
$users{$login} = $rh_user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
<td nowrap>
[% IF member.mfa %]
[% member.mfa FILTER html %]
[% " (weakened)" IF member.settings.api_key_only.value == "off" %]
[% ELSE %]
-
[% END %]
Expand Down
6 changes: 2 additions & 4 deletions js/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ $(function() {
$('#update').attr('disabled', true);
$('#mfa-totp-enable-code').attr('required', true);
$('#mfa-confirm').show();
$('.mfa-api-blurb').show();
$('#mfa-enable-shared').show();
$('#mfa-enable-totp').show();
$('#mfa-totp-throbber').show();
Expand Down Expand Up @@ -126,7 +125,6 @@ $(function() {
$('#update').attr('disabled', false);
$('#mfa-duo-user').attr('required', true);
$('#mfa-confirm').show();
$('.mfa-api-blurb').show();
$('#mfa-enable-shared').show();
$('#mfa-enable-duo').show();
$('#mfa-password').focus();
Expand All @@ -135,7 +133,7 @@ $(function() {
$('#mfa-disable')
.click(function(event) {
event.preventDefault();
$('.mfa-api-blurb, .mfa-buttons').hide();
$('.mfa-buttons').hide();
$('#mfa-disable-container, #mfa-auth-container').show();
$('#mfa-confirm').show();
$('#mfa-password').focus();
Expand All @@ -147,7 +145,7 @@ $(function() {
$('#mfa-recovery')
.click(function(event) {
event.preventDefault();
$('.mfa-api-blurb, .mfa-buttons').hide();
$('.mfa-buttons').hide();
$('#mfa-recovery-container, #mfa-auth-container').show();
$('#mfa-password').focus();
$('#update').attr('disabled', false).val('Generate Printable Recovery Codes');
Expand Down
1 change: 0 additions & 1 deletion skins/standard/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ th.title {
cursor: help;
}

.mfa-api-blurb,
.mfa-disable-blurb {
width: 70%;
}
Expand Down
25 changes: 0 additions & 25 deletions template/en/default/account/prefs/mfa.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,6 @@
[% END %]
</div>

<p class="mfa-api-blurb">
[% IF user.settings.api_key_only.value == 'on' %]
Enabling two-factor authentication has also required systems that
interface with [% terms.Bugzilla %]'s API to use <a href="[% basepath FILTER none %]userprefs.cgi?tab=apikey">API keys</a>
for authentication.<br>
<br>
While not recommended, this limitation can be lifted by changing the
<a href="[% basepath FILTER none %]userprefs.cgi?tab=settings#api_key_only">Require API key authentication for API requests</a>
preference.
[% ELSE %]
Systems that interface with [% terms.Bugzilla %]'s API are not required to use API keys.<br>
Change the
<a href="[% basepath FILTER none %]userprefs.cgi?tab=settings#api_key_only">Require API key authentication for API requests</a>
preference to enforce API key usage.
[% END %]
</p>

<p class="mfa-disable-blurb">
You will need to disable your two-factor authentication in order to change to a different method.
There will be a small amount of time when your account will not be as secure, so you may use the
Expand Down Expand Up @@ -289,14 +272,6 @@
<b>Submit Changes</b>.
</p>

<p class="mfa-api-blurb" style="display:none">
Enabling two-factor authentication will also require systems that
interface with [% terms.Bugzilla %]'s API to use <a href="[% basepath FILTER none %]userprefs.cgi?tab=apikey">API keys</a>
for authentication. While not recommended, this limitation can be lifted by changing the
<a href="[% basepath FILTER none %]userprefs.cgi?tab=settings#api_key_only">Require API key authentication for API requests</a>
preference after 2FA is enabled.
</p>

<p>
<em>Warning:</em> Changing your Two-factor authentication settings will
automatically log out other login sessions except for the current one.
Expand Down
3 changes: 0 additions & 3 deletions template/en/default/account/prefs/settings.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
</option>
[% END %]
</select>
[% IF setting_name == "api_key_only" %]
[% INCLUDE "mfa/protected.html.tmpl" %]
[% END %]
</td>
</tr>
[% END %]
Expand Down
1 change: 0 additions & 1 deletion template/en/default/global/setting-descs.none.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"bugmail_flag_prefix" => "Add the flag request or answer (e.g. 'needinfo requested:') to the start of the subject line of email about flags requested of me or answered for me",
"possible_duplicates" => "Display possible duplicates when reporting a new $terms.bug",
"requestee_cc" => "Automatically add me to the CC list of $terms.bugs I am requested to review",
"api_key_only" => "Require API key authentication for API requests",
}
%]

Expand Down
4 changes: 0 additions & 4 deletions template/en/default/global/user-error.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1050,10 +1050,6 @@
[% title = "Invalid Attachment ID" %]
The attachment id [% attach_id FILTER html %] is invalid.

[% ELSIF error == "invalid_auth_method" %]
[% title = "Invalid Authentication Method" %]
API key authentication is required.

[% ELSIF error == "invalid_params" %]
[% title = "Invalid Params" %]
API method received invalid params: [% type_error FILTER html %]
Expand Down
57 changes: 3 additions & 54 deletions userprefs.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -260,75 +260,28 @@ sub SaveSettings {

my $settings = $user->settings;
my @setting_list = keys %$settings;
my $mfa_event = undef;

foreach my $name (@setting_list) {
next if !($settings->{$name}->{'is_enabled'});
my $value = $cgi->param($name);
next unless defined $value;
my $setting = new Bugzilla::User::Setting($name);

if (
$name eq 'api_key_only'
&& $user->mfa
&& ($value eq 'off'
|| ($value eq 'api_key_only-isdefault' && $setting->{default_value} eq 'off'))
)
{
$mfa_event = {};
}

if ($value eq "${name}-isdefault") {
if (!$settings->{$name}->{'is_default'}) {
if ($mfa_event) {
$mfa_event->{reset} = 1;
}
else {
$settings->{$name}->reset_to_default;
}
$settings->{$name}->reset_to_default;
}
}
else {
$setting->validate_value($value);
if ($name eq 'api_key_only' && $mfa_event) {
$mfa_event->{set} = $value;
}
else {
$settings->{$name}->set($value);
}
$settings->{$name}->set($value);
}
}

Bugzilla::Hook::process('settings_after_update');

$vars->{'settings'} = $user->settings(1);
clear_settings_cache($user->id);

if ($mfa_event) {
$mfa_event->{reason} = 'Disabling API key authentication requirements';
$mfa_event->{postback}
= {action => 'userprefs.cgi', fields => {tab => 'settings',},};
$user->mfa_provider->verify_prompt($mfa_event);
}
}

sub MfaSettings {
my $mfa_token = shift;
my $user = Bugzilla->user;
return unless $user->mfa;

my $event = $user->mfa_provider->verify_token($mfa_token);

my $settings = $user->settings;
if ($event->{reset}) {
$settings->{api_key_only}->reset_to_default();
}
elsif (my $value = $event->{set}) {
$settings->{api_key_only}->set($value);
}

$vars->{settings} = $user->settings(1);
clear_settings_cache($user->id);
}

sub DoEmail {
Expand Down Expand Up @@ -794,9 +747,6 @@ sub SaveMFAupdate {
$user->set_mfa($mfa);
$user->mfa_provider->enrolled();
Bugzilla->request_cache->{mfa_warning} = 0;
my $settings = Bugzilla->user->settings;
$settings->{api_key_only}->set('on');
clear_settings_cache(Bugzilla->user->id);

$user->set_mfa_required_date(undef); # Clear requirement date if set

Expand Down Expand Up @@ -1169,8 +1119,7 @@ SWITCH: for ($current_tab_name) {
last SWITCH;
};
/^settings$/ && do {
MfaSettings($mfa_token) if $mfa_token;
SaveSettings() if $save_changes;
SaveSettings() if $save_changes;
DoSettings();
last SWITCH;
};
Expand Down