Skip to content

Commit 02c0f59

Browse files
Merge pull request #2779 from blacklanternsecurity/fix-openssl-deps
Fix Medusa Deps Failure
2 parents 50811a7 + 677f4f5 commit 02c0f59

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

bbot/core/helpers/depsinstaller/installer.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import sys
33
import stat
44
import json
5+
import mmh3
6+
import orjson
57
import shutil
68
import getpass
79
import logging
@@ -68,7 +70,7 @@ class DepsInstaller:
6870
},
6971
],
7072
# to compile just about any tool, we need the openssl dev headers
71-
"openssl": [
73+
"openssl_dev_headers": [
7274
{
7375
"name": "Install OpenSSL library and development headers (Debian/Ubuntu)",
7476
"package": {"name": ["libssl-dev", "openssl"], "state": "present"},
@@ -439,6 +441,13 @@ def ensure_root(self, message=""):
439441
log.warning("Incorrect password")
440442

441443
async def install_core_deps(self):
444+
# skip if we've already successfully installed core deps for this definition
445+
core_deps_hash = str(mmh3.hash(orjson.dumps(self.CORE_DEPS, option=orjson.OPT_SORT_KEYS)))
446+
core_deps_cache_file = self.parent_helper.cache_dir / core_deps_hash
447+
if core_deps_cache_file.exists():
448+
log.debug("Skipping core dependency installation (cache hit)")
449+
return
450+
442451
to_install = set()
443452
to_install_friendly = set()
444453
playbook = []
@@ -454,6 +463,7 @@ async def install_core_deps(self):
454463
else:
455464
playbook.extend(package_name_or_playbook)
456465
# install ansible community.general collection
466+
overall_success = True
457467
if not self.setup_status.get("ansible:community.general", False):
458468
log.info("Installing Ansible Community General Collection")
459469
try:
@@ -465,6 +475,7 @@ async def install_core_deps(self):
465475
log.warning(
466476
f"Failed to install Ansible Community.General Collection (return code {err.returncode}): {err.stderr}"
467477
)
478+
overall_success = False
468479
# construct ansible playbook
469480
if to_install:
470481
playbook.append(
@@ -478,7 +489,13 @@ async def install_core_deps(self):
478489
if playbook:
479490
log.info(f"Installing core BBOT dependencies: {','.join(sorted(to_install_friendly))}")
480491
self.ensure_root()
481-
self.ansible_run(tasks=playbook)
492+
success, _ = self.ansible_run(tasks=playbook)
493+
overall_success &= success
494+
495+
# mark cache only if everything succeeded (or nothing needed doing)
496+
if overall_success:
497+
with suppress(Exception):
498+
core_deps_cache_file.touch()
482499

483500
def _setup_sudo_cache(self):
484501
if not self._sudo_cache_setup:

0 commit comments

Comments
 (0)