presto中ldaps配置完整流程

  最近开始转战presto,至于前面章节中的Hbase,我也会持续更新,喜欢个人能够关注我。关于这个流程,我看过阿里云的的一篇文章,但看后仍是不知所云,就写下了这篇博客,你们感兴趣的能够访问那篇文章—— https://yq.aliyun.com/articles/670066
  闲话不说,让咱们来到正题。今天,咱们要分四个内容要讲——一.keytool生成ssl协议须要的相关文件 二.基于OpenSSL自建CA和颁发SSL证书 三.ldaps服务器搭建 四.presto-ldap插件启用,以及如何使用客户端访问。(另外,简单说一下这里的环境,其中ldaps是搭建在linux上的,而其余的组件是搭建在我本机mac上的)
  一.keytool生成ssl协议须要的相关文件
  1.建立证书
  keytool -genkey -v -keystore presto-private.keystore -alias presto-private -keyalg RSA -dname "CN=localhost, OU=, O=, L=, ST=, C=CN" -validity 20000 -keypass fvsord -storepass fvsord
  这里的-dname选项要求填不少,其实真正要填的只有Common Name,一般填写你服务器的域名,或者你服务器的IP地址(localhost),其它均可以留空的.
  2.导出证书,由客户端安装
  keytool -export -alias presto-private -keystore presto-private.keystore -file presto-public.cer -storepass fvsord
  3.客户端配置:(这里的alias没必要与上面的一致)
  keytool -import -alias presto-public -file presto-public.cer -keystore presto-public.store -storepass fvsord
  4.能够经过下面的命令查看签名信息
  keytool -v -list -keystore /usr/local/keystores/test/presto-test.keystore
  关于keytool中各个选项的详解,我在这里就再也不详细介绍了,毕竟,咱们这一节的内容是presto中的ldaps。
  二.基于OpenSSL自建CA和颁发SSL证书(linux默认已经安装了openssl,所以我在这里假设已经安装好openssl)
  1.在linux中默认的CA路径是/etc/pki/CA,关于该路径,咱们能够在vi /etc/pki/tls/openssl.cnf中看到,以下图所示:   默认安装的opnessl可能并无其中的一些文件(夹),须要咱们本身来建立。
  2.在上面的文件中,咱们要注意其中在[ policy_match ]中的设定的匹配规则,这里匹配规则与咱们后面要生成的csr有关系。其实也就是在第一部分中讲到的-dname 选项中的各个条目。
  在CA目录下建立两个文件:
  touch index.txt serial
  echo 00 > serial
  3.生成根密钥(来到/etc/pki/CA目录)
  cd /etc/pki/CA/
  openssl genrsa -out private/cakey.pem 2048
  4.生成根证书
  使用req命令生成自签证书:
  openssl req -new -x509 -key private/cakey.pem -out cacert.pem
  这里会输入一些内容,与咱们上面使用keytool建立证书是输入的内容大体同样,这里咱们一样只关注Common Name。
  5.接下来,咱们就能够为咱们的ldap服务器生成ssl密钥(这里生成的密钥能够在ldap服务器上,也能够在上面的CA服务器上。假设咱们在上面的CA服务器上生成密钥,另外,咱们在 /usrl/local/CA目录下生成ssl密钥)
  cd /usrl/local/CA
  openssl genrsa -out ldap.key
  6.为ldap生成证书签署请求
  openssl req -new -key ldap.key -out ldap.csr
  7.ca根据请求签发证书,获得.crt证书文件
  openssl x509 -req -in ldap.csr -CA /etc/pki/CA/cacert.pem -CAkey /etc/pki/CA/private/cakey.pem -CAcreateserial -out ldap.crt
  这里生成的证书为咱们后面的ldap服务器的搭建作前提准备。
  三.ldaps服务器搭建(以linux为例)
  1.安装ldap
    yum install -y openldap*
  2.在网上看到上面安装后会有/usr/share/openldap-servers/slapd.conf.obsolete文件,而我在新版的Linux环境中安装屡次后并无找到该文件。每每须要咱们本身手动完成,如下是测试经过的完整版本。
  =================================================
  include /etc/openldap/schema/corba.schema
  include /etc/openldap/schema/core.schema
  include /etc/openldap/schema/cosine.schema
  include /etc/openldap/schema/duaconf.schema
  include /etc/openldap/schema/dyngroup.schema
  include /etc/openldap/schema/inetorgperson.schema
  include /etc/openldap/schema/java.schema
  include /etc/openldap/schema/misc.schema
  include /etc/openldap/schema/nis.schema
  include /etc/openldap/schema/openldap.schema
  include /etc/openldap/schema/ppolicy.schema
  include /etc/openldap/schema/collective.schema
  access to *
    by self write
    by anonymous auth
    by * read
  pidfile /var/run/openldap/slapd.pid
  argsfile /var/run/openldap/slapd.args
  database bdb
  suffix "dc=fly,dc=com"
  rootdn "cn=sky,dc=fly,dc=com"
  TLSCACertificateFile /etc/pki/CA/cacert.pem
  TLSCertificateFile /usrl/local/CA/ldap.crt
  TLSCertificateKeyFile /usrl/local/CA/ldap.key
  TLSVerifyClient never
  # Cleartext passwords, especially for the rootdn, should
  # be avoid. See slappasswd(8) and slapd.conf(5) for details.
  # Use of strong authentication encouraged.
  rootpw {SSHA}YgXdmGu8hrIE10JMEhkW6p2QBfPF+62J
  # The database directory MUST exist prior to running slapd AND
  # should only be accessible by the slapd and slap tools.
  # Mode 700 recommended.
  directory /var/lib/ldap
  # Indices to maintain
  index objectClass eq
  =================================================
  3.设置管理员密码
  slappasswd
  键入新密码后,会弹出生成的密码。咱们将其粘到上面文件的rootpw后面,其间使用Tab键分隔。
  4.修改slapd.conf 核心配置
  database bdb
  suffix "dc=fly,dc=com"
  rootdn "cn=sky,dc=fly,dc=com"
  rootpw {SSHA}YgXdmGu8hrIE10JMEhkW6p2QBfPF+62J
  5.修改slapd.conf 权限配置
  access to *
         by self write
         by anonymous auth
         by * read
  6.添加ssl认证
  TLSCACertificateFile /etc/pki/CA/cacert.pem
  TLSCertificateFile /usrl/local/CA/ldap.crt
  TLSCertificateKeyFile /usrl/local/CA/ldap.key
  TLSVerifyClient never
  7.检测配置是否正确
  slaptest -u
  8.配置数据库
   cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
  9.删除默认内容
   rm -rf /etc/openldap/slapd.d/*
  10.启动ldap
  /usr/sbin/slapd -h 'ldaps://192.168.0.76:636/' -f /etc/openldap/slapd.conf -d 255
  11.状态查看:
  systemctl status slapd.service
  12.使用客户端验证
  咱们这里的默认路径是/etc/openldap/ldap.conf
  咱们须要在最后添加
  TLS_CACERT /etc/pki/CA/cacert.pem
  而后,咱们能够执行一下操做来验证咱们是否安装好ldaps服务器:
  ldapsearch -x -b "cn=sky,dc=fly,dc=com" -H ldaps://192.168.0.76:636
  若是没有报异常,则ldaps服务安装成功。
  四.presto-ldap插件启用
  presto中若是启动了ssl认证,则一样要求启动ldaps认证。
  对于启动ssl认证,咱们须要在etc/config.properties这样配置:
  另外,咱们须要在etc/password-authenticator.properties文件中这样配置:
  password-authenticator.name=ldap
  ldap.url=ldaps://192.168.0.76:636
  ldap.user-bind-pattern=cn=sky,dc=fly,dc=com
  若是仅仅是上面的配置,仍是不够,一般会报。由于咱们并无将ldaps的客户端证书添加到咱们的presto相关文件中。
  其实一开始我觉得是要将ldaps中的文件(/usrl/local/CA/ldap.key或/etc/pki/CA/cacert.pem皆可)导入到上面配置的/usr/local/keystores/for-presto/presto-private.keystore中。但一直报上面的错,后来我追踪了源码,发现其就是使用jdk中的证书,因此,这里,咱们应该将其中的证书添加到jdk中。这里我要执行的操做是:
sudo keytool -delete -alias ldap-remote-server -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/security/cacerts -storepass changeit(更正为:sudo keytool -import -file /etc/pki/CA/cacert.pem -alias ldap-remote-server -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/security/cacerts -storepass changeit)
  至此,就安装成功了,若是有问题,能够在下面留言。
相关文章
相关标签/搜索