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

Allow str booleans for osquery file carving opts #1100

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions tests/osquery/test_osquery_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,174 @@ def test_config_ok(self):
'removed': False}}}}
)

def test_config_disable_carver_true_str(self):
self.configuration.options = {"disable_carver": "true"}
self.configuration.save()
self.assertEqual(
self.configuration.get_all_flags(),
{'config_plugin': 'tls',
'config_refresh': 1200,
'config_tls_endpoint': '/public/osquery/config',
'disable_carver': 'true',
'disable_distributed': False,
'disable_enrollment': False,
'distributed_interval': 60,
'distributed_plugin': 'tls',
'distributed_tls_read_endpoint': '/public/osquery/distributed/read',
'distributed_tls_write_endpoint': '/public/osquery/distributed/write',
'enroll_tls_endpoint': '/public/osquery/enroll',
'logger_plugin': 'tls',
'logger_tls_compress': True,
'logger_tls_endpoint': '/public/osquery/log',
'logger_tls_period': 60,
'pack_delimiter': '/',
'tls_hostname': 'zentral'}
)
em = self.force_enrolled_machine()
response = self.post_as_json("config", {"node_key": em.node_key})
config = response.json()
# carve options are cli only flags
self.assertEqual(
config["options"],
{'disable_distributed': False,
'distributed_interval': 60,
'distributed_plugin': 'tls',
'distributed_tls_read_endpoint': '/public/osquery/distributed/read',
'distributed_tls_write_endpoint': '/public/osquery/distributed/write',
'logger_tls_compress': True,
'logger_tls_endpoint': '/public/osquery/log',
'logger_tls_period': 60,
'pack_delimiter': '/'}
)

def test_config_carver_disable_function_true_bool(self):
self.configuration.options = {"carver_disable_function": True}
self.configuration.save()
self.assertEqual(
self.configuration.get_all_flags(),
{'carver_disable_function': True,
'config_plugin': 'tls',
'config_refresh': 1200,
'config_tls_endpoint': '/public/osquery/config',
'disable_distributed': False,
'disable_enrollment': False,
'distributed_interval': 60,
'distributed_plugin': 'tls',
'distributed_tls_read_endpoint': '/public/osquery/distributed/read',
'distributed_tls_write_endpoint': '/public/osquery/distributed/write',
'enroll_tls_endpoint': '/public/osquery/enroll',
'logger_plugin': 'tls',
'logger_tls_compress': True,
'logger_tls_endpoint': '/public/osquery/log',
'logger_tls_period': 60,
'pack_delimiter': '/',
'tls_hostname': 'zentral'}
)
em = self.force_enrolled_machine()
response = self.post_as_json("config", {"node_key": em.node_key})
config = response.json()
# carve options are cli only flags
self.assertEqual(
config["options"],
{'disable_distributed': False,
'distributed_interval': 60,
'distributed_plugin': 'tls',
'distributed_tls_read_endpoint': '/public/osquery/distributed/read',
'distributed_tls_write_endpoint': '/public/osquery/distributed/write',
'logger_tls_compress': True,
'logger_tls_endpoint': '/public/osquery/log',
'logger_tls_period': 60,
'pack_delimiter': '/'}
)

def test_config_disable_carver_false_bool(self):
self.configuration.options = {"disable_carver": False}
self.configuration.save()
self.assertEqual(
self.configuration.get_all_flags(),
{'carver_compression': False,
'carver_continue_endpoint': '/public/osquery/carver/continue',
'carver_disable_function': False,
'carver_start_endpoint': '/public/osquery/carver/start',
'config_plugin': 'tls',
'config_refresh': 1200,
'config_tls_endpoint': '/public/osquery/config',
'disable_carver': False,
'disable_distributed': False,
'disable_enrollment': False,
'distributed_interval': 60,
'distributed_plugin': 'tls',
'distributed_tls_read_endpoint': '/public/osquery/distributed/read',
'distributed_tls_write_endpoint': '/public/osquery/distributed/write',
'enroll_tls_endpoint': '/public/osquery/enroll',
'logger_plugin': 'tls',
'logger_tls_compress': True,
'logger_tls_endpoint': '/public/osquery/log',
'logger_tls_period': 60,
'pack_delimiter': '/',
'tls_hostname': 'zentral'}
)
em = self.force_enrolled_machine()
response = self.post_as_json("config", {"node_key": em.node_key})
config = response.json()
# carve options are cli only flags
self.assertEqual(
config["options"],
{'disable_distributed': False,
'distributed_interval': 60,
'distributed_plugin': 'tls',
'distributed_tls_read_endpoint': '/public/osquery/distributed/read',
'distributed_tls_write_endpoint': '/public/osquery/distributed/write',
'logger_tls_compress': True,
'logger_tls_endpoint': '/public/osquery/log',
'logger_tls_period': 60,
'pack_delimiter': '/'}
)

def test_config_disable_carver_false_str(self):
self.configuration.options = {"disable_carver": "FaLse"}
self.configuration.save()
self.assertEqual(
self.configuration.get_all_flags(),
{'carver_compression': False,
'carver_continue_endpoint': '/public/osquery/carver/continue',
'carver_disable_function': False,
'carver_start_endpoint': '/public/osquery/carver/start',
'config_plugin': 'tls',
'config_refresh': 1200,
'config_tls_endpoint': '/public/osquery/config',
'disable_carver': False,
'disable_distributed': False,
'disable_enrollment': False,
'distributed_interval': 60,
'distributed_plugin': 'tls',
'distributed_tls_read_endpoint': '/public/osquery/distributed/read',
'distributed_tls_write_endpoint': '/public/osquery/distributed/write',
'enroll_tls_endpoint': '/public/osquery/enroll',
'logger_plugin': 'tls',
'logger_tls_compress': True,
'logger_tls_endpoint': '/public/osquery/log',
'logger_tls_period': 60,
'pack_delimiter': '/',
'tls_hostname': 'zentral'}
)
em = self.force_enrolled_machine()
response = self.post_as_json("config", {"node_key": em.node_key})
config = response.json()
# carve options are cli only flags
self.assertEqual(
config["options"],
{'disable_distributed': False,
'distributed_interval': 60,
'distributed_plugin': 'tls',
'distributed_tls_read_endpoint': '/public/osquery/distributed/read',
'distributed_tls_write_endpoint': '/public/osquery/distributed/write',
'logger_tls_compress': True,
'logger_tls_endpoint': '/public/osquery/log',
'logger_tls_period': 60,
'pack_delimiter': '/'}
)

def test_os_version_with_build_numbers_cleanup(self):
tree = {}
snapshot = self.get_default_inventory_query_snapshot("macos")
Expand Down
14 changes: 13 additions & 1 deletion zentral/contrib/osquery/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,19 @@ def get_all_flags(self):
"logger_tls_compress": True,
}
flags.update(self.options)
if not flags.get("disable_carver", True) or not flags.get("carver_disable_function", True):

def check_bool_flag(v):
if isinstance(v, bool):
return v
elif isinstance(v, str):
return v.upper() == "TRUE"
else:
return False

if (
not check_bool_flag(flags.get("disable_carver", True))
or not check_bool_flag(flags.get("carver_disable_function", True))
):
flags.update({
"carver_disable_function": False,
"disable_carver": False,
Expand Down
Loading