Skip to content

Commit b11d223

Browse files
mm-webersyrull
andauthored
⭐ Adds: aws.macie resource (#5988)
* resolved mr Signed-off-by: Manuel Weber <manuel@mondoo.com> * fix: update go.mod after tidy to resolve CI failure * spellcheck Signed-off-by: Manuel Weber <manuel@mondoo.com> * Add new consts * refactor: replace string literals with resource constants in aws.macie * add new aws.lr.go * fix error handling Signed-off-by: Manuel Weber <manuel@mondoo.com> --------- Signed-off-by: Manuel Weber <manuel@mondoo.com> Co-authored-by: Dimitar ganev <dimitar@mondoo.com>
1 parent 8de045b commit b11d223

File tree

11 files changed

+2379
-0
lines changed

11 files changed

+2379
-0
lines changed

.github/actions/spelling/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ notebookinstancedetails
8383
nsrecord
8484
nullgroup
8585
nullstring
86+
oidc
8687
opcplc
8788
openssh
8889
openssl

go.sum

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

providers/aws/connection/clients.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/aws/aws-sdk-go-v2/service/inspector2"
3939
"github.com/aws/aws-sdk-go-v2/service/kms"
4040
"github.com/aws/aws-sdk-go-v2/service/lambda"
41+
"github.com/aws/aws-sdk-go-v2/service/macie2"
4142
"github.com/aws/aws-sdk-go-v2/service/neptune"
4243
"github.com/aws/aws-sdk-go-v2/service/organizations"
4344
"github.com/aws/aws-sdk-go-v2/service/rds"
@@ -635,6 +636,30 @@ func (t *AwsConnection) Lambda(region string) *lambda.Client {
635636
return client
636637
}
637638

639+
func (t *AwsConnection) Macie2(region string) *macie2.Client {
640+
// if no region value is sent in, use the configured region
641+
if len(region) == 0 {
642+
region = t.cfg.Region
643+
}
644+
cacheVal := "_macie2_" + region
645+
646+
// check for cached client and return it if it exists
647+
c, ok := t.clientcache.Load(cacheVal)
648+
if ok {
649+
log.Debug().Msg("use cached macie2 client")
650+
return c.Data.(*macie2.Client)
651+
}
652+
653+
// create the client
654+
cfg := t.cfg.Copy()
655+
cfg.Region = region
656+
client := macie2.NewFromConfig(cfg)
657+
658+
// cache it
659+
t.clientcache.Store(cacheVal, &CacheEntry{Data: client})
660+
return client
661+
}
662+
638663
func (t *AwsConnection) Dynamodb(region string) *dynamodb.Client {
639664
// if no region value is sent in, use the configured region
640665
if len(region) == 0 {

providers/aws/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ require (
4141
github.com/aws/aws-sdk-go-v2/service/inspector2 v1.44.6
4242
github.com/aws/aws-sdk-go-v2/service/kms v1.45.6
4343
github.com/aws/aws-sdk-go-v2/service/lambda v1.78.0
44+
github.com/aws/aws-sdk-go-v2/service/macie2 v1.49.6
4445
github.com/aws/aws-sdk-go-v2/service/neptune v1.42.5
4546
github.com/aws/aws-sdk-go-v2/service/organizations v1.45.3
4647
github.com/aws/aws-sdk-go-v2/service/rds v1.108.2

providers/aws/go.sum

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

providers/aws/resources/aws.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ func Is400AccessDeniedError(err error) bool {
7070
return false
7171
}
7272

73+
// IsMacieNotEnabledError checks if the error indicates Macie is not enabled in the region
74+
func IsMacieNotEnabledError(err error) bool {
75+
if err == nil {
76+
return false
77+
}
78+
79+
var respErr *http.ResponseError
80+
if errors.As(err, &respErr) {
81+
// Macie returns 401 status code with AccessDeniedException when not enabled
82+
if respErr.HTTPStatusCode() == 401 && strings.Contains(respErr.Error(), "AccessDeniedException: Macie is not enabled") {
83+
return true
84+
}
85+
// Also catch general access denied cases for Macie
86+
if (respErr.HTTPStatusCode() == 400 || respErr.HTTPStatusCode() == 401 || respErr.HTTPStatusCode() == 403) &&
87+
(strings.Contains(respErr.Error(), "AccessDeniedException") || strings.Contains(respErr.Error(), "AccessDenied")) {
88+
return true
89+
}
90+
}
91+
return false
92+
}
93+
7394
func Is400InstanceNotFoundError(err error) bool {
7495
var respErr *http.ResponseError
7596
if errors.As(err, &respErr) {

providers/aws/resources/aws.lr

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,122 @@ private aws.guardduty.finding @defaults("title region severity") {
13541354
updatedAt time
13551355
}
13561356

1357+
// Amazon Macie
1358+
aws.macie {
1359+
// List of Macie sessions
1360+
sessions() []aws.macie.session
1361+
// List of classification jobs
1362+
classificationJobs() []aws.macie.classificationJob
1363+
// List of findings
1364+
findings() []aws.macie.finding
1365+
// List of custom data identifiers
1366+
customDataIdentifiers() []aws.macie.customDataIdentifier
1367+
}
1368+
1369+
// Amazon Macie session
1370+
private aws.macie.session @defaults("arn region status") {
1371+
// ARN of the Macie session
1372+
arn string
1373+
// Region where Macie is enabled
1374+
region string
1375+
// Status of the Macie session: ENABLED or PAUSED
1376+
status string
1377+
// Date and time when the Macie session was created
1378+
createdAt time
1379+
// Date and time when the Macie session was last updated
1380+
updatedAt time
1381+
// Finding publishing frequency: FIFTEEN_MINUTES, ONE_HOUR, or SIX_HOURS
1382+
findingPublishingFrequency() string
1383+
// Service role ARN used by Macie
1384+
serviceRole() string
1385+
// Number of S3 buckets monitored by Macie
1386+
s3BucketCount() int
1387+
}
1388+
1389+
// Amazon Macie classification job
1390+
private aws.macie.classificationJob @defaults("jobId name status region") {
1391+
// ARN of the classification job
1392+
arn string
1393+
// Unique ID of the job
1394+
jobId string
1395+
// Name of the job
1396+
name string
1397+
// Region where the job runs
1398+
region string
1399+
// Status of the job: RUNNING, PAUSED, CANCELLED, COMPLETE, IDLE, or USER_PAUSED
1400+
status string
1401+
// Type of job: ONE_TIME or SCHEDULED
1402+
jobType string
1403+
// Date and time when the job was created
1404+
createdAt time
1405+
// Date and time when the job was last run
1406+
lastRunTime() time
1407+
// Sampling percentage for the job
1408+
samplingPercentage() int
1409+
// Bucket definitions for the job
1410+
bucketDefinitions() []dict
1411+
// Schedule frequency for the job
1412+
scheduleFrequency() dict
1413+
// Statistics for the job
1414+
statistics() dict
1415+
// Tags for the job
1416+
tags() map[string]string
1417+
}
1418+
1419+
// Amazon Macie finding
1420+
private aws.macie.finding @defaults("id arn region type severity") {
1421+
// Unique ID of the finding
1422+
id string
1423+
// ARN of the finding
1424+
arn string
1425+
// Region where the finding was discovered
1426+
region string
1427+
// Account ID where the finding was discovered
1428+
accountId string
1429+
// Type of the finding
1430+
type string
1431+
// Severity details of the finding
1432+
severity dict
1433+
// Category of the finding: CLASSIFICATION or POLICY
1434+
category string
1435+
// Whether the finding is archived
1436+
archived bool
1437+
// Count of occurrences for this finding
1438+
count int
1439+
// Date and time when the finding was created
1440+
createdAt time
1441+
// Date and time when the finding was last updated
1442+
updatedAt time
1443+
// Title of the finding
1444+
title string
1445+
// Description of the finding
1446+
description string
1447+
// Classification details for the finding
1448+
classificationDetails() dict
1449+
// Resources affected by the finding
1450+
resourcesAffected() dict
1451+
}
1452+
1453+
// Amazon Macie custom data identifier
1454+
private aws.macie.customDataIdentifier @defaults("id name") {
1455+
// Unique ID of the custom data identifier
1456+
id string
1457+
// ARN of the custom data identifier
1458+
arn string
1459+
// Name of the custom data identifier
1460+
name string
1461+
// Description of the custom data identifier
1462+
description() string
1463+
// Regular expression pattern for the identifier
1464+
regex() string
1465+
// Keywords for the identifier
1466+
keywords() []string
1467+
// Date and time when the identifier was created
1468+
createdAt time
1469+
// Tags for the identifier
1470+
tags() map[string]string
1471+
}
1472+
13571473
// AWS Security Hub
13581474
aws.securityhub {
13591475
// List of Security Hubs in the account

0 commit comments

Comments
 (0)