Skip to content

Commit

Permalink
⭐️ Added Trust relationship policy to the role (aws) (#3445)
Browse files Browse the repository at this point in the history
* added support to retrieve IAM-Support for each role

Signed-off-by: Hossein Rouhani <[email protected]>

* added support to retrieve IAM-Support for each role

Signed-off-by: Hossein Rouhani <[email protected]>

---------

Signed-off-by: Hossein Rouhani <[email protected]>
  • Loading branch information
HRouhani authored Mar 5, 2024
1 parent 1326076 commit e13f4f2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
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
}

// 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

0 comments on commit e13f4f2

Please sign in to comment.