百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 热门文章 > 正文

用户冒充机制

bigegpt 2024-08-26 11:13 3 浏览

How-To: Impersonation | Tutorial

HDFS file system support — Trino 452 Documentation

什么是用户冒充

配置 hive.metastore.thrift.impersonation.enabled=true 是在 Trino 与 Hive Metastore 进行交互时启用用户冒充(impersonation)的设置。让我们深入解释这个配置项及其用途。

什么是用户冒充(Impersonation)?

用户冒充是一种机制,允许服务在与其他服务交互时,代表实际用户执行操作。在 Hadoop 和 Hive 环境中,用户冒充非常重要,因为它确保了权限和审计的一致性。例如,Trino 代表实际的用户访问 Hive Metastore,以确保数据访问权限和操作都能正确地记录和控制。

配置项解释

hive.metastore.thrift.impersonation.enabled=true

  • hive.metastore.thrift.impersonation.enabled:这是一个布尔值配置项,用于启用或禁用 Trino 在访问 Hive Metastore 时的用户冒充功能。
  • true:启用用户冒充。Trino 在与 Hive Metastore 交互时,会以实际用户的身份进行操作。
  • false:禁用用户冒充。Trino 将以自己的身份与 Hive Metastore 交互,不会代表实际用户。

配置文件

此配置通常位于 Trino 的 Hive catalog 配置文件中,例如 hive.properties 文件。

connector.name=hive
hive.metastore.uri=thrift://<metastore-host>:<metastore-port>
hive.metastore.authentication.type=KERBEROS
hive.metastore.thrift.impersonation.enabled=true
hive.metastore.service.principal=hive/<hive-metastore-host>@<REALM>
hive.metastore.client.principal=trino/<trino-host>@<REALM>
hive.metastore.client.keytab=/path/to/trino.keytab
# 其他相关配置
hive.s3.aws-access-key=<your-access-key>
hive.s3.aws-secret-key=<your-secret-key>
hive.s3.endpoint=http://<s3-endpoint>
hive.s3.path-style-access=true
hive.s3.ssl.enabled=false
hive.security=allow-all
hive.non-managed-table-writes-enabled=true

如何工作

  1. 身份验证:Trino 使用 Kerberos 对 Hive Metastore 进行身份验证。
  1. 用户冒充:启用用户冒充后,Trino 在访问 Hive Metastore 时,将使用实际用户的身份。这意味着 Hive Metastore 将认为请求来自实际用户,而不是 Trino 服务本身。
  1. 权限控制:Hive Metastore 根据实际用户的权限进行访问控制。只有实际用户有权限访问的数据,才能被 Trino 访问。

使用场景

  • 多用户环境:在具有多个用户的环境中,这种设置确保每个用户的操作都能被正确审计和控制。
  • 安全合规:启用用户冒充有助于满足数据访问的安全和合规要求,因为每个操作都是由实际用户执行的,而不是通过一个共享的服务账户。

总结

通过设置 hive.metastore.thrift.impersonation.enabled=true,您可以确保 Trino 在访问 Hive Metastore 时,能够代表实际用户执行操作。这对于确保权限控制和审计一致性非常重要,特别是在多用户和高安全性要求的环境中。这一设置结合 Kerberos 认证机制,提供了强大的安全性和灵活性。

实际用户是什么

在上述解释中,“实际用户”是指发起查询或操作的真实用户,而不是中间代理服务或系统用户。实际用户代表在系统中拥有身份和权限的个体或应用程序用户。

实际用户的概念

  • 实际用户:执行查询或操作的终端用户,例如一个数据分析师、数据工程师,或运行查询的应用程序的用户。
  • 中间服务用户:代表实际用户执行操作的服务账户,例如 trino 用户。

为什么需要实际用户?

当启用用户冒充(Impersonation)时,Trino 代表实际用户向 Hive Metastore 发起请求,这样可以确保:

  1. 权限控制:Hive Metastore 将基于实际用户的权限来处理请求,而不是基于 Trino 服务账户的权限。
  1. 审计和日志记录:所有操作都会记录为实际用户的操作,便于追踪和审计。

举例说明

假设有一个数据分析师 alice 通过 Trino 查询 Hive 数据:

  1. 没有启用用户冒充
  • Trino 服务账户 trino 直接与 Hive Metastore 交互。
  • Hive Metastore 只知道是 trino 用户发起的请求,无法知道实际是谁在使用这些数据。
  • 权限检查基于 trino 用户的权限,而不是 alice 的权限。
  1. 启用用户冒充
  • alice 通过 Trino 发起查询请求。
  • Trino 在与 Hive Metastore 交互时,代表 alice 发起请求。
  • Hive Metastore 看到的请求来自 alice,而不是 trino。
  • 权限检查基于 alice 的权限。
  • 操作日志记录为 alice 的操作。

配置和操作流程

配置

Trino 和 Hive Metastore 的配置文件设置用户冒充:

Trino Hive Catalog 配置 (hive.properties)

connector.name=hive
hive.metastore.uri=thrift://<metastore-host>:<metastore-port>
hive.metastore.authentication.type=KERBEROS
hive.metastore.thrift.impersonation.enabled=true
hive.metastore.service.principal=hive/<hive-metastore-host>@<REALM>
hive.metastore.client.principal=trino/<trino-host>@<REALM>
hive.metastore.client.keytab=/path/to/trino.keytab

Hadoop Core-site 配置 (core-site.xml)

<configuration>
<property>
<name>hadoop.security.authentication</name>
<value>kerberos</value>
</property>
<property>
<name>hadoop.proxyuser.trino.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.trino.groups</name>
<value>*</value>
</property>
</configuration>

操作流程

  1. Alice 登录 Trino
  • Alice 使用 Kerberos 认证登录 Trino。
  1. Trino 发起查询
  • Alice 发起一个查询请求。
  • Trino 代理 Alice 向 Hive Metastore 发起请求。
  1. Hive Metastore 处理请求
  • Hive Metastore 接收到来自 Trino 的请求,但请求中包含 Alice 的身份信息。
  • Hive Metastore 基于 Alice 的权限处理请求,并将结果返回给 Trino。
  1. 结果返回
  • Trino 将查询结果返回给 Alice。

总结

实际用户是指在系统中执行查询或操作的终端用户。在启用用户冒充的配置下,Trino 可以代表实际用户与 Hive Metastore 交互,这样可以确保基于实际用户的权限进行访问控制和审计记录。这对于权限管理和合规性至关重要。

用户冒充工作流程启用用户冒充时,Hive Metastore 看到请求来自 alice,而不是 trino,这是通过 Kerberos 认证和用户冒充机制共同实现的。以下是详细的工作原理:

用户冒充工作原理

  1. 用户认证:实际用户 alice 通过 Kerberos 认证登录 Trino。
  1. 用户冒充配置:Trino 配置了 Hive Metastore 的用户冒充,并启用了 Kerberos 认证。
  1. 代理请求:Trino 代表 alice 发起对 Hive Metastore 的请求,并在请求中包含 alice 的身份信息。

详细步骤

  1. Alice 登录 Trino
  • alice 使用 Kerberos 认证登录 Trino,获得 Kerberos 票据。
  • 例如,alice 登录命令:

kinit alice

  1. Trino 配置
  • Trino 的配置中启用了 Kerberos 认证和用户冒充。
  • Trino 使用服务票据(trino 用户的 Kerberos 票据)与 Hive Metastore 通信。
  • Trino 的 hive.properties 配置文件:

connector.name=hive
hive.metastore.uri=thrift://<metastore-host>:<metastore-port>
hive.metastore.authentication.type=KERBEROS
hive.metastore.thrift.impersonation.enabled=true
hive.metastore.service.principal=hive/<hive-metastore-host>@<REALM>
hive.metastore.client.principal=trino/<trino-host>@<REALM>
hive.metastore.client.keytab=/path/to/trino.keytab

  1. 代理请求
  • alice 在 Trino 中执行查询。
  • Trino 在执行查询时,使用 alice 的身份信息生成对 Hive Metastore 的请求。
  1. Hive Metastore 认证和授权
  • Hive Metastore 收到来自 Trino 的请求,但请求中包含 alice 的 Kerberos 票据。
  • Hive Metastore 验证 alice 的 Kerberos 票据,并确定请求是由 alice 发起的。
  • Hive Metastore 根据 alice 的权限处理请求。
  1. 返回结果
  • Hive Metastore 将查询结果返回给 Trino。
  • Trino 将结果返回给 alice。

配置和示例

Trino Hive Catalog 配置 (hive.properties)

