Skip to content

Commit 84aa760

Browse files
(v1.4.1 hotfix) Fix multi-arch container image scanning (#136)
* added multi-arch image workflow * disable scan validator * debugging multi arch CICD * added 'platform' argument to action.yml * set action version to investigation branch * test amd64 images * test multi-arch matrix * verify workaround * Add multi-platform validation to prevent regression of platform argument - Add validate_multi_platform_image_support.py script to validate SBOM architecture matches expected platform - Update test_multi_arch_images.yml workflow to validate platform argument is correctly passed through to inspector-sbomgen * re-enable inspector scan validation * remove inspector-scan validator, not applicable * remove boilerplate * test action against multi-arch fix * revert test workflows to v1.4.0 * remove emoji characters from console logs
1 parent c55a96c commit 84aa760

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Test Multi-arch images
2+
3+
on:
4+
schedule:
5+
- cron: '0 */6 * * *' # runs every 6 hours
6+
push:
7+
branches: #
8+
- '*'
9+
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
jobs:
15+
test_multi_arch:
16+
runs-on: ubuntu-latest
17+
environment:
18+
name: plugin-development
19+
strategy:
20+
matrix:
21+
platform:
22+
- "linux/386"
23+
- "linux/amd64"
24+
- "linux/arm/v5"
25+
- "linux/arm/v7"
26+
- "linux/arm64/v8"
27+
- "linux/ppc64le"
28+
- "linux/riscv64"
29+
- "linux/s390x"
30+
31+
steps:
32+
33+
- name: Checkout this repository
34+
uses: actions/checkout@v4
35+
36+
- name: Configure AWS credentials
37+
uses: aws-actions/configure-aws-credentials@v4
38+
with:
39+
aws-region: ${{ secrets.AWS_REGION }}
40+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
41+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
42+
role-to-assume: ${{ secrets.AWS_IAM_ROLE }}
43+
44+
- name: Test multi-arch image - ${{ matrix.platform }}
45+
id: inspector
46+
uses: aws-actions/vulnerability-scan-github-action-for-amazon-inspector@investigate_multi_arch
47+
with:
48+
artifact_type: 'container'
49+
artifact_path: 'debian:trixie'
50+
platform: ${{ matrix.platform }}
51+
display_vulnerability_findings: "enabled"
52+
sbomgen_version: "latest"
53+
54+
- name: Demonstrate SBOM Output (JSON)
55+
run: cat ${{ steps.inspector.outputs.artifact_sbom }}
56+
57+
- name: Display scan results
58+
run: cat ${{ steps.inspector.outputs.inspector_scan_results }}
59+
60+
- name: Validate multi-arch - ${{ matrix.platform }}
61+
run: python3 validator/validate_multi_platform_image_support.py --platform "${{ matrix.platform }}" --sbom "${{ steps.inspector.outputs.artifact_sbom }}"
62+
63+

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ runs:
162162
- --thresholds
163163
- ${{ inputs.threshold_fixable_only == 'true' && '--threshold-fixable-only' || '--no-op' }}
164164
- ${{ inputs.show_only_fixable_vulns == 'true' && '--show-only-fixable-vulns'|| '--no-op' }}
165+
- --platform=${{ inputs.platform || '' }}
165166
- --critical=${{ inputs.critical_threshold }}
166167
- --high=${{ inputs.high_threshold }}
167168
- --medium=${{ inputs.medium_threshold }}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import json
5+
import sys
6+
7+
8+
def get_expected_arch(platform):
9+
"""Map platform string to expected architecture value in SBOM"""
10+
platform_to_arch = {
11+
"linux/386": "386",
12+
"linux/amd64": "amd64",
13+
"linux/arm/v5": "arm",
14+
"linux/arm/v7": "arm",
15+
"linux/arm64/v8": "arm64",
16+
"linux/ppc64le": "ppc64le",
17+
"linux/riscv64": "riscv64",
18+
"linux/s390x": "s390x"
19+
}
20+
21+
if platform not in platform_to_arch:
22+
raise ValueError(f"Unknown platform: {platform}")
23+
24+
return platform_to_arch[platform]
25+
26+
27+
def extract_arch_from_sbom(sbom_file):
28+
"""Extract architecture from SBOM metadata"""
29+
try:
30+
with open(sbom_file, 'r') as f:
31+
sbom = json.load(f)
32+
33+
properties = sbom.get('metadata', {}).get('component', {}).get('properties', [])
34+
35+
for prop in properties:
36+
if prop.get('name') == 'amazon:inspector:sbom_generator:image_arch':
37+
return prop.get('value')
38+
39+
raise ValueError("Architecture property not found in SBOM")
40+
41+
except Exception as e:
42+
raise ValueError(f"Failed to parse SBOM: {e}")
43+
44+
45+
def main():
46+
parser = argparse.ArgumentParser(description='Validate SBOM architecture matches expected platform')
47+
parser.add_argument('--platform', required=True, help='Expected platform (e.g., linux/amd64)')
48+
parser.add_argument('--sbom', required=True, help='Path to SBOM file')
49+
50+
args = parser.parse_args()
51+
52+
try:
53+
expected_arch = get_expected_arch(args.platform)
54+
actual_arch = extract_arch_from_sbom(args.sbom)
55+
56+
print(f"Platform: {args.platform}")
57+
print(f"Expected arch: {expected_arch}")
58+
print(f"Actual arch: {actual_arch}")
59+
60+
if actual_arch != expected_arch:
61+
print(f" Architecture mismatch for platform {args.platform}")
62+
print(f" Expected: {expected_arch}")
63+
print(f" Found: {actual_arch}")
64+
sys.exit(1)
65+
66+
print(f"Architecture validation passed: {actual_arch} matches expected {expected_arch}")
67+
68+
except Exception as e:
69+
print(f"Validation failed: {e}")
70+
sys.exit(1)
71+
72+
73+
if __name__ == '__main__':
74+
main()

0 commit comments

Comments
 (0)