Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

더비창고방

elasticsearch-kibana 사용자 인증 및 관리 본문

STUDY

elasticsearch-kibana 사용자 인증 및 관리

moongzeee 2022. 12. 20. 17:55

[목차]

  1. 개요
    1.1 es-kibana 사용자 인증 및 관리
  2. 보안 설정 방법
    2.1 elasticsearch 다중 노드 클러스터 사용자 인증 설정
    2.2 kibana 사용자 인증 설정

 

1. 개요

1.1 es-kibana 사용자 인증 및 관리

  • 목표
    • 사용자 별로 ID/PW 를 부여하여, ID/PW를 이용하여 elasticsearch와 kibana 접속이 가능토록 한다.
    • elasticsearch 내부에 .security index를 생성하여 사용자 정보를 저장하여 사용자 계정관리를 한다.

구성도

 

 

2. 사용자 인증 설정 방법

elasticsearch-kibana 사용자 인증 설정에는 3단계가 있다

  • elastic search 다중노드 클러스터 보안 설정
  • Kibana 보안설정
  • 시스템 계정의 password 설정

2.1 elasticsearch 다중 노드 클러스터 사용자 인증 설정

elasticsearch 클러스터의 사용자 인증설정은 사용자 계정 정보를 저장하는 index (.security_index)에 대한 생성과 시스템 계정의 password 설정 과정이다.

[elasticsearch 다중 노드 클러스터 사용자 인증 설정 방법]

<step1> elasticsearch TLS 통신을 위한 인증서 생성

elasticsearch node1에서 인증서를 생성하고, 이 인증서를 나머지 노드에 복사한다.

우선, elasticsearch를 아래 명령어를 실행하여 종료한다.

sudo -i service elastcisearch stop

아래 명령어를 순서대로 실행하여, elasticseach node1의 CA를 생성한다. 파일명은 elastic-stack-ca.cp12로 지정한다.

cd /usr/share/elasticsearch
./bin/elasticsearch-certutil ca

아래 명령어를 실행하여, 생성된 CA를 이용해 certificate and private key를 생성한다. 파일명은 elastic-certificates.p12로 지정후, 비밀번호는 기억해 둔다.

./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 

생성된 elastic-certificates.p12를 /etc/elasticsearch/ 경로로 옮기고, 나머지 elasticsearch node2, elasticsearch node3 에도 /etc/elasticsearch/ 경로로 생성된 인증서 파일을 복사한다.

<step2> elasticsearch.yml 파일 설정

다음과 같이 elasticsearch.yml파일을 각 elasticsearch 노드서버 마다 작성한다.

** node.name은 각 서버마다 다르게 지정해야한다.

[/etc/elasticsearch/elasticsearch.yml]

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# <https://www.elastic.co/guide/en/elasticsearch/reference/index.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: es-cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
node.master: true
node.data: true
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: [_local_, _site_]
transport.profiles.default.port: 9300
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
# For more information, consult the network module documentation.
# **The setting configuration below is set only on the first node**
**transport.host:[_local_, _site_]**
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["host1", "host2","host3"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#
# ---------------------------------- Security ----------------------------------
#
#                                 *** WARNING ***
#
# Elasticsearch security features are not enabled by default.
# These features are free, but require configuration changes to enable them.
# This means that users don’t have to provide credentials and can get full access
# to the cluster. Network connections are also not encrypted.
#
# To protect your data, we strongly encourage you to enable the Elasticsearch security features. 
# Refer to the following documentation for instructions.
#
# <https://www.elastic.co/guide/en/elasticsearch/reference/7.16/configuring-stack-security>
#
# enable security
**xpack.security.enabled: true
# make sure the nodes talk in SSL to each other 
xpack.security.transport.ssl:
	enabled: true
	verification_mode: certificate
	client_authentication: required
	keystore.path: elastic-certificates.p12
	truststore.path: elastic-certificates.p12**

<step3>elasticsearch-keystore에 password 저장

아래 명령어를 실행하여 elasticsearch-keystore에 xpack security password를 저장한다.

cd /usr/share/elasticsearch
./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
./bin/elasticsearch-keysoter add xpack.security.transport.ssl.truststore.secure_password

여기까지 모든 elasticsearch 노드들의 설정이 완료되면, 다시 elasticsearch를 기동한다.

## elasticsearch 시작 명령어
sudo -i service elasticsearch start

<step4> elastic stack 시스템 계정 비밀번호 설정

** elastic stack : elasticsearch + kibana

시스템 계정 비밀번호 설정에는 대화형으로 비밀번호를 입력하는 방식으로 진행한다.

cd /usr/share/elasticsearch
./bin/elatsicsearch-setup-password interactive 

 

<step5> elasticsearch 보안 설정 확인

curl 명령어로, 기본계정 ID/PW를 이용해 보안설정이 완료되었는지 확인한다.

curl --user elastic es_host_ip:9200

“Enter host password for user ‘elastic’ : “ 이 나오면 <step4> 에서 설정한 elastic의 비밀번호를 입력한다.

elasticsearch의 정보가 나오면 elasticsearch 보안설정이 완료된 것이다.

 

 

2.2 Kibana 사용자 인증 설정

Kibana 사용자 인증설정은 Kibana 대시보드 접속시 로그인 설정 과정이다.

[Kibana 사용자 인증 설정 방법]

<step1> kibana.yml 설정

2.1 <step4> ****에서 생성한 kibana-system 계정의 아이디와 비밀번호를 kibana.yml에 추가 후, kibana를 재시작한다.

# For more configuration options see the configuration guide for Kibana in
# <https://www.elastic.co/guide/index.html>

# =================== System: Kibana Server ===================
# Kibana is served by a back end server. This setting specifies the port to use.
server.port: 5601

# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
server.host: "0.0.0.0"

# Enables you to specify a path to mount Kibana at if you are running behind a proxy.
# Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
# from requests it receives, and to prevent a deprecation warning at startup.
# This setting cannot end in a slash.
#server.basePath: ""

# Specifies whether Kibana should rewrite requests that are prefixed with
# `server.basePath` or require that they are rewritten by your reverse proxy.
# Defaults to `false`.
#server.rewriteBasePath: false

# Specifies the public URL at which Kibana is available for end users. If
# `server.basePath` is configured this URL should end with the same basePath.
#server.publicBaseUrl: ""

# The maximum payload size in bytes for incoming server requests.
#server.maxPayload: 1048576

# The Kibana server's name. This is used for display purposes.
#server.name: "your-hostname"

# =================== System: Kibana Server (Optional) ===================
# Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
# These settings enable SSL for outgoing requests from the Kibana server to the browser.
#server.ssl.enabled: false
#server.ssl.certificate: /path/to/your/server.crt
#server.ssl.key: /path/to/your/server.key

# =================== System: Elasticsearch ===================
# The URLs of the Elasticsearch instances to use for all your queries.
elasticsearch.hosts: ["http://node1_ip:9200","http://node2_ip:9200","http://node3_ip:9200"]

# If your Elasticsearch is protected with basic authentication, these settings provide
# the username and password that the Kibana server uses to perform maintenance on the Kibana
# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# is proxied through the Kibana server.
**elasticsearch.username: "kibana_system"
elasticsearch.password: "kibana_system_password"**

<step2> Kibana 접속확인

http://kibana_host_ip:5601에 접속해, 아래 화면이 나오면 보안설정이 완료 된것이다. 아직 user 생성을 하지 않았기 때문에 시스템계정인 elastic으로 접속 한다.