I'm not sure if this is a bug or a documentation issue, but it poses an issue when setting up the module.
If someone that is not user 1 enables this module, there is no way to log in as user 1. Since core automatically returns TRUE for any user_access call on user number 1, the admin user is forced into having "require TFA" as TRUE.
- remove the 'require tfa' permission from tfa.module
- alter the permission check in tfa_login_submit() and tfa_user_login() to call a hook for whether login is blocked
- update tfa.test to remove requirement check
- document this new hook in the readme
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 2371315-tfa-require-hook-31.patch | 6.86 KB | coltrane |
| #30 | 2371315-tfa-require-hook-30.patch | 6.81 KB | coltrane |
| #29 | 2371315-tfa-require-hook-29.patch | 6.96 KB | coltrane |
| #28 | 2371315-27-28-interdiff-do-not-test.patch | 4.72 KB | coltrane |
| #28 | 2371315-tfa-require-hook-28.patch | 7.04 KB | coltrane |
Comments
Comment #1
morseCode commentedComment #2
coltraneHi, thanks for raising this issue. It's true that because the 'require TFA' permission defaults to enabled for the administrator role that once TFA is enabled it can lock out the UID 1 user.
One proposal might be to expose a UID1 TFA bypass option on the TFA admin settings page. Something like "Allow UID 1 to skip TFA login requirement when they haven't set up TFA".
What do think of an option like that?
Comment #3
morseCode commentedI think that would work just fine.
I also wrote a small module that forces users to enable TFA after they log in. essentially it defines a new permission called "force TFA" that allows the user to sign in, but then uses hook_page_alter to restrict the user to only using user/* paths. If they attempt to use any other paths after logging in, they get a message saying they have to enable TFA along with a very rude drupal_goto that sends them to the TFA setup page.
If you are interested, i will share the code.
Comment #4
coltrane@morseCode I've done similar code before with TFA so there's definitely need for something like that. Are you using that with TFA Basic module? If so perhaps that's a worthy feature to add to it. Otherwise it could be a separate module.
Comment #5
morseCode commentedyes, i am using it with the TFA Basic module. I have it here: https://www.drupal.org/sandbox/morsecode/2372189
Comment #6
morseCode commented@coltrane,
After another review, i realized that i am getting the TFA module and TFA basic mixed together in my head. This module i wrote would be better suited for addition to TFA basic as it is dependent on the tfa_basic_get_tfa_data function which determines if the user has enrolled in TFA.
Thanks!
Comment #7
johnennew commentedI've just been testing the TFA module and got the same issue with user 1.
I was thinking the permission "Require TFA" should instead be "Bypass TFA if not configured"
There should then also be a module setting called 'Require TFA' which redirects a user to the user/security page after they login until they have setup their TFA unless they have the permission "Bypass TFA if not configured".
This means User 1 always has to opt into TFA.
Comment #8
johnennew commentedPlease find attached a patch which does the following:
1. Gives special consideration to user 1 so it is never locked out by the 'require tfa' permission. User 1 must opt into TFA by completing the TFA setup.
2. Adds a workflow such that once a user logs in they must then complete TFA setup using the code @morseCode provided as a base. This is a less aggressive option than 'require tfa' which prevents login if TFA is not setup.
3. Adds a new permission 'bypass tfa setup' to prevent the action introduced by 2 above on a per role basis
This solves my particular workflow and I hope it is of interest to others.
Also, I shouldn't the permission 'setup own tfa' be provided by the TFA module rather than tfa_basic?
Comment #9
johnennew commentedPlease find a better patch attached with some typos corrected.
Comment #10
johnennew commentedComment #11
pachabhaiya commentedPatch #9 works perfectly for my workflow too.
Thanks !
Comment #12
jibranThis fix the problem for me. Made some doc changes.
I think we should add some kind of setting to tfa_admin_settings page for that.
Comment #13
pachabhaiya commented@jibran
Great !!!... it worked for you too.
One thing, your patch file seems to be empty.
Comment #14
jibranThanks for pointing that.
At least interdiff was there :P
Comment #15
realkevinoshea commentedPatch in #14 seems to force all users to use TFA even if they do not have the require TFA permission. Updated patch to fix that attached.
In the long term is a permission really the right place to be defining who is required to use TFA? It is not really a permission and setting it in another manner would clear up this whole ugly deal with UID 1.
Comment #17
realkevinoshea commentedI could be wrong but I believe the tests are only failing because the user in the test does not have the require tfa permission set. Adding that to patch.
Comment #18
realkevinoshea commentedComment #19
coltraneThanks all for the code and reviews here, but I think this needs to be split up. The User 1 login without TFA setup permission change is right for TFA module but the user/security path is defined by TFA Basic module so needs to be there.
Comment #20
realkevinoshea commented@coltrane: That makes sense to me. I would like to get this patched and working properly so that we don't have to worry about our site breaking when upgrading to future versions of your modules.
What course would you recommend in the short term? Sticking with the logic from this patch of completely excluding UID 1 (maybe this should be a setting?) and then go with the same type of bypass permission in this patch but moved to the appropriate place in the TFA Basic module?
Long term what do you think about the idea of moving require TFA out of permissions entirely and avoiding the whole UID 1 issue? I think this might make sense as you could open up the ability to require TFA for a single user, with a hook, etc. "require TFA" doesn't really feel like a permission to me.
Thanks!
kevin
Comment #21
coltraneFair points @koshea2 and I think you're right, it is making more sense to remove the 'require tfa' permission.
Is anyone opposed to this plan?
Since TFA module does not provide any TFA plugins and the require tfa permission is immediately applied to UID 1 the permission has the unintended affect of blocking UID 1 from logging in without providing any way to do so. Instead, required TFA-setup should be provided by plugin modules.
Let me know any thoughts or I'll update the summary here and create a new TFA Basic issue to match the latest functionality proposed in #17.
Comment #22
greggles+1 to the plan in #21.
Comment #23
johnennew commentedI am also happy with approach suggested in #21
Comment #24
pachabhaiya commented+1 to #21
Comment #25
coltraneThanks for the feedback! Updating summary with steps needed for TFA module and created https://www.drupal.org/node/2457823 to handle requirement for TFA Basic.
Comment #26
jibraninterdiff please.
Comment #27
coltraneAttached patch invokes new hook_tfa_require() and if any implementations return TRUE will disallow login. Implementers can now set the visible message.
Comment #28
coltraneUpdated patch to simplify code flow in login handlers and minor updates to documentation. Moves tfa_login_complete() code within tfa_login_allowed().
Comment #29
coltranePatch in 28 missed a few other minor doc changes.
Comment #30
coltraneAnd minor update to change hook name to 'tfa_ready_require' to be more explicit on what's being required. Patches 27-29 also removed a test on plugin readiness so this restores that.
I'm planning to commit this soon so any reviews/testing is greatly appreciated in case there are needed changes.
Comment #31
coltraneJust a re-roll for clean apply.
Comment #32
coltraneUpdating title since redirect isn't handled here.
Comment #34
coltraneCommitted #31.