-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: Add SetupCheck to warn about missing second factor provider #57854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Settings\SetupChecks; | ||
|
|
||
| use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor; | ||
| use OC\Authentication\TwoFactorAuth\ProviderLoader; | ||
| use OC\Authentication\TwoFactorAuth\ProviderSet; | ||
| use OCP\IL10N; | ||
| use OCP\SetupCheck\ISetupCheck; | ||
| use OCP\SetupCheck\SetupResult; | ||
|
|
||
| class TwoFactorConfiguration implements ISetupCheck { | ||
| public function __construct( | ||
| private IL10N $l10n, | ||
| private ProviderLoader $providerLoader, | ||
| private MandatoryTwoFactor $mandatoryTwoFactor, | ||
| ) { | ||
| } | ||
|
|
||
| public function getName(): string { | ||
| return $this->l10n->t('Second factor configuration'); | ||
| } | ||
|
|
||
| public function getCategory(): string { | ||
| return 'security'; | ||
| } | ||
|
|
||
| public function run(): SetupResult { | ||
| $providers = $this->providerLoader->getProviders(); | ||
come-nc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $providerSet = new ProviderSet($providers, false); | ||
| $primaryProviders = $providerSet->getPrimaryProviders(); | ||
| if (count($primaryProviders) === 0) { | ||
| return SetupResult::warning($this->l10n->t('This instance has no second factor provider available.')); | ||
| } | ||
|
Comment on lines
+39
to
+41
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use SSO on my instance (with enforced 2FA), so after the update my admin overview tells me that this is an issue. Could this setup check also check if there are other backends and hide itself, because it can't know if 2FA is enabled/enforced in that case?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Having other backends is not enough reason to hide it. Basically all backends would need it, and then there is still the installing admin user on the database backend.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually don't have an admin user who is on the DB backend since #53212 |
||
|
|
||
| $state = $this->mandatoryTwoFactor->getState(); | ||
|
|
||
| if (!$state->isEnforced()) { | ||
come-nc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return SetupResult::info( | ||
| $this->l10n->t( | ||
| 'Second factor providers are available but two-factor authentication is not enforced.' | ||
| ) | ||
| ); | ||
| } else { | ||
| return SetupResult::success( | ||
| $this->l10n->t( | ||
| 'Second factor providers are available and enforced: %s.', | ||
| [ | ||
| implode(', ', array_map( | ||
| fn ($p) => '"' . $p->getDisplayName() . '"', | ||
| $primaryProviders) | ||
| ) | ||
| ] | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.