DEV Community

Rodrigo Fernandes
Rodrigo Fernandes

Posted on

AWS IAM - Policy - Troubleshooting

Anotações sobre o AWS IAM Policy - Troubleshooting para ajudar na preparação das certificações AWS.

Até o momento as anotações são para as certificações abaixo:

Image description


JSON Error Bucket S3

{
    "Statement": {
        "Effect": "Allow",
        "Action": "*",
        "Resource": "arn:aws:s3:::examplebucket",
        "Resource": "arn:aws:s3:::examplebucket/*"
    }
}
Enter fullscreen mode Exit fullscreen mode

Resolução

  • Só pode haver 1 Resource
  • Inserir o Version
  • Tabular e inserir os Resources em []

Policy corrigida

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "*",
            "Resource": [
                "arn:aws:s3:::nomedobucket",
                "arn:aws:s3:::nomedobucket/*"
            ]
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

IAM Policy user access

{
    "Statement": [
        {
            "Action": [
                "iam:*AccessKey*"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:iam::id-conta-aws:user/${aws:username}"
            ]
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Resolução

  • Por não estar difinido na policy o Version está com o padrão "Version": "2008-10-17" e os Elementos da Policy são compativeis somente na nova versão - "Version": "2012-10-17"
  • Alterar a variável ${aws:username} para o _username _estático

Policy corrigida - Sem Version

{
    "Statement": [
        {
            "Action": [
                "iam:*AccessKey*"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:iam::id-conta-aws:user/username"
            ]
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Policy corrigida - Com Version

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "iam:*AccessKey*"
            ],
            "Effect": "Allow",
            "Resource": [
                "arn:aws:iam::id-conta-aws:user/${aws:username}"
            ]
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Policy acesso CloudFront

{
    "Version": "2012-10-17",
    "Statement": [{
        "Effect": "Allow",
        "Action": "cloudfront:*",
        "Resource": [
            "arn:aws:cloudfront:*"
        ]
    }]
}
Enter fullscreen mode Exit fullscreen mode

Resolução

  • Cada serviço da AWS pode definir ações, recursos e chaves de contexto de condição para uso em políticas do IAM. No caso do CloudFront basta especificar "*" no Resource.

Policy corrigida

{
    "Version": "2012-10-17",
    "Statement": [{
        "Effect": "Allow",
        "Action": "cloudfront:*",
        "Resource": "*"
    }]
}
Enter fullscreen mode Exit fullscreen mode

Bucket Policy

{
    "Version": "2012-10-17",
    "Statement": [{
        "Effect": "Allow"
        "Action": "s3:*"
        "Resource": [
            "*"
        ]
    }]
}
Enter fullscreen mode Exit fullscreen mode

Resolução

  • Validação da estrutura da Policy, falta a "," no Effect

Policy corrigida

{
    "Version": "2012-10-17",
    "Statement": [{
        "Effect": "Allow",
        "Action": "s3:*",
        "Resource": [
            "*"
        ]
    }]
}
Enter fullscreen mode Exit fullscreen mode

Policy 5

{
      "Version": "2012-10-17",
      "Statement": {
         "Effect":"Allow",
         "Action":"ec2:Describe*",
         "Resource":"*"
      }
}
{ 
      "Statement": {
         "Effect": "Allow",
         "Action": "s3:*",
         "Resource": "arn:aws:s3:::my-bucket/*"
      }
}
Enter fullscreen mode Exit fullscreen mode

Resolução

  • Só pode haver 1 statement
  • Quebrar a Police em Blocos c/ []

Policy corrigida

{
      "Version": "2012-10-17",
      "Statement": [{
         "Effect":"Allow",
         "Action":"ec2:Describe*",
         "Resource":"*"
      },
      {
         "Effect": "Allow",
         "Action": "s3:*",
         "Resource": "arn:aws:s3:::my-bucket/*"
       }
      ]
}
Enter fullscreen mode Exit fullscreen mode

Referências

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay