Help us understand the problem. What is going on with this article?

IAM の NotAction で指定された権限の一部を解放してみる

More than 5 years have passed since last update.

NotActionで除外したものを部分的にAllowにして、そのAPIが利用できるかどうかはっきり分かっていなかったので確認してみました。

NotAction だけの場合

※以下のようにNotActionを書くと、IAM以外にはアクセスできるので注意。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1421508859000",
      "Effect": "Allow",
      "NotAction": [
        "iam:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}
$ aws iam list-users

出力結果

A client error (AccessDenied) occurred when calling the ListUsers operation: User: arn:aws:iam::xxxxxxxxxxxx:user/test-user is not authorized to perform: iam:ListUsers on resource: arn:aws:iam::xxxxxxxxxxxx:user/

IAMへのアクセスはもちろんできません。
権限がないと言われます。

NotAction + Allowで部分的に許可

IAMに

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1421508701000",
      "Effect": "Allow",
      "Action": [
        "iam:ListUsers"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Sid": "Stmt1421508859000",
      "Effect": "Allow",
      "NotAction": [
        "iam:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}
$ aws iam list-users

出力結果

{
    "Users": [
        {
            "UserName": "simeji",
            "PasswordLastUsed": "2015-01-17T15:08:07Z",
            "CreateDate": "2014-12-20T12:24:28Z",
            "UserId": "AIDAXXXXXXXXXXXXXXXXXA",
            "Path": "/",
            "Arn": "arn:aws:iam::xxxxxxxxxx:user/simeji"
        },
        {
            "UserName": "test-user",
            "Path": "/",
            "CreateDate": "2015-01-17T15:25:29Z",
            "UserId": "AIDAXXXXXXXXXXXXXXXXU",
            "Arn": "arn:aws:iam::xxxxxxxxxx:user/test-user"
        }
    ]
}

結果が取得できました。
NotActionによって除外された物も明示的にAllowしてやればアクセスできるようです。

NotAction => Deny に変更 + Allowで部分的に許可

念のためDenyに変えた場合も確認してみました。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1421508701000",
      "Effect": "Allow",
      "Action": [
        "iam:ListUsers"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Sid": "Stmt1421508859000",
      "Effect": "Deny",
      "Action": [
        "iam:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

$ aws iam list-users

出力結果

A client error (AccessDenied) occurred when calling the ListUsers operation: User: arn:aws:iam::xxxxxxxxxxxx:user/test-user is not authorized to perform: iam:ListUsers on resource: arn:aws:iam::xxxxxxxxxxxx:user/

権限がないと言われます。

lifull
日本最大級の不動産・住宅情報サイト「LIFULL HOME'S」を始め、人々の生活に寄り添う様々な情報サービス事業を展開しています。
https://lifull.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした