8000 KEYCLOAK-12473 Add possibility to specify length of event detail when… by vramik · Pull Request #6576 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

KEYCLOAK-12473 Add possibility to specify length of event detail when… - #6576

Merged
hmlnarik merged 1 commit into
keycloak:masterfrom
vramik:KEYCLOAK-11987-long-redirect-uri-with-login-events-enabled
Dec 17, 2019
Merged

hmlnarik merged 1 commit into
keycloak:masterfrom
vramik:KEYCLOAK-11987-long-redirect-uri-with-login-events-enabled

Conversation

@vramik
@vramik vramik commented Dec 6, 2019
Copy link
Copy Markdown
Contributor

… storing to database

@stianst
stianst commented Dec 6, 2019
Copy link
Copy Markdown
Contributor

Would it not make more sense to just increase the size of the field in the DB?

@vramik
vramik commented Dec 6, 2019
Copy link
Copy Markdown
Contributor Author

@stianst the size of the filed is 2550 atm, how would you determine what size should be enough and how would you ensure the redirect_uri param has lesser size? I think increasing the size would be more like workaround than a proper solution.

@vramik
vramik force-pushed the KEYCLOAK-11987-long-redirect-uri-with-login-events-enabled branch from d45c19d to 918cb28 Compare December 6, 2019 12:35
@hmlnarik
hmlnarik commented Dec 6, 2019
Copy link
Copy Markdown
Contributor

Would it not make more sense to just increase the size of the field in the DB?

Yes, it would be possible to use CLOB or similar for empty database. For big databases with millions of records, this could involve (depending on DB vendor) downtime.

The proposed way is conservative in this regard.

@hmlnarik hmlnarik 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.

Thanks @vramik! Overall LGTM, after fixing the test failures, it is IMO ready to go in.

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.

Suggested change
if (maxDetailLength > 0) {
if (maxDetailLength > 0 && event.getDetails() != null) {

@stianst
stianst commented Dec 8, 2019
Copy link
Copy Markdown
Contributor

If we're going with trimming, which I would argue is a workaround as you are loosing data, we should not require users to configure it (there's a max size of the field in the db and we should just automatically trim it to fit, without user having to first get and issue then figure out what length to set it to), we also should make it obvious that the field has been trimmed (perhaps adding ... to the end)

@vramik
vramik force-pushed the KEYCLOAK-11987-long-redirect-uri-with-login-events-enabled branch 2 times, most recently from 423773a to 4901b6b Compare December 9, 2019 10:33
@vramik
vramik commented Dec 9, 2019
Copy link
Copy Markdown
Contributor Author

@stianst I've added ... to the trimmed string to make it obvious it was trimmed, there is also warning in log about that.

We've discussed the approach you're suggesting (trim it to the maximum length left) in puma team, and we decided to go with adding possibility to configure it for use-cases where the problems appears. The reason for that was different coding has different length of characters. I can explore this approach further.

@vramik
vramik commented Dec 10, 2019
Copy link
Copy Markdown
Contributor Author

@stianst it seems to me trimming the length to maximum length left is not the trivial thing to do. Different databases can have different characters encoding and each encoding uses different length for each character.

@stianst
stianst commented Dec 10, 2019
Copy link
Copy Markdown
Contributor

So basically what we are saying is that if someone runs into an issue in production, then they need to discover this config option, then they somehow need to figure out what to set it to (which you are saying is far from trivial). Not really an ideal solution.

@stianst
stianst commented Dec 10, 2019
Copy link
Copy Markdown
Contributor

Isn't the field a varchar? So it should support X characters regardless of encoding?

@vramik
vramik commented Dec 10, 2019
Copy link
Copy Markdown
Contributor Author

I'm investigating it for all supported databases.

@vramik
vramik commented Dec 11, 2019
Copy link
Copy Markdown
Contributor Author
8000

Isn't the field a varchar? So it should support X characters regardless of encoding?

It's true for all these databases: MySQL, Postgresql, MariaDB, MariaDB Galera, MSSql.

Unfortunately for Oracle database is VARCHAR2 datatype used, by default oracle uses max_size in BYTEs so the column is able to hold 2550 bytes of character. For redirect_uri we're fine as there are only non US-ASCII characters or encoded ones but the problem is with username (which is also part of the login event detail). The username doesn't have any limitation so there comes the issue with finding out the actual length stored.

I could come up with following solutions, but there might be better one.

  • we can somehow (needs further investigation) to find out the actual length of the string counting special characters in username and cut the rest what cannot fit in.

  • we can update liquibase jpa-changelog for oracle database to redefine the column to use max_size in CHARs instead of BYTEs. It should theoretically (needs to check that) be then in the same state as other databases and we would be able to easily count precise number of characters what would have to be cut. The migration has to be also checked.

  • we can leave it configurable and introduce some default value for the maxDetailLength, e.g. 1000 or 1500, similar to the one for the testsuite: https://github.com/keycloak/keycloak/pull/6576/files#diff-29f12bca9bfc7631a703c2f241220680R26. It will prevent users to run into the issue in production and it gives them possibility to set up their own preferred value.

@stianst, @hmlnarik wdyt?

@stianst
stianst commented Dec 11, 2019
Copy link
Copy Markdown
Contributor

So you are saying that setting max value to 2500 would work for all DB except Oracle, and for Oracle it would still work for URLs?

If so I'd set it to 2500 and make it configurable in case some runs into issues with Oracle, which seems less likely if it's not an issue for URLs.

@vramik
vramik commented Dec 12, 2019
Copy link
Copy Markdown
Contributor Author

No, that's not what I'm saying. I was trying to say that for all DBs except Oracle would be possible to relatively easily count the number of characters and based on that we would be able to cut the redirect_uri to make sure we cut the minimum characters.

For Oracle it's not so easy to count.

IMO if we set default to 1500 we should be ok for almost all cases.

@pskopek
pskopek commented Dec 12, 2019
Copy link
Copy Markdown
Contributor

I think that make it configurable with default == 1500 and 0 == "do not trim" can do the trick.

< 8000 include-fragment loading="lazy" src="/keycloak/keycloak/issue_comments/564917988/edit_form?textarea_id=issuecomment-564917988-body&comment_context=" data-nonce="v2:a712f565-c38e-c675-82e7-f5392cb965d1" data-view-component="true" class="previewable-comment-form js-comment-edit-form-deferred-include-fragment">

@vramik
vramik commented Dec 12, 2019
Copy link
Copy Markdown
Contributor Author

@stianst wdyt? Should we go with 1500 characters default cut?

@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.

LGTM - just some minor comments left

@vramik
vramik force-pushed the KEYCLOAK-11987-long-redirect-uri-with-login-events-enabled branch from 4901b6b to edc6e73 Compare December 13, 2019 12:06
@vramik vramik changed the title KEYCLOAK-11987 Add possibility to specify length of event detail when… KEYCLOAK-124733 Add possibility to specify length of event detail when… Dec 13, 2019
@vramik vramik changed the title KEYCLOAK-124733 Add possibility to specify length of event detail when… KEYCLOAK-12473 Add possibility to specify length of event detail when… Dec 13, 2019
@pskopek pskopek 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.

Looks good!

@hmlnarik
hmlnarik merged commit c3d8065 into keycloak:master Dec 17, 2019
@vramik
vramik deleted the KEYCLOAK-11987-long-redirect-uri-with-login-events-enabled branch January 7, 2020 08:45
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.

4 participants

0