H2CK/oidc

Exception on install

Closed this issue · 6 comments

Hi, I have the following exception on install of the OIDC 0.4.8 on Nextcloud 25.0.4 (snap):

An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 3072 bytes

Before the (automatic) Nextcloud update, I had the OIDC extension installed (not really sure which version). It failed to upgrade with the following message:

Database error when running migration 0009Date20230401232100 for app oidc
An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 3072 bytes

Then, I tried to manually remove the extension (including manually removing *oidc* tables and all the settings) since my current setup is mostly experimental, but still, it didn't change the last message. I installed the extension on another Nextcloud instance (custom Docker setup), and it was installed successfully. Is there anything else I need to clean up before reinstalling the extension?

H2CK commented

Which special kind of database are you using (SQLite, MySQL, Postgres, ...)?

The error is an error from the database which does not allow to create the necessary index. Does the database have a specific configuration limiting the index names?

It seems that you are not aware how Nextcloud applications are performing database scheme modifications. If you have deleted all oidc you have to recreate them by your own again. The app will not recreate them for you.
Except you delete the migration steps for the oidc app from your Nextcloud database by your own manually. Then the migration steps would be executed again and the database scheme is recreated.

If you want to disable a not working app just disable it using e.g. the occ command.

The database I'm using is MySQL. I looked at the changes between 0.4.7 and 0.4.8, and I think that the issue is with the oidc_loredirect_uris table. I'm definitely not a db specialist, but here is my thought process: The new table has redirect_uri set as an index, which is 2000 long string. I have the utf8mb4 collation in the database, so I presume that it's a 2000×4=8000B index which is way over the 3072B limit I have (apparently). I'm unsure what could be done about it, especially since the snap version of Nextcloud doesn't allow for edits to my.cnf.

Pretty good read: https://stackoverflow.com/a/30838729

TL;DR (in my understanding): It's tricky (if not impossible) to support indexes with lengths over 3072B. The question is if you need an index for theredirect_uri or could you make it shorter?

FYI, I created the oidc_loredirect_uris table manually, and indeed my assumption that with utf8mb4 you could have a max of 768 characters in varchar is correct.

For reference, this query worked (i.e., replaced 2000 in redirect_uri with 768):

CREATE TABLE `oc_oidc_loredirect_uris` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `redirect_uri` varchar(768) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `oidc_loredir_uri_idx` (`redirect_uri`)
);
H2CK commented

Please try version 0.4.9. This should fix this MySQL issue. Index is removed completely since it should not be really necessary.

Now it works. Thank you for the prompt patch and release 😃