透明加密:http://blog.csdn.net/linlinv3/article/details/44963429

hadoop透明加密  kms


简介 
     Hadoop Key Management Server(KMS)是一个基于HadoopKeyProvider API编写的密钥管理服务器。他提供了一个client和一个server组件,client和server之间基于HTTP协议使用REST API通信。Client是一个KeyProvider的实现,使用KMS HTTP REST API与KMS交互。KMS和它的client有内置的安全机制,支持HTTP SPNEGO Kerberos认证和HTTPS安全传输。KMS是一个Java Web应用程序,运行在与Hadoop发行版绑定在一起的预先配置好的Tomcat服务器上。
  HDFS 实现透明,端到端加密。配置完成后,用户往hdfs上存储数据的时候,无需用户做任何程序代码的更改(意思就是调用KeyProvider API ,用于在数据存入到HDFS上面的时候进行数据加密,解密的过程一样)。这意味着数据加密和解密由客户端完成的。HDFS 不会存储或访问未加密的数据或数据加密密钥(由kms管理)。


连接地址:    



背景介绍
    越来越多的用户关注安全问题,都在寻找一种有效的,方便的加密方式。hadoop提供了几种不同形式的加密,最底层的加密,加密所有节点数据,有效地保护了数据,但是却缺乏更细粒度的加密;
kms 透明加密可以做到更细粒度的加密;
    加密可以在不同的层级进行,包括软件/软件堆栈,选择不同的加密层级各有优缺点
  • 应用程序级加密。这是最安全、最灵活的方法。应用程序最终控制是什么加密,可以准确地反映用户的需求。然而,编写应用程序这样做是很难的。这也不是一个选择为客户现有的应用程序不支持加密。
  • 数据库级加密。类似的应用程序级加密的属性。大多数数据库厂商提供某种形式的加密。然而,可能有性能问题。一个例子是,索引不能加密。
  • 文件系统级进行加密。该选项提供了高性能、应用程序透明,通常容易部署。但是,它无法模型应用程序级别的一些政策。例如,多租户应用程序基于最终用户可能想要加密。一个数据库可能需要不同的加密设置每一列存储在单个文件中。
  • 磁盘级别加密。容易部署和高性能,但也很不灵活。
  hdfs处于数据库加密层和文件系统加密层之间。能有效地防止对文件系统的攻击,因为他的存储都是加密的。对于每个用户可以有不同的加密区



体系结构  
    Kms 有一个加密区 这个特殊的区域 对于能够进行操作他的用户 提供有写入和读取的权限。当加密区被创建的时候,每个加密区有唯一的秘钥, data encryption key (DEK),秘钥dek不由hdfs直接控制,但是hdfs控制encrypted data encryption key (EDEK),被加密的秘钥;由客户端解密EDEK;
    kms server  kms 服务器
    kms client    kms 客户端
    kms zone    kms 加密区


配置

kms 配置

kms server配置

 kms-site.xml 文件配置
1、kms backed keyProvider keyProvider 存储地方的配置
Configure the KMS backing KeyProvider properties in the etc/hadoop/kms-site.xml configuration file:
配置kms keyProvider存储的地方
<!-- KMS Backend KeyProvider -->
<property>
<name>hadoop.kms.key.provider.uri</name>
<value>jceks://file@/${user.home}/kms.keystore</value>
<description>
URI of the backing KeyProvider for the KMS.
</description>
</property>
<property>
<name>hadoop.security.keystore.java-keystore-provider.password-file</name>
<value>kms.keystore</value>
<description>
If using the JavaKeyStoreProvider, the password for the keystore file.
</description>
</property>
这里的keystore需要用 java 秘钥生成器来生成
    keytool -genkey  -alias 'key1';
    keytool -delete  -alias 'key1';

2、kms cache  kms 缓存配置
The cache is used with the following 3 methods only, getCurrentKey() and getKeyVersion() and getMetadata().
配置缓冲区,这样的话,当获取  getCurrentKey() and getKeyVersion() and getMetadata() 的时候 不用每次去访问 keystore 只用从缓存中读取就可以。当然,秘钥更新或者被删除的时候,会自动更新。
 <!-- KMS Cache -->
