View a markdown version of this page

IAM 角色设置 - Amazon EMR
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

IAM 角色设置

先决条件

在开始之前,请确保您满足以下条件:

  • 具有 IAM 管理权限的 Amazon 账户

  • Amazon 已安装并配置 CLI。有关更多信息,请参阅安装 Amazon CLI

  • 用于暂存升级后的工件的 Amazon S3 存储桶

设置以下变量以便在后续命令中使用(my-staging-bucket替换为您的存储桶名称):

ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) REGION=$(aws configure get region) STAGING_BUCKET=my-staging-bucket

步骤 1:创建 IAM 角色

SMUS MCP 服务器使用您的 IAM 角色对 Amazon 服务级别的操作进行授权。不需要单独的 MCP-specific 权限。

创建 IAM 角色 (Amazon CLI)

  1. 创建信任策略文档:

    cat > mcp-trust-policy.json << EOF { "Version": "2012-10-17", "Statement": [ { "Sid": "AllowAccountToAssumeRole", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::${ACCOUNT_ID}:root" }, "Action": "sts:AssumeRole" } ] } EOF
  2. 创建该角色:

    aws iam create-role \ --role-name SparkUpgradeMCPRole \ --assume-role-policy-document file://mcp-trust-policy.json

步骤 2:为您的部署模式附加权限

附上与您的 EMR 部署平台相匹配的权限策略。

选项 A:EC2 上的 EMR

  1. 创建策略文档(替换为您的 <STAGING_BUCKET> Amazon S3 存储桶名称):

    cat > emr-ec2-upgrade-policy.json << EOF { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "elasticmapreduce:DescribeCluster", "elasticmapreduce:DescribeStep", "elasticmapreduce:ListSteps", "elasticmapreduce:ListClusters", "elasticmapreduce:DescribeJobFlows", "elasticmapreduce:AddJobFlowSteps", "elasticmapreduce:CreatePersistentAppUI", "elasticmapreduce:DescribePersistentAppUI", "elasticmapreduce:GetPersistentAppUIPresignedURL" ], "Resource": "*" }, { "Effect": "Allow", "Action": ["s3:GetBucket*", "s3:GetObject*", "s3:List*", "s3:Put*"], "Resource": [ "arn:aws:s3:::${STAGING_BUCKET}", "arn:aws:s3:::${STAGING_BUCKET}/*" ] } ] } EOF
  2. 附上政策:

    aws iam put-role-policy \ --role-name SparkUpgradeMCPRole \ --policy-name EMREC2UpgradeAccess \ --policy-document file://emr-ec2-upgrade-policy.json

或者,为您的暂存存储桶附加AmazonElasticMapReduceFullAccess托管策略和 Amazon S3 策略。

KMS 权限-暂存存储桶

如果暂存存储桶使用 CMK 加密,请添加以下策略。上传数据时,该服务将自动使用在存储桶上配置的 CMK(<KEY_ID>替换为您的 KMS 密钥 ID):

aws iam put-role-policy \ --role-name SparkUpgradeMCPRole \ --policy-name KMSStagingBucketEncrypt \ --policy-document "{ \"Version\": \"2012-10-17\", \"Statement\": [{ \"Effect\": \"Allow\", \"Action\": [\"kms:GenerateDataKey\", \"kms:Encrypt\"], \"Resource\": \"arn:aws:kms:${REGION}:${ACCOUNT_ID}:key/<KEY_ID>\" }] }"

选项 B:EMR 无服务器

  1. 创建策略文档(替换为您的 <STAGING_BUCKET> Amazon S3 存储桶名称):

    cat > emr-serverless-upgrade-policy.json << EOF { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "emr-serverless:StartJobRun", "emr-serverless:GetJobRun", "emr-serverless:GetApplication", "emr-serverless:ListApplications", "emr-serverless:GetDashboardForJobRun" ], "Resource": "*" }, { "Effect": "Allow", "Action": "iam:PassRole", "Resource": "*", "Condition": { "StringLike": { "iam:PassedToService": "emr-serverless.amazonaws.com" } } }, { "Effect": "Allow", "Action": ["logs:GetLogEvents", "logs:DescribeLogStreams"], "Resource": "arn:aws:logs:*:*:log-group:*" }, { "Effect": "Allow", "Action": ["s3:GetBucket*", "s3:GetObject*", "s3:List*", "s3:Put*"], "Resource": [ "arn:aws:s3:::${STAGING_BUCKET}", "arn:aws:s3:::${STAGING_BUCKET}/*" ] } ] } EOF
  2. 附上政策:

    aws iam put-role-policy \ --role-name SparkUpgradeMCPRole \ --policy-name EMRServerlessUpgradeAccess \ --policy-document file://emr-serverless-upgrade-policy.json

