Skip to content
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

Increase the size of the webauthn_credential credential_id field #18739

Merged
merged 14 commits into from Feb 13, 2022

Conversation

zeripath
Copy link
Contributor

Unfortunately credentialIDs in u2f are 255 bytes long which with base32 encoding
becomes 408 bytes. The default size of a xorm string field is only a VARCHAR(255)

This problem is not apparent on SQLite because strings get mapped to TEXT there.

Fix #18727

Signed-off-by: Andrew Thornton art27@cantab.net

Unfortunately credentialIDs in u2f are 255 bytes long which with base32 encoding
becomes 408 bytes. The default size of a xorm string field is only a VARCHAR(255)

This problem is not apparent on SQLite because strings get mapped to TEXT there.

Fix go-gitea#18727

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

I don't know if we should remigrate the U2F keys or not.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 12, 2022
Signed-off-by: Andrew Thornton <art27@cantab.net>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 12, 2022
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 12, 2022
@fnetX
Copy link
Contributor

fnetX commented Feb 12, 2022

remigrate the U2F

What do you mean? Is the original U2F data still present (like redo the migration) or do you mean doing a fix for first-time migrations?

If the first is possible, this might fix some broken keys. Maybe check that the key wasn't removed in the meantime if this is possible?

@zeripath
Copy link
Contributor Author

zeripath commented Feb 12, 2022

the original table is still there - because I worried that this might happen.

So we would remigrate the data - but - actually users might have removed those old keys already.

OK I've tried to do that.

Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
@fnetX
Copy link
Contributor

fnetX commented Feb 12, 2022

actually users might have removed those old keys already.

That's what I meant by

Maybe check that the key wasn't removed in the meantime

But it should be possible to check the webauthn table for fields that are using the maximum length and then try to remigrate that data, right?

Edit: That doesn't make much sense, it's probably better to skip the old migration and (re-)migrate in any case. It would be nonsense to migrate twice - once broken once correctly - and my approach would rely on the data to be already migrated.

Still, checking if the table is already present and not adding new records could be a solution-

…fix of the credID and use recreateTable

Signed-off-by: Andrew Thornton <art27@cantab.net>
@lunny
Copy link
Member

lunny commented Feb 12, 2022

Details

Ah. Checking the records of the webauthn and u2f and decide if the migration is necessary.

@zeripath
Copy link
Contributor Author

@fnetX are you able to test this to see if it works for your data?

@lunny
Copy link
Member

lunny commented Feb 13, 2022

make L-G-T-M work.

lunny
lunny previously requested changes Feb 13, 2022
models/migrations/v209.go Outdated Show resolved Hide resolved
_ = sess.Close()
return err
}
if err := recreateTable(sess, new(webauthnCredential)); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Why not just modify the column for non-sqlite database?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

	// This column has an index on it. I could write all of the code to attempt to change the index OR
	// I could just use recreate table.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly it's a nightmare handling all of the hoops which the various databases would require one to jump through to handle the index.

Certainly MSSQL won't allow you adjust a column that has a contraint on it already - that would need to be dropped first but I'm not sure about when you're allowed to readd the constraint.

Then MYSQL - which I think will allow you to change the column if it's empty - but if it contains data I have a feeling it would need to drop the constraint. Then IIRC if I would try to readd the constraint that won't work.

I think Postgres is fine simply because of cascade.

@lunny lunny dismissed their stale review February 13, 2022 17:09

Block problem resolved.

lunny and others added 5 commits February 14, 2022 01:12
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

OK I've written a test and this appears to be working as intended - so I think we can merge.

@zeripath zeripath merged commit 32599bf into go-gitea:main Feb 13, 2022
@zeripath zeripath deleted the fix-18727-longer-id branch February 13, 2022 21:19
zeripath added a commit to zeripath/gitea that referenced this pull request Feb 13, 2022
…gitea#18739)

Backport go-gitea#18739

Unfortunately credentialIDs in u2f are 255 bytes long which with base32 encoding
becomes 408 bytes. The default size of a xorm string field is only a VARCHAR(255)

This problem is not apparent on SQLite because strings get mapped to TEXT there.

Fix go-gitea#18727

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added the backport/done All backports for this PR have been created label Feb 13, 2022
if err != nil {
return err
}
case schemas.ORACLE:
Copy link
Member

Choose a reason for hiding this comment

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

Wow, Gitea hasn't support ORACLE yet.

zeripath added a commit that referenced this pull request Feb 14, 2022
) (#18756)

* Increase the size of the webauthn_credential credential_id field (#18739)

Backport #18739

Unfortunately credentialIDs in u2f are 255 bytes long which with base32 encoding
becomes 408 bytes. The default size of a xorm string field is only a VARCHAR(255)

This problem is not apparent on SQLite because strings get mapped to TEXT there.

Fix #18727

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Ignore the migrate if u2f_registration is not exist (#18760)

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 15, 2022
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Prevent dangling GetAttribute calls (go-gitea#18754)
  Add example to render html files (go-gitea#18736)
  Fix a broken link in `commits_list_small.tmpl` (go-gitea#18763)
  Fix broken cancel button link on patch page (go-gitea#18718)
  Ignore the migrate if u2f_registration is not exist (go-gitea#18760)
  [skip ci] Updated translations via Crowdin
  Increase the size of the webauthn_credential credential_id field (go-gitea#18739)
  Fix isempty detection of git repository (go-gitea#18746)
Caellion added a commit to Caellion/gitea that referenced this pull request Feb 16, 2022
* 'main' of https://github.com/go-gitea/gitea: (87 commits)
  Fix template bug of LFS lock (go-gitea#18784)
  Various Mermaid improvements (go-gitea#18776)
  [skip ci] Updated translations via Crowdin
  Fix display time of milestones (go-gitea#18753)
  [skip ci] Updated translations via Crowdin
  Prevent dangling GetAttribute calls (go-gitea#18754)
  Add example to render html files (go-gitea#18736)
  Fix a broken link in `commits_list_small.tmpl` (go-gitea#18763)
  Fix broken cancel button link on patch page (go-gitea#18718)
  Ignore the migrate if u2f_registration is not exist (go-gitea#18760)
  [skip ci] Updated translations via Crowdin
  Increase the size of the webauthn_credential credential_id field 
(go-gitea#18739)
  Fix isempty detection of git repository (go-gitea#18746)
  [skip ci] Updated translations via Crowdin
  Send mail to issue/pr assignee/reviewer also when OnMention is set 
(go-gitea#18707)
  Reduce CI go module downloads, add make targets (go-gitea#18708)
  Add number in queue status to monitor page (go-gitea#18712)
  Fix source code line highlighting (go-gitea#18729)
  Fix forked repositories missed tags (go-gitea#18719)
  [skip ci] Updated translations via Crowdin
  ...
Chianina pushed a commit to Chianina/gitea that referenced this pull request Mar 28, 2022
…gitea#18739)

Unfortunately credentialIDs in u2f are 255 bytes long which with base32 encoding
becomes 408 bytes. The default size of a xorm string field is only a VARCHAR(255)

This problem is not apparent on SQLite because strings get mapped to TEXT there.

Fix go-gitea#18727

Signed-off-by: Andrew Thornton <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migration from 1.15 to 1.16 fails on webauthn table
5 participants