在 EKS 上使用亚马逊 EMR 启用 Lake Formation - Amazon EMR
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

在 EKS 上使用亚马逊 EMR 启用 Lake Formation

在 Amazon EMR 7.7 及更高版本中,您可以利用 Amazon Lake Formation 对由 Amazon S3 支持的数据目录表应用精细的访问控制。此功能允许您在 EKS Spark Jobs 上的 Amazon EMR 中为读取查询配置表、行、列和单元级别的访问控制。

本节介绍如何创建安全配置和设置 Lake Formation 以使用亚马逊 EMR。它还描述了如何使用您为 Lake Formation 创建的安全配置创建虚拟集群。这些部分应按顺序完成。

步骤 1:设置基于 Lake Formation 的列、行或单元格级权限

首先,要对 Lake Formation 应用行和列级权限,Lake Formation 的数据湖管理员必须设置LakeFormationAuthorizedCaller会话标签。Lake Formation 使用该会话标签来授权调用者并提供对数据湖的访问权限。

导航到 Amazon Lake Formation 控制台,然后从侧栏的 “管理” 部分中选择 “应用程序集成设置” 选项。然后,选中 “允许外部引擎筛选在 Lake Formation 中注册的 Amazon S3 位置中的数据” 复选框。添加要运行 Spark 任务的Amazon 账户 IDs 和会话标签值

应用程序集成设置

请注意,此处传递的LakeFormationAuthorizedCaller会话标签SecurityConfiguration将在稍后设置 IAM 角色时在第 3 节中传递。

第 2 步:设置 EKS RBAC 权限

其次,您可以为基于角色的访问控制设置权限。

在 EKS 服务上向 Amazon EMR 提供 EKS 集群权限

EKS 服务上的 Amazon EMR 必须具有 EKS 集群角色权限,这样它才能为系统驱动程序创建跨命名空间权限,以分拆用户命名空间中的用户执行者。

创建集群角色

此示例定义了资源集合的权限。

vim emr-containers-cluster-role.yaml --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: emr-containers rules: - apiGroups: [""] resources: ["namespaces"] verbs: ["get"] - apiGroups: [""] resources: ["serviceaccounts", "services", "configmaps", "events", "pods", "pods/log"] verbs: ["get", "list", "watch", "describe", "create", "edit", "delete", "deletecollection", "annotate", "patch", "label"] - apiGroups: [""] resources: ["secrets"] verbs: ["create", "patch", "delete", "watch"] - apiGroups: ["apps"] resources: ["statefulsets", "deployments"] verbs: ["get", "list", "watch", "describe", "create", "edit", "delete", "annotate", "patch", "label"] - apiGroups: ["batch"] resources: ["jobs"] verbs: ["get", "list", "watch", "describe", "create", "edit", "delete", "annotate", "patch", "label"] - apiGroups: ["extensions", "networking.k8s.io"] resources: ["ingresses"] verbs: ["get", "list", "watch", "describe", "create", "edit", "delete", "annotate", "patch", "label"] - apiGroups: ["rbac.authorization.k8s.io"] resources: ["clusterroles","clusterrolebindings","roles", "rolebindings"] verbs: ["get", "list", "watch", "describe", "create", "edit", "delete", "deletecollection", "annotate", "patch", "label"] - apiGroups: [""] resources: ["persistentvolumeclaims"] verbs: ["get", "list", "watch", "describe", "create", "edit", "delete", "deletecollection", "annotate", "patch", "label"] ---
kubectl apply -f emr-containers-cluster-role.yaml

创建集群角色绑定

vim emr-containers-cluster-role-binding.yaml --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: emr-containers subjects: - kind: User name: emr-containers apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: emr-containers apiGroup: rbac.authorization.k8s.io ---
kubectl apply -f emr-containers-cluster-role-binding.yaml

提供对 EKS 上的 Amazon EMR 服务的命名空间访问权限

创建两个 Kubernetes 命名空间,一个用于用户驱动程序和执行器,另一个用于系统驱动程序和执行器,并启用 EKS 上的 Amazon EMR 服务访问权限,以便在用户和系统命名空间中提交作业。按照现有指南为每个命名空间提供访问权限,该指南可在使用启用集群访问中找到aws-auth

步骤 3:为用户和系统配置文件组件设置 IAM 角色

第三,您可以为特定组件设置角色。支持 Lake Formation 的 Spark Job 有两个组件,即用户和系统。用户驱动程序和执行器在 User 命名空间中运行,并与 StartJobRun API 中传递的 JobExecutionRole 命名空间相关联。系统驱动程序和执行器在 System 命名空间中运行,并与QueryEngine角色相关联。

配置查询引擎角色

