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

KeyError: 'LOGIN_REQUIRED' #400

Closed
tw-sentry-io bot opened this issue Aug 1, 2020 · 2 comments · Fixed by #401
Closed

KeyError: 'LOGIN_REQUIRED' #400

tw-sentry-io bot opened this issue Aug 1, 2020 · 2 comments · Fixed by #401
Assignees
Labels
bug Something isn't working critical Added to bug issues if it causes catastrophic failures in common situations server affecting natlas-server

Comments

@tw-sentry-io
Copy link

tw-sentry-io bot commented Aug 1, 2020

It looks like when creating a new database, the required values aren't being set correctly. Lazy initialization of these config options is probably to blame and the database config options should probably be moved into a migration. Either that or we need to make a clear distinction to ensure the app's first launch does all the setup things it needs to do.

Sentry Issue: NATLAS-SERVER-10

KeyError: 'LOGIN_REQUIRED'
(2 additional frame(s) were not displayed)
...
  File "flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "flask/_compat.py", line 39, in reraise
    raise value
  File "flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "app/auth/wrappers.py", line 13, in decorated_function
    if current_app.config["LOGIN_REQUIRED"] and not current_user.is_authenticated:
@0xdade 0xdade added bug Something isn't working server affecting natlas-server labels Aug 1, 2020
@0xdade
Copy link
Member

0xdade commented Aug 1, 2020

Confirmed behavior:

In development, these values get populated because the app context is restarted to go into debugging mode, but in production the app context doesn't restart so they after first launch they are just left empty.

Workaround

Restarting the container should cause the values to get populated and workaround this bug until the update is merged that fixes this issue.

Production

