ElasticSearch RPM 패키지 설치 Security

ElasticSearch 를 RPM 패키지로 설치할 경우에 Security 설정을 어떻게 해야하는지에 대해서 다룬다. Security 설정은 X-Pack 을 활성화 하기 위함이며 이를 위해서는 인증서 관련 문제를 해결해야 한다.

사례

일단, 엘라스틱 서치는 대부분 3대로 구성한다. 대부분 호스트를 다음과 같이 정할 것이다.

  • es-01
  • es-02
  • es-03

이때, es-01 서버에서 다음과 같은 작업을 해야 한다.

es-01 서버에서 인증서 작업

X-Pack 을 활성화하기 위해서는 보안을 활성화해야 하는데, 보안을 활성화할 경우에 각 노드별로 SSL 통신을 하게된다. 이때 인증서가 필요한데, 인증서 작업을 해야 한다.

중요한 것은 인증서를 한 곳에서 해야하고 모두 서버에 배포를 해야 한다. 여기서는 es-01 서버에서 하는 것으로 가정한다.

]# # root 계정
]# cd /usr/share/elasticsearch
]# ./bin/elasticsearch-certutil ca
If you elect to generate PEM format certificates (the -pem option), then the output will
be a zip file containing individual files for the CA certificate and private key

Please enter the desired output file [elastic-stack-ca.p12]: 
Enter password for elastic-stack-ca.p12 :
]#

뭐라 뭐라 나오지만 중요한건 위 두줄인데, 그냥 Enter 만 두번 쳐주면 된다. 이렇게 하면 /usr/share/elasticsearch 디렉토리에 ‘elastic-stack-ca.p12’ 파일이 생성된다.

그리고 이제 루트 인증서를 가지고 인증서를 다음과 같이 만든다.

]# cd /usr/share/elasticsearch
]# ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
Enter password for CA (elastic-stack-ca.p12) : 
Please enter the desired output file [elastic-certificates.p12]: 
Enter password for elastic-certificates.p12 :

Certificates written to /usr/share/elasticsearch/elastic-certificates.p12

역시 뭐라뭐라 나오는데, Enter 만 세번 쳐준다. 이렇게하면 /usr/share/elasticsearch 디렉토리에 ‘elastic-certificates.p12’ 파일이 생성된다.

위 과정으로 인해서 2개의 파일 ‘elastic-stack-ca.p12’, ‘elastic-certificates.p12’ 파일이 생성된다.

이 두개의 파일을 이제 3개의 엘라스틱서버 모두에 /etc/elasticsearch 디렉토리로 복사해 준다. 그리고 다음과 같이 소유권과 퍼미션을 변경해 준다.

]# cd /etc/elasticsearch
]# chown root:elasticsearch elastic-*
]# chmod 660 elastic-*

설정

이제 3대 서버 모두에 ‘elastic-stack-ca.p12’, ‘elastic-certificates.p12’ 두개 파일이 /etc/elasticsearch 디렉토리에 있을 것이다. 모두 es-01 에서 만든 같은 파일이다.

이제 각 서버의 /etc/elasticsearch/elasticsearch.yml 파일 맨 마지막에 다음과 같이 설정을 해준다.

# vim /etc/elasticsearch/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: /etc/elasticsearch/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12

xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.verification_mode: certificate
xpack.security.http.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12
xpack.security.http.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12

이게 es-01 서버부터 시작을 해준다. 그러면 잘 될 것이다.

패스워드 생성

마지막으로 엘라스틱서치에 인증이 필요한 계정에 패스워드를 생성해 준다.

]# cd /usr/share/elasticsearch/
]# ./bin/elasticsearch-setup-passwords auto
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
The passwords will be randomly generated and printed to the console.
Please confirm that you would like to continue [y/N]y


Changed password for user apm_system
PASSWORD apm_system = 1QzJrrJ5DPaRJj7BOPRz

Changed password for user kibana
PASSWORD kibana = 8HlolrAt0Xoh2HMjUGds

Changed password for user logstash_system
PASSWORD logstash_system = fS6R6b42i7gq0oWX4SaA

Changed password for user beats_system
PASSWORD beats_system = 0hmbPnLbhoYAuqyQWlDf

Changed password for user remote_monitoring_user
PASSWORD remote_monitoring_user = 981aW8DqT1bQH6ivJB95

Changed password for user elastic
PASSWORD elastic = v2m83v658paNU6ensJ6A

Kibana 에서는 username 이 kibana 계정과 위에서 생성한 패스워드를 입력해 준다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다