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

Log in on Island restart bug #3122

Closed
4 tasks done
Tracked by #2049
shreyamalviya opened this issue Mar 17, 2023 · 0 comments · Fixed by #3154 or #3178
Closed
4 tasks done
Tracked by #2049

Log in on Island restart bug #3122

shreyamalviya opened this issue Mar 17, 2023 · 0 comments · Fixed by #3154 or #3178
Assignees
Labels
Bug An error, flaw, misbehavior or failure in the Monkey or Monkey Island. Complexity: Medium Impact: Critical
Milestone

Comments

@shreyamalviya
Copy link
Contributor

shreyamalviya commented Mar 17, 2023

Describe the bug

If you run the Island, stop it, and run it again within a few seconds (I don't know the exact time for which this happens), you don't have to log in to the Island again, and you get an error in the credentials repository (because without logging in again, the encryptor can't be unlocked).

It goes away if you logout (using the /logout endpoint) and then login again, and any credentials configured will also appear in the configuration then.

To Reproduce

Steps to reproduce the behavior:

  1. Run the Island
  2. Configure some credentials
  3. Stop the Island
  4. Run the Island again
  5. Check Island logs for error
  6. Check configured credentials to see none
  7. Use the /logout endpoint to log out
  8. Log in again
  9. Check Island logs for no errors
  10. Check configured credentials, you can see them again

Expected behavior

You should be asked to log in again if the Island is restarted. The credentials repository error will also go away then.

Logs and Video

Relevant Island logs
2023-03-17 07:33:47,234 - ERROR - app.py:1744 - log_exception() - Exception on /api/propagation-credentials/configured-credentials [GET]
Traceback (most recent call last):
  File "/home/shreya_malviya/infection_monkey/monkey/monkey_island/cc/repositories/mongo_credentials_repository.py", line 63, in _get_credentials_from_collection
    plaintext_credentials = self._decrypt_credentials_mapping(encrypted_credentials)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shreya_malviya/infection_monkey/monkey/monkey_island/cc/repositories/mongo_credentials_repository.py", line 103, in _decrypt_credentials_mapping
    decrypted_component = {
                          ^
  File "/home/shreya_malviya/infection_monkey/monkey/monkey_island/cc/repositories/mongo_credentials_repository.py", line 104, in <dictcomp>
    key: self._repository_encryptor.decrypt(value).decode()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shreya_malviya/infection_monkey/monkey/monkey_island/cc/server_utils/encryption/repository_encryptor.py", line 67, in decrypt
    raise LockedKeyError("Cannot decrypt while the encryptor is locked")
monkey_island.cc.server_utils.encryption.i_lockable_encryptor.LockedKeyError: Cannot decrypt while the encryptor is locked

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/shreya_malviya/.local/share/virtualenvs/monkey_island-KafKf6jB/lib/python3.11/site-packages/flask/app.py", line 1823, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shreya_malviya/.local/share/virtualenvs/monkey_island-KafKf6jB/lib/python3.11/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shreya_malviya/.local/share/virtualenvs/monkey_island-KafKf6jB/lib/python3.11/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shreya_malviya/.local/share/virtualenvs/monkey_island-KafKf6jB/lib/python3.11/site-packages/flask/views.py", line 107, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shreya_malviya/.local/share/virtualenvs/monkey_island-KafKf6jB/lib/python3.11/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/shreya_malviya/infection_monkey/monkey/monkey_island/cc/resources/propagation_credentials.py", line 22, in get
    propagation_credentials = self._credentials_repository.get_configured_credentials()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shreya_malviya/infection_monkey/monkey/monkey_island/cc/repositories/mongo_credentials_repository.py", line 27, in get_configured_credentials
    return self._get_credentials_from_collection(self._database.configured_credentials)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shreya_malviya/infection_monkey/monkey/monkey_island/cc/repositories/mongo_credentials_repository.py", line 68, in _get_credentials_from_collection
    raise RetrievalError(err)
monkey_island.cc.repositories.errors.RetrievalError: Cannot decrypt while the encryptor is locked
2023-03-17 07:33:47,237 - INFO - pywsgi.py:1226 - write() - 127.0.0.1 - "GET /api/propagation-credentials/configured-credentials HTTP/1.1" 500 163 0.007080
Video
2023-03-17.13-25-51.mp4

Machine version (please complete the following information):

  • OS: Linux

Tasks

  • Modify the AuthenticationService to invalidate all sessions/tokens on startup (0d)
    • Clear uuid field for all users on startup (call the AuthenticationService.logout() function??)
  • Unit test for logout on restart (0.25d) @cakekoa
  • BB test for logout (0d) @cakekoa
@shreyamalviya shreyamalviya added Bug An error, flaw, misbehavior or failure in the Monkey or Monkey Island. Impact: Critical Complexity: Medium labels Mar 17, 2023
@shreyamalviya shreyamalviya self-assigned this Mar 28, 2023
@mssalvatore mssalvatore added this to the v2.1.0 milestone Mar 28, 2023
@mssalvatore mssalvatore reopened this Mar 29, 2023
@cakekoa cakekoa mentioned this issue Mar 29, 2023
10 tasks
ilija-lazoroski added a commit that referenced this issue Mar 30, 2023
ilija-lazoroski added a commit that referenced this issue Mar 30, 2023
mssalvatore pushed a commit that referenced this issue Mar 30, 2023
@mssalvatore mssalvatore reopened this Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An error, flaw, misbehavior or failure in the Monkey or Monkey Island. Complexity: Medium Impact: Critical
Projects
None yet
2 participants