방법은 CA부터 만들고 elasticsearch-certutil http에서 생성한 CA를 선택해서 진행하는 방식과
elasticsearch-certutil http로 바로 시작해서 CA를 만들면서 시작하는 방식이 있는데 공식문서에는 첫번재 방식에 대해서 자세히 설명이 되어 있지만 저는 두번째 방식으로 진행했습니다.
우분투 18.04에 elasticsearch와 kibana만 설치하고 진행했습니다.
#우분투에 설치된 경로 기준
sudo /usr/share/elasticesearch/bin/elasticsearch-certutil htt
해당 명령어를 입력하면 인증서를 만들기 위해 옵션 설정 항목들이 나옵니다.
## Elasticsearch HTTP Certificate Utility
# Do you wish to generate a Certificate Signing Request (CSR)?
Generate a CSR? [y/N]n
## Do you have an existing Certificate Authority (CA) key-pair that you wish to use to sign your certificate?
Use an existing CA? [y/N]n
## CA Generation Options
Do you wish to change any of these options? [y/N]n
## CA password
CA password: [<ENTER> for none] 패스워드입력
Repeat password to confirm: 패스워드입력
## How long should your certificates be valid?
For how long should your certificate be valid? [5y] 2y
## Do you wish to generate one certificate per node?
Generate a certificate per node? [y/N]n
## Which hostnames will be used to connect to your nodes?
localhost
Is this correct [Y/n]y
## Which IP addresses will be used to connect to your nodes?
127.0.0.1
Is this correct [Y/n]y
## Other certificate options
Do you wish to change any of these options? [y/N]n
## What password do you want for your private key(s)?
Provide a password for the "http.p12" file: [<ENTER> for none] 패스워드입력
Repeat password to confirm: 패스워드입력
## Where should we save the generated files?
What filename should be used for the output zip file? [/usr/share/elasticsearch/elasticsearch-ssl-http.zip] 엔터
마지막 output zip file 에서 파일명 변경없이 엔터 치면 Zip file written to /usr/share/elasticsearch/elasticsearch-ssl-http.zip 메시지와 함께 제안해준 파일이 생성이 됩니다.
sudo unzip /usr/share/elasticsearch/elasticsearch-ssl-http.zip -d /etc/elasticsearch/certs/http
압축파일을 /etc/elasticsearch/certs/http 아래에 풀었는데요 기본적으로 /etc/elasticsearch/certs까지 구성되어 있기 때문에 http 디렉토리를 먼저 만들고 진행하면 됩니다.
Archive: /usr/share/elasticsearch/elasticsearch-ssl-http.zip
creating: /etc/elasticsearch/certs/http/elasticsearch/
inflating: /etc/elasticsearch/certs/http/elasticsearch/README.txt
inflating: /etc/elasticsearch/certs/http/elasticsearch/http.p12
inflating: /etc/elasticsearch/certs/http/elasticsearch/sample-elasticsearch.yml
creating: /etc/elasticsearch/certs/http/ca/
inflating: /etc/elasticsearch/certs/http/ca/README.txt
inflating: /etc/elasticsearch/certs/http/ca/ca.p12
creating: /etc/elasticsearch/certs/http/kibana/
inflating: /etc/elasticsearch/certs/http/kibana/README.txt
inflating: /etc/elasticsearch/certs/http/kibana/elasticsearch-ca.pem
inflating: /etc/elasticsearch/certs/http/kibana/sample-kibana.yml
압축을 풀면 위와 같이 어떤 파일들이 압축해제 되었는지 보여줍니다.
파일들에 대해서 요약해보자면
- Elasticsearch 관련 파일 (/elasticsearch/ 디렉터리)
- http.p12: Elasticsearch HTTP 통신에 사용할 인증서와 개인 키.
- sample-elasticsearch.yml: 해당 인증서를 사용하는 설정 예시.
- CA 관련 파일 (/ca/ 디렉터리)
- ca.p12: Elasticsearch HTTP 인증서를 서명한 CA 정보가 담긴 키스토어.
- Kibana 관련 파일 (/kibana/ 디렉터리)
- elasticsearch-ca.pem: Kibana가 Elasticsearch의 인증서를 검증할 때 사용하는 CA 인증서.
- sample-kibana.yml: Kibana의 SSL/TLS 설정 예시 파일.
sudo vi /etc/elasticsearch/elasticsearch.yml
elasticsearch.yml 파일을 열어서 keystore.path 설정 변경을 해줍니다.
xpack.security.http.ssl:
enabled: true
keystore.path: certs/http/elasticsearch/http.p12
그리고 Elasticsearch의 보안 설정에 개인 키의 비밀번호를 추가합니다.
sudo /usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password
기존에 생성되어 있는 키가 있기때문에 덮어씌우기하시면 됩니다.
sudo systemctl restart elasticsearch
elasticsearch를 재시작해하면 elasticsearch와 관련된 설정은 끝이고 kibana 설정을 해보겠습니다.
sudo cp /etc/elasticsearch/certs/http/kibana/elasticsearch-ca.pem /var/lib/kibana/
압축파일에 있던 인증서를 복사합니다.
sudo openssl x509 -in /var/lib/kibana/elasticsearch-ca.pem -noout -fingerprint -sha256
설정파일을 수정할때 ca_trusted_fingerprint값도 바꿔야 하기때문에 미리 출력합니다.
sudo vi /etc/kibana/kibana.yml
kibana.yml파일을 열어서 기존에 있던 인증서 설정값을 새로운 인증서로 변경합니다.
elasticsearch.ssl.certificateAuthorities: [/var/lib/kibana/elasticsearch-ca.pem]
xpack.fleet.outputs:[{......, ca_trusted_figerprint: "sha256 값"
sudo systemctl restart kibana
kibana를 재실행 하면 설정은 끝납니다.