connector.name=hive
hive.metastore.uri=thrift://<metastore-host>:<metastore-port>
hive.metastore.authentication.type=KERBEROS
hive.metastore.thrift.impersonation.enabled=true
hive.metastore.service.principal=hive/<hive-metastore-host>@<REALM>
hive.metastore.client.principal=trino/<trino-host>@<REALM>
hive.metastore.client.keytab=/path/to/trino.keytab

Hadoop Core-site 配置 (core-site.xml)

<configuration>
<property>
<name>hadoop.security.authentication</name>
<value>kerberos</value>
</property>
<property>
<name>hadoop.proxyuser.trino.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.trino.groups</name>
<value>*</value>
</property>
</configuration>

总结

通过配置 Kerberos 认证和启用用户冒充,Trino 在与 Hive Metastore 交互时,可以代表实际用户(如 alice)发起请求。Hive Metastore 通过验证请求中的用户身份(Kerberos 票据)来确认请求是由实际用户发起的,而不是由中间服务用户(如 trino)发起的。这样可以确保权限控制和审计记录的准确性。

hive.metastore.service.principal

配置项 hive.metastore.service.principal=hive/<hive-metastore-host>@<REALM> 指定了 Hive Metastore 服务的 Kerberos 主要身份(Principal)。这个配置项的作用是确保 Trino 客户端能够正确地与 Hive Metastore 进行 Kerberos 认证通信。让我们详细解释它的作用和工作原理。

Kerberos 主要身份(Principal)

在 Kerberos 认证系统中,每个参与通信的实体(包括用户和服务)都有一个唯一的 Kerberos 主要身份(Principal)。一个典型的 Kerberos Principal 的格式如下:

primary/instance@REALM

  • primary:主要部分,通常是服务的名称。例如,对于 Hive Metastore 服务,通常是 hive。
  • instance:实例部分,通常是服务运行的主机名。例如,如果 Hive Metastore 运行在 hive-metastore-host 上,实例部分就是 hive-metastore-host。
  • REALM:Kerberos 域,通常是大写的 DNS 域名,例如 EXAMPLE.COM。

配置项解释

hive.metastore.service.principal

hive.metastore.service.principal=hive/<hive-metastore-host>@<REALM>

  • hive:这是服务名称部分,表示 Hive Metastore 服务。
  • :这是实例部分,表示 Hive Metastore 服务运行的具体主机名。例如,如果 Hive Metastore 运行在 hive.example.com,这里就应该配置为 hive.example.com。
  • @:这是 Kerberos 域,表示 Hive Metastore 服务所在的 Kerberos 域。例如,如果域是 EXAMPLE.COM,这里就配置为 @EXAMPLE.COM。

作用

  1. 服务认证:这个配置项告诉 Trino 客户端,Hive Metastore 服务的 Kerberos 主要身份是什么。这样,Trino 客户端在与 Hive Metastore 服务进行 Kerberos 认证时,可以正确地识别并认证 Hive Metastore 服务。
  1. 安全通信:Kerberos 认证确保了 Trino 与 Hive Metastore 之间的通信是安全的,并且双方都能够验证对方的身份。这防止了中间人攻击(MITM)和其他安全风险。
  1. 访问控制:通过指定服务的 Kerberos Principal,确保只有合法的 Trino 客户端能够访问 Hive Metastore 服务。这是基于 Kerberos 强认证机制的。

配置示例

假设 Hive Metastore 运行在 hive.example.com,Kerberos 域是 EXAMPLE.COM,配置项将如下:

hive.metastore.service.principal=hive/hive.example.com@EXAMPLE.COM

工作流程

  1. Trino 客户端初始化
  • Trino 客户端读取配置文件,知道 Hive Metastore 服务的 Kerberos 主要身份是 hive/hive.example.com@EXAMPLE.COM。
  1. Kerberos 票据请求
  • Trino 客户端使用其自己的 Kerberos 票据(如 trino/trino-host@EXAMPLE.COM)向 Kerberos 服务器请求服务票据,以便访问 hive/hive.example.com@EXAMPLE.COM。
  1. 认证请求
  • Trino 客户端使用获得的服务票据与 Hive Metastore 服务建立连接,并进行 Kerberos 认证。
  1. 认证成功
  • 如果认证成功,Hive Metastore 服务接受 Trino 客户端的请求,并允许进行后续的操作。
  1. 用户冒充(Impersonation)
  • 如果启用了用户冒充,Trino 客户端还会在请求中包含实际用户的身份信息(例如,alice),Hive Metastore 服务将根据实际用户的权限处理请求。

