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

⭐️ Added Trust relationship policy to the role (aws) #3445

Merged
merged 2 commits into from
Mar 5, 2024
Merged
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
2 changes: 2 additions & 0 deletions providers/aws/resources/aws.lr
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,8 @@ private aws.iam.role @defaults("arn name") {
tags map[string]string
// Time when the role was created
createDate time
// The policy document that grants an entity permission to assume the role
assumeRolePolicyDocument dict
Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder if we shouldn't make this a real resource object? is there a specific test you're targeting with this resource? what would the query look like with this as a dict vs a defined resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your feedback. So far I wrote like following:

Screenshot from 2024-02-29 18-39-45

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, that makes sense. prob better to just leave as a dict

}

// AWS IAM group
Expand Down
12 changes: 12 additions & 0 deletions providers/aws/resources/aws.lr.go

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

1 change: 1 addition & 0 deletions providers/aws/resources/aws.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,7 @@ resources:
The `aws.iam.role` provides fields for assessing the configuration of individual IAM Roles. For usage, read the `aws.iam` resource documentation.
fields:
arn: {}
assumeRolePolicyDocument: {}
createDate: {}
description: {}
id: {}
Expand Down
27 changes: 18 additions & 9 deletions providers/aws/resources/aws_iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ func (a *mqlAwsIam) policies() ([]interface{}, error) {

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

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

Expand All @@ -435,17 +434,27 @@ func (a *mqlAwsIam) roles() ([]interface{}, error) {
return nil, err
}

for i := range rolesResp.Roles {
role := rolesResp.Roles[i]
// Added Trust relationship policy attached to each role
for _, role := range rolesResp.Roles {
policyOutput, err := svc.GetRole(ctx, &iam.GetRoleInput{RoleName: role.RoleName})
var policyDocumentMap map[string]interface{}
if err == nil && policyOutput.Role != nil && policyOutput.Role.AssumeRolePolicyDocument != nil {
policyDocument := *policyOutput.Role.AssumeRolePolicyDocument
decodedPolicyDocument, decodeErr := url.QueryUnescape(policyDocument)
if decodeErr == nil {
json.Unmarshal([]byte(decodedPolicyDocument), &policyDocumentMap)
}
}

mqlAwsIamRole, err := CreateResource(a.MqlRuntime, "aws.iam.role",
map[string]*llx.RawData{
"arn": llx.StringDataPtr(role.Arn),
"id": llx.StringDataPtr(role.RoleId),
"name": llx.StringDataPtr(role.RoleName),
"description": llx.StringDataPtr(role.Description),
"tags": llx.MapData(iamTagsToMap(role.Tags), types.String),
"createDate": llx.TimeDataPtr(role.CreateDate),
"arn": llx.StringDataPtr(role.Arn),
"id": llx.StringDataPtr(role.RoleId),
"name": llx.StringDataPtr(role.RoleName),
"description": llx.StringDataPtr(role.Description),
"tags": llx.MapData(iamTagsToMap(role.Tags), types.String),
"createDate": llx.TimeDataPtr(role.CreateDate),
"assumeRolePolicyDocument": llx.MapData(policyDocumentMap, types.Any),
})
if err != nil {
return nil, err
Expand Down
Loading