Repository navigation
feat(idp): add built-in two-factor authentication (TOTP) to the builtin IDP - #4001
davemathews12 wants to merge 4 commits into
Conversation
Users of the builtin IDP can protect their account with a time-based one-time password (RFC 6238) from an authenticator app. It is optional per user and available by default, IDP_MFA_ENABLED=false switches it off. - new page /signin/v1/mfa to set up, turn off and get recovery codes - the login page asks for a code after the password - the second factor is checked in a wrapper around the lico identifier backend, after the password was verified - secrets are stored encrypted, recovery codes hashed - `opencloud idp mfa list|disable` for administrators
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| ErrorProne | 1 high |
🟢 Metrics 448 complexity · -3 duplication
Metric Results Complexity 448 Duplication -3
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
- return to the two-factor page after login via the router instead of a redirect built from props - use function declarations and drop unused imports in the new page - read the logon result header by its literal name - document why SHA-1 (HMAC-SHA1, RFC 6238) and the configured CA file path are fine and silence the findings
|
Hi! This is my first contribution here, so please tell me if I should do anything differently. The server part is in this pull request, the matching switch for the account settings is in opencloud-eu/web#4471, and the idea is described in #3999. I saw #1695 and the plan in #355 to embed Authelia. but I'm offering it as something that works with the current built-in IDP today. I'm happy to make any changes you need to get this integrated, for example making it opt-in instead of on by default?, splitting it into smaller pull requests, or adding acceptance tests. Just let me know what you'd prefer. i really love this proyect! ai disclosure: this was NOT vibe coded, but I used an LLM for some testing and reviewing |
|
Update: as suggested in #3999, I've also proposed the second factor step upstream in libregraph/lico#305. So there are two options now we can go now?:
Both use the same settings, setup page and account switch (opencloud-eu/web#4471). I'm happy to go with whichever you prefer. even a redesign, or well... anything, just ask me! |
The lock after five wrong codes ended after five minutes and the count started again, so somebody who has the password could keep on guessing five codes every five minutes. Every further round of wrong codes now doubles the lock, up to a day, until a correct code is entered.
The settings page keeps the view and the data only it shows in one state, so they change in one update and a view never renders without its data. The second step of the login page is a component of its own, and a logon refused by the second factor is built in one place. The password check moves next to the backend it uses.
|
Pushed two follow-ups:
The lico-based variant (branch idp-totp-mfa-lico) is updated to match libregraph/lico#305 as reworked after longsleep's feedback, so both options stay available. |
Description
Adds built-in two-factor authentication (TOTP, RFC 6238) to the builtin IDP. It is optional per user: only users who turn it on are asked for a code. It is available by default without configuration,
IDP_MFA_ENABLED=falseswitches it off (then the unchanged lico LDAP backend is registered and no new routes are mounted)./signin/v1/mfato set it up (password, QR code, confirm with a code, ten recovery codes), turn it off or get new recovery codes. The login page asks for a code after the password. Web, desktop and mobile clients all use this page.opencloud idp mfa listandopencloud idp mfa disable <user>. SettingsIDP_MFA_ENABLED,IDP_MFA_ISSUER,IDP_MFA_STORE*.How it works:
services/idp/pkg/mfaholds TOTP (stdlib only), storage, the settings API and a wrapper around the lico identifier backend. The second factor is checked in the wrappedLogon, after the password. Without a code it fails closed.params. A rejected logon keeps lico's204and adds the headerOpenCloud-MFA: required|invalid|locked, only after a correct password.pkg/backends/ldap/bootstrapis a copy with the wrapper added (like the cs3 bootstrap). Only used when the feature is on.IDP_ENCRYPTION_SECRET_FILE, recovery codes as hashes. Codes are single use, five wrong codes lock for five minutes.Related Issue
Motivation and Context
Small deployments on the builtin IDP have no second factor without running an external IDP.
How Has This Been Tested?
opencloud serverfrom this branch, demo users,ldapidentity manager,nats-js-kvstorego test -race ./services/idp/...OpenCloudDesktop,OpenCloudAndroid,OpenCloudIOSthrough the login page with device emulation, incl. consent, token, refreshNot tested: the
cs3identity manager end to end, the real apps on real devices, scanning the QR code with a phone, several idp instances, the project CI, golangci-lint and acceptance tests.Screenshots
Types of changes
Checklist:
Notes for reviewers
nats-js-kvon127.0.0.1:9233) and logins fail closed when it cannot. Single-binary and compose deployments work as is; deployments that run idp separately needIDP_MFA_STORE_NODES. If you prefer opt-in, it is a one-line change of the default.translation.potwas not regenerated.qrcode.react(ISC).