Elastic Beanstalk サービスロール - AWS Elastic Beanstalk

Elastic Beanstalk サービスロール

サービスロールは、他のサービスを代理で呼び出すときに Elastic Beanstalk が引き受ける IAM ロールです。例えば、Elastic Beanstalk は、Amazon Elastic Compute Cloud (Amazon EC2)、Elastic Load Balancing、Amazon EC2 Auto Scaling の各 API を呼び出すときに、サービスロールを使用して情報を収集します。Elastic Beanstalk が使用するサービスロールは、Elastic Beanstalk 環境を作成するときに指定したサービスロールになります。

サービスロールにアタッチする管理ポリシーには 2 つの種類があります。これらのポリシーによって、環境の作成と管理に必要な AWS リソースにアクセスするための権限を Elastic Beanstalk に付与します。1 つは、拡張ヘルスモニタリングと、ワーカー層の Amazon SQS サポートに必要なアクセス権限を付与する管理ポリシーであり、もう 1 つは、マネージドプラットフォームの更新に必要な追加のアクセス権限を付与する管理ポリシーです。

このポリシーによって、環境のヘルスモニタリングに必要なすべてのアクセス権限を Elastic Beanstalk に付与します。このポリシーには、Elastic Beanstalk にワーカー環境のキューアクティビティのモニタリングを許可する Amazon SQS アクションも含まれています。

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "elasticloadbalancing:DescribeInstanceHealth", "elasticloadbalancing:DescribeLoadBalancers", "elasticloadbalancing:DescribeTargetHealth", "ec2:DescribeInstances", "ec2:DescribeInstanceStatus", "ec2:GetConsoleOutput", "ec2:AssociateAddress", "ec2:DescribeAddresses", "ec2:DescribeSecurityGroups", "sqs:GetQueueAttributes", "sqs:GetQueueUrl", "autoscaling:DescribeAutoScalingGroups", "autoscaling:DescribeAutoScalingInstances", "autoscaling:DescribeScalingActivities", "autoscaling:DescribeNotificationConfigurations", "sns:Publish" ], "Resource": [ "*" ] } ] }

このポリシーでは、お客様に代わって環境を更新してマネージドプラットフォームを更新するアクセス許可を Elastic Beanstalk に付与します。

サービスレベルでのアクセス許可のグループ化

