Skip to content

Conversation

@Rihoj
Copy link
Contributor

@Rihoj Rihoj commented Aug 9, 2021

add invalid sid rules fixes #149

This should loop through all SIDs in a policy and make sure all of them fit the pattern.

return err
}
policy := unMarshaledPolicy.(map[string]interface{})
statements := policy["Statement"].([]interface{})
Copy link
Member

Choose a reason for hiding this comment

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

Casting interface{} can cause panic. In this case, it's a good idea to declare a structure for the policy and unmarshal it there.
https://gobyexample.com/json

if r.validCharacters.MatchString(statement["Sid"].(string)) == false {
runner.EmitIssueOnExpr(
r,
"The policy's sid contains invalid characters.",
Copy link
Member

Choose a reason for hiding this comment

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

The error message should clearly indicate why it is invalid. Perhaps it would be nice to include a regexp pattern.

@Rihoj
Copy link
Contributor Author

Rihoj commented Aug 9, 2021

@wata727 those should be fixed. Thank you for the feedback.

@wata727 wata727 merged commit ccdd4aa into terraform-linters:master Aug 10, 2021
@wata727
Copy link
Member

wata727 commented Aug 10, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

rule: aws_iam_policy_document - Sid string check

2 participants