总结

配置项 hive.metastore.service.principal=hive/<hive-metastore-host>@<REALM> 的主要作用是指定 Hive Metastore 服务的 Kerberos 主要身份,以便 Trino 客户端能够正确地与 Hive Metastore 进行 Kerberos 认证通信。这确保了通信的安全性和正确的访问控制。

相关推荐

Docker篇(二):Docker实战,命令解析

大家好,我是杰哥上周我们通过几个问题,让大家对于Docker有了一个全局的认识。然而,说跟练往往是两个概念。从学习的角度来说,理论知识的学习,往往只是第一步,只有经过实战,才能真正掌握一门技术所以,本...

docker学习笔记——安装和基本操作

今天学习了docker的基本知识,记录一下docker的安装步骤和基本命令(以CentOS7.x为例)一、安装docker的步骤:1.yuminstall-yyum-utils2.yum-con...

不可错过的Docker完整笔记(dockerhib)

简介一、Docker简介Docker是一个开源的应用容器引擎,基于Go语言并遵从Apache2.0协议开源。Docker可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,...

扔掉运营商的 IPTV 机顶盒,全屋全设备畅看 IPTV!

其实现在看电视节目的需求确实大大降低了,折腾也只是为了单纯的让它实现,享受这个过程带来的快乐而已,哈哈!预期构想家里所有设备直接接入网络随时接收并播放IPTV直播(电信点播的节目不是太多,但好在非常稳...

第五节 Docker 入门实践:从 Hello World 到容器操作

一、Docker容器基础运行(一)单次命令执行通过dockerrun命令可以直接在容器中执行指定命令,这是体验Docker最快捷的方式:#在ubuntu:15.10容器中执行ech...

替代Docker build的Buildah简单介绍

Buildah是用于通过较低级别的coreutils接口构建OCI兼容镜像的工具。与Podman相似,Buildah不依赖于Docker或CRI-O之类的守护程序,并且不需要root特权。Builda...

Docker 命令大全(docker命令大全记录表)

容器生命周期管理run-创建并启动一个新的容器。start/stop/restart-这些命令主要用于启动、停止和重启容器。kill-立即终止一个或多个正在运行的容器rm-于删除一个或...

docker常用指令及安装rabbitMQ(docker安装rabbitmq配置环境)

一、docker常用指令启动docker:systemctlstartdocker停止docker:systemctlstopdocker重启docker:systemctlrestart...

使用Docker快速部署Storm环境(docker部署confluence)

Storm的部署虽然不是特别麻烦,但是在生产环境中,为了提高部署效率,方便管理维护,使用Docker来统一管理部署是一个不错的选择。下面是我开源的一个新的项目,一个配置好了storm与mono环境的D...

Docker Desktop安装使用指南:零基础教程

在之前的文章中,我多次提到使用Docker来安装各类软件,尤其是开源软件应用。鉴于不少读者对此有需求,我决定专门制作一期关于Docker安装与使用的详细教程。我主要以Macbook(Mac平台)为例进...

Linux如何成功地离线安装docker(linux离线安装httpd)

系统环境:Redhat7.2和Centos7.4实测成功近期因项目需要用docker,所以记录一些相关知识,由于生产环境是不能直接连接互联网,尝试在linux中离线安装docker。步骤1.下载...

Docker 类面试题(常见问题)(docker面试题目)

Docker常见问题汇总镜像相关1、如何批量清理临时镜像文件?可以使用sudodockerrmi$(sudodockerimages-q-fdanging=true)命令2、如何查看...

面试官:你知道Dubbo怎么优雅上下线的吗?你:优雅上下线是啥?

最近无论是校招还是社招,都进行的如火如荼,我也承担了很多的面试工作,在一次面试过程中,和候选人聊了一些关于Dubbo的知识。Dubbo是一个比较著名的RPC框架,很多人对于他的一些网络通信、通信协议、...

【Docker 新手入门指南】第五章:Hello Word

适合人群:完全零基础新手|学习目标:30分钟掌握Docker核心操作一、准备工作:先确认是否安装成功打开终端(Windows用户用PowerShell或GitBash),输入:docker--...

松勤软件测试:详解Docker,如何用portainer管理Docker容器

镜像管理搜索镜像dockersearch镜像名称拉取镜像dockerpullname[:tag]列出镜像dockerimages删除镜像dockerrmiimage名称或id删除...