-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add support for login policies #40574
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
Conversation
The Idea with #31546 was to use an IAuthModule or a similar PAM concept for thngs like this. But if you think it does not fit ... go ahead ... |
At least for this particular use case, I don't think we can use #31546 . We need to know how the user is being logged in or how he has logged in, and we don't have that information there. This would require changes in the interface. In addition, I'm not exactly sure about the architecture. It seems the AuthModule depends on the AccountModule. This would mean that each AuthModule would depend and use the AccountModuleManager, which I'm not sure if it happens already (for openidconnect, kerberos and others). |
return true; | ||
} | ||
|
||
if (isset($policyConfig[$loginType])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usage of ??
can reduce line number .....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
For the "reject" and "allowOnly", I think it's clearer this way because we won't check anything if the keys aren't present.
I guess the idea is also to allow apps to add login policies via calling the manager in app.php. |
That's the idea. I haven't tested it yet though. I'll probably check it by adding the expected code in a random app instead of creating one from scratch. |
@jvillafanez pls do not forget to add a |
For testing, I've used the brute_force_protection app as base. Added the "lib/ProtPolicy.php" and the patch:
patch:
Note that the brute_force_protection app is of the type "prelogin", so the app is expected to load quite early. The basic idea is that the
I think this is enough as a PoC that 3rd party apps can also provide custom login policies with this mechanism. I don't think we want to create a complete app just for testing this feature, at least without specific use cases. |
32b4557
to
a39cebb
Compare
💥 Acceptance tests pipeline cliExternalStorage-git-mariadb10.2-php7.4 failed. The build has been cancelled. |
This is ready to review. I've checked the original issue and it works fine with this PR (tested with openidconnect and guests app to ensure it works). @mmattel I guess this will need to end up in the docs eventually. There should be enough information in this PR, but feel free to ask any question. |
That's a bit odd from my pov that this has to be setup in two places..... |
The registration part is for the devs. If we want to give them a chance to implement custom policies, someone will need to create the objects, and for core to create them will require a specific signature in the constructors, which will limit the options. By using a registration process, it's expected that the app will provide the objects already created, so it will just need to register them. Now, the admin needs a way to control the registered policies. Since core policies will always be registered, the admin needs a way to activate or deactivate them. In addition, he also has control over the policy order, so maybe he wants a custom policy to be checked before any of the core ones. Maybe the confusion comes from using the class names there... we could require a Note that an app could provide and register multiple login policies. There could be an app that groups a bunch of policies and registers 10 policies; in this case it's very unlikely that the admin will use all of them, but maybe 2 or 3. |
@jvillafanez merge it? |
no problems from my side |
A policy has been implemented so admins can allow or reject groups of users to access via specific login mechanisms
263f53c
to
03aad46
Compare
I fixed the last-mentioned grammar thing in config.sample.php |
Kudos, SonarCloud Quality Gate passed! |
A policy has been implemented so admins can allow or reject groups of users to access via specific login mechanisms
Description
Add support for login policies. An initial login policy has been implemented so admins can allow or reject groups to access ownCloud via specific login mechanism.
For example, only the groups "guests" and "admin" could access via username + password, while the rest of users must access through other mechanisms such as openidconnect.
Login policies will emit a "failed login" event if the user isn't allowed to login.
Some additional changes have been made in the token access (app password) so it isn't invalidated under some circumstances (login policies were causing the invalidation of the token if the policy rejected the user.)
Related Issue
https://github.com/owncloud/enterprise/issues/5295
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist:
TODO:
Usage:
The
GroupLoginPolicy
is already pre-registered, so there is nothing to do in order to register this policy in theLoginPolicyManager
The
LoginPolicyManager
will use theloginPolicy.order
key in the config.php file to activate and use the policies in the list in the specified order.If no login policy is activated in the
loginPolicy.order
list, ownCloud will work normally. Only registered policies can be activated.For now, only the
OC\Authentication\LoginPolicies\GroupLoginPolicy
is available.GroupLoginPolicy configuration.
The configuration of the
GroupLoginPolicy
is done through the config.php file.Each key of the forbidMap is a known login type (to be listed every known login type), and the value is a map containing a list of groups that are allow to use that login type (rejecting everyone else), and a list of groups that are rejected from using that login type.
In the above example, users belonging to the admin group won't be able to access via token (app password), while the rest of the users can.
Only users from group1 and group2 are allowed to access through username + password, and users from group3 will be rejected. In case a users is member of an allowOnly group and a reject group, rejection will take priority. This means that even if user1 is member of group1 he won't be able to access if he's also member of group3.
In some weird cases the login type is unknown (there was an issue with openidconnect which should be solved in the master code of the branch). In this case, the login type might be the empty string
''
.