KMS 权限-暂存存储桶

如果暂存存储桶使用 CMK 加密,请添加以下策略。上传数据时,该服务将自动使用在存储桶上配置的 CMK(<KEY_ID>替换为您的 KMS 密钥 ID):

aws iam put-role-policy \ --role-name SparkUpgradeMCPRole \ --policy-name KMSStagingBucketEncrypt \ --policy-document "{ \"Version\": \"2012-10-17\", \"Statement\": [{ \"Effect\": \"Allow\", \"Action\": [\"kms:GenerateDataKey\", \"kms:Encrypt\"], \"Resource\": \"arn:aws:kms:${REGION}:${ACCOUNT_ID}:key/<KEY_ID>\" }] }"

KMS 权限- CloudWatch 日志

如果 CloudWatch 日志是使用 CMK 加密的,请添加以下策略,以便服务可以读取 EMR Serverless 应用程序日志(<KEY_ID>替换为您的 KMS 密钥 ID):

aws iam put-role-policy \ --role-name SparkUpgradeMCPRole \ --policy-name KMSCloudWatchLogsDecrypt \ --policy-document "{ \"Version\": \"2012-10-17\", \"Statement\": [{ \"Effect\": \"Allow\", \"Action\": [\"kms:Decrypt\", \"kms:DescribeKey\"], \"Resource\": \"arn:aws:kms:${REGION}:${ACCOUNT_ID}:key/<KEY_ID>\" }] }"

步骤 3:配置您的 MCP 客户端

将你的 MCP 客户端(例如 Claude Desktop 或 Amazon Q Developer)配置为使用你创建的角色 ARN:

echo "arn:aws:iam::${ACCOUNT_ID}:role/SparkUpgradeMCPRole"

有关如何配置 Amazon 凭证(通常通过担任此角色的配置文件),请参阅 MCP 客户端的文档。 Amazon

MCP 服务器请求的条件密钥

两个条件键会自动添加到通过 SMUS MCP 服务器发出的所有请求中:

  • aws:ViaAWSMCPServicetrue 对于通过 Amazon 托管 MCP 服务器发出的任何请求,设置为。

  • aws:CalledViaAWSMCP— 设置为 MCP 服务器服务主体(例如,sagemaker-unified-studio-mcp.amazonaws.com)。

当请求来自 Amazon 托管 MCP 服务器时,您可以使用这些条件键来控制对资源的访问。

示例:仅在通过 SMUS MCP 服务器访问时才允许 EMR 操作:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowEMRReadViaSMUSMCP", "Effect": "Allow", "Action": [ "elasticmapreduce:DescribeCluster", "elasticmapreduce:ListClusters", "elasticmapreduce:ListSteps", "emr-serverless:GetJobRun", "emr-serverless:GetApplication" ], "Resource": "*", "Condition": { "StringEquals": { "aws:CalledViaAWSMCP": "sagemaker-unified-studio-mcp.amazonaws.com" } } } ] }

示例:拒绝通过任何 Amazon 托管 MCP 服务器进行的所有操作:

{ "Effect": "Deny", "Action": "*", "Resource": "*", "Condition": { "Bool": { "aws:ViaAWSMCPService": "true" } } }

示例:通过特定的 Amazon 托管 MCP 服务器拒绝特定操作:

{ "Effect": "Deny", "Action": ["glue:GetJobRun", "glue:StartJobRun"], "Resource": "*", "Condition": { "StringEquals": { "aws:CalledViaAWSMCP": "sagemaker-unified-studio-mcp.amazonaws.com" } } }

有关条件键的更多信息,请参阅 IAM 用户指南中的Amazon 全局条件上下文密钥