IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> Elasticsearch5.X权限管理 -> 正文阅读

[大数据]Elasticsearch5.X权限管理

ES6以前的开源版本,默认情况下是没有账户体系,但是可以通过以下开源的插件进行用户权限管理。下面就以search-guard插件来实践下

1、安装search-guard 插件,对应我们的es版本

cd $ES_HOME
bin/elasticsearch-plugin install -b com.floragunn:search-guard-5:5.4.0-15

2、生成证书

访问
:https://search-guard.com/tls-certificate-generator/

ES权限管理

填写相关信息,发送,会生效相关信息到你邮箱

去邮箱下载过来,目录如下:

ES权限管理

打开README.txt,其中有2种方式,我们选择一种

# Using the keystore- and truststore file                                      
                                                              
If you want to use keystore and truststore files, follow the steps here.
If you want to use certificates in PEM format, follow the steps above in section 'Using PEM certificates'.
                                                              
## Copying the keystore and truststore files                                      
 
For each node:
 
* Copy the file 'truststore.jks' to the config directory of your node
* Copy the file 'node-certificates/CN=[hostname]-keystore.jks' to the config directory of your node, where [hostname] is the hostname of your Elasticsearch node
 
## Configuring TLS on each node                                      
 
For each node, add the following lines to elasticsearch.yml.
Replace [hostname] with the hostname of the node, and [keystore password for this node]
with the keystore password of the keystore of the node. All settings and
passwords for each node are listed further down in this README.
                                                              
searchguard.ssl.transport.keystore_filepath: CN=[hostname]-keystore.jks
searchguard.ssl.transport.keystore_password: [keystore password for this node]
searchguard.ssl.transport.truststore_filepath: truststore.jks
searchguard.ssl.transport.truststore_password: e901ad3fc9a4e66d6687
searchguard.ssl.transport.enforce_hostname_verification: false
searchguard.ssl.http.enabled: true
searchguard.ssl.http.keystore_filepath: CN=[hostname]-keystore.jks
searchguard.ssl.http.keystore_password: [keystore password for this node]
searchguard.ssl.http.truststore_filepath: truststore.jks
searchguard.ssl.http.truststore_password: e901ad3fc9a4e66d6687
                                                              
searchguard.authcz.admin_dn:                               
  - CN=sgadmin 
                                                              
After that, start the node.
                                                              
## Using sgadmin with keystore- and truststore files                                     
 
To initialize the Search Guard configuration, you need to execute the sgadmin command line tool.
This can be done on any machine that has access to the transport port of your Elasticsearch cluster,
for example, a node in the cluster:
 
On the node where you want to execute sgadmin on:
* Copy the file 'truststore.jks' to the directory 'plugins/search-guard-<version>/tools'
* Copy the file 'client-certificates/CN=sgadmin-keystore.jks' to the directory 'plugins/search-guard-<version>/tools'
 
Change to the 'plugins/search-guard-<version>/tools' and execute:
 
chmod 755 ./sgadmin.sh
./sgadmin.sh -ts truststore.jks -tspass e901ad3fc9a4e66d6687 -ks CN=sgadmin-keystore.jks -kspass bf7af9f7aa2e650c5c93 -nhnv -icl -cd ../sgconfig/
 
If the node does not listen on default transport port 9300 and/or has a hostname other than localhost,
you can add:
 
-h,--hostname [host]        Elasticsearch host (default: localhost)
-p,--port [port]            Elasticsearch transport port (default: 9300)
 
 
## Passwords                                      
 
### Common passwords                                     
 
Root CA password: 6c5d561f574fb1f9f4d535b1656b87b25f0a8224                                      
Truststore password: e901ad3fc9a4e66d6687                              
Admin keystore and private key password: bf7af9f7aa2e650c5c93                      
Demouser keystore and private key password: 261f2834dff0795ee68b              
 
## Host/Node specific passwords                                      
 
Host: hz22-es-c1n1                                                
hz22-es-c1n1 keystore and private key password: 2a2e910a4d8d83454deb                          
hz22-es-c1n1 keystore: node-certificates/CN=hz22-es-c1n1-keystore.jks    
hz22-es-c1n1 PEM certificate: node-certificates/CN=hz22-es-c1n1.crtfull.pem    
hz22-es-c1n1 PEM private key: node-certificates/CN=hz22-es-c1n1.key.pem  

按照里面的提示修改配置完成后 重启es服务

如果没有报错说明没有问题,如果报错 具体看错误提示,基本应该是keystore这些信息配置的不对

3、初始化

任意节点执行初始化操作