➜ docker-compose up natlas-server               
elastic is up-to-date
Recreating natlas_natlas-server_1 ... done
Attaching to natlas_natlas-server_1
natlas-server_1   | INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
natlas-server_1   | INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade  -> ed2f92f790d3, users table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade ed2f92f790d3 -> 271044238ee1, empty message
natlas-server_1   | /.venv/lib/python3.8/site-packages/alembic/ddl/sqlite.py:40: UserWarning: Skipping unsupported ALTER for creation of implicit constraintPlease refer to the batch mode feature which allows for SQLite migrations using a copy-and-move strategy.
natlas-server_1   |   util.warn(
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 271044238ee1 -> aeb6c660a13a, empty message
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade aeb6c660a13a -> 997bbd9a505a, empty message
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 997bbd9a505a -> c5cf61d816c9, Add results_per_page and preview_length to user
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade c5cf61d816c9 -> 3fb710fe0fe1, ConfigItem table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 3fb710fe0fe1 -> 7d9abd1be32c, NatlasServices table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 7d9abd1be32c -> 571892d95516, agent config table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 571892d95516 -> b9aebd0a8593, RescanTasks
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade b9aebd0a8593 -> e59d726ef9c1, scopetags
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade e59d726ef9c1 -> 690687d71334, agent tracking
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 690687d71334 -> 09ac195ca9c7, Better agent config control
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 09ac195ca9c7 -> 580dfaf7e3f5, Email Token table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 580dfaf7e3f5 -> a1738920a0d3, User Result Format Selection
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade a1738920a0d3 -> d4685e98a91f, add udpScan to agent config
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade d4685e98a91f -> 6147093c140b, process timeouts for web and vnc screenshots
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 6147093c140b -> 9b9fdebcdcb8, Add ScopeLogs to db
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 9b9fdebcdcb8 -> 6eb79ba67acb, better invitations and resets
natlas-server_1   |  * Serving Flask app "./natlas-server.py"
natlas-server_1   |  * Environment: production
natlas-server_1   |    WARNING: This is a development server. Do not use it in a production deployment.
natlas-server_1   |    Use a production WSGI server instead.
natlas-server_1   |  * Debug mode: off
natlas-server_1   | [2020-08-01 22:46:57,315] WARNING in scan_group: 2020-08-01 22:46:57.315726 - Scan manager could not be instantiated because there was no scope configured.
natlas-server_1   | 
natlas-server_1   |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

Development

➜ docker-compose up natlas-server               
elastic is up-to-date
Starting natlas_natlas-server_1 ... done
Attaching to natlas_natlas-server_1
natlas-server_1   | INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
natlas-server_1   | INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade  -> ed2f92f790d3, users table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade ed2f92f790d3 -> 271044238ee1, empty message
natlas-server_1   | /.venv/lib/python3.8/site-packages/alembic/ddl/sqlite.py:40: UserWarning: Skipping unsupported ALTER for creation of implicit constraintPlease refer to the batch mode feature which allows for SQLite migrations using a copy-and-move strategy.
natlas-server_1   |   util.warn(
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 271044238ee1 -> aeb6c660a13a, empty message
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade aeb6c660a13a -> 997bbd9a505a, empty message
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 997bbd9a505a -> c5cf61d816c9, Add results_per_page and preview_length to user
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade c5cf61d816c9 -> 3fb710fe0fe1, ConfigItem table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 3fb710fe0fe1 -> 7d9abd1be32c, NatlasServices table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 7d9abd1be32c -> 571892d95516, agent config table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 571892d95516 -> b9aebd0a8593, RescanTasks
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade b9aebd0a8593 -> e59d726ef9c1, scopetags
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade e59d726ef9c1 -> 690687d71334, agent tracking
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 690687d71334 -> 09ac195ca9c7, Better agent config control
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 09ac195ca9c7 -> 580dfaf7e3f5, Email Token table
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 580dfaf7e3f5 -> a1738920a0d3, User Result Format Selection
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade a1738920a0d3 -> d4685e98a91f, add udpScan to agent config
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade d4685e98a91f -> 6147093c140b, process timeouts for web and vnc screenshots
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 6147093c140b -> 9b9fdebcdcb8, Add ScopeLogs to db
natlas-server_1   | INFO  [alembic.runtime.migration] Running upgrade 9b9fdebcdcb8 -> 6eb79ba67acb, better invitations and resets
natlas-server_1   |  * Serving Flask app "./natlas-server.py" (lazy loading)
natlas-server_1   |  * Environment: development
natlas-server_1   |  * Debug mode: on
natlas-server_1   |  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
natlas-server_1   |  * Restarting with stat
natlas-server_1   |  * Debugger is active!
natlas-server_1   |  * Debugger PIN: 288-269-163
natlas-server_1   | [2020-08-01 22:45:53,282] INFO in __init__: NatlasServices populated with defaults
natlas-server_1   | [2020-08-01 22:45:53,295] INFO in __init__: AgentConfig populated with defaults
natlas-server_1   | [2020-08-01 22:45:53,304] INFO in __init__: AgentScript populated with default
natlas-server_1   | [2020-08-01 22:45:53,307] WARNING in scan_group: 2020-08-01 22:45:53.307736 - Scan manager could not be instantiated because there was no scope configured.
natlas-server_1   | 
natlas-server_1   | [2020-08-01 22:45:53,621] WARNING in scan_group: 2020-08-01 22:45:53.621139 - Scan manager could not be instantiated because there was no scope configured.

The correct thing to do here is to move these to migrations that do conditional execution (i.e. if the value is already set in the database, don't set change the user's setting).

@0xdade 0xdade self-assigned this Aug 1, 2020
0xdade referenced this issue in 0xdade/natlas Aug 2, 2020
… at init

This closes #400 and sets the standard behavior of any new required defaults being populated in migrations.
0xdade referenced this issue in 0xdade/natlas Aug 2, 2020
… at init

This closes #400 and sets the standard behavior of any new required defaults being populated in migrations.
@0xdade 0xdade added the critical Added to bug issues if it causes catastrophic failures in common situations label Aug 2, 2020
@tw-sentry-io
Copy link
Author

tw-sentry-io bot commented Aug 2, 2020

Sentry issue: NATLAS-SERVER-Z

0xdade referenced this issue in 0xdade/natlas Aug 4, 2020
… at init

This closes #400 and sets the standard behavior of any new required defaults being populated in migrations.
0xdade added a commit that referenced this issue Aug 5, 2020
… at init

This closes #400 and sets the standard behavior of any new required defaults being populated in migrations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working critical Added to bug issues if it causes catastrophic failures in common situations server affecting natlas-server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant