/
findings.go
200 lines (195 loc) · 6.38 KB
/
findings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package inspector2
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/inspector2"
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
//go:generate cq-gen --resource findings --config gen.hcl --output .
func Findings() *schema.Table {
return &schema.Table{
Name: "aws_inspector2_findings",
Description: "Details about an Amazon Inspector finding",
Resolver: fetchInspector2Findings,
Multiplex: client.ServiceAccountRegionMultiplexer("inspector2"),
IgnoreError: client.IgnoreCommonErrors,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}},
Columns: []schema.Column{
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the finding",
Type: schema.TypeString,
Resolver: schema.PathResolver("FindingArn"),
},
{
Name: "region",
Description: "The AWS Region of the resource",
Type: schema.TypeString,
Resolver: client.ResolveAWSRegion,
},
{
Name: "account_id",
Description: "The Amazon Web Services account ID associated with the finding",
Type: schema.TypeString,
Resolver: schema.PathResolver("AwsAccountId"),
},
{
Name: "description",
Description: "The description of the finding",
Type: schema.TypeString,
},
{
Name: "finding_arn",
Description: "The Amazon Resource Number (ARN) of the finding",
Type: schema.TypeString,
},
{
Name: "first_observed_at",
Description: "The date and time that the finding was first observed",
Type: schema.TypeTimestamp,
},
{
Name: "last_observed_at",
Description: "The date and time that the finding was last observed",
Type: schema.TypeTimestamp,
},
{
Name: "remediation_recommendation_text",
Description: "The recommended course of action to remediate the finding",
Type: schema.TypeString,
Resolver: schema.PathResolver("Remediation.Recommendation.Text"),
},
{
Name: "remediation_recommendation_url",
Description: "The URL address to the CVE remediation recommendations",
Type: schema.TypeString,
Resolver: schema.PathResolver("Remediation.Recommendation.Url"),
},
{
Name: "severity",
Description: "The severity of the finding",
Type: schema.TypeString,
},
{
Name: "status",
Description: "The status of the finding",
Type: schema.TypeString,
},
{
Name: "type",
Description: "The type of the finding",
Type: schema.TypeString,
},
{
Name: "inspector_score",
Description: "The Amazon Inspector score given to the finding",
Type: schema.TypeFloat,
},
{
Name: "inspector_score_details",
Description: "An object that contains details of the Amazon Inspector score",
Type: schema.TypeJSON,
IgnoreInTests: true,
},
{
Name: "network_reachability_details",
Description: "An object that contains the details of a network reachability finding",
Type: schema.TypeJSON,
IgnoreInTests: true,
},
{
Name: "package_vulnerability_details",
Description: "An object that contains the details of a package vulnerability finding",
Type: schema.TypeJSON,
IgnoreInTests: true,
},
{
Name: "title",
Description: "The title of the finding",
Type: schema.TypeString,
},
{
Name: "updated_at",
Description: "The date and time the finding was last updated at",
Type: schema.TypeTimestamp,
},
},
Relations: []*schema.Table{
{
Name: "aws_inspector2_finding_resources",
Description: "Details about the resource involved in a finding",
Resolver: schema.PathTableResolver("Resources"),
Columns: []schema.Column{
{
Name: "finding_cq_id",
Description: "Unique CloudQuery ID of aws_inspector2_findings table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "id",
Description: "The ID of the resource",
Type: schema.TypeString,
},
{
Name: "type",
Description: "The type of resource",
Type: schema.TypeString,
},
{
Name: "aws_ec2_instance",
Description: "An object that contains details about the Amazon EC2 instance involved in the finding",
Type: schema.TypeJSON,
Resolver: schema.PathResolver("Details.AwsEc2Instance"),
IgnoreInTests: true,
},
{
Name: "aws_ecr_container_image",
Description: "An object that contains details about the Amazon ECR container image involved in the finding",
Type: schema.TypeJSON,
Resolver: schema.PathResolver("Details.AwsEcrContainerImage"),
IgnoreInTests: true,
},
{
Name: "partition",
Description: "The partition of the resource",
Type: schema.TypeString,
},
{
Name: "region",
Description: "The Amazon Web Services Region the impacted resource is located in",
Type: schema.TypeString,
},
{
Name: "tags",
Description: "The tags attached to the resource",
Type: schema.TypeJSON,
},
},
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchInspector2Findings(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
c := meta.(*client.Client)
svc := c.Services().InspectorV2
input := inspector2.ListFindingsInput{MaxResults: aws.Int32(100)}
for {
response, err := svc.ListFindings(ctx, &input)
if err != nil {
return diag.WrapError(err)
}
res <- response.Findings
if aws.ToString(response.NextToken) == "" {
break
}
input.NextToken = response.NextToken
}
return nil
}