Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⭐ Draft: Enhancing Users Key Metadata retrieval (aws) #3453

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion providers/aws/resources/aws.lr
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,21 @@ private aws.iam.user @defaults("arn name") {
// List of group ARNs that the user belongs to
groups() []string
// List of access keys metadata associated with the user
accessKeys() []dict
accessKeys() []aws.iam.accessKey
// Login profile for the user
loginProfile() aws.iam.loginProfile
}

// AWS IAM accessKey definition
private aws.iam.accessKey @defaults("accessKeyId status") {
// Access Key ID
accessKeyId string
// Status of the access key (Active/Inactive)
status string
// Time when the access key was created
createDate time
}

// AWS IAM login profile for a user
private aws.iam.loginProfile @defaults("createdAt") {
// Time when the login profile was created
Expand Down Expand Up @@ -2588,3 +2598,4 @@ private aws.eks.cluster @defaults("arn version status") {
// Cluster creation timestamp
createdAt time
}

95 changes: 94 additions & 1 deletion providers/aws/resources/aws.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions providers/aws/resources/aws.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,10 @@ resources:
desc: |
Use the `aws.iam` resource to assess the configuration of the AWS IAM service. The resource provides a list of `aws.iam.user` resources representing GuardDuty Detectors deployed across all enabled regions.
fields:
accessKeyMetadata:
min_mondoo_version: latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
min_mondoo_version: latest
min_mondoo_version: 9.0.0

accessKeys:
min_mondoo_version: latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
min_mondoo_version: latest
min_mondoo_version: 9.0.0

accountPasswordPolicy: {}
accountSummary: {}
attachedPolicies: {}
Expand Down Expand Up @@ -1702,6 +1706,28 @@ resources:
!= null\n ) \n"
title: Do not setup access keys during initial user setup for all IAM users
that have a console password
aws.iam.accessKey:
docs:
desc: |
The `aws.iam.accessKey` provides fields for assessing the configuration of individual IAM Access Keys. For usage, read the `aws.iam` resource documentation. This resource helps in identifying and analyzing the state and configurations of access keys, allowing for better security and management of AWS IAM credentials.
fields:
accessKeyId: {}
createDate: {}
status: {}
is_private: true
min_mondoo_version: 9.0.0
platform:
name:
- aws
aws.iam.accessKeys:
fields:
accessKeyId: {}
createDate: {}
status: {}
min_mondoo_version: latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
min_mondoo_version: latest
min_mondoo_version: 9.0.0

platform:
name:
- aws
aws.iam.group:
docs:
desc: |
Expand Down Expand Up @@ -1817,6 +1843,9 @@ resources:
accessKey2LastUsedDate: {}
accessKey2LastUsedRegion: {}
accessKey2LastUsedService: {}
accessKeyMetadata:
min_mondoo_version: latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
min_mondoo_version: latest
min_mondoo_version: 9.0.0

accessKeys: {}
arn: {}
cert1Active: {}
cert1LastRotated: {}
Expand Down
26 changes: 18 additions & 8 deletions providers/aws/resources/aws_iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,14 +756,13 @@ func (a *mqlAwsIamUser) id() (string, error) {

func (a *mqlAwsIamUser) accessKeys() ([]interface{}, error) {
conn := a.MqlRuntime.Connection.(*connection.AwsConnection)

svc := conn.Iam("")
ctx := context.Background()

username := a.Name.Data

var marker *string
res := []interface{}{}
var resources []interface{} // This will store the created resources.

for {
keysResp, err := svc.ListAccessKeys(ctx, &iam.ListAccessKeysInput{
UserName: &username,
Expand All @@ -772,18 +771,29 @@ func (a *mqlAwsIamUser) accessKeys() ([]interface{}, error) {
if err != nil {
return nil, err
}
metadata, err := convert.JsonToDictSlice(keysResp.AccessKeyMetadata)
if err != nil {
return nil, err

for _, keyMetadata := range keysResp.AccessKeyMetadata {
// Create a resource for each access key.
accessKeyResource, err := CreateResource(a.MqlRuntime, "aws.iam.accessKey",
map[string]*llx.RawData{
"accessKeyId": llx.StringDataPtr(keyMetadata.AccessKeyId),
"status": llx.StringData(string(keyMetadata.Status)),
"createDate": llx.TimeDataPtr(keyMetadata.CreateDate),
},
)
if err != nil {
return nil, err
}
resources = append(resources, accessKeyResource)
}
res = append(res, metadata)

if !keysResp.IsTruncated {
break
}
marker = keysResp.Marker
}

return res, nil
return resources, nil
}

func (a *mqlAwsIamUser) policies() ([]interface{}, error) {
Expand Down
Loading