<property>
<name>hadoop.kms.cache.enable</name>
<value>true</value>
<description>
Whether the KMS will act as a cache for the backing KeyProvider.
When the cache is enabled, operations like getKeyVersion, getMetadata,
and getCurrentKey will sometimes return cached data without consulting
the backing KeyProvider. Cached values are flushed when keys are deleted
or modified.
</description>
</property> <property>
<name>hadoop.kms.cache.timeout.ms</name>
<value>600000</value>
<description>
Expiry time for the KMS key version and key metadata cache, in
milliseconds. This affects getKeyVersion and getMetadata.
</description>
</property> <property>
<name>hadoop.kms.current.key.cache.timeout.ms</name>
<value>30000</value>
<description>
Expiry time for the KMS current key cache, in milliseconds. This
affects getCurrentKey operations.
</description>
</property>
3、kms audit log  消息聚合日志配置

Audit logs are aggregated for API accesses to the GET_KEY_VERSION, GET_CURRENT_KEY, DECRYPT_EEK, GENERATE_EEK operations.

 Entries are grouped by the (user,key,operation) combined key for a configurable aggregation interval after which the number of accesses to the specified end-point by the user for a given key is flushed to the audit log.
配置聚合日志,将会对 (user,key,operation) 一样的操作进行合并输出,减少日志流量
<!-- KMS Audit -->
<property>
<name>hadoop.kms.audit.aggregation.window.ms</name>
<value>10000</value>
<description>
Duplicate audit log events within the aggregation window (specified in
ms) are quashed to reduce log traffic. A single message for aggregated
events is printed at the end of the window, along with a count of the
number of aggregated eventsfu.
</description>
</property>
4、kms security    kms  安全配置  
这里可以有两种配置 一种是使用simple 一种是使用 kerberos
使用 simple 只用如下配置就可以
  <!-- KMS Security -->

  <property>
<name>hadoop.kms.authentication.type</name>
<value>simple</value>
<description>
Authentication type for the KMS. Can be either &quot;simple&quot;
or &quot;kerberos&quot;.
</description>
</property>

kms-ent.sh 配置
  • KMS_HTTP_PORT
  • KMS_ADMIN_PORT
  • KMS_MAX_THREADS
  • KMS_LOG
 export KMS_LOG=${KMS_HOME}/logs/kms

 export KMS_HTTP_PORT=16000

 export KMS_ADMIN_PORT=16001
配置完成后 
启动 kms  sbin/kms.sh start ;
停止 ksm  sbin/kms.sh stop ;
jps 后发现进程有  Bootstrap 这个进程就说明启动成功;




kms 客户端配置

 kms-site.xml 配置如下参数
/etc/hadoop/conf/hdfs-site.xml
<property>
     <name>dfs.encryption.key.provider.uri</name>
     <value>kms://http@localhost:16000/kms</value>
</property>
/etc/hadoop/confcore-site.xml
<property>
      <name>hadoop.security.key.provider.path</name>
      <value>kms://http@localhost:16000/kms</value>
</property>
重新启动hadoop

 创建key
# su - hdfs
# hadoop key create key1  
# hadoop key list -metadata


创建加密区
# hdfs dfs -mkdir /secureweblogs
# hdfs crypto -createZone -keyName key1 -path /secureweblogs
# hdfs crypto -listZones
   



实验结果:
  用 casliyang用户 在加密区上传文件:
 hdfs dfs -copyFromLocal  /home/casliyang/read.log /zone1/web.log
 下载文件
 hdfs dfs -copyToLocal    /zone1/web.log /home/casliyang/3.log 
都可以成功

用hadoop220用户 在加密区上上传或者下载或者查看均失败,提示没有权限





 



补充说明:
1、kms 启动时候报错,说找不到加密文件
此处的加密文件可以是java自动生成的keystore 使用java keytool命令
生成秘钥 keytool -delete -alias 'kms.keystore'; 删除别名为kms.keystore的秘钥
keytool -genkey -alias 'kms.keystore';  生成 别名为kms.keystore的秘钥
使用生成秘钥的命令后,会在用户根目录下生成相应的文件
2、kms 启动时候 报错

首先检查 是否kms已经启动,若 kms 确实没有启动起来,这时候需要到 根目录root下的 temp文件夹  手动删除 kms.pid 然后再次启动kms

3、加密区建立成功后,任何用户都能进行访问等一系列操作


4、加密文件的原始隐藏路径 :
hdfs dfs -cat /.reserved/raw/zone1/localfile.dat     zone1 是加密区  localfile.dat 是加密文件 ,查看该文件 显示的是被加密的文件(乱码);

