InfoGrab Docs

Teleport 애플리케이션 액세스로 REST API 접근

요약

Teleport Application Service는 curl이나 Postman과 같은 도구를 사용하여 애플리케이션의 (REST 또는 Teleport 자체 gRPC) API에 접근하는 데 사용할 수 있습니다. 비-HTTP API(예: gRPC)에는 TCP 애플리케이션 액세스를 사용하세요.

Teleport Application Service는 curl이나 Postman과 같은 도구를 사용하여 애플리케이션의 (REST 또는 Teleport 자체 gRPC) API에 접근하는 데 사용할 수 있습니다.

비-HTTP API 지원

비-HTTP API(예: gRPC)에는 TCP 애플리케이션 액세스를 사용하세요.

사전 조건#

  • 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.

  • 간단한 설명을 위해 Docker 컨테이너에서 실행 중인 Grafana를 사용하고 API 쿼리를 실행합니다. 다음 단일 Docker 명령으로 Grafana를 실행할 수 있습니다:

    $ docker run -d -p 3000:3000 grafana/grafana
    

    Teleport App Service YAML 구성 파일에 다음 섹션을 추가하여 Grafana를 Teleport 클러스터에 연결합니다:

    app_service:
      enabled: true
      apps:
      - name: "grafana"
        description: "Test Grafana server"
        uri: "http://localhost:3000"
        labels:
          "env": "dev"
    

API 접근#

Teleport 클러스터에 로그인하고 사용 가능한 애플리케이션을 확인합니다:

$ tsh login --proxy=teleport.example.com
$ tsh apps ls

# Application Description         Public Address               Labels
# ----------- ------------------- ---------------------------- -------
# grafana     Test Grafana server grafana.teleport.example.com env=dev

애플리케이션에 대한 단기 X.509 인증서를 가져옵니다:

$ tsh apps login grafana
# Logged into app grafana. Example curl command:

$ curl \
  --cert /Users/alice/.tsh/keys/teleport.example.com/alice-app/cluster-name/grafana-x509.pem \
  --key /Users/alice/.tsh/keys/teleport.example.com/alice \
  https://grafana.teleport.example.com:3080

로그인 메시지에는 Teleport App Access를 통해 대상 애플리케이션의 API를 호출하기 위해 실행할 수 있는 curl 명령 예시가 표시됩니다.

CA 및 키 쌍 파일

명령에서 사용자의 인증서/키 쌍 경로를 참고하세요 - curl은 클라이언트 인증서를 사용하여 Teleport와 인증합니다.

Teleport Proxy Service는 일반적으로 Let's Encrypt와 같은 공개 인증 기관에서 발급한 와일드카드 인증서로 구성됩니다. 자체 호스팅 Teleport 클러스터를 실행 중이고 Teleport Proxy Service가 자체 서명 인증서를 사용하도록 구성된 경우, --cacert <path>를 사용하여 curl 명령에 포함해야 합니다.

Grafana의 API는 인증이 필요하므로 기본 Grafana 사용자 이름/비밀번호를 사용한 기본 인증 정보를 제공하고 /api/users 엔드포인트를 호출하도록 curl 명령을 업데이트합니다:

$ curl --user admin:admin \
  --cert /Users/alice/.tsh/keys/teleport.example.com/alice-app/cluster-name/grafana-x509.pem \
  --key /Users/alice/.tsh/keys/teleport.example.com/alice \
    https://grafana.teleport.example.com:3080/api/users

# [{"id":1,"name":"","login":"admin","email":"admin@localhost","avatarUrl":"/avatar/46d229b033af06a191ff2267bca9ae56","isAdmin":true,"isDisabled":false,"lastSeenAt":"2021-03-18T17:25:59Z","lastSeenAtAge":"\u003c 1m","authLabels":[]}]

앱의 X.509 인증서는 사용자 역할에서 허용하는 TTL이 지나면 자동으로 만료됩니다. 명시적으로 제거할 수도 있습니다:

$ tsh apps logout
# Logged out of app "grafana"

애플리케이션 정보#

$ tsh apps config

현재 앱 URI와 비밀의 경로를 표시합니다.

이는 CLI 도구(예: curl) 또는 GUI 도구(예: Postman)를 구성할 때 유용합니다.

앱 정보를 테이블 형식으로 출력합니다:

$ tsh apps config

# Name:      grafana
# URI:       https://grafana.teleport.example.com:3080
# CA:        /Users/alice/.tsh/keys/teleport.example.com/certs.pem
# Cert:      /Users/alice/.tsh/keys/teleport.example.com/alice-app/cluster-name/grafana-x509.pem
# Key:       /Users/alice/.tsh/keys/teleport.example.com/alice

다른 --format 값을 제공하여 앱 구성의 특정 부분을 출력할 수도 있습니다:

$ tsh apps config --format=uri
# https://grafana-root.gravitational.io:3080

$ tsh apps config --format=ca
# /Users/alice/.tsh/keys/teleport.example.com/certs.pem

$ tsh apps config --format=cert
# /Users/alice/.tsh/keys/teleport.example.com/alice-app/cluster-name/grafana-x509.pem

$ tsh apps config --format=key
# /Users/alice/.tsh/keys/teleport.example.com/alice

이는 자동화에서 적절한 curl 명령을 구성하기 위한 간단한 템플릿 작성에 유용할 수 있습니다. 위의 Grafana /api/users 예시를 사용하여:

$ curl --user admin:admin \
  --cert $(tsh apps config --format=cert) \
  --key $(tsh apps config --format=key) \
    $(tsh apps config --format=uri)/api/users

