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

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more