Elasticsearch와 함께 JWT 인증 사용하기
이 가이드는 Teleport와 함께 Elasticsearch JWT 인증을 구성하는 방법을 설명합니다. A running Teleport cluster. The tctl and tsh clients. Determine the version of your Teleport cluster.
이 가이드는 Teleport와 함께 Elasticsearch JWT 인증을 구성하는 방법을 설명합니다.
사전 조건#
-
A running Teleport cluster. If you want to get started with Teleport, sign up for a free trial or set up a demo environment.
-
The
tctlandtshclients.Installing `tctl` and `tsh` clients
-
Determine the version of your Teleport cluster. The
tctlandtshclients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at/v1/webapi/findand use a JSON query tool to obtain your cluster version. Replace with the web address of your Teleport Proxy Service:$ TELEPORT_DOMAIN= $ TELEPORT_VERSION="$(curl -s https://$TELEPORT_DOMAIN/v1/webapi/find | jq -r '.server_version')" -
Follow the instructions for your platform to install
tctlandtshclients:
-
To check that you can connect to your Teleport cluster, sign in with tsh login, then
verify that you can run tctl commands using your current credentials.
For example, run the following command, assigning to the domain name of the Teleport Proxy Service in your cluster and to your Teleport username:
$ tsh login --proxy= --user=
$ tctl status
# Cluster (=teleport.url=)
# Version (=teleport.version=)
# CA pin (=presets.ca_pin=)
If you can connect to the cluster and run the tctl status command, you can use your
current credentials to run subsequent tctl commands from your workstation.
If you host your own Teleport cluster, you can also run tctl commands on the computer that
hosts the Teleport Auth Service for full permissions.
- Application Service 실행 중.
- Elasticsearch 클러스터 버전 >=
8.2.0.
1/3단계. Elasticsearch에서 JWT 영역 활성화#
Elasticsearch 구성 파일 elasticsearch.yaml을 업데이트하여 JWT 영역을 활성화합니다:
xpack.security.authc.realms.jwt.teleport:
order: 1
client_authentication.type: none
pkc_jwkset_path: https://proxy.example.com/.well-known/jwks.json
claims.principal: sub
claims.groups: roles
allowed_issuer: example-cluster
allowed_audiences: ["https://elasticsearch.example.com:9200"]
Elastic Cloud의 호스팅된 배포의 경우, 배포를 편집하여 동일한 설정을 구성할 수 있습니다.
"Elasticsearch"의 "사용자 설정 및 확장 관리"로 이동한 다음 "사용자 설정"에서 위의 구성 스니펫을 추가합니다. 1보다 큰 순서 번호를 사용해야 할 수도 있습니다.
Elastic Cloud 서버리스 프로젝트는 외부 영역 연결을 지원하지 않으므로 JWT 인증으로 구성할 수 없습니다.
매개변수와 그 값을 자세히 살펴보겠습니다:
client_authentication.type을none으로 설정합니다. 그렇지 않으면 Elasticsearch가 클라이언트에게 각 요청과 함께 공유 비밀 값을 전송하도록 요구합니다.pkc_jwkset_path를 Teleport Proxy의 JWT 키 세트 파일 URL로 설정합니다. 이는https://<proxy>/.well-known/jwks.json엔드포인트에서 사용할 수 있습니다. URL 대신 동일한 URL에서 JSON 파일을 다운로드하여 파일 경로를 직접 지정할 수도 있습니다.claims.principal과claims.groups를 각각sub와roles로 설정합니다. 이는 Teleport가 JWT 토큰에서 사용자 및 역할 정보를 전달하는 데 사용하는 클레임입니다.allowed_issuer를 Teleport 클러스터의 이름으로 설정합니다.allowed_audiences를 Teleport Application Service가 Elasticsearch에 연결하는 데 사용할 URL로 설정합니다.
2/3단계. Teleport에 Elasticsearch 애플리케이션 등록#
Teleport Application Service 구성 파일 teleport.yaml에 Elasticsearch 항목을 등록합니다:
app_service:
enabled: true
apps:
- name: "elastic"
uri: https://elasticsearch.example.com:9200
rewrite:
headers:
- "Authorization: Bearer {{internal.jwt}}"
Elasticsearch는 JWT 토큰이 Authorization 헤더 내에 전달되어야 합니다. 위의 헤더 재작성 구성은 각 요청에서 {{internal.jwt}} 템플릿 변수를 Teleport 서명 JWT 토큰으로 대체합니다.
3/3단계. ElasticSearch API에 연결#
tsh login으로 Teleport 클러스터에 로그인하고 Elasticsearch 애플리케이션이 사용 가능한지 확인합니다:
$ tsh apps ls
Application Description Public Address Labels
----------- ------------- ---------------------------- -------------------------------
elastic elastic.teleport.example.com
Elasticsearch에 대한 단기 X.509 인증서를 가져옵니다:
$ tsh apps login elastic
그런 다음 curl 명령을 사용하여 Elasticsearch API와 통신할 수 있으며, Teleport 사용자로 인증됩니다:
$ curl \
--cacert ~/.tsh/keys/teleport.example.com/cas/root.pem \
--cert ~/.tsh/keys/teleport.example.com/alice-app/example-cluster/elastic-x509.pem \
--key ~/.tsh/keys/teleport.example.com/alice \
https://elastic.teleport.example.com/_security/_authenticate | jq
다음 단계#
- Teleport JWT 토큰 통합에 대한 자세한 정보를 얻으세요.
- 동적 등록 가이드를 참조하세요.
- Teleport Application Service로 API 접근에 대해 자세히 알아보세요.
- 애플리케이션 관련 접근 제어를 살펴보세요.
