elasticsearch開啟密碼訪問

本文記錄了elastic search開始密碼訪問chart中所需要的配置,當(dāng)前使用的chart包版本是elasticsearch-7.16.2.tgz。

配置chart中的變量

首先是在values.yaml文件中需要開始的配置項如下所示:

secret:
  enabled: true
  password: "listai"

secretMounts:
  - name: elastic-certificates
    secretName: elastic-certificates
    path: /usr/share/elasticsearch/config/certs

extraEnvs:
  - name: ELASTIC_USERNAME
    valueFrom:
      secretKeyRef:
        name: elastic-credentials
        key: username
  - name: ELASTIC_PASSWORD
    valueFrom:
      secretKeyRef:
        name: elastic-credentials
        key: password

esConfig:
  elasticsearch.yml: |
    xpack.security.enabled: true
    xpack.security.transport.ssl.enabled: true
    xpack.security.transport.ssl.verification_mode: certificate
    xpack.security.transport.ssl.keystore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
    xpack.security.transport.ssl.truststore.path: /usr/share/elasticsearch/config/certs/elastic-certificates.p12

主要內(nèi)容是需要創(chuàng)建兩個secret,一個存儲username和password,一個存儲證書,證書是如何生成的請看后續(xù)。
通過env引用username和password,通過volume的方式將證書掛載到容器中對應(yīng)的目錄中。

  • 需要注意的是開始密碼認證必須要開啟es節(jié)點之間的ssl訪問認證,需要使用es自帶的工具elasticsearch-certutil生成ssl訪問所需要的證書
  • 用戶名默認的內(nèi)置的super user:elastic,密碼自己設(shè)定
  • 集群實例個數(shù)不能低于2個才能正常使用

如何創(chuàng)建證書

1、生成CA 證書elastic-stack-ca.p12

elasticsearch-certutil ca --days 35600

查看證書的內(nèi)容:

openssl pkcs12 -info -nodes -in elastic-stack-ca.p12

查看證書有效期,此證書簽35600天:

openssl pkcs12 -in elastic-stack-ca.p12 -nodes -nokeys -clcerts | openssl x509 -enddate -noout
Enter Import Password:
notAfter=Apr 19 09:45:23 2121 GMT

2、創(chuàng)建es證書

elasticsearch-certutil cert --ca elastic-stack-ca.p12 --days 35600

查看證書內(nèi)容:

openssl pkcs12 -info -nodes -in elastic-certificates.p12

查看時間:

openssl pkcs12 -in elastic-certificates.p12 -nodes -nokeys -clcerts | openssl x509 -enddate -noout

3、基于elastic-certificates.p12創(chuàng)建secret資源:

cat > secret.yaml <<EOF
apiVersion: v1
kind: Secret
metadata:
  name: elastic-certificates
type: Opaque
data:
  elastic-certificates.p12: $(cat elastic-certificates.p12 | base64 | tr -d '\n')
EOF

如何測試安裝后的es的用戶名密碼是正確的:

curl -k  http://10.233.10.80:9200 -u elastic:listai
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容