Grafana에서 JWT 인증 사용하기
Teleport v18.9이 가이드에서는 JSON Web Token 인증을 사용하는 Teleport 보호 애플리케이션으로 Grafana를 등록합니다. Teleport는 단기 JWT를 발급하여 Grafana로 프록시되는 각 요청에 주입합니다. 실행 중인 Teleport 클러스터.
이 가이드에서는 JSON Web Token 인증을 사용하는 Teleport 보호 애플리케이션으로 Grafana를 등록합니다.
작동 방식#
Teleport는 단기 JWT를 발급하여 Grafana로 프록시되는 각 요청에 주입합니다. Grafana는 Teleport의 JWT 서명자를 신뢰하도록 구성되어 있어 사용자의 아이덴티티를 검증하고 Teleport가 서명한 토큰에서 역할 정보를 가져올 수 있습니다.
사전 요구사항#
-
실행 중인 Teleport 클러스터. Teleport를 시작하려면 무료 체험판에 가입하거나 데모 환경을 구성하세요.
-
tctlandtshclients.Installing `tctl` and `tsh` clients
-
Teleport 클러스터의 버전을 확인합니다.
tctlandtshclients는 Teleport 클러스터 버전보다 최대 한 개의 메이저 버전까지만 뒤처질 수 있습니다. Proxy Service의/v1/webapi/find로 GET 요청을 보내고 JSON 쿼리 도구를 사용하여 클러스터 버전을 확인합니다.teleport.example.com:443를 Teleport Proxy Service의 웹 주소로 바꿉니다:$ TELEPORT_DOMAIN=teleport.example.com:443 $ TELEPORT_VERSION="$(curl -s https://$TELEPORT_DOMAIN/v1/webapi/find | jq -r '.server_version')" -
사용 중인 플랫폼에 대한 지침에 따라
tctlandtshclients를 설치합니다:
-
Mac
`tctl` and `tsh` clients가 포함된, 서명된 Teleport macOS .pkg 설치 프로그램을 다운로드합니다:
```code
$ curl -O https://cdn.teleport.dev/teleport-${TELEPORT_VERSION?}.pkg
```
Finder에서 `pkg` 파일을 더블 클릭하여 설치를 시작합니다.
Homebrew를 사용하여 Teleport를 설치하는 것은 지원되지 않습니다. Homebrew의
Teleport 패키지는 Teleport에서 유지 관리하지 않으므로 신뢰성이나 보안을
보장할 수 없습니다.
Windows - Powershell
```code
$ curl.exe -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION?}-windows-amd64-bin.zip
# Unzip the archive and move the `tctl` and `tsh` clients to your %PATH%
# NOTE: Do not place the `tctl` and `tsh` clients in the System32 directory, as this can cause issues when using WinSCP.
# Use %SystemRoot% (C:\Windows) or %USERPROFILE% (C:\Users\<username>) instead.
```
Linux
Linux 설치판의 모든 Teleport 바이너리에는 `tctl` and `tsh` clients가 포함되어 있습니다. RPM/DEB
패키지 및 i386/ARM/ARM64용 다운로드를 포함한 더 많은 옵션은
[설치 페이지](../installation/installation.mdx)를 참조하세요.
```code
$ curl -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gz
$ tar -xzf teleport-v${TELEPORT_VERSION?}-linux-amd64-bin.tar.gz
$ cd teleport
$ sudo ./install
# Teleport binaries have been copied to /usr/local/bin
```
Teleport cluster에 연결할 수 있는지 확인하려면 tsh login으로 로그인한 다음,
현재 자격 증명으로 tctl 명령을 실행할 수 있는지 확인합니다.
예를 들어, teleport.example.com에 cluster 내 Teleport Proxy Service의
도메인 이름을, email@example.com에 Teleport 사용자 이름을 지정하여
다음 명령을 실행합니다:
$ tsh login --proxy=teleport.example.com --user=email@example.com
$ tctl status
# Cluster (=teleport.url=)
# Version (=teleport.version=)
# CA pin (=presets.ca_pin=)
cluster에 연결하여 tctl status 명령을 실행할 수 있다면, 현재 자격 증명을 사용하여
워크스테이션에서 이후의 tctl 명령을 실행할 수 있습니다.
자체 Teleport cluster를 호스팅하는 경우, 전체 권한을 얻기 위해 Teleport Auth Service를
호스팅하는 컴퓨터에서 tctl 명령을 실행할 수도 있습니다.
- 실행 중인 Application Service
- Grafana 인스턴스의 기본 구성에 대한 접근 권한
1/3단계. Grafana에서 JWT 인증 구성#
Grafana의 기본 구성 파일에 auth.jwt 섹션을 추가합니다. teleport.example.com를 Teleport 클러스터의 도메인 이름으로 교체하세요:
[auth.jwt]
enabled = true
# HTTP header to look into to get a JWT token.
header_name = Authorization
# JSON Web Key Set (JWKS) URL from your Teleport cluster.
jwk_set_url = https://teleport.example.com/.well-known/jwks.json
# Teleport username can be found in "sub" or "username" claims.
username_claim = sub
# Map Teleport users to Grafana organization roles based on their Teleport
# roles. Adjust accordingly.
#
# In this example, if the user's Teleport role list (the "roles" claim) contains
# "editor", assign them the Grafana "Editor" role. All other users get the
# "Viewer" role.
#
# Teleport user traits are also available in the "traits" claim and can be
# used in expressions in the same way as roles.
role_attribute_path = contains(roles[*], 'editor') && 'Editor' || 'Viewer'
# auto-create users if they are not already matched.
auto_sign_up = true
구성을 업데이트한 후 Grafana 인스턴스를 재시작하세요.
2/3단계. Teleport에 Grafana 애플리케이션 등록#
Teleport Application Service 구성에서 정의하거나, tctl 또는 Terraform을 사용한 동적 등록을
통해 Teleport에 Grafana 애플리케이션을 등록할 수 있습니다. http://grafana.example.com:3000을 Grafana 인스턴스의 도메인으로
지정합니다:
Teleport Application Service 구성 파일인 teleport.yaml에 애플리케이션 항목을 추가합니다:
app_service:
enabled: true
apps:
- name: "grafana"
uri: app URI
rewrite:
headers:
- "Authorization: Bearer {{internal.jwt}}"
Teleport Application Service를 재시작합니다.
app-grafana.yaml이라는 이름의 app 리소스 정의 파일을 만듭니다:
# app-grafana.yaml
kind: app
version: v3
metadata:
name: grafana
spec:
uri: app URI
rewrite:
headers:
- name: "Authorization"
value: "Bearer {{internal.jwt}}"
다음 명령으로 app 리소스를 생성합니다:
$ tctl create -f app-grafana.yaml
Terraform에서 teleport_app 리소스를 생성합니다:
resource "teleport_app" "grafana" {
version = "v3"
metadata = {
name = "grafana"
labels = {
"teleport.dev/origin" = "dynamic"
}
}
spec = {
uri = "app URI"
rewrite = {
headers = [{
name = "Authorization"
value = "Bearer {{internal.jwt}}"
}]
}
}
}
구성을 적용합니다:
$ terraform apply
위의 헤더 재작성 구성은 각 요청에서 {{internal.jwt}} 템플릿 변수를 Teleport가 서명한 JWT
토큰으로 대체합니다.
3/3단계. Grafana에 연결#
브라우저에서 https://teleport.example.com에 접속하여 Teleport 클러스터에 로그인합니다.
리소스 탭에서 grafana 애플리케이션을 찾아 실행을 클릭합니다.
Grafana가 열리고 Teleport 사용자로 자동 로그인됩니다. 오른쪽 상단 모서리에 있는 프로필 아이콘을 클릭하여 이를 확인할 수 있습니다.
다음 단계#
- Teleport JWT 토큰 통합에 대한 자세한 정보를 얻으세요.
- 동적 등록 가이드를 참조하세요.
- Teleport Application Service로 API 접근에 대해 자세히 알아보세요.
- 애플리케이션 관련 접근 제어를 살펴보세요.