View a markdown version of this page

创建和使用 CloudShell VPC 环境所需的 IAM 权限 - AWS CloudShell

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建和使用 CloudShell VPC 环境所需的 IAM 权限

要创建和使用 CloudShell VPC 环境,IAM 管理员必须允许访问 VPC 特定 Amazon EC2 权限。本节列出了创建和使用 VPC 环境所需的 Amazon EC2 权限。

要创建 VPC 环境,分配给您的角色的 IAM 策略必须包含以下 Amazon EC2 权限:

  • ec2:DescribeVpcs

  • ec2:DescribeSubnets

  • ec2:DescribeSecurityGroups

  • ec2:DescribeDhcpOptions

  • ec2:DescribeNetworkInterfaces

  • ec2:CreateTags

  • ec2:CreateNetworkInterface

  • ec2:CreateNetworkInterfacePermission

建议包括:

  • ec2:DeleteNetworkInterface

注意

此权限不是强制性的,但这是清理 CloudShell 其创建的 ENI 资源(为 CloudShell VPC 环境创建的 ENI 用ManagedByCloudShell密钥标记)所必需的。如果未启用此权限,则必须在每次使用 CloudShell VPC 环境后手动清理 ENI 资源。

IAM 政策授予完全 CloudShell 访问权限,包括对 VPC 的访问权限

以下示例显示如何启用全部权限,包括对 VPC 的访问权限 CloudShell:

JSON
{ "Version":"2012-10-17", "Statement": [ { "Sid": "AllowCloudShellOperations", "Effect": "Allow", "Action": [ "cloudshell:*" ], "Resource": "*" }, { "Sid": "AllowDescribeVPC", "Effect": "Allow", "Action": [ "ec2:DescribeSubnets", "ec2:DescribeSecurityGroups", "ec2:DescribeVpcs" ], "Resource": "*" }, { "Sid": "AllowInspectVPCConfigurationViaCloudShell", "Effect": "Allow", "Action": [ "ec2:DescribeDhcpOptions", "ec2:DescribeNetworkInterfaces" ], "Resource": "*", "Condition": { "ForAnyValue:StringEquals": { "aws:CalledVia": "cloudshell.amazonaws.com" } } }, { "Sid": "AllowCreateTagWithCloudShellKeyViaCloudShell", "Effect": "Allow", "Action": [ "ec2:CreateTags" ], "Resource": "arn:aws:ec2:*:*:network-interface/*", "Condition": { "StringEquals": { "ec2:CreateAction": "CreateNetworkInterface" }, "ForAnyValue:StringEquals": { "aws:TagKeys": "ManagedByCloudShell", "aws:CalledVia": "cloudshell.amazonaws.com" } } }, { "Sid": "AllowCreateNetworkInterfaceWithSubnetsAndSGViaCloudShell", "Effect": "Allow", "Action": [ "ec2:CreateNetworkInterface" ], "Resource": [ "arn:aws:ec2:*:*:subnet/*", "arn:aws:ec2:*:*:security-group/*" ], "Condition": { "ForAnyValue:StringEquals": { "aws:CalledVia": "cloudshell.amazonaws.com" } } }, { "Sid": "AllowCreateNetworkInterfaceWithCloudShellTagViaCloudShell", "Effect": "Allow", "Action": [ "ec2:CreateNetworkInterface" ], "Resource": "arn:aws:ec2:*:*:network-interface/*", "Condition": { "ForAnyValue:StringEquals": { "aws:TagKeys": "ManagedByCloudShell", "aws:CalledVia": "cloudshell.amazonaws.com" } } }, { "Sid": "AllowCreateNetworkInterfacePermissionWithCloudShellTagViaCloudShell", "Effect": "Allow", "Action": [ "ec2:CreateNetworkInterfacePermission" ], "Resource": "arn:aws:ec2:*:*:network-interface/*", "Condition": { "StringEquals": { "aws:ResourceTag/ManagedByCloudShell": "" }, "ForAnyValue:StringEquals": { "aws:CalledVia": "cloudshell.amazonaws.com" } } }, { "Sid": "AllowDeleteNetworkInterfaceWithCloudShellTagViaCloudShell", "Effect": "Allow", "Action": [ "ec2:DeleteNetworkInterface" ], "Resource": "arn:aws:ec2:*:*:network-interface/*", "Condition": { "StringEquals": { "aws:ResourceTag/ManagedByCloudShell": "" }, "ForAnyValue:StringEquals": { "aws:CalledVia": "cloudshell.amazonaws.com" } } } ] }

