6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

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/

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

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?