InfoGrab Docs

Grafana에서 JWT 인증 사용하기

요약

이 가이드는 Teleport와 함께 Grafana JWT 인증을 구성하는 방법을 설명합니다. Teleport는 단기 JWT를 발급하고 Grafana로 프록시된 각 요청에 이를 주입합니다. A running Teleport cluster.

이 가이드는 Teleport와 함께 Grafana JWT 인증을 구성하는 방법을 설명합니다.

작동 방식#

Teleport는 단기 JWT를 발급하고 Grafana로 프록시된 각 요청에 이를 주입합니다. Grafana는 Teleport의 JWT 서명자를 신뢰하도록 구성되어 사용자의 ID를 확인하고 Teleport 서명 토큰에서 역할 정보를 가져올 수 있습니다.

사전 조건#

  • 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 tctl and tsh clients.

    Installing `tctl` and `tsh` clients
    1. Determine the version of your Teleport cluster. The tctl and tsh clients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at /v1/webapi/find and 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')"
      
    2. Follow the instructions for your platform to install tctl and tsh clients:

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 실행 중.
  • Grafana 인스턴스의 기본 구성에 대한 접근 권한

1/3단계. Grafana에서 JWT 인증 구성#

Add an auth.jwt section in Grafana’s main configuration file. Replace with the domain name of your Teleport cluster:

[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

Restart your Grafana instance after updating the config.

2/3단계. Teleport에 Grafana 애플리케이션 등록#

Teleport Application Service 구성에서 정의하거나, tctl 또는 Terraform을 사용한 동적 등록을 통해 Teleport에 Grafana 애플리케이션을 등록할 수 있습니다. 을 Grafana 인스턴스의 도메인으로 설정합니다:

Teleport Application Service 구성 파일 teleport.yaml에 애플리케이션 항목을 추가합니다:

app_service:
  enabled: true
  apps:
  - name: "grafana"
    uri:  name="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:  name="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 = ""
    rewrite = {
      headers = [{
        name  = "Authorization"
        value = "Bearer {{internal.jwt}}"
      }]
    }
  }
}

구성을 적용합니다:

$ terraform apply

위의 헤더 재작성 구성은 각 요청에서 {{internal.jwt}} 템플릿 변수를 Teleport 서명 JWT 토큰으로 대체합니다.

3/3단계. Grafana에 연결#

https://에서 브라우저로 Teleport 클러스터에 로그인합니다.

리소스 탭에서 grafana 애플리케이션을 찾아 실행을 클릭합니다.

Grafana가 열리고 Teleport 사용자로 자동 로그인됩니다. 오른쪽 상단 모서리에 있는 프로필 아이콘을 클릭하여 이를 확인할 수 있습니다.

다음 단계#

Grafana에서 JWT 인증 사용하기

원문 보기
요약

이 가이드는 Teleport와 함께 Grafana JWT 인증을 구성하는 방법을 설명합니다. Teleport는 단기 JWT를 발급하고 Grafana로 프록시된 각 요청에 이를 주입합니다. A running Teleport cluster.

이 가이드는 Teleport와 함께 Grafana JWT 인증을 구성하는 방법을 설명합니다.

작동 방식#

Teleport는 단기 JWT를 발급하고 Grafana로 프록시된 각 요청에 이를 주입합니다. Grafana는 Teleport의 JWT 서명자를 신뢰하도록 구성되어 사용자의 ID를 확인하고 Teleport 서명 토큰에서 역할 정보를 가져올 수 있습니다.

사전 조건#

  • 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 tctl and tsh clients.

    Installing `tctl` and `tsh` clients
    1. Determine the version of your Teleport cluster. The tctl and tsh clients must be at most one major version behind your Teleport cluster version. Send a GET request to the Proxy Service at /v1/webapi/find and 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')"
      
    2. Follow the instructions for your platform to install tctl and tsh clients:

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 실행 중.
  • Grafana 인스턴스의 기본 구성에 대한 접근 권한

1/3단계. Grafana에서 JWT 인증 구성#

Add an auth.jwt section in Grafana’s main configuration file. Replace with the domain name of your Teleport cluster:

[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

Restart your Grafana instance after updating the config.

2/3단계. Teleport에 Grafana 애플리케이션 등록#

Teleport Application Service 구성에서 정의하거나, tctl 또는 Terraform을 사용한 동적 등록을 통해 Teleport에 Grafana 애플리케이션을 등록할 수 있습니다. 을 Grafana 인스턴스의 도메인으로 설정합니다:

Teleport Application Service 구성 파일 teleport.yaml에 애플리케이션 항목을 추가합니다:

app_service:
  enabled: true
  apps:
  - name: "grafana"
    uri:  name="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:  name="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 = ""
    rewrite = {
      headers = [{
        name  = "Authorization"
        value = "Bearer {{internal.jwt}}"
      }]
    }
  }
}

구성을 적용합니다:

$ terraform apply

위의 헤더 재작성 구성은 각 요청에서 {{internal.jwt}} 템플릿 변수를 Teleport 서명 JWT 토큰으로 대체합니다.

3/3단계. Grafana에 연결#

https://에서 브라우저로 Teleport 클러스터에 로그인합니다.

리소스 탭에서 grafana 애플리케이션을 찾아 실행을 클릭합니다.

Grafana가 열리고 Teleport 사용자로 자동 로그인됩니다. 오른쪽 상단 모서리에 있는 프로필 아이콘을 클릭하여 이를 확인할 수 있습니다.

다음 단계#