-
Notifications
You must be signed in to change notification settings - Fork 7
fix(terraform): improve the adaptation of IAM resources #37
Conversation
@simar7 Do we need to verify that IAM resources have the same provider? . Why is it only present on theirs? AWS documentation says that IAM services are not region specific:
I have successfully created the following IAC: provider "aws" {
region = "us-east-1"
alias = "us-east"
}
provider "aws" {
region = "us-west-1"
alias = "us-west"
}
resource "aws_iam_role_policy" "this" {
provider = aws.us-east
name = "test_policy"
role = aws_iam_role.this.id
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"ec2:Describe*",
]
Effect = "Allow"
Resource = "*"
},
]
})
}
resource "aws_iam_role" "this" {
provider = aws.us-west
name = "test_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "ec2.amazonaws.com"
}
},
]
})
} As you can see, I've used different provider configurations for role and policy, but it doesn't affect anything. aws_iam_role.this: Creating...
aws_iam_role.this: Creation complete after 2s [id=test_role]
aws_iam_role_policy.this: Creating...
aws_iam_role_policy.this: Creation complete after 1s [id=test_role:test_policy] But through the github search I found where separate provider configurations are used for IAM services, am I missing something? Ref: |
As per your example resource "aws_iam_role_policy" "this" {
provider = aws.us-east
name = "test_policy"
role = aws_iam_role.this.id Does the provider attribute exist? I don't see it document in terraform docs https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy#argument-reference - this omission makes sense to me because IAM is region agnostic as you pointed out. As for the same provider code, I'm not sure. Have you checked git blame history in older version of defsec to see why it was added? |
@simar7 |
ah I missed that. I would assume aws doesn't care about it as IAM is region agnostic. I was reading the docs for the CLI and they do expose a region option (not sure why) my guess it was autogenerated doc and region is just a global option. https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/create-policy.html But if you see the IAM ARN info page, they talk about |
Could the check be in place to resolve such issues? https://stackoverflow.com/a/66859239 |
@simar7 Which check do you mean? |
I couldn't find any information on why the check was added: |
@nikpivkin looks like there are some merge conflicts to resolve. |
@simar7 Done. |
See aquasecurity/trivy#5013
Also fixed aquasecurity/trivy#5452