このポリシーは、提供された一連の許可に基づくステートメントごとにグループ化されます。

  • ElasticBeanstalkPermissions – このアクセス許可グループは、Elastic Beanstalk サービスアクション (Elastic Beanstalk API) を呼び出す際に使用します。

  • AllowPassRoleToElasticBeanstalkAndDownstreamServices – このアクセス許可グループにより、Elastic Beanstalk や AWS CloudFormation などのダウンストリームサービスに対し、任意のロールを渡すことが可能になります。

  • ReadOnlyPermissions – このアクセス許可グループは、実行中の環境に関する情報を収集するため使用します。

  • *OperationPermissions – この命名パターンを持つグループは、プラットフォームの更新を実行するために必要なオペレーションを呼び出すためのものです。

  • *BroadOperationPermissions – この命名パターンを持つグループは、プラットフォームの更新を実行するために必要なオペレーションを呼び出すためのものです。またこれには、レガシー環境をサポートするための広範なアクセス許可も含まれています。

  • *TagResource– この命名パターンのグループは、tag-on-create API を使用して Elastic Beanstalk 環境で作成されているリソースにタグをアタッチする呼び出し用です。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ElasticBeanstalkPermissions", "Effect": "Allow", "Action": [ "elasticbeanstalk:*" ], "Resource": "*" }, { "Sid": "AllowPassRoleToElasticBeanstalkAndDownstreamServices", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:aws:iam::*:role/*", "Condition": { "StringEquals": { "iam:PassedToService": [ "elasticbeanstalk.amazonaws.com", "ec2.amazonaws.com", "ec2.amazonaws.com.cn", "autoscaling.amazonaws.com", "elasticloadbalancing.amazonaws.com", "ecs.amazonaws.com", "cloudformation.amazonaws.com" ] } } }, { "Sid": "ReadOnlyPermissions", "Effect": "Allow", "Action": [ "autoscaling:DescribeAccountLimits", "autoscaling:DescribeAutoScalingGroups", "autoscaling:DescribeAutoScalingInstances", "autoscaling:DescribeLaunchConfigurations", "autoscaling:DescribeLoadBalancers", "autoscaling:DescribeNotificationConfigurations", "autoscaling:DescribeScalingActivities", "autoscaling:DescribeScheduledActions", "ec2:DescribeAccountAttributes", "ec2:DescribeAddresses", "ec2:DescribeAvailabilityZones", "ec2:DescribeImages", "ec2:DescribeInstanceAttribute", "ec2:DescribeInstances", "ec2:DescribeKeyPairs", "ec2:DescribeLaunchTemplates", "ec2:DescribeLaunchTemplateVersions", "ec2:DescribeSecurityGroups", "ec2:DescribeSnapshots", "ec2:DescribeSpotInstanceRequests", "ec2:DescribeSubnets", "ec2:DescribeVpcClassicLink", "ec2:DescribeVpcs", "elasticloadbalancing:DescribeInstanceHealth", "elasticloadbalancing:DescribeLoadBalancers", "elasticloadbalancing:DescribeTargetGroups", "elasticloadbalancing:DescribeTargetHealth", "logs:DescribeLogGroups", "rds:DescribeDBEngineVersions", "rds:DescribeDBInstances", "rds:DescribeOrderableDBInstanceOptions", "sns:ListSubscriptionsByTopic" ], "Resource": [ "*" ] }, { "Sid": "EC2BroadOperationPermissions", "Effect": "Allow", "Action": [ "ec2:AllocateAddress", "ec2:AssociateAddress", "ec2:AuthorizeSecurityGroupEgress", "ec2:AuthorizeSecurityGroupIngress", "ec2:CreateLaunchTemplate", "ec2:CreateLaunchTemplateVersion", "ec2:CreateSecurityGroup", "ec2:DeleteLaunchTemplate", "ec2:DeleteLaunchTemplateVersions", "ec2:DeleteSecurityGroup", "ec2:DisassociateAddress", "ec2:ReleaseAddress", "ec2:RevokeSecurityGroupEgress", "ec2:RevokeSecurityGroupIngress" ], "Resource": "*" }, { "Sid": "EC2RunInstancesOperationPermissions", "Effect": "Allow", "Action": "ec2:RunInstances", "Resource": "*", "Condition": { "ArnLike": { "ec2:LaunchTemplate": "arn:aws:ec2:*:*:launch-template/*" } } }, { "Sid": "EC2TerminateInstancesOperationPermissions", "Effect": "Allow", "Action": [ "ec2:TerminateInstances" ], "Resource": "arn:aws:ec2:*:*:instance/*", "Condition": { "StringLike": { "ec2:ResourceTag/aws:cloudformation:stack-id": [ "arn:aws:cloudformation:*:*:stack/awseb-e-*", "arn:aws:cloudformation:*:*:stack/eb-*" ] } } }, { "Sid": "ECSBroadOperationPermissions", "Effect": "Allow", "Action": [ "ecs:CreateCluster", "ecs:DescribeClusters", "ecs:RegisterTaskDefinition" ], "Resource": "*" }, { "Sid": "ECSDeleteClusterOperationPermissions", "Effect": "Allow", "Action": "ecs:DeleteCluster", "Resource": "arn:aws:ecs:*:*:cluster/awseb-*" }, { "Sid": "ASGOperationPermissions", "Effect": "Allow", "Action": [ "autoscaling:AttachInstances", "autoscaling:CreateAutoScalingGroup", "autoscaling:CreateLaunchConfiguration", "autoscaling:CreateOrUpdateTags", "autoscaling:DeleteLaunchConfiguration", "autoscaling:DeleteAutoScalingGroup", "autoscaling:DeleteScheduledAction", "autoscaling:DetachInstances", "autoscaling:DeletePolicy", "autoscaling:PutScalingPolicy", "autoscaling:PutScheduledUpdateGroupAction", "autoscaling:PutNotificationConfiguration", "autoscaling:ResumeProcesses", "autoscaling:SetDesiredCapacity", "autoscaling:SuspendProcesses", "autoscaling:TerminateInstanceInAutoScalingGroup", "autoscaling:UpdateAutoScalingGroup" ], "Resource": [ "arn:aws:autoscaling:*:*:launchConfiguration:*:launchConfigurationName/awseb-e-*", "arn:aws:autoscaling:*:*:launchConfiguration:*:launchConfigurationName/eb-*", "arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/awseb-e-*", "arn:aws:autoscaling:*:*:autoScalingGroup:*:autoScalingGroupName/eb-*" ] }, { "Sid": "CFNOperationPermissions", "Effect": "Allow", "Action": [ "cloudformation:*" ], "Resource": [ "arn:aws:cloudformation:*:*:stack/awseb-*", "arn:aws:cloudformation:*:*:stack/eb-*" ] }, { "Sid": "ELBOperationPermissions", "Effect": "Allow", "Action": [ "elasticloadbalancing:AddTags", "elasticloadbalancing:ApplySecurityGroupsToLoadBalancer", "elasticloadbalancing:ConfigureHealthCheck", "elasticloadbalancing:CreateLoadBalancer", "elasticloadbalancing:DeleteLoadBalancer", "elasticloadbalancing:DeregisterInstancesFromLoadBalancer", "elasticloadbalancing:DeregisterTargets", "elasticloadbalancing:RegisterInstancesWithLoadBalancer", "elasticloadbalancing:RegisterTargets" ], "Resource": [ "arn:aws:elasticloadbalancing:*:*:targetgroup/awseb-*", "arn:aws:elasticloadbalancing:*:*:targetgroup/eb-*", "arn:aws:elasticloadbalancing:*:*:loadbalancer/awseb-*", "arn:aws:elasticloadbalancing:*:*:loadbalancer/eb-*", "arn:aws:elasticloadbalancing:*:*:loadbalancer/*/awseb-*/*", "arn:aws:elasticloadbalancing:*:*:loadbalancer/*/eb-*/*" ] }, { "Sid": "CWLogsOperationPermissions", "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:DeleteLogGroup", "logs:PutRetentionPolicy" ], "Resource": "arn:aws:logs:*:*:log-group:/aws/elasticbeanstalk/*" }, { "Sid": "S3ObjectOperationPermissions", "Effect": "Allow", "Action": [ "s3:DeleteObject", "s3:GetObject", "s3:GetObjectAcl", "s3:GetObjectVersion", "s3:GetObjectVersionAcl", "s3:PutObject", "s3:PutObjectAcl", "s3:PutObjectVersionAcl" ], "Resource": "arn:aws:s3:::elasticbeanstalk-*/*" }, { "Sid": "S3BucketOperationPermissions", "Effect": "Allow", "Action": [ "s3:GetBucketLocation", "s3:GetBucketPolicy", "s3:ListBucket", "s3:PutBucketPolicy" ], "Resource": "arn:aws:s3:::elasticbeanstalk-*" }, { "Sid": "SNSOperationPermissions", "Effect": "Allow", "Action": [ "sns:CreateTopic", "sns:GetTopicAttributes", "sns:SetTopicAttributes", "sns:Subscribe" ], "Resource": "arn:aws:sns:*:*:ElasticBeanstalkNotifications-*" }, { "Sid": "SQSOperationPermissions", "Effect": "Allow", "Action": [ "sqs:GetQueueAttributes", "sqs:GetQueueUrl" ], "Resource": [ "arn:aws:sqs:*:*:awseb-e-*", "arn:aws:sqs:*:*:eb-*" ] }, { "Sid": "CWPutMetricAlarmOperationPermissions", "Effect": "Allow", "Action": [ "cloudwatch:PutMetricAlarm" ], "Resource": [ "arn:aws:cloudwatch:*:*:alarm:awseb-*", "arn:aws:cloudwatch:*:*:alarm:eb-*" ] }, { "Sid": "AllowECSTagResource", "Effect": "Allow", "Action": [ "ecs:TagResource" ], "Resource": "*", "Condition": { "StringEquals": { "ecs:CreateAction": [ "CreateCluster", "RegisterTaskDefinition" ] } } } ] }

