Skip to content

Commit 016a421

Browse files
bluesentinelsecMichael Long
andauthored
Support aarch64 systems (#62)
* WIP: fix aarch64 issue * refactor & add more test cases --------- Co-authored-by: Michael Long <[email protected]>
1 parent c4d48d4 commit 016a421

File tree

2 files changed

+75
-10
lines changed

2 files changed

+75
-10
lines changed

entrypoint/entrypoint/orchestrator.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import platform
66
import shutil
7+
import sys
78
import tempfile
89

910
from entrypoint import dockerfile
@@ -80,18 +81,13 @@ def post_dockerfile_step_summary(args, total_vulns):
8081

8182
def download_install_sbomgen(sbomgen_version: str, install_dst: str) -> bool:
8283
cpu_arch = platform.machine()
83-
if "x86_64" in cpu_arch:
84-
cpu_arch = "amd64"
85-
86-
elif "arm64" in cpu_arch:
87-
cpu_arch = "arm64"
88-
89-
else:
90-
logging.error(f"expected a CPU architecture of x86_64, arm64, or amd64, but received: {cpu_arch}")
91-
return False
84+
sbomgen_arch = get_sbomgen_arch(cpu_arch)
85+
if not sbomgen_arch:
86+
logging.error(f"expected a CPU architecture of x86_64, amd64, arm64, or aarch64, but received: {cpu_arch}")
87+
sys.exit(1)
9288

9389
# download sbomgen
94-
url = installer.get_sbomgen_url("Linux", cpu_arch, sbomgen_version)
90+
url = installer.get_sbomgen_url("Linux", sbomgen_arch, sbomgen_version)
9591
dst = tempfile.gettempdir()
9692
dst = os.path.join(dst, "inspector-sbomgen.zip")
9793
ret = installer.download_sbomgen(url, dst)
@@ -124,6 +120,32 @@ def download_install_sbomgen(sbomgen_version: str, install_dst: str) -> bool:
124120
return True
125121

126122

123+
def get_sbomgen_arch(host_cpu):
124+
"""
125+
get the CPU architecture for the
126+
inspector-sbomgen release binary
127+
based on the host system's CPU arch
128+
"""
129+
if not host_cpu:
130+
return None
131+
132+
# map the host platform's CPU architecture to
133+
# the correct sbomgen binary architecture
134+
architecture_map = {
135+
"x86_64": "amd64",
136+
"amd64": "amd64",
137+
"arm64": "arm64",
138+
"aarch64": "arm64"
139+
}
140+
141+
for supported_cpu in architecture_map:
142+
if host_cpu.lower() == supported_cpu:
143+
sbomgen_arch = architecture_map[supported_cpu]
144+
return sbomgen_arch
145+
146+
return None
147+
148+
127149
def invoke_sbomgen(args) -> int:
128150
sbomgen = installer.get_sbomgen_install_path()
129151
if sbomgen == "":

entrypoint/tests/test_orchestrator.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,49 @@ def test_system_against_dockerfile_findings(self):
116116
dockerfile.write_dockerfile_report_csv(args.out_scan, args.out_dockerfile_scan_csv)
117117
dockerfile.write_dockerfile_report_md(args.out_scan, args.out_dockerfile_scan_md)
118118

119+
def test_get_sbomgen_arch(self):
120+
121+
test_cases = [
122+
# supported platforms (ARM and Intel 64-bit)
123+
{"input": "x86_64", "expected": "amd64"},
124+
{"input": "amd64", "expected": "amd64"},
125+
{"input": "arm64", "expected": "arm64"},
126+
{"input": "aarch64", "expected": "arm64"},
127+
128+
# test case insensitivity
129+
{"input": "X86_64", "expected": "amd64"},
130+
{"input": "AMD64", "expected": "amd64"},
131+
{"input": "ARM64", "expected": "arm64"},
132+
{"input": "aARCh64", "expected": "arm64"},
133+
134+
# unsupported platforms (32-bit, non-intel, non-arm)
135+
{"input": "arm", "expected": None},
136+
{"input": "armv6l", "expected": None},
137+
{"input": "armv7l", "expected": None},
138+
{"input": "armv8l", "expected": None},
139+
{"input": "i386", "expected": None},
140+
{"input": "i486", "expected": None},
141+
{"input": "i586", "expected": None},
142+
{"input": "i686", "expected": None},
143+
{"input": "ppc", "expected": None},
144+
{"input": "ppc64", "expected": None},
145+
{"input": "ppc64le", "expected": None},
146+
{"input": "sparc", "expected": None},
147+
{"input": "sparc64", "expected": None},
148+
{"input": "mips", "expected": None},
149+
{"input": "mips64", "expected": None},
150+
151+
# malformed input
152+
{"input": "garbage", "expected": None},
153+
{"input": "213123123123", "expected": None},
154+
{"input": "", "expected": None},
155+
{"input": None, "expected": None},
156+
]
157+
158+
for each_test in test_cases:
159+
result = orchestrator.get_sbomgen_arch(each_test["input"])
160+
self.assertEqual(result, each_test["expected"])
161+
119162

120163
def read_test_file(file: str) -> str:
121164
file_contents = ""

0 commit comments

Comments
 (0)