Skip to content

Commit 8626219

Browse files
1101-1aquamatthias
andauthored
[aws][feat] Add collection of Inspector resource (#2242)
Co-authored-by: Matthias Veit <matthias_veit@yahoo.de>
1 parent 6cacdf9 commit 8626219

File tree

7 files changed

+695
-5
lines changed

7 files changed

+695
-5
lines changed

plugins/aws/fix_plugin_aws/collector.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
backup,
5050
bedrock,
5151
scp,
52+
inspector,
5253
)
5354
from fix_plugin_aws.resource.base import (
5455
AwsAccount,
@@ -117,6 +118,7 @@
117118
+ backup.resources
118119
+ amazonq.resources
119120
+ bedrock.resources
121+
+ inspector.resources
120122
)
121123
all_resources: List[Type[AwsResource]] = global_resources + regional_resources
122124

plugins/aws/fix_plugin_aws/resource/backup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class AwsBackupProtectedResource(AwsResource):
175175
}
176176
api_spec: ClassVar[AwsApiSpec] = AwsApiSpec("backup", "list-protected-resources", "Results")
177177
mapping: ClassVar[Dict[str, Bender]] = {
178-
"id": S("ResourceArn") >> F(lambda arn: arn.rsplit("/")[1]),
178+
"id": S("ResourceArn") >> F(AwsResource.id_from_arn),
179179
"name": S("ResourceName"),
180180
"resource_arn": S("ResourceArn"),
181181
"resource_type": S("ResourceType"),

plugins/aws/fix_plugin_aws/resource/inspector.py

Lines changed: 434 additions & 0 deletions
Large diffs are not rendered by default.

plugins/aws/test/collector_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def count_kind(clazz: Type[AwsResource]) -> int:
3434
# make sure all threads have been joined
3535
assert len(threading.enumerate()) == 1
3636
# ensure the correct number of nodes and edges
37-
assert count_kind(AwsResource) == 261
38-
assert len(account_collector.graph.edges) == 575
37+
assert count_kind(AwsResource) == 262
38+
assert len(account_collector.graph.edges) == 577
3939
assert len(account_collector.graph.deferred_edges) == 2
4040
for node in account_collector.graph.nodes:
4141
if isinstance(node, AwsRegion):
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
{
2+
"findings": [
3+
{
4+
"awsAccountId": "foo",
5+
"codeVulnerabilityDetails": {
6+
"cwes": [
7+
"foo",
8+
"foo",
9+
"foo"
10+
],
11+
"detectorId": "foo",
12+
"detectorName": "foo",
13+
"detectorTags": [
14+
"foo",
15+
"foo",
16+
"foo"
17+
],
18+
"filePath": {
19+
"endLine": 123,
20+
"fileName": "foo",
21+
"filePath": "foo",
22+
"startLine": 123
23+
},
24+
"referenceUrls": [
25+
"foo",
26+
"foo",
27+
"foo"
28+
],
29+
"ruleId": "foo",
30+
"sourceLambdaLayerArn": "foo"
31+
},
32+
"description": "foo",
33+
"epss": {
34+
"score": 1.234
35+
},
36+
"exploitAvailable": "NO",
37+
"exploitabilityDetails": {
38+
"lastKnownExploitAt": "2024-10-14T18:00:11Z"
39+
},
40+
"findingArn": "foo",
41+
"firstObservedAt": "2024-10-14T18:00:11Z",
42+
"fixAvailable": "NO",
43+
"inspectorScore": 1.234,
44+
"inspectorScoreDetails": {
45+
"adjustedCvss": {
46+
"adjustments": [
47+
{
48+
"metric": "foo",
49+
"reason": "foo"
50+
},
51+
{
52+
"metric": "foo",
53+
"reason": "foo"
54+
},
55+
{
56+
"metric": "foo",
57+
"reason": "foo"
58+
}
59+
],
60+
"cvssSource": "foo",
61+
"score": 1.234,
62+
"scoreSource": "foo",
63+
"scoringVector": "foo",
64+
"version": "foo"
65+
}
66+
},
67+
"lastObservedAt": "2024-10-14T18:00:11Z",
68+
"networkReachabilityDetails": {
69+
"networkPath": {
70+
"steps": [
71+
{
72+
"componentId": "foo",
73+
"componentType": "foo"
74+
},
75+
{
76+
"componentId": "foo",
77+
"componentType": "foo"
78+
},
79+
{
80+
"componentId": "foo",
81+
"componentType": "foo"
82+
}
83+
]
84+
},
85+
"openPortRange": {
86+
"begin": 123,
87+
"end": 123
88+
},
89+
"protocol": "UDP"
90+
},
91+
"packageVulnerabilityDetails": {
92+
"cvss": [
93+
{
94+
"baseScore": 1.234,
95+
"scoringVector": "foo",
96+
"source": "foo",
97+
"version": "foo"
98+
},
99+
{
100+
"baseScore": 1.234,
101+
"scoringVector": "foo",
102+
"source": "foo",
103+
"version": "foo"
104+
},
105+
{
106+
"baseScore": 1.234,
107+
"scoringVector": "foo",
108+
"source": "foo",
109+
"version": "foo"
110+
}
111+
],
112+
"referenceUrls": [
113+
"foo",
114+
"foo",
115+
"foo"
116+
],
117+
"relatedVulnerabilities": [
118+
"foo",
119+
"foo",
120+
"foo"
121+
],
122+
"source": "foo",
123+
"sourceUrl": "https://example.com",
124+
"vendorCreatedAt": "2024-10-14T18:00:11Z",
125+
"vendorSeverity": "foo",
126+
"vendorUpdatedAt": "2024-10-14T18:00:11Z",
127+
"vulnerabilityId": "foo",
128+
"vulnerablePackages": [
129+
{
130+
"arch": "foo",
131+
"epoch": 123,
132+
"filePath": "foo",
133+
"fixedInVersion": "foo",
134+
"name": "foo",
135+
"packageManager": "CARGO",
136+
"release": "foo",
137+
"remediation": "foo",
138+
"sourceLambdaLayerArn": "foo",
139+
"sourceLayerHash": "foo",
140+
"version": "foo"
141+
}
142+
]
143+
},
144+
"remediation": {
145+
"recommendation": {
146+
"Url": "https://example.com",
147+
"text": "foo"
148+
}
149+
},
150+
"resources": [
151+
{
152+
"details": {
153+
"awsEc2Instance": {
154+
"iamInstanceProfileArn": "foo",
155+
"imageId": "foo",
156+
"ipV4Addresses": [
157+
"foo",
158+
"foo",
159+
"foo"
160+
],
161+
"ipV6Addresses": [
162+
"foo",
163+
"foo",
164+
"foo"
165+
],
166+
"keyName": "foo",
167+
"launchedAt": "2024-10-14T18:00:11Z",
168+
"platform": "foo",
169+
"subnetId": "foo",
170+
"type": "foo",
171+
"vpcId": "foo"
172+
},
173+
"awsEcrContainerImage": {
174+
"architecture": "foo",
175+
"author": "foo",
176+
"imageHash": "foo",
177+
"imageTags": [
178+
"foo",
179+
"foo",
180+
"foo"
181+
],
182+
"platform": "foo",
183+
"pushedAt": "2024-10-14T18:00:11Z",
184+
"registry": "foo",
185+
"repositoryName": "foo"
186+
},
187+
"awsLambdaFunction": {
188+
"architectures": [
189+
"ARM64",
190+
"ARM64",
191+
"ARM64"
192+
],
193+
"codeSha256": "foo",
194+
"executionRoleArn": "foo",
195+
"functionName": "foo",
196+
"lastModifiedAt": "2024-10-14T18:00:11Z",
197+
"layers": [
198+
"foo",
199+
"foo",
200+
"foo"
201+
],
202+
"packageType": "ZIP",
203+
"runtime": "NODEJS_12_X",
204+
"version": "foo",
205+
"vpcConfig": {
206+
"securityGroupIds": [
207+
"foo",
208+
"foo",
209+
"foo"
210+
],
211+
"subnetIds": [
212+
"foo",
213+
"foo",
214+
"foo"
215+
],
216+
"vpcId": "foo"
217+
}
218+
}
219+
},
220+
"id": "foo",
221+
"partition": "foo",
222+
"region": "foo",
223+
"tags": {
224+
"0": "foo"
225+
},
226+
"type": "AWS_ECR_CONTAINER_IMAGE"
227+
}
228+
],
229+
"severity": "LOW",
230+
"status": "SUPPRESSED",
231+
"title": "foo",
232+
"type": "PACKAGE_VULNERABILITY",
233+
"updatedAt": "2024-10-14T18:00:11Z"
234+
}
235+
],
236+
"nextToken": "foo"
237+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from fix_plugin_aws.resource.inspector import AwsInspectorFinding
2+
from test.resources import round_trip_for
3+
4+
5+
def test_inspector_findings() -> None:
6+
round_trip_for(AwsInspectorFinding)

plugins/aws/tools/aws_model_gen.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ def process_shape_items(shape_items: List[Tuple[Any, Any]], prop_prefix: str, cl
239239
elif isinstance(shape, StringShape):
240240
return []
241241
elif isinstance(shape, ListShape):
242+
if isinstance(shape.member, StringShape):
243+
return []
242244
process_shape_items(shape.member.members.items(), prop_prefix, clazz_name)
243245
else:
244246
if getattr(shape, "members", None) is None:
@@ -280,7 +282,7 @@ def create_test_response(service: str, function: str, is_pascal: bool = False) -
280282

281283
def sample(shape: Shape) -> JsonElement:
282284
if isinstance(shape, StringShape) and shape.enum:
283-
return shape.enum[1]
285+
return shape.enum[-1]
284286
elif isinstance(shape, StringShape) and "8601" in shape.documentation:
285287
return utc_str()
286288
elif isinstance(shape, StringShape) and "URL" in shape.documentation:
@@ -983,12 +985,21 @@ def default_imports() -> str:
983985
# prefix="Bedrock",
984986
# )
985987
],
988+
"inspector2": [
989+
# Findings
990+
AwsFixModel(
991+
api_action="list-findings",
992+
result_property="findings",
993+
result_shape="ListFindingsResponse",
994+
prefix="InspectorV2",
995+
),
996+
],
986997
}
987998

988999

9891000
if __name__ == "__main__":
9901001
"""print some test data"""
991-
print(json.dumps(create_test_response("bedrock-agent", "get-knowledge-base"), indent=2))
1002+
# print(json.dumps(create_test_response("inspector2", "list-coverage"), indent=2))
9921003

9931004
"""print the class models"""
9941005
# print(default_imports())

0 commit comments

Comments
 (0)