Teleport 애플리케이션 액세스로 REST API 접근

원문 보기
요약

Teleport Application Service는 curl이나 Postman과 같은 도구를 사용하여 애플리케이션의 (REST 또는 Teleport 자체 gRPC) API에 접근하는 데 사용할 수 있습니다. 비-HTTP API(예: gRPC)에는 TCP 애플리케이션 액세스를 사용하세요.

Teleport Application Service는 curl이나 Postman과 같은 도구를 사용하여 애플리케이션의 (REST 또는 Teleport 자체 gRPC) API에 접근하는 데 사용할 수 있습니다.

비-HTTP API 지원

비-HTTP API(예: gRPC)에는 TCP 애플리케이션 액세스를 사용하세요.

사전 조건#

  • 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.

  • 간단한 설명을 위해 Docker 컨테이너에서 실행 중인 Grafana를 사용하고 API 쿼리를 실행합니다. 다음 단일 Docker 명령으로 Grafana를 실행할 수 있습니다:

    $ docker run -d -p 3000:3000 grafana/grafana
    

    Teleport App Service YAML 구성 파일에 다음 섹션을 추가하여 Grafana를 Teleport 클러스터에 연결합니다:

    app_service:
      enabled: true
      apps:
      - name: "grafana"
        description: "Test Grafana server"
        uri: "http://localhost:3000"
        labels:
          "env": "dev"
    

API 접근#

Teleport 클러스터에 로그인하고 사용 가능한 애플리케이션을 확인합니다:

$ tsh login --proxy=teleport.example.com
$ tsh apps ls

# Application Description         Public Address               Labels
# ----------- ------------------- ---------------------------- -------
# grafana     Test Grafana server grafana.teleport.example.com env=dev

애플리케이션에 대한 단기 X.509 인증서를 가져옵니다:

$ tsh apps login grafana
# Logged into app grafana. Example curl command:

$ curl \
  --cert /Users/alice/.tsh/keys/teleport.example.com/alice-app/cluster-name/grafana-x509.pem \
  --key /Users/alice/.tsh/keys/teleport.example.com/alice \
  https://grafana.teleport.example.com:3080

로그인 메시지에는 Teleport App Access를 통해 대상 애플리케이션의 API를 호출하기 위해 실행할 수 있는 curl 명령 예시가 표시됩니다.

CA 및 키 쌍 파일

명령에서 사용자의 인증서/키 쌍 경로를 참고하세요 - curl은 클라이언트 인증서를 사용하여 Teleport와 인증합니다.

Teleport Proxy Service는 일반적으로 Let's Encrypt와 같은 공개 인증 기관에서 발급한 와일드카드 인증서로 구성됩니다. 자체 호스팅 Teleport 클러스터를 실행 중이고 Teleport Proxy Service가 자체 서명 인증서를 사용하도록 구성된 경우, --cacert <path>를 사용하여 curl 명령에 포함해야 합니다.

Grafana의 API는 인증이 필요하므로 기본 Grafana 사용자 이름/비밀번호를 사용한 기본 인증 정보를 제공하고 /api/users 엔드포인트를 호출하도록 curl 명령을 업데이트합니다:

$ curl --user admin:admin \
  --cert /Users/alice/.tsh/keys/teleport.example.com/alice-app/cluster-name/grafana-x509.pem \
  --key /Users/alice/.tsh/keys/teleport.example.com/alice \
    https://grafana.teleport.example.com:3080/api/users

# [{"id":1,"name":"","login":"admin","email":"admin@localhost","avatarUrl":"/avatar/46d229b033af06a191ff2267bca9ae56","isAdmin":true,"isDisabled":false,"lastSeenAt":"2021-03-18T17:25:59Z","lastSeenAtAge":"\u003c 1m","authLabels":[]}]

앱의 X.509 인증서는 사용자 역할에서 허용하는 TTL이 지나면 자동으로 만료됩니다. 명시적으로 제거할 수도 있습니다:

$ tsh apps logout
# Logged out of app "grafana"

애플리케이션 정보#

$ tsh apps config

현재 앱 URI와 비밀의 경로를 표시합니다.

이는 CLI 도구(예: curl) 또는 GUI 도구(예: Postman)를 구성할 때 유용합니다.

앱 정보를 테이블 형식으로 출력합니다:

$ tsh apps config

# Name:      grafana
# URI:       https://grafana.teleport.example.com:3080
# CA:        /Users/alice/.tsh/keys/teleport.example.com/certs.pem
# Cert:      /Users/alice/.tsh/keys/teleport.example.com/alice-app/cluster-name/grafana-x509.pem
# Key:       /Users/alice/.tsh/keys/teleport.example.com/alice

다른 --format 값을 제공하여 앱 구성의 특정 부분을 출력할 수도 있습니다:

$ tsh apps config --format=uri
# https://grafana-root.gravitational.io:3080

$ tsh apps config --format=ca
# /Users/alice/.tsh/keys/teleport.example.com/certs.pem

$ tsh apps config --format=cert
# /Users/alice/.tsh/keys/teleport.example.com/alice-app/cluster-name/grafana-x509.pem

$ tsh apps config --format=key
# /Users/alice/.tsh/keys/teleport.example.com/alice

이는 자동화에서 적절한 curl 명령을 구성하기 위한 간단한 템플릿 작성에 유용할 수 있습니다. 위의 Grafana /api/users 예시를 사용하여:

$ curl --user admin:admin \
  --cert $(tsh apps config --format=cert) \
  --key $(tsh apps config --format=key) \
    $(tsh apps config --format=uri)/api/users