cd $ES_HOME/plugins/search-guard-5/tools/
 
./sgadmin.sh -ts truststore.jks -tspass e901ad3fc9a4e66d6687 -ks CN=sgadmin-keystore.jks -kspass bf7af9f7aa2e650c5c93 -cn hz22-es-cluster1 -nhnv -cd ../sgconfig/ -p 9301 -h hz22-es-c1n1

提示成功,说明没有问题

4、访问测试

默认有个admin,密码admin

curl --user admin:admin "https://192.168.1.152:7200" -k

客户端访问

下载jar包依赖

https://search-guard.com/searchguard-elasicsearch-transport-clients/

客户端代码修改

相关文件放到 path.conf

public static void main(String[] args) throws UnknownHostException {
        Settings settings = Settings.builder()
                .put("path.home", ".")
                .put("path.conf", "E:\\workspace_idea\\es_test\\src\\main\\resources")
                .put("cluster.name", "es-cluster")
                .put("searchguard.ssl.transport.enabled", true)
                .put("searchguard.ssl.transport.keystore_filepath", "sgadmin-keystore.jks")
                .put("searchguard.ssl.transport.truststore_filepath", "truststore.jks")
                .put("searchguard.ssl.http.keystore_password", "password")
                .put("searchguard.ssl.http.truststore_password", "password")
                .put("searchguard.ssl.transport.keystore_password", "password")
                .put("searchguard.ssl.transport.truststore_password", "password")
                .put("searchguard.ssl.transport.enforce_hostname_verification", false)
                .build();
 
        TransportClient client = new PreBuiltTransportClient(settings, SearchGuardSSLPlugin.class)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("esnode1"), 9300))
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("esnode2"), 9300))
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("esnode3"), 9300));
 
        client.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet();
 
        //搜索数据
        GetResponse response = client.prepareGet("test", "name", "1").execute().actionGet();
        //输出结果
        System.out.println(response.getSourceAsString());
        //关闭client
        client.close();
    }

5、增加用户以及权限

searchguard 主要有5个配置文件在
plugins/search-guard-5/sgconfig 下:

1、sg_config.yml:主配置文件不需要做改动。

2、sg_internal_users.yml:本地用户文件,定义用户密码以及对应的权限。

3、sg_roles.yml:权限配置文件

4、sg_roles_mapping.yml:定义用户的映射关系

5、sg_action_groups.yml:定义权限

修改内置用户密码,然后再运行一次search guard 配置写入命令。

则先用
plugins/search-guard-5/tools/hash.sh生成hash字符串,生成密码:

cd $ES_HOME
 
plugins/search-guard-5/tools/hash.sh -p 123456

如果提示没有操作权限,则必须先把hash.sh文件的权限开放

chmod -R 777 plugins/search-guard-5/tools/hash.sh

获得哈希生成后的密码

$2a$12$xoY/DeHFWKILD3J.588A5eVmvr5UZSnYSQi8v2EMNUMXm.NTLL2/u

将字符串复制到sg_internal_users.yml文件的对应用户密码位置,在密码下面记得写入原密码的提示,难保你那天忘记了。

vim plugins/search-guard-5/sgconfig/sg_internal_users.yml
 
test1:
  hash: $2a$12$xoY/DeHFWKILD3J.588A5eVmvr5UZSnYSQi8v2EMNUMXm.NTLL2/u
  #password:123456

添加用户权限

vim plugins/search-guard-5/sgconfig/sg_roles_mapping.yml
 
sg_all_access:
  users:
    - admin
    - test1

重新写入配置

cd $ES_HOME/plugins/search-guard-5/tools/
 
./sgadmin.sh -ts truststore.jks -tspass e901ad3fc9a4e66d6687 -ks CN=sgadmin-keystore.jks -kspass bf7af9f7aa2e650c5c93 -cn hz22-es-cluster1 -nhnv -cd ../sgconfig/ -p 9301 -h hz22-es-c1n1

测试

ES权限管理

curl --user test1:123456 "https://192.168.1.152:7200" -k

返回结果

{
  "name" : "hz22-es-c1n1",
  "cluster_name" : "hz22-es-cluster1",
  "cluster_uuid" : "VIDwM4qLSL2g11pjx2Ay-M_A",
  "version" : {
    "number" : "5.4.0",
    "build_hash" : "780f8c4",
    "build_date" : "2017-04-28T17:43:27.229Z",
    "build_snapshot" : false,
    "lucene_version" : "6.5.0"
  },
  "tagline" : "You Know, for Search"
}
  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-07-28 07:53:02  更:2021-07-28 07:55:46 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/7 0:02:25-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码