将 IAM 条件键用于 VPC 环境

您可以使用 VPC 设置的 CloudShell-specific 条件密钥为您的 VPC 环境提供额外的权限控制。还可以指定可以使用和不能使用 VPC 环境的子网和安全组。

CloudShell 在 IAM 策略中支持以下条件密钥:

  • CloudShell:VpcIds – 允许或拒绝一个或多个 VPC

  • CloudShell:SubnetIds – 允许或拒绝一个或多个子网

  • CloudShell:SecurityGroupIds – 允许或拒绝一个或多个安全组

注意

如果修改了有权访问公共 CloudShell 环境的用户的权限以增加对cloudshell:createEnvironment操作的限制,则他们仍然可以访问其现有的公共环境。但是,如果您想修改具有此限制的 IAM 策略并禁用他们对现有公共环境的访问权限,则必须首先使用该限制更新 IAM 政策,然后确保您账户中的每个 CloudShell 用户使用 CloudShell Web 用户界面(操作 删除 CloudShell 环境)手动删除现有的公共环境。

带有用于 VPC 设置的条件键的策略示例

以下示例演示如何将条件键用于 VPC 设置。创建具有所需限制的策略语句后,为目标用户或角色附加策略语句。

确保用户仅创建 VPC 环境并拒绝创建公共环境

要确保用户只能创建 VPC 环境,请使用拒绝权限,如以下示例所示:

{ "Statement": [ { "Sid": "DenyCloudShellNonVpcEnvironments", "Action": [ "cloudshell:CreateEnvironment" ], "Effect": "Deny", "Resource": "*", "Condition": { "Null": { "cloudshell:VpcIds": "true" } } } ] }

拒绝用户访问特定的 VPC、子网或安全组

要拒绝用户访问特定 VPC,请使用 StringEquals 检查 cloudshell:VpcIds 条件的值。以下示例拒绝用户访问 vpc-1vpc-2

要拒绝用户访问特定 VPC,请使用 StringEquals 检查 cloudshell:SubnetIds 条件的值。以下示例拒绝用户访问 subnet-1subnet-2

要拒绝用户访问特定 VPC,请使用 StringEquals 检查 cloudshell:SecurityGroupIds 条件的值。以下示例拒绝用户访问 sg-1sg-2

JSON
{ "Version":"2012-10-17", "Statement": [ { "Sid": "EnforceOutOfSecurityGroups", "Action": [ "cloudshell:CreateEnvironment" ], "Effect": "Deny", "Resource": "*", "Condition": { "ForAnyValue:StringEquals": { "cloudshell:SecurityGroupIds": [ "sg-1", "sg-2" ] } } } ] }

允许用户使用特定 VPC 配置创建环境

要允许用户访问特定 VPC,请使用 StringEquals 检查 cloudshell:VpcIds 条件的值。以下示例允许用户访问 vpc-1vpc-2

要允许用户访问特定 VPC,请使用 StringEquals 检查 cloudshell:SubnetIds 条件的值。以下示例允许用户访问 subnet-1subnet-2

JSON
{ "Version":"2012-10-17", "Statement": [ { "Sid": "EnforceStayInSpecificSubnets", "Action": [ "cloudshell:CreateEnvironment" ], "Effect": "Allow", "Resource": "*", "Condition": { "ForAllValues:StringEquals": { "cloudshell:SubnetIds": [ "subnet-1", "subnet-2" ] } } } ] }

要允许用户访问特定 VPC,请使用 StringEquals 检查 cloudshell:SecurityGroupIds 条件的值。以下示例允许用户访问 sg-1sg-2

JSON
{ "Version":"2012-10-17", "Statement": [ { "Sid": "EnforceStayInSpecificSecurityGroup", "Action": [ "cloudshell:CreateEnvironment" ], "Effect": "Allow", "Resource": "*", "Condition": { "ForAllValues:StringEquals": { "cloudshell:SecurityGroupIds": [ "sg-1", "sg-2" ] } } } ] }