十三:Transparent Encryption in HDFS(转)的更多相关文章

  1. hadoop2.6.0汇总:新增功能最新编译 32位、64位安装、源码包、API下载及部署文档

    相关内容: hadoop2.5.2汇总:新增功能最新编译 32位.64位安装.源码包.API.eclipse插件下载Hadoop2.5 Eclipse插件制作.连接集群视频.及hadoop-eclip ...

  2. 安装部署Apache Hadoop (本地模式和伪分布式)

    本节内容: Hadoop版本 安装部署Hadoop 一.Hadoop版本 1. Hadoop版本种类 目前Hadoop发行版非常多,有华为发行版.Intel发行版.Cloudera发行版(CDH)等, ...

  3. 【转载 Hadoop&Spark 动手实践 2】Hadoop2.7.3 HDFS理论与动手实践

    简介 HDFS(Hadoop Distributed File System )Hadoop分布式文件系统.是根据google发表的论文翻版的.论文为GFS(Google File System)Go ...

  4. [HDFS Manual] CH3 HDFS Commands Guide

    HDFS Commands Guide HDFS Commands Guide 3.1概述 3.2 用户命令 3.2.1 classpath 3.2.2 dfs 3.2.3 envvars 3.2.4 ...

  5. 从零自学Hadoop(12):Hadoop命令中

    阅读目录 序 HDFS Commands User Commands Administration Commands Debug Commands 引用 系列索引 本文版权归mephisto和博客园共 ...

  6. HBASE 基础命令总结

    HBASE基础命令总结 一,概述 本文中介绍了hbase的基础命令,作者既有记录总结hbase基础命令的目的还有本着分享的精神,和广大读者一起进步.本文的hbase版本是:HBase 1.2.0-cd ...

  7. 【大数据系列】hadoop命令指导官方文档翻译

    Hadoop Commands Guide Overview Shell Options Generic Options User Commands archive checknative class ...

  8. Rootkit Hacking Technology && Defence Strategy Research

    目录 . The Purpose Of Rootkit . Syscall Hijack . LKM Module Hidden . Network Communication Hidden . Fi ...

  9. OCP读书笔记(27) - 题库(ExamG)

    601.You need to perform a block media recovery on the tools01.dbf data file in the SALES database by ...

随机推荐

  1. SSM整合时初始化出现异常

    java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException  ...

  2. Jquery中复选框选中取消实现文本框的显示隐藏

    标签内容 <div class="box"> 请编写javascript代码,完成如下功能要求:<br /> 1.取消复选款后,要求促销价格.促销开始结束日 ...

  3. Asp.Net Core使用Log4Net优化日志【项目开源】

    我在前一篇文章中介绍了一种使用Log4Net的方法,但是那种方法打出来的日志不是很直观 然后我前不久阅读了一篇非常不错的博客:https://www.cnblogs.com/guolianyu/p/9 ...

  4. sea.js模块化工具

    sea.js 一. sea.js向全局中引入了两个变量seajs.define: 1.seajs用加载文件 seajs.use(deps,callback)异步引入入口模块 路径要以sea.js文件所 ...

  5. Flume:source和sink

    Flume – 初识flume.source和sink 目录基本概念常用源 Source常用sink 基本概念  什么叫flume? 分布式,可靠的大量日志收集.聚合和移动工具.  events ...

  6. spark源码编译记录

    spark在项目中已经用了一段时间了,趁现在空闲,下个源码编译在IDEA里面阅读下,特此记录过程. 前提已经安装maven和git 1.上官网下载源码的包: 2.然后解压到一个文件夹 3.编译,编译的 ...

  7. java 递归打印20个斐波那契数

    class Test { public static void main(String[] args) { // feibo j=new feibo(); for (int n = 1; n < ...

  8. php+IIS 配置环境(windows环境)

    继php7+apache2.4 配置环境(window环境)后,由于B2C项目准备上线:特此小编在阿里云上搭建PHP7环境,为此特写上搭建过程希望正处于搭建php7+IIS(windows环境)中的朋 ...

  9. sql,lambda,linq语句

    实例 Code 查询Student表的所有记录. select * from student Linq: from s in Students select s Lambda: Students.Se ...

  10. 为啥学蛇和python10年后的变化

    作者:cheng rianley链接:https://www.zhihu.com/question/22112542/answer/166053516来源:知乎著作权归作者所有.商业转载请联系作者获得 ...