From d1d7fb72a84c596b33946e5445f647443e407596 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Thu, 23 May 2024 16:30:15 +0530 Subject: [PATCH] feat: parse role policy as nested json --- scrapers/aws/aws.go | 7 +++++++ utils/json.go | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/scrapers/aws/aws.go b/scrapers/aws/aws.go index eed8688a..31f0057e 100644 --- a/scrapers/aws/aws.go +++ b/scrapers/aws/aws.go @@ -1074,6 +1074,13 @@ func (aws Scraper) iamProfiles(ctx *AWSContext, config v1.AWS, results *v1.Scrap return } + // We need to cast roles as []map[string]any to update the policy doc + var profileRoles []map[string]any + for _, r := range profileMap["Roles"].([]any) { + profileRoles = append(profileRoles, r.(map[string]any)) + } + profileMap["Roles"] = profileRoles + for _, role := range profileMap["Roles"].([]map[string]any) { if val, exists := role["AssumeRolePolicyDocument"]; exists { policyDocEncoded := val.(string) diff --git a/utils/json.go b/utils/json.go index 69a05966..a2e15cd2 100644 --- a/utils/json.go +++ b/utils/json.go @@ -24,11 +24,11 @@ func ToJSONMap(s any) (map[string]any, error) { var raw []byte var err error - switch s.(type) { + switch s := s.(type) { case string: - raw = []byte(s.(string)) + raw = []byte(s) case []byte: - raw = s.([]byte) + raw = s default: raw, err = json.Marshal(s) if err != nil {