elasticsearch / / 2022. 12. 22. 20:36

elasticsearch에서 기본인증을 사용하는 경우 rest 접속 방법

기본적으로 elasticsearch는 rest로 접근이 가능하다.
하지만 elasticsearch에 인증을 설정하게 되면 인증정보 없이는 접근이 불가능하다.

인증 설정방법은 elasticsearch.yml파일에 아래 내용을 추가하고 재시작하면 된다.

xpack.security:
  enabled: true
  transport:
    ssl:
      enabled: true

인증이 설정된 상태에서 http://localhost:9200/_search로 접속하면 아래 오류가 발생한다.

{
  "error": {
    "root_cause": [
      {
        "type": "security_exception",
        "reason": "missing authentication credentials for REST request [/_search]",
        "header": {
          "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
        }
      }
    ],
    "type": "security_exception",
    "reason": "missing authentication credentials for REST request [/_search]",
    "header": {
      "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
    }
  },
  "status": 401
}

elasticsearch-setup-passwords를 통해 비밀번호를 설정한다.

elasticsearch-setup-passwords interactive

Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:

elasticsearch에서 기본 인증을 사용하는 경우 접속방법은 2가지가 있다.

  1. header에 Authorization 추가
  2. URL에 아이디:비밀번호 추가

1. header에 Authorization 추가

id: elastic, password: asdf123 이고
elastic:asdf123을 base64 encoding한 결과가 ZWxhc3RpYzphc2RmMTIz이라면
Authorization에 넣어준다.

GET http://localhost:9200/_search
Authorization: Basic ZWxhc3RpYzphc2RmMTIz

2. URL에 아이디:비밀번호 추가

id: elastic, password: asdf123 이라면

GET http://elastic:asdf123@localhost:9200/_search
반응형
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유