-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Internal Server Error when importing juiceshop challenges due to lack of SQLite migration support #1988
Comments
https://github.com/juice-shop/juice-shop-ctf is compatible with CTFd 2.x or newer officially. I'm pretty sure up until recently CTFd 3.x also worked, or I would expect a few people to have complained by now. Either 3.4 made an incompatible data model change or some version before that is not very old either. Would be easiest to get this info from the CTFd developers, then I could at least update the Juice shop CTF tool docs to state the max. version that is supported. Then we can open a ticket on our end to create a new importer for the changed data model, in parallel to the existing 2.x-3.? one. |
I have an old Docker image 3.2.1 lying around and imported an older backup file. The challenges were successfully imported, but the admin panel throws a 500 error after the import. So, this might be an older issue. As CTFd is too complex for me to dive into, I'd have to rely on assistance by its developers to check our current export data format for incompatibility with their latest 3.x model. Then I'm happy to add a second exporter for that format. This is the main file for the CTFd export: https://github.com/juice-shop/juice-shop-ctf/blob/master/lib/generators/ctfd.js - Please point me to where changes are necessary to have a valid 3.x data package. |
The issue here is that you're using SQLite instead of MySQL/MariaDB. The docs should be updated to reflect this expectation but the recommended server is MySQL/MariaDB https://docs.ctfd.io/docs/deployment/#database-server. SQLite doesn't really do migrations very well (last I checked) so it's hard to import the data from Juice Shop at it's older migration version and then upgrade. This should work in MySQL but when I have time I will investigate how this either be made to work in SQLite or suggest changes in Juice Shop CLI. |
Thanks. I'll need to check whether this works when having a MySQL back-end instead. That might take me some time as I have to do this as an in-between lots of other work. With help of @bkimminich I verified that version 2.5.0-dev does correctly import the zip file, so the most imminent problem for me has been handled. We can use v2.5 in case I can't get it working using MySQL in time. But I'll give it a go nonetheless. |
I ended up using 2.5 with MySQL back-end for now. After our event I'll see if I can up the version to latest and try it again with the back-end in place. But for me the issue was mitigated by downgrading CTFd. |
I dug into this and found that migrations dont work well b/c SQLite doesn't support ALTER TABLE very well: https://blog.miguelgrinberg.com/post/fixing-alter-table-errors-with-flask-migrate-and-sqlite. SQLite also doesn't support ALTER COLUMN. Thus to migrate you need to create a new table and migrate the previous data. This can be done with alembic's batch mode: https://alembic.sqlalchemy.org/en/latest/batch.html#batch-mode-with-autogenerate. However while I think this is technically possible I don't really think that it's worth the difficulty. The above alembic page outlines a lot of edge cases for this. It might be worth it if this could somehow help the import process in other database types (the alembic page talks a bit about this) but I'd rather view SQLite as primarily a development and testing backend. I'll take a PR for this if someone wants to do the large amt of work & testing needed for this. If this somehow ends up affecting a lot of people perhaps I will take it on. |
I might be wrong but I think SQLite is quite fitting for small to medium sized CTFs. It would also make CTFd extremely easy to deploy since all you need is the docker image and import/export to setup/template/share/recover CTFs. Ex:
It's already quite easy I guess but setting up a DB is a bit of a hassle depending on infrastructure. I've tried adding render_as_batch in env.py and some more migrate boilerplate I've found in different places but I'm kind of fumbling in the dark with this. If someone has some knowledge about this stuff or hints would be nice :) I kinda like the idea of the above "workflow" but tbh I've never hosted myself and first time looking at this so not sure it's a valid point for smaller things? |
I hosted a smallish CTF a few years ago using SQLite with CTFd, and now I need to restore it to extract all the challenges for a new CTF we're hosting. Does this issue mean that I can't restore at all, or would it work with a restore if the CTFd instance I'm restoring to uses MySQL? I can extract the files and all the text from the export itself, but would be nicer/easier to just restore the CTF. |
Environment:
What happened?
I'm trying to import the zip file that I exported from my configured juiceshop instance. This didn't work, I'm getting a database related error which states:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: pages.format
What did you expect to happen?
I expected the import to work.
How to reproduce your issue
I used the latest versions of both juiceshop as well as CTFd. I've exported the juiceshop challenges using the
juice-shop-ctf
command, which produces the zip file. I then created a new instance of CTFd and imported the zip file, which triggers the error for me. I didn't do any customization to either.Any associated stack traces or error logs
I am not 100% sure what's to blame here: the juiceshop export file or the import routine. But if the export file is wrong somehow I would expect CTFd to complain about that.
The text was updated successfully, but these errors were encountered: