0
0

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 1 year has passed since last update.

特定のEC2のみセッションマネージャの利用を可能にする

Posted at

やりたいこと

以下にポリシーを限定したい。

  • EC2インスタンスのタグの検索
  • 特定のEC2インスタンスの起動、開始、再起動
  • 特定のEC2インスタンスのみセッションマネージャを利用可能にする

やりたいことは基本的なことであるが、ドキュメントはデフォルトのIAMポリシーと追加のIAMポリシーとわかりずらかったため、一つに纏めてみた。

作成したポリシー

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ec2-1",
            "Effect": "Allow",
            "Action": [
                "ec2:RebootInstances",
                "ec2:StartInstances",
                "ec2:StopInstances"
            ],
            "Resource": "arn:aws:ec2:ap-northeast-1:<XXXXXXXXXXXX>:instance/*",
            "Condition": {
                "StringEquals": {
                    "ec2:ResourceTag/<value>": "<key>"
                }
            }
        },
        {
            "Sid": "ec2-2",
            "Effect": "Allow",
            "Action": [
                "ssm:GetConnectionStatus",
                "ec2:DescribeInstances",
                "ssm:DescribeInstanceInformation",
                "ssm:DescribeSessions",
                "ec2:DescribeTags",
                "ssm:DescribeInstanceProperties"
            ],
            "Resource": "*"
        },
        {
            "Sid": "ssm-1",
            "Effect": "Allow",
            "Action": "ssm:StartSession",
            "Resource": "arn:aws:ec2:ap-northeast-1:XXXXXXXXXXXX:instance/*",
            "Condition": {
                "StringLike": {
                    "ssm:resourceTag/<value>": "<key>"
                }
            }
        },
        {
            "Sid": "ssm-2",
            "Effect": "Allow",
            "Action": [
                "ssm:ResumeSession",
                "ssm:TerminateSession"
            ],
            "Resource": "arn:aws:ssm:*:*:session/${aws:username}-*"
        }
    ]
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?