次のいずれかの方法で Elastic Beanstalk 環境を作成できます。各セクションでは、このアプローチがサービスロールを処理する方法について説明します。

Elastic Beanstalk コンソール

Elastic Beanstalk コンソールを使って環境を作成する場合、Elastic Beanstalk で、aws-elasticbeanstalk-service-role という名前のサービスロールを作成するよう指示されます。Elastic Beanstalk を介して作成されたこのロールには、Elastic Beanstalk がそのサービスロールを担うことを許可する信頼ポリシーが含まれます。このトピックで前述した 2 つの管理ポリシーもこのロールにアタッチされています。

Elastic Beanstalk コマンドラインインターフェイス (EB CLI)

Elastic Beanstalk コマンドラインインターフェイス (EB CLI) の eb create コマンドを使用して環境を作成できます。--service-role オプションを使用してサービスロールを指定しない場合は、Elastic Beanstalk が同じデフォルトサービスロール aws-elasticbeanstalk-service-role を作成します。デフォルトのサービスロールが既に存在する場合、Elastic Beanstalk はそのサービスロールを新しい環境で使用します。Elastic Beanstalk を介して作成されたこのロールには、Elastic Beanstalk がそのサービスロールを担うことを許可する信頼ポリシーが含まれます。このトピックで前述した 2 つの管理ポリシーもこのロールにアタッチされています。

Elastic Beanstalk API

Elastic Beanstalk API の CreateEnvironment アクションを使用して環境を作成することができます。サービスロールを指定しない場合、Elastic Beanstalk がモニタリングサービスリンクロールを作成します。この一意のタイプのサービスロールは、Elastic Beanstalk によって事前定義されており、お客様の代わりにサービスが他の AWS のサービス を呼び出すために必要なアクセス許可がすべて含まれています。このサービスリンクロールはお客様のアカウントに関連付けられています。Elastic Beanstalk によって一度作成されたロールは、追加の環境を作成するときにも使用されます。IAM を使用して、アカウント用のモニタリングサービスリンクロールを事前に作成することもできます。アカウントにモニタリングサービスリンクロールがある場合は、Elastic Beanstalk コンソール、Elastic Beanstalk API、または EB CLI のいずれかを使用して、そのロールで環境を作成することができます。サービスリンクロールを Elastic Beanstalk 環境で使用する方法については、「Elastic Beanstalk でのサービスにリンクされたロールの使用」を参照してください。

サービスロールの詳細については、「Elastic Beanstalk サービスロールの管理」を参照してください。