该 QueryEngine 角色与系统空间组件相关联,并且有权担任 with Sess JobExecutionRolei LakeFormationAuthorizedCalleron 标签。查询引擎角色的 IAM 权限策略如下:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "AssumeJobRoleWithSessionTagAccessForSystemDriver", "Effect": "Allow", "Action": [ "sts:AssumeRole", "sts:TagSession" ], "Resource": "arn:aws:iam::Account:role/JobExecutionRole", "Condition": { "StringLike": { "aws:RequestTag/LakeFormationAuthorizedCaller": "EMR on EKS Engine" } } }, { "Sid": "AssumeJobRoleWithSessionTagAccessForSystemExecutor", "Effect": "Allow", "Action": [ "sts:AssumeRole" ], "Resource": "arn:aws:iam::Account:role/JobExecutionRole", }, { "Sid": "CreateCertificateAccessForTLS", "Effect": "Allow", "Action": "emr-containers:CreateCertificate", "Resource": "*" } ] }

将查询引擎角色的信任策略配置为信任 Kubernetes 系统命名空间。

aws emr-containers update-role-trust-policy \ --cluster-name eks cluster \ --namespace eks system namespace \ --role-name query_engine_iam_role_name

有关更多信息,请参阅更新角色信任策略

配置 Job 执行角色

Lake For Amazon mation 权限控制对 Glue 数据目录资源、Amazon S3 位置以及这些位置的基础数据的访问权限。IAM 权限控制对 Lake Formation 和 Amazon Glue APIs 以及资源的访问。尽管您可能拥有 Lake Formation 访问数据目录(SELECT)中表的权限,但如果您没有 glue:Get* API 操作的 IAM 权限,则操作将失败。

IAM 权限策略JobExecutionRole为:JobExecution角色的权限策略中应包含策略声明。

{ "Version": "2012-10-17", "Statement": [ { "Sid": "GlueCatalogAccess", "Effect": "Allow", "Action": [ "glue:Get*", "glue:Create*", "glue:Update*" ], "Resource": ["*"] }, { "Sid": "LakeFormationAccess", "Effect": "Allow", "Action": [ "lakeformation:GetDataAccess" ], "Resource": ["*"] }, { "Sid": "CreateCertificateAccessForTLS", "Effect": "Allow", "Action": "emr-containers:CreateCertificate", "Resource": "*" } ] }

适用于以下内容的 IAM 信任政策 JobExecutionRole

{ "Version": "2012-10-17", "Statement": [ { "Sid": "TrustQueryEngineRoleForSystemDriver", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::your_account:role/QueryExecutionRole" }, "Action": [ "sts:AssumeRole", "sts:TagSession" ], "Condition": { "StringLike": { "aws:RequestTag/LakeFormationAuthorizedCaller": "EMR on EKS Engine" } } }, { "Sid": "TrustQueryEngineRoleForSystemExecutor", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::your_account:role/QueryEngineRole" }, "Action": "sts:AssumeRole" } ] }

将 Job 执行角色的信任策略配置为信任 Kubernetes 用户命名空间:

aws emr-containers update-role-trust-policy \ --cluster-name eks cluster \ --namespace eks User namespace \ --role-name job_execution_role_name

有关更多信息,请参阅更新任务执行角色的信任策略

步骤 4:设置安全配置

要运行启用 Lake Formation 的作业,您必须创建安全配置。

aws emr-containers create-security-configuration \ --name 'security-configuration-name' \ --security-configuration '{ "authorizationConfiguration": { "lakeFormationConfiguration": { "authorizedSessionTagValue": "SessionTag configured in LakeFormation", "secureNamespaceInfo": { "clusterId": "eks-cluster-name", "namespace": "system-namespace-name" }, "queryEngineRoleArn": "query-engine-IAM-role-ARN" } } }'

确保在 “authorizedSessionTag值” 字段中传递的会话标签可以授权 Lake Formation。将该值设置为在 Lake Formation 中配置的值步骤 1:设置基于 Lake Formation 的列、行或单元格级权限

步骤 5:创建虚拟集群

使用安全配置在 EKS 虚拟集群上创建 Amazon EMR。

aws emr-containers create-virtual-cluster \ --name my-lf-enabled-vc \ --container-provider '{ "id": "eks-cluster", "type": "EKS", "info": { "eksInfo": { "namespace": "user-namespace" } } }' \ --security-configuration-id SecurityConfiguraionId

确保通过上一步中的 SecurityConfigurationID,以便将 Lake Formation 授权配置应用于虚拟集群上运行的所有作业。有关更多信息,请参阅使用亚马逊 EMR 注册 Amazon EKS 集群

步骤 6:在 FGAC 中提交 Job 已启用 VirtualCluster

非 Lake Formation 和 Lake Formation 职位的提交流程相同。有关更多信息,请参阅提交使用运行的作业StartJobRun

系统驱动程序的 Spark 驱动程序、执行器和事件日志存储在 Amazon 服务帐户的 S3 存储桶中以进行调试。我们建议在 Job Run 中配置客户管理的 KMS 密钥,以加密存储在 Amazon 服务存储桶中的所有日志。有关启用日志加密的更多信息,请参阅在 EKS 日志上加密 Amazon EMR