Skip to content

Commit

Permalink
Formatting the MI arn so we can appropriately check the ARN against o…
Browse files Browse the repository at this point in the history
…ur API.
  • Loading branch information
Andrew Magana committed Jun 9, 2020
1 parent 5587d3e commit 5e76f2f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/aws/aws-sdk-go/aws/defaults"
"github.com/aws/aws-sdk-go/aws/ec2metadata"

alks "github.com/Cox-Automotive/alks-go"
"github.com/Cox-Automotive/alks-go"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
Expand Down Expand Up @@ -187,9 +187,16 @@ func isValidIAM(arn *string, client *alks.Client) bool {
}

// Check if MI...
_, err := client.SearchRoleMachineIdentity(*arn)
arnParts := strings.FieldsFunc(*arn, splitBy)
iamArn := fmt.Sprintf("arn:aws:iam::%s:role/acct-managed/%s", arnParts[3], arnParts[5])

_, err := client.SearchRoleMachineIdentity(iamArn)
if err != nil {
return false
}
return true
}

func splitBy(r rune) bool {
return r == ':' || r == '/'
}

0 comments on commit 5e76f2f

Please sign in to comment.