-
Notifications
You must be signed in to change notification settings - Fork 792
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
Data dir #994
Conversation
@@ -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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
monkey/monkey_island/cc/encryptor.py
Outdated
|
||
|
||
encryptor = Encryptor() | ||
def encryptor(): |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
monkey/monkey_island/cc/encryptor.py
Outdated
|
||
def __init__(self): | ||
self._load_key() | ||
def __init__(self, data_dir): |
There was a problem hiding this comment.
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
monkey/monkey_island/cc/encryptor.py
Outdated
return self._unpad(cipher.decrypt(enc_message[AES.block_size :]).decode()) | ||
|
||
|
||
def initialize_encryptor(data_dir): |
There was a problem hiding this comment.
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 = ( |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 @@ | |||
{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
What does this PR do?
Adds a
data_dir
field toserver_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 indata_dir
. Unit tests have been added forEncryptor
.PR Checklist
Testing Checklist