8000 KEYCLOAK-17622 Terms and Conditions - periodically ask for reacceptance by laskasn · Pull Request #7895 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

KEYCLOAK-17622 Terms and Conditions - periodically ask for reacceptance - #7895

Closed
laskasn wants to merge 1 commit into
keycloak:mainfrom
eosc-kc:49_only
Closed

laskasn wants to merge 1 commit into
keycloak:mainfrom
eosc-kc:49_only

Conversation

@laskasn
@laskasn laskasn commented Mar 30, 2021
Copy link
Copy Markdown
Contributor

@stianst stianst left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly, I'm sorry for the long time to respond to this PR.

There's a few issues I see with the approach taken in this PR:

  • T&C are periodically invalidated, which means a user could have to approve terms and conditions again a few minutes after they've already done so.
  • Background/timer task to periodically expire T&C is fairly expensive and not needed really. It would be better to simple check during authentication time if a given users acceptance has expired or not.
  • The approach to providing configuration for the T&C is not ideal, and should rather be configuration on the required action itself, instead at the realm level. This makes it quite a bit more tricky to implement this change as a first step would be to support configuration options for required actions themselves.

Rather than having a time that invalidates terms and conditions periodically for all users I'd rather like to see an max-age on terms and conditions approval, and then check that when users authenticate.

@stianst stianst self-assigned this Aug 24, 2022
@laskasn
laskasn commented Aug 26, 2022 •
Copy link
Copy Markdown
Contributor Author

Firstly, I'm sorry for the long time to respond to this PR.

There's a few issues I see with the approach taken in this PR:

  • T&C are periodically invalidated, which means a user could have to approve terms and conditions again a few minutes after they've already done so.
  • Background/timer task to periodically expire T&C is fairly expensive and not needed really. It would be better to simple check during authentication time if a given users acceptance has expired or not.
  • The approach to providing configuration for the T&C is not ideal, and should rather be configuration on the required action itself, instead at the realm level. This makes it quite a bit more tricky to implement this change as a first step would be to support configuration options for required actions themselves.

Rather than having a time that invalidates terms and conditions periodically for all users I'd rather like to see an max-age on terms and conditions approval, and then check that when users authenticate.

First of all, thanks @stianst for evaluating this PR.

Let me answer on your points, one by one (i am struggling a bit to remember what i have done many months before :P )

