'Basic'에 해당되는 글 2건

  1. 2021.08.12 [Elasticsearch] RESTful API + ID:PASSWORD 요청.
  2. 2020.09.03 [Elasticsearch] API Key (중복)

[Elasticsearch] RESTful API + ID:PASSWORD 요청.

Elastic/Elasticsearch 2021. 8. 12. 13:18

분명 어딘가에 기록해 두었는데 이걸 왜 못찾고 있는 거지..ㅡ.ㅡ;

 

http://elastic:password@localhost:9200/test-index

 

elasticsearch 에서 기본 인증을 사용 할 경우 API token 사용 이런게 아니라면 단순하게는 저렇게 보낼 수 있습니다.

 

https://www.ietf.org/rfc/rfc2617.txt

공식 스펙은 위 문서 참고 하시면 됩니다. (Basic Authentication)

 

URL 로 보내기 싫으시면 header 로 보내시면 됩니다.

 

elastic:password 를 base64 인코딩 하시고 "Authorization" 헤더로 값을 보내시면 되겠습니다.

 

KEY : Authorization

VALUE : Basic ZWxhc3RpYzpwYXNzd29yZA==

 

:

[Elasticsearch] API Key (중복)

Elastic/Elasticsearch 2020. 9. 3. 10:16

이전에 작성한 글과 중복 내용이 있습니다.

 

이전 글)

jjeong.tistory.com/1487

 

Elasticsearch + Kibana 사용 시 basic security 설정을 enable 하게 되면 Restful API 사용을 위한 API Key 를 생성 해서 사용을 해야 합니다.

 

Kibana devtools 를 이용해서 할 경우 인증이 되어 있어서 /_security/api_key 사용이 가능 하지만 Postman 과 같은 걸 이용할 경우 id:pwd 를 넣어 줘야 합니다.

[Case 1]
http://elastic:elasticpassword@localhost:9200/_security/api_key

[Case 2]
curl -XPUT -u elastic:elasticpassword "http://localhost:9200/_security/api_key" -d
{
  "name": "team-index-command",
  "expiration": "10m", 
  "role_descriptors": { 
    "role-team-index-command": {
      "cluster": ["all"],
      "index": [
        {
          "names": ["*"],
          "privileges": ["all"]
        }
      ]
    }
  }
}

 

API Key 구조)

- /_security/api_key 를 이용해서 생성을 하면 아래와 같은 값이 나옵니다.

[Request]
POST /_security/api_key
{
  "name": "team-index-command",
  "expiration": "10m", 
  "role_descriptors": { 
    "role-team-index-command": {
      "cluster": ["all"],
      "index": [
        {
          "names": ["*"],
          "privileges": ["all"]
        }
      ]
    }
  }
}

[Response]
{
  "id" : "87cuynIBjKAXtnkobGgo",
  "name" : "team-index-command",
  "expiration" : 1592529999478,
  "api_key" : "OlVGT_Q8RGq1C_ASHW7pGg"
}

- API Key 는 id:api_key 조합으로 base64 encoding 된 값입니다.

base64_encode("87cuynIBjKAXtnkobGgo"+":"+"OlVGT_Q8RGq1C_ASHW7pGg")

 

API Key 를 이용한 Restful API 호출)

$ curl 
  -H "Authorization: ApiKey VGVVOXluSUJHUUdMaHpvcUxDVWo6aUtfSmlEMmdSMy1FUUFpdENCYzF1QQ==" 
  http://localhost:9200/_cluster/health

 

: