Skip to content

Commit c22f979

Browse files
authored
[aws][feat] Add searching instances also by region and make SEVERITY_MAPPING statically (#2272)
1 parent 65c98f7 commit c22f979

File tree

4 files changed

+142
-11
lines changed

4 files changed

+142
-11
lines changed

fixlib/fixlib/baseresources.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ class Finding:
263263
details: Optional[Json] = None
264264

265265

266+
SEVERITY_MAPPING = {
267+
"INFORMATIONAL": Severity.info,
268+
"LOW": Severity.low,
269+
"MEDIUM": Severity.medium,
270+
"HIGH": Severity.high,
271+
"CRITICAL": Severity.critical,
272+
}
273+
274+
266275
@define(slots=True)
267276
class Assessment:
268277
# The provider of the security assessment

plugins/aws/fix_plugin_aws/resource/ec2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,9 @@ class AwsEc2Instance(EC2Taggable, AwsResource, BaseInstance):
14121412
def collect_resources(cls, builder: GraphBuilder) -> None:
14131413
super().collect_resources(builder)
14141414
ec2_instance_types = set()
1415-
for instance in builder.nodes(clazz=AwsEc2Instance):
1416-
ec2_instance_types.add(instance.instance_type)
1415+
for instance in builder.nodes(clazz=AwsEc2Instance, _region=builder.region):
1416+
if instance.instance_type:
1417+
ec2_instance_types.add(instance.instance_type)
14171418
if ec2_instance_types:
14181419
builder.submit_work(
14191420
service_name, AwsEc2InstanceType.collect_resource_types, builder, list(ec2_instance_types)

plugins/aws/fix_plugin_aws/resource/inspector.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from fix_plugin_aws.resource.ec2 import AwsEc2Instance
1111
from fix_plugin_aws.resource.ecr import AwsEcrRepository
1212
from fix_plugin_aws.resource.lambda_ import AwsLambdaFunction
13-
from fixlib.baseresources import PhantomBaseResource, Severity, Finding
13+
from fixlib.baseresources import SEVERITY_MAPPING, PhantomBaseResource, Severity, Finding
1414
from fixlib.json_bender import Bender, S, ForallBend, Bend, F
1515
from fixlib.types import Json
1616

@@ -105,18 +105,11 @@ class AwsInspectorFinding(AwsResource, PhantomBaseResource):
105105
updated_at: Optional[datetime] = field(default=None, metadata={"description": "The date and time the finding was last updated at."}) # fmt: skip
106106

107107
def parse_finding(self, source: Json) -> Finding:
108-
severity_mapping = {
109-
"INFORMATIONAL": Severity.info,
110-
"LOW": Severity.low,
111-
"MEDIUM": Severity.medium,
112-
"HIGH": Severity.high,
113-
"CRITICAL": Severity.critical,
114-
}
115108
finding_title = self.safe_name
116109
if not self.finding_severity:
117110
finding_severity = Severity.medium
118111
else:
119-
finding_severity = severity_mapping.get(self.finding_severity, Severity.medium)
112+
finding_severity = SEVERITY_MAPPING.get(self.finding_severity, Severity.medium)
120113
description = self.description
121114
remediation = ""
122115
if self.remediation and self.remediation.recommendation:
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{
2+
"InstanceTypes": [
3+
{
4+
"InstanceType": "m4.large",
5+
"CurrentGeneration": true,
6+
"FreeTierEligible": false,
7+
"SupportedUsageClasses": [
8+
"on-demand",
9+
"spot"
10+
],
11+
"SupportedRootDeviceTypes": [
12+
"ebs"
13+
],
14+
"SupportedVirtualizationTypes": [
15+
"hvm"
16+
],
17+
"BareMetal": false,
18+
"Hypervisor": "nitro",
19+
"ProcessorInfo": {
20+
"SupportedArchitectures": [
21+
"x86_64"
22+
],
23+
"SustainedClockSpeedInGhz": 3.5
24+
},
25+
"VCpuInfo": {
26+
"DefaultVCpus": 8,
27+
"DefaultCores": 4,
28+
"DefaultThreadsPerCore": 2,
29+
"ValidCores": [
30+
2,
31+
4
32+
],
33+
"ValidThreadsPerCore": [
34+
1,
35+
2
36+
]
37+
},
38+
"MemoryInfo": {
39+
"SizeInMiB": 16384
40+
},
41+
"InstanceStorageSupported": false,
42+
"InstanceStorageInfo": {
43+
"EbsInfo": {
44+
"EbsStorageSupported": false,
45+
"EbsStorageInfo": {
46+
"VolumeTypes": [
47+
"standard"
48+
],
49+
"VolumeSizeInGiBMin": 1,
50+
"VolumeSizeInGiBMax": 1024
51+
}
52+
},
53+
"InstanceStorageSupported": false,
54+
"InstanceStorageInfo": {
55+
"VolumeTypes": [
56+
"standard"
57+
],
58+
"VolumeSizeInGiBMin": 1,
59+
"VolumeSizeInGiBMax": 1024
60+
}
61+
},
62+
"GpuInfo": {
63+
"GPUsSupported": false,
64+
"GPUSupported": false,
65+
"GPUSupportedOnDemand": false,
66+
"GPUSupportedSpot": false
67+
},
68+
"FpgaInfo": {
69+
"FPGAsSupported": false,
70+
"FPGASupported": false,
71+
"FPGASupportedOnDemand": false,
72+
"FPGASupportedSpot": false
73+
},
74+
"InferenceAcceleratorInfo": {
75+
"InferenceAcceleratorsSupported": false,
76+
"InferenceAcceleratorsSupportedOnDemand": false,
77+
"InferenceAcceleratorsSupportedSpot": false
78+
},
79+
"EbsInfo": {
80+
"EbsOptimizedSupport": "default",
81+
"EncryptionSupport": "supported",
82+
"EbsOptimizedInfo": {
83+
"BaselineBandwidthInMbps": 2500,
84+
"BaselineThroughputInMBps": 312.5,
85+
"BaselineIops": 12000,
86+
"MaximumBandwidthInMbps": 10000,
87+
"MaximumThroughputInMBps": 1250,
88+
"MaximumIops": 40000
89+
},
90+
"NvmeSupport": "required"
91+
},
92+
"NetworkInfo": {
93+
"NetworkPerformance": "Up to 12.5 Gigabit",
94+
"MaximumNetworkInterfaces": 4,
95+
"MaximumNetworkCards": 1,
96+
"DefaultNetworkCardIndex": 0,
97+
"NetworkCards": [
98+
{
99+
"NetworkCardIndex": 0,
100+
"NetworkPerformance": "Up to 12.5 Gigabit",
101+
"MaximumNetworkInterfaces": 4
102+
}
103+
],
104+
"Ipv4AddressesPerInterface": 15,
105+
"Ipv6AddressesPerInterface": 15,
106+
"Ipv6Supported": true,
107+
"EnaSupport": "required",
108+
"EfaSupported": false,
109+
"EncryptionInTransitSupported": true
110+
},
111+
"PlacementGroupInfo": {
112+
"SupportedStrategies": [
113+
"cluster",
114+
"partition",
115+
"spread"
116+
]
117+
},
118+
"HibernationSupported": false,
119+
"BurstablePerformanceSupported": false,
120+
"DedicatedHostsSupported": true,
121+
"AutoRecoverySupported": true,
122+
"SupportedBootModes": [
123+
"legacy-bios",
124+
"uefi"
125+
]
126+
}
127+
]
128+
}

0 commit comments

Comments
 (0)