Regarding the first one, the T&C are not just periodically invalidated. What really happens is that they are periodically checked and if an expiry has occured, then they get invalidated :)

  • The last time (timestamp) user has accepted the task is stored in the user attributes (by the requiredActionModel.getProviderId() field name). The task checks for all users
    if(epochSecondsNow > expiryOffset + userLastAcceptTime)
    and if true, it resets the relevant required action.
    If the user accepts at some time the required action, then the userLastAcceptTime will be updated and the (epochSecondsNow > expiryOffset + userLastAcceptTime) of the next task will be false till the expiryOffset has elapsed. (So no invalidation will occur)

  • About the second point, the background task runs every 900 sec (15 mins) which i think is quite "sparce" to add a large processing burden on a running instance (moreover, it's asynchronous).
    Of cource, this depends on the number of users in a realm, and the user list might grow really large.
    What you propose is a nice idea though, and i will try to add the check during the authentication (hopefully, it will not add any delay to the authentication hotcode path), instead of having a periodic task.

  • About the third point, why not have both? We could have a default-global, and an override (if an override is specified for the user, it is evaluated instead of the realm's default).

@stianst Please, check also the PR #7841 which is simpler - whenever an admin changes the T&C, he/she might wish to require all users to reaccept the new one!!!

@stianst
stianst commented Aug 26, 2022
Copy link
Copy Markdown
Contributor

With regard to performance this is going to be pretty horrible. Let's say you have 1000+ realms you're fetching and looping over all those realms every 15 minutes. Now let's say you have 100+ million users in one realm, you're again fetching and looping over all those users every 15 minutes.

@stianst
stianst commented Aug 26, 2022
Copy link
Copy Markdown
Contributor

With regard to how it is configured it really isn't suitable to hard-code the config for a specific action like you're doing in the admin console. Nor is it really ideal to use realm config for this purpose. This results in code that is hard for us to maintain, so I'm afraid we really can't accept this approach.

@laskasn
laskasn commented Aug 26, 2022
Copy link
Copy Markdown
Contributor Author

With regard to how it is configured it really isn't suitable to hard-code the config for a specific action like you're doing in the admin console. Nor is it really ideal to use realm config for this purpose. This results in code that is hard for us to maintain, so I'm afraid we really can't accept this approach.

How would you envisage the configuration of the "max-age on terms and conditions approval" you mention? We could change the way the whole thing is defined.

@laskasn
laskasn commented Aug 26, 2022
Copy link
Copy Markdown
Contributor Author

With regard to performance this is going to be pretty horrible. Let's say you have 1000+ realms you're fetching and looping over all those realms every 15 minutes. Now let's say you have 100+ million users in one realm, you're again fetching and looping over all those users every 15 minutes.

Indeed. I'll remove the periodical task and add the checks during the auth phase.

@stianst
stianst commented Aug 26, 2022
Copy link
Copy Markdown
Contributor

With regard to how it is configured it really isn't suitable to hard-code the config for a specific action like you're doing in the admin console. Nor is it really ideal to use realm config for this purpose. This results in code that is hard for us to maintain, so I'm afraid we really can't accept this approach.

How would you envisage the configuration of the "max-age on terms and conditions approval" you mention? We could change the way the whole thing is defined.

It's a non-trivial thing I'm afraid as it would require updating required actions to be configurable like authenticators are. @mposolda wdyt?

@mposolda
Copy link
Copy Markdown
Contributor

With regard to how it is configured it really isn't suitable to hard-code the config for a specific action like you're doing in the admin console. Nor is it really ideal to use realm config for this purpose. This results in code that is hard for us to maintain, so I'm afraid we really can't accept this approach.

How would you envisage the configuration of the "max-age on terms and conditions approval" you mention? We could change the way the whole thing is defined.

It's a non-trivial thing I'm afraid as it would require updating required actions to be configurable like authenticators are. @mposolda wdyt?

Yes, we don't have configuration at the level of required actions, we have just the configuration at the level of authenticators in the authentication flow.

And agree that adding configuration for the required actions would be non-trivial thing. I am not sure if we should rather do it as part of the "Authentication policies" effort instead of introducing "required action configuration" now?

@stianst
stianst commented Aug 29, 2022
Copy link
Copy Markdown
Contributor

@mposolda with auth policies in mind, perhaps we would just need to allow this PR to configure through realm attributes for now, with an plan to refactor it down the line?

@mposolda
Copy link
Copy Markdown
Contributor

@mposolda with auth policies in mind, perhaps we would just need to allow this PR to configure through realm attributes for now, with an plan to refactor it down the line?

@stianst +1

@stianst
stianst commented Sep 2, 2022
Copy link
Copy Markdown
Contributor

@laskasn are you still interested in working on this issue? For it to reach a mergeable state we'd need:

  • To resolve performance issues move te check of terms and conditions expirations to authentication time, instead of using a background
  • Revert changes to the old admin console and send a PR to https://github.com/keycloak/keycloak-ui, we may want to reconsider how it is configured in the admin-ui. Perhaps it should be a separate section that is visible when the t&c required action is enabled. @ssilvert wdyt?
  • We'd probably want to update docs as well to mention this capability

@laskasn
laskasn commented Sep 2, 2022 •
Copy link
Copy Markdown
C 8000 ontributor Author

@stianst
YES ! i have completed the reform!

  • Now it's done during the authentication of the user (i admit your idea was very good)
  • Reformed/Created 2 tests το cover the basic "execution" paths.
  • Rebased on main branch.

I am updating the PR!

@laskasn
laskasn requested a review from stianst September 2, 2022 10:19
@laskasn
laskasn marked this pull request as draft September 2, 2022 10:24
@laskasn
laskasn marked this pull request as ready for review September 2, 2022 11:14
@laskasn
laskasn marked this pull request as draft September 2, 2022 14:17
@laskasn
laskasn marked this pull request as ready for review September 2, 2022 14:49
@ssilvert
ssilvert commented Sep 6, 2022
Copy link
Copy Markdown
Contributor

@laskasn are you still interested in working on this issue? For it to reach a mergeable state we'd need:

  • Revert changes to the old admin console and send a PR to https://github.com/keycloak/keycloak-ui, we may want to reconsider how it is configured in the admin-ui. Perhaps it should be a separate section that is visible when the t&c required action is enabled. @ssilvert wdyt?
  • We'd probably want to update docs as well to mention this capability

@stianst @mposolda
Maybe I missed something but it does seem to me that this belongs in authentication policies. Is there some reason we can't put the UI for it in auth policies now so we don't have to refactor later?

@laskasn Once this is settled and an API is place, open an issue at https://github.com/keycloak/keycloak-ui/issues. The UI team will work with you to get this done quickly.

@laskasn
laskasn force-pushed the 49_only branch 2 times, most recently from af97872 to e15a412 Compare October 7, 2022 09:49
@laskasn
laskasn commented Oct 7, 2022 •
Copy link
Copy Markdown
Contributor Author

@laskasn are you still interested in working on this issue? For it to reach a mergeable state we'd need:

  • Revert changes to the old admin console and send a PR to https://github.com/keycloak/keycloak-ui, we may want to reconsider how it is configured in the admin-ui. Perhaps it should be a separate section that is visible when the t&c required action is enabled. @ssilvert wdyt?
  • We'd probably want to update docs as well to mention this capability

@stianst @mposolda Maybe I missed something but it does seem to me that this belongs in authentication policies. Is there some reason we can't put the UI for it in auth policies now so we don't have to refactor later?

@laskasn Once this is settled and an API is place, open an issue at https://github.com/keycloak/keycloak-ui/issues. The UI team will work with you to get this done quickly.

OK, i removed the UI part, and i am posting an issue on the keycloak-ui team to see how this is going to be implemented in the new UI.

Please, note that it looked like this on the old admin console! It was getting enabled only if the "terms and conditions" flag (leftmost one) was "true".
reset_interval

@laskasn
laskasn commented Oct 7, 2022 •
Copy link
Copy Markdown
Contributor Author

I am thining about the removal you asked @ssilvert of the UI part on the old admin console. Why do you prefer to remove it and not let it there (since it's a deprecated/fallback UI) and just add also the required stuff on the new admin console?
I believe the addition on the old admin console would allow people using the old console to have access to this feature, plus the js and the html would help the guys from the new UI admin console to understand what we are trying to do. What do you think @stianst @mposolda ?

@xianli123
Copy link
Copy Markdown
Contributor

I looked through all the comments. I'm curious if we decided to add editing capabilities to T&C. In addition, should the version control be added? Once we have the final decision, I can come up with some UX solutions for the requirements.

@mposolda
mposolda commented Aug 7, 2023
Copy link
Copy Markdown
Contributor

So if I understand correctly, there are really 2 separate use-cases:

  1. Ask users for re-acceptance always when terms&conditions are changed
  2. Ask users for re-acceptance every 12 months (even if nothing is changed in terms & conditions).

@cgeorgilakis Could you confirm that (1) is not sufficient for you and you also need to cover use-case (2) ? For instance, if you can live with (1), it means that administrator will need to update the terms & conditions required action every 12 months to enforce that users will re-approve 10000 them during their next authentication. This is not entirely same like periodic re-acceptance (as also users who accepted yesterday will be asked again today for re-acceptance due version change), but maybe it is sufficient compromise?

@mposolda
mposolda commented Aug 7, 2023
Copy link
Copy Markdown
Contributor

One generic question: Are the use-cases for "periodic re-acceptance" or "versioning" specific only to Terms & Conditions? Or do we want them to be applied also for other required actions?

I can imagine periodic updates for more actions (Like Make sure user is required to update his profile every 12 months or Make sure user is required to update his TOTP every 12 months etc), however things like "versioning" with the use-case like (Make sure all users are required to update their profile now) likely does not makes sense to every action? Just trying to figure if we should introduce "configuration options" in the RequiredActionProvider and make sure that admin console UI will render just the configuration options, which are applicable for the particular required-action implementation?

@ssilvert
ssilvert commented Aug 7, 2023
Copy link
Copy Markdown
Contributor

One generic question: Are the use-cases for "periodic re-acceptance" or "versioning" specific only to Terms & Conditions? Or do we want them to be applied also for other required actions?

with the use-case like (Make sure all users are required to update their profile now) likely does not makes sense to every action?

Apply required action to all users immediately could make sense for most required actions. It would be a simple change to the UI in the Authentication section.

@xianli123
Copy link
Copy Markdown
Contributor

@mposolda @ssilvert Thanks. If I understand correctly, we need to allow administrators to configure T&C and periodically make the general users accept new or old T&C at the UI level. Is that right?

@mposolda
mposolda commented Aug 8, 2023
Copy link
Copy Markdown
Contributor

I guess it makes sense to plan the UI if we agree on what we want to achieve? I am still not 100% sure if it is clear TBH. Few use-cases come to me, which we might agree on:

  1. Use-case Ask all users for re-acceptance terms & conditions during their next login (aka versioning). Do we want to support this? AFAIK answer is yes

  2. Use-case Apply required action XY to all users during their next login. More generic version of above, which is not specific only to "terms & conditions", but pretty much to all required actions. @ssilvert mentioned it can makes sense for most required actions. I agree with that, however I think that required actions makes sense only to some "applicable users", not to all users of the realm. For instance "Ask all users to update their TOTP" - this would makes sense only to users with TOTP, likely not to all users in the realm? Similarly "Verify email" applicable only to users with the email, which may not be all realm users etc.

  3. Use-case Ask all users to re-accept terms & conditions every 12 hours . Do we want to support this? IMO yes as "versioning" (or "Asking all users to re-acceptance") is not exactly same use-case as periodic re-accept

  4. Periodic re-acceptance for all required actions (not specific only to terms & conditions). IMO makes sense to have this capability for all required actions, but again, usually just for "Applicable" users. So for instance: Ask users to update their TOTP every 6 months, but just those users with TOTP already set. For Update Password, we already have password policy Expire Password, which effectively does this, so no need to have this also through required action IMO.

I guess that for Milestone 1, we can do this only for Terms & Conditions and then at next stage extend to other required actions? Maybe in tab Authentication -> Required actions, we can have "Config" action to allow configure particular required actions? Similarly like we have in the Authentication -> Flows for individual authentication executions?

@ssilvert
ssilvert commented Aug 8, 2023
Copy link
Copy Markdown
Contributor

I guess it makes sense to plan the UI if we agree on what we want to achieve? I am still not 100% sure if it is clear TBH. Few use-cases come to me, which we might agree on:

  1. Use-case Ask all users for re-acceptance terms & conditions during their next login (aka versioning). Do we want to support this? AFAIK answer is yes
  2. Use-case Apply required action XY to all users during their next login. More generic version of above, which is not specific only to "terms & conditions", but pretty much to all required actions. @ssilvert mentioned it can makes sense for most required actions. I agree with that, however I think that required actions makes sense only to some "applicable users", not to all users of the realm. For instance "Ask all users to update their TOTP" - this would makes sense only to users with TOTP, likely not to all users in the realm? Similarly "Verify email" applicable only to users with the email, which may not be all realm users etc.
  3. Use-case Ask all users to re-accept terms & conditions every 12 hours . Do we want to support this? IMO yes as "versioning" (or "Asking all users to re-acceptance") is not exactly same use-case as periodic re-accept
  4. Periodic re-acceptance for all required actions (not specific only to terms & conditions). IMO makes sense to have this capability for all required actions, but again, usually just for "Applicable" users. So for instance: Ask users to update their TOTP every 6 months, but just those users with TOTP already set. For Update Password, we already have password policy Expire Password, which effectively does this, so no need to have this also through required action IMO.

I guess that for Milestone 1, we can do this only for Terms & Conditions and then at next stage extend to other required actions? Maybe in tab Authentication -> Required actions, we can have "Config" action to allow configure particular required actions? Similarly like we have in the Authentication -> Flows for individual authentication executions?

I think this is very good @mposolda. I agree with all of it.

The only part that might be a little tricky is figuring out who an "applicable user" is. I guess you would need some sort of callback where you pass the user and ask the required action to decide if the user is "applicable". It's doable though.

@pedroigor
pedroigor commented Aug 8, 2023 •
Copy link
Copy Markdown
Contributor

@mposolda Sounds like a good plan.

However, I agree with @cgeorgilakis that we should let administrators indicate whether a required action should run for users. I'm wondering how the "version property" in a resource bundle/theme would work considering that themes are also deployed as JARs.

Looking at the T&C required action, a timestamp is already set for the user. What we need now is to allow administrators to set a global timestamp to compare and check if the action should run again for a particular user (similar to not-before when expiring sessions at the realm level, I think). For now, we could store the global config as a realm attribute ... Or just think about enabling a component model to required actions.

@xianli123
Copy link
Copy Markdown
Contributor

@mposolda @ssilvert @pedroigor I will come up with some designs based on the discussions and decisions. Once I have some deliverables, I will share them with you.

@xianli123
Copy link
Copy Markdown
Contributor

Hi @mposolda @pedroigor , if the admin can configure the T&C, what attributes should be included in the T&C configurations? Does it just include the Reset interval including some number input fileds and time units, like the image shows below?
image

@pedroigor
pedroigor commented Aug 10, 2023 •
Copy link
Copy Markdown
Contributor

For now, and based on the discussions, I would say the Reset interval (not sure if the name is the best, perhaps Expires in or something) is enough for now and allows defining the validity period for the T&C acceptance.

However, in case you want to force users to accept the T&C when it changes, we need something else. Something along the lines suggested by Stian like a version. As I'm not sure how to deal with a version property, we could have an option to set the "not-before" timestamp. This timestamp will basically invalidate any previous T&C accepted by the user before it and force the user to re-accept the T&C. You don't necessarily need to provide a date/time but just a button that sets this "not-before" timestamp based on the current time. We probably need to show this information to administrators too so that they know the last timestamp set.

Makes sense?

I see you are also working with the old administration console ... Ideally, you should consider developing on top of the new admin console. I think they have specific components there that can be re-used from authentication flows to configure required actions.

@xianli123
Copy link
Copy Markdown
Contributor

@pedroigor Thanks.

What's the deadline for your plan? @laskasn @mposolda @pedroigor @stianst

@pedroigor
Copy link
Copy Markdown
Contributor

@xianli123 Not sure. As this is touching the UI (in addition to storing new data to realm/actions) we probably need more discussions to make sure we agree about the solution.

I see a lot of benefit on this proposal so it would be nice to have it done before 23.

@ssilvert
Copy link
Copy Markdown
Contributor

Hi @mposolda @pedroigor , if the admin can configure the T&C, what attributes should be included in the T&C configurations? Does it just include the Reset interval including some number input fileds and time units, like the image shows below? image

@xianli123 I believe this needs a way to select that you want no reset interval. Maybe some sort of enable/disable.

@xianli123
Copy link
Copy Markdown
Contributor

As this is touching the UI (in addition to storing new data to realm/actions) we probably need more discussions to make sure we agree about the solution.

Thanks @pedroigor Who can help us review the solution and make the final decisions? Is it necessary to have a meeting to discuss the solution?

@xianli123
Copy link
Copy Markdown
Contributor

I believe this needs a way to select that you want no reset interval. Maybe some sort of enable/disable.

@ssilvert Yes. I agree. That's also a use case.

@xianli123
xianli123 commented Aug 16, 2023 •
Copy link
Copy Markdown
Contributor

Can users upload or create a term and condition in the UI? The Keycloak documentation mentioned that Edit the terms.ftl file in the base login theme. So I wonder if it's possible to allow the admin to edit the content of the terms and conditions in the UI when the admin can configure the Terms and conditions. @pedroigor @mposolda

@ssilvert
Copy link
Copy Markdown
Contributor

@xianli123 Yes, it is possible to upload the text. If you are using our version of ftl files like terms.ftl and register-commons.ftl, you can override the text in those files if you re-define these messages:

termsTitle=Terms and Conditions
termsText=<p>Terms and conditions to be defined</p>
termsPlainText=Terms and conditions to be defined.
termsAcceptanceRequired=You must agree to our terms and conditions.
acceptTerms=I agree to the terms and conditions

So, an administrator can go to Realm settings --> Localization and define these from the UI.

BTW, I'm not sure where all those messages are used.

@xianli123
Copy link
Copy Markdown
Contributor

@ssilvert I think the message will display on the login page if the admin enables the "Terms and conditions".

Screenshot 2023-08-21 at 17 36 51

@ssilvert
Copy link
Copy Markdown
Contributor

@ssilvert I think the message will display on the login page if the admin enables the "Terms and conditions".

Screenshot 2023-08-21 at 17 36 51

Yeah. Some of those messages are easy to track down. Others take a little more digging to find out what they are for.

@cgeorgilakis
Copy link
Copy Markdown
Contributor

So if I understand correctly, there are really 2 separate use-cases:

  1. Ask users for re-acceptance always when terms&conditions are changed
  2. Ask users for re-acceptance every 12 months (even if nothing is changed in terms & conditions).

@cgeorgilakis Could you confirm that (1) is not sufficient for you and you also need to cover use-case (2) ? For instance, if you can live with (1), it means that administrator will need to update the terms & conditions required action every 12 months to enforce that users will re-approve them during their next authentication. This is not entirely same like periodic re-acceptance (as also users who accepted yesterday will be asked again today for re-acceptance due version change), but maybe it is sufficient compromise?

@mposolda yes we want both uses cases. This issue is for use case 1 and this for use case 2. What you describe after can not work in a real environment. Although now we want these only for T&C, I agree that it would be nice to have them for all Required Actions.

terms_and_conditions

@xianli123 the previous icon was for reset button in old admin console. @ssilvert has proposed for new admin console:

I suspect we would add a kabab menu to trigger a popup for required actions that have config settings.

Finally, T&C can be changed with custom theme ( changing terms.ftl). We use this.

@xianli123
Copy link
Copy Markdown
Contributor

@cgeorgilakis What is the aim of the Reset icon, to refresh the T&C or reset the intervals?

@cgeorgilakis
Copy link
Copy Markdown
Contributor

@cgeorgilakis What is the aim of the Reset icon, to refresh the T&C or reset the intervals?

Refresh T&C. This is from our PR. We could decide the appropriate name.

@ssilvert
Copy link
Copy Markdown
Contributor

@cgeorgilakis What is the aim of the Reset icon, to refresh the T&C or reset the intervals?

Refresh T&C. This is from our PR. We could decide the appropriate name.

So does it mean, "Make all users perform the action on next login."?

@xianli123
Copy link
Copy Markdown
Contributor

@cgeorgilakis Ok. I created a conceptual design as shown in the screen below. I put the configurations on this separate page. Users can configure the T&C in this page. Does it make sense?

Create_conditional_flow 2

@cgeorgilakis
Copy link
Copy Markdown
Contributor

@cgeorgilakis Ok. I created a conceptual design as shown in the screen below. I put the configurations on this separate page. Users can configure the T&C in this page. Does it make sense?

Create_conditional_flow 2

Yes. It looks good.

@jonkoops
Copy link
Copy Markdown
Contributor

I am closing this PR as it has already been out there for some time and seems to be stuck in eternal review. We have this tracked under #19275, so we can continue further discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

0