Skip to content

Commit

Permalink
feat: parse role policy as nested json
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored and moshloop committed May 23, 2024
1 parent 6533ecd commit d1d7fb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions scrapers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions utils/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d1d7fb7

Please sign in to comment.