Feature | Implement Two-Factor Authentication (2FA) support for users#126
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-126/ This page is automatically updated on each push to this PR. |
c3c6568 to
15f001a
Compare
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-126/ This page is automatically updated on each push to this PR. |
15f001a to
561ef7c
Compare
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-126/ This page is automatically updated on each push to this PR. |
561ef7c to
c081f57
Compare
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-126/ This page is automatically updated on each push to this PR. |
c081f57 to
d71d733
Compare
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-126/ This page is automatically updated on each push to this PR. |
feat(2fa): add migration for 2FA schema foundation (Phase I) feat(2fa): add UserTrustedDevice entity feat(2fa): add TwoFactorAuditLog entity feat(2fa): add UserRecoveryCode entity feat(2fa): add repository interfaces for 2FA entities feat(2fa): add Doctrine implementations for 2FA repositories feat(2fa): register 2FA repositories in service container test(2fa): add repository round-trip tests for 2FA entities Co-authored-by: Copilot <copilot@github.com>
d71d733 to
1d8c6e4
Compare
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-126/ This page is automatically updated on each push to this PR. |
martinquiroga-exo
left a comment
There was a problem hiding this comment.
@matiasperrone-exo please see comments. Thanks.
| */ | ||
| public function shouldRequire2FA(): bool | ||
| { | ||
| return ($this->isAdmin() || (bool) $this->two_factor_enabled); |
There was a problem hiding this comment.
This should check for members listed in two_factor.enforced_groups not only isAdmin()
public function isAdmin(): bool
{
return $this->belongToGroup(IGroupSlugs::SuperAdminGroup) || $this->belongToGroup(IGroupSlugs::AdminGroup);
}
It only checks for SuperAdminGroup and AdminGroup which is not enough:
'enforced_groups' => [
IGroupSlugs::SuperAdminGroup,
IGroupSlugs::AdminGroup,
IGroupSlugs::OAuth2ServerAdminGroup,
IGroupSlugs::OpenIdServerAdminsGroup,
],
There was a problem hiding this comment.
All tests pass only if shouldRequire2FA() ignores two_factor.enforced_groups
| $this->assertTrue($user->shouldRequire2FA()); | ||
| } | ||
|
|
||
| public function testShouldRequire2FA_oauth2AdminUser(): void |
There was a problem hiding this comment.
This proves OAuth2 admin is not covered
| $setter->invoke($user, 'bogus'); | ||
| } | ||
|
|
||
| public function testShouldRequire2FA_emptyEnforcedGroups_fallsThroughToFlag(): void |
There was a problem hiding this comment.
This test only validates the fallback path (two_factor_enabled flag) and does not actually prove that config('two_factor.enforced_groups') is used.
Even after fixing shouldRequire2FA() to read config, this test would still pass if config logic is broken again.
Add a complementary test where a user belongs to a group in enforced_groups and two_factor_enabled = false, asserting that shouldRequire2FA() returns true. This ensures config-driven enforcement is actually covered.
f75c63d to
4624ff5
Compare
Task:
Ref: https://app.clickup.com/t/86b9h8xt1
Changes
Verification:
Card Description
GOAL
Current state
The User entity (Auth\User) has no 2FA-related properties or methods. Role checking exists via isSuperAdmin() and isAdmin() but there is no mechanism to determine whether a user requires two-factor authentication.
Target state
The User entity exposes the three new database fields as Doctrine-mapped properties and provides the business logic methods needed by the controller and services:
shouldRequire2FA(), enable2FA(), getAvailableTwoFactorMethods(), isTwoFactorMethodEnable(), getTwoFactorMethod(), and the ValidMFAMethods constant.
TASKS
isTOTPConfirmed(), isPassKeyEnabled() return false.
ACCEPTANCE CRITERIA
DEVELOPMENT NOTES
Key files:
Gotchas:
config('two_factor.enforced_groups'), not hardcode group slugs.
Out of scope: Database migration (Ticket 1), controller integration, service layer.