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)
  至此,就安裝成功了,如果有問題,可以在下面留言。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM