feat(mfa): add schema for recovery codes factor - #2725
Conversation
xlgmokha
left a comment
There was a problem hiding this comment.
I left a few questions for you to consider. Otherwise, it looks good to me.
| id uuid primary key, | ||
| user_id uuid not null unique references {{ index .Options "Namespace" }}.users (id) on delete cascade, | ||
| mfa_factor_id uuid not null unique references {{ index .Options "Namespace" }}.mfa_factors (id) on delete cascade, | ||
| failed_verification_count integer not null default 0 check (failed_verification_count >= 0), |
There was a problem hiding this comment.
what do you think about failed_attempts vs. failed_verification_count? thinking this terminology would be a good thing to align on because I'll be adding a similar column as part of the OTP work.
There was a problem hiding this comment.
I don't have a strong opinion as both make sense. The verification terminology comes from the POST /factors/recovery-codes/verify and the rest of the MFA factors.
It boils down to building the feature around the specific MFA terminology versus having something more generic: #2725 (comment)
| user_id uuid not null unique references {{ index .Options "Namespace" }}.users (id) on delete cascade, | ||
| mfa_factor_id uuid not null unique references {{ index .Options "Namespace" }}.mfa_factors (id) on delete cascade, | ||
| failed_verification_count integer not null default 0 check (failed_verification_count >= 0), | ||
| verification_locked_until timestamptz, |
There was a problem hiding this comment.
nit: wondering if verification_* as a prefix is necessary, or if we could just do locked_until
There was a problem hiding this comment.
It's for consistency between failed_verification_count and verification_locked_until.
713c62f to
5f66657
Compare
- Adds unique user_id to mfa_recovery_code_sets as a workaround to avoid creating a unique index on mfa_factors (user_id) which would impact large tables. - Renames fields for consistency - Adds unique index on mfa_recovery_codes (mfa_recovery_code_set_id, code_hash) to prevent duplicate codes per set.
Adds the schemas required to support MFA recovery codes factor.
Note
To avoid long running migration on Auth server startup due to
mfa_factors (user_id) where factor_type = 'recovery_codes', we've decided to denormalize theuser_idfield and add it to themfa_recovery_code_setswhich would provide similar guarantees of a user only allowed to have a single set of recovery codes.