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

Data dir #994

Merged
merged 9 commits into from
Feb 25, 2021
Merged

Data dir #994

merged 9 commits into from
Feb 25, 2021

Conversation

mssalvatore
Copy link
Collaborator

What does this PR do?

Adds a data_dir field to server_config.json so that Infection Monkey can store runtime artifacts in a location that is configurable at runtime.

The mongo_key.bin is now stored in data_dir. Unit tests have been added for Encryptor.

PR Checklist

  • Have you added an explanation of what your changes do and why you'd like to include them?
  • Is the TravisCI build passing?
  • Was the documentation framework updated to reflect the changes?

Testing Checklist

  • Added relevant unit tests?
  • Have you successfully tested your changes locally? Elaborate:

    Tested by running the monkey locally and building/running an AppImage

  • If applicable, add screenshots or log transcripts of the feature working

@mssalvatore mssalvatore requested a review from VakarisZ February 24, 2021 16:14
@@ -16,3 +16,5 @@
DEFAULT_LOGGER_CONFIG_PATH = os.path.join(
MONKEY_ISLAND_ABS_PATH, "cc", "island_logger_default_config.json"
)

DEFAULT_DATA_DIR = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc")
Copy link
Contributor

@VakarisZ VakarisZ Feb 25, 2021

Choose a reason for hiding this comment

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

Term "Data" is misleading. This is a path to island codebase, that's what I'd call this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By default it is, only because that's what we're doing today. We need to move away from storing data generated at runtime alongside our code. Since we're so close to a release, I don't want to change that right now, except when running from an AppImage.



encryptor = Encryptor()
def encryptor():
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice application of singleton pattern, but I'd still prefer method names to be verbs. So maybe get_encryptor()?

@@ -22,6 +22,7 @@
STANDARD_WITH_CREDENTIALS = os.path.join(
TEST_RESOURCES_DIR, "server_config_standard_with_credentials.json"
)
DATA_DIR = os.path.join(TEST_RESOURCES_DIR, "server_config_data_dir.json")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a path to a file server_config_data_dir.json. Name DATA_DIR implies that it's a directory full of some kind of data. Find a more specific name for this variable, that would convey what server_config_data_dir.json is, like PATH_TO_SOMETHING


def __init__(self):
self._load_key()
def __init__(self, data_dir):
Copy link
Contributor

Choose a reason for hiding this comment

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

Data_dir is too abstract. I'd rename this to something like password_file_dir

return self._unpad(cipher.decrypt(enc_message[AES.block_size :]).decode())


def initialize_encryptor(data_dir):
Copy link
Contributor

Choose a reason for hiding this comment

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

Once again, this is not data_dir. In the context of encryptor, this is where password is, so it's password_file_dir_path or something like that.

@@ -37,22 +39,29 @@ def _load_from_json(self, config_json: str) -> EnvironmentConfig:

def _load_from_dict(self, dict_data: Dict):
user_creds = UserCreds.get_from_dict(dict_data)
aws = dict_data['aws'] if 'aws' in dict_data else None
aws = dict_data["aws"] if "aws" in dict_data else None
data_dir = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Var name should be more explicit if possible

config_dict = {
"server_config": self.server_config,
"deployment": self.deployment,
"data_dir": self.data_dir,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same complaint, this should be more specific. In the context of environment config, this could be something like path_to_dir_of_config_files or something.

Comment on lines 14 to 23
def test_aes_cbc_encryption():
initialize_encryptor(TEST_DATA_DIR)

assert encryptor().enc(PLAINTEXT) != PLAINTEXT


def test_aes_cbc_decryption():
initialize_encryptor(TEST_DATA_DIR)

assert encryptor().dec(CYPHERTEXT) == PLAINTEXT
Copy link
Contributor

Choose a reason for hiding this comment

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

I think more important than both of these cases would be to test assert encryptor().dec(encryptor().enc(PLAINTEXT)) == PLAINTEXT. Currently, if encryption fails, but still generates something your test would pass.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I waffled back and forth on this. I'll add it.

@@ -0,0 +1,7 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Name for this file doesn't make sense. If this is our new format of server_config.json then we should move this file to test_common folder (so we can reuse it for all tests that involve server_config.json) and rename it to server_config_test_data.json or something similar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I renamed it to server_config_with_data_dir.json to help alleviate some ambiguity. As for it's placement, it's currently in the testing directory. It looks like we have testing and test_common. Since we're planning on moving all of our tests under a common directory, we can sort out the finer details of where this file lives when we undertake that endeavor.

Copy link
Contributor

@VakarisZ VakarisZ left a comment

Choose a reason for hiding this comment

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

Please review my comments.

I approve this PR, because I haven't found issues big enough to be worth a discussion (feel free to zoom if you think otherwise). Resolve my comments how you best see fit and merge.

@mssalvatore mssalvatore merged commit 8264b5a into appimage Feb 25, 2021
@mssalvatore mssalvatore deleted the data-dir branch April 15, 2021 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants