InfoGrab DocsInfoGrab Docs

GitLab CI에 tbot 배포

요약

이 가이드에서는 Teleport 머신 및 워크로드 아이덴티티를 사용하여 GitLab 파이프라인이 장기 시크릿 없이 Teleport SSH 노드에 안전하게 연결할 수 있도록 합니다. GitLab용 머신 및 워크로드 아이덴티티는 GitLab의 클라우드 호스팅 옵션과 자체 호스팅 GitLab 설치와 함께 작동합니다.

이 가이드에서는 Teleport 머신 및 워크로드 아이덴티티를 사용하여 GitLab 파이프라인이 장기 시크릿 없이 Teleport SSH 노드에 안전하게 연결할 수 있도록 합니다.

GitLab용 머신 및 워크로드 아이덴티티는 GitLab의 클라우드 호스팅 옵션과 자체 호스팅 GitLab 설치와 함께 작동합니다. 최소 지원 GitLab 버전은 15.7입니다.

이는 GitLab 조직에서 비밀번호 또는 SSH 개인 키와 같은 장기 시크릿이 유출되는 위험을 완화하고 감사 및 세밀한 접근 제어와 같은 Teleport의 여러 다른 이점을 제공합니다.

사전 요구사항#

  • 실행 중인 Teleport 클러스터. Teleport를 시작하려면 무료 체험판에 가입하거나 데모 환경을 구성하세요.

  • tctl and tsh clients.

    Installing `tctl` and `tsh` clients
    1. Teleport 클러스터의 버전을 확인합니다. tctl and tsh clients는 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')"
      
    2. 사용 중인 플랫폼에 대한 지침에 따라 tctl and tsh clients를 설치합니다:

Mac

     `tctl` and `tsh` clients가 포함된, 서명된 Teleport macOS .pkg 설치 프로그램을 다운로드합니다:
 
     ```code
     $ curl -O https://cdn.teleport.dev/teleport-${TELEPORT_VERSION?}.pkg
     ```

     Finder에서 `pkg` 파일을 더블 클릭하여 설치를 시작합니다.
 
     
Warning
       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 명령을 실행할 수도 있습니다.

  • Teleport에 연결할 GitLab 프로젝트. GitLab의 클라우드 호스팅 서비스(gitlab.com) 또는 자체 호스팅 GitLab 인스턴스에 있을 수 있습니다. 자체 호스팅 GitLab 인스턴스를 사용하는 경우 Teleport Auth Service가 GitLab 인스턴스에 연결할 수 있어야 하고 GitLab 인스턴스에 유효한 TLS 인증서가 설정되어 있어야 합니다.

1단계/3단계. 봇 만들기#

다음으로 Bot을 생성해야 합니다. Bot은 머신 또는 머신 그룹을 위한 Teleport identity입니다. 사용자와 마찬가지로 bot에는 무엇에 액세스할 수 있는지 정의하는 role 및 trait 집합이 있습니다.

bot.yaml을 생성합니다:

kind: bot
version: v1
metadata:
  # name is a unique identifier for the Bot in the cluster.
  name: example
spec:
  # roles is a list of roles to grant to the Bot. Don't worry if you don't know
  # what roles you need to specify here, the Access Guides will walk you through
  # creating and assigning roles to the already created Bot.
  roles: []

example을 Bot에 대한 고유하고 설명적인 이름으로 반드시 교체하십시오.

tctl을 사용하여 이 파일을 적용합니다:

$ tctl create bot.yaml

2단계/3단계. 조인 토큰 만들기#

GitLab CI가 Teleport 클러스터에 인증할 수 있도록 하려면 먼저 조인 토큰을 만들어야 합니다. GitLab 조인 토큰에는 Teleport 클러스터에 조인하기 위해 해당 토큰을 사용할 수 있는 파이프라인을 설명하는 허용 규칙이 포함됩니다. 규칙에는 여러 필드가 포함될 수 있으며, 단일 규칙 내의 모든 필드와 일치하는 모든 파이프라인에 접근이 허용됩니다.

이 예시에서는 특정 GitLab 프로젝트 내의 모든 GitLab CI 작업에 접근을 허용하는 규칙이 있는 토큰을 만듭니다. GitLab 프로젝트의 정규화된 경로를 확인합니다. 여기에는 사용자명(또는 그룹)과 프로젝트 이름이 포함됩니다(예: my-user/my-project).

bot-token.yaml 파일을 만듭니다. 이 예시의 주석에서 제안한 대로 모든 값을 교체합니다:

kind: token
version: v2
metadata:
  name: example-bot
spec:
  # The Bot role indicates that this token grants access to a bot user, rather
  # than allowing a node to join. This role is built in to Teleport.
  roles: [Bot]
  join_method: gitlab
  # The bot_name indicates which bot user this token grants access to. This
  # should match the name of the bot that you created in step 1.
  bot_name: example
  gitlab:
    # domain should be the domain of your GitLab instance. If you are using
    # GitLab's cloud hosted offering, omit this field entirely.
    domain: gitlab.example.com
    # allow specifies rules that control which GitLab tokens will be accepted
    # by Teleport. Tokens not matching any allow rule will be denied.
    allow:
        # project_path should be the fully qualified path of your GitLab
        # project that you determined earlier. This will grant access to any
        # GitLab CI run in that project.
      - project_path: my-user/my-project

GitLab 조인에 대한 토큰 설정 옵션 전체 목록은 조인 토큰 레퍼런스 페이지에서 확인할 수 있습니다.

tctl을 사용하여 이것을 Teleport 클러스터에 적용합니다:

$ tctl create -f bot-token.yaml

3단계/3단계. GitLab 파이프라인 설정#

봇과 조인 토큰이 만들어지면 이를 사용하도록 tbot을 설정하는 GitLab 파이프라인을 이제 설정할 수 있습니다.

tbot을 설정하기 위해 YAML 파일이 사용됩니다. 이 예시에서는 저장소 자체 내에 이 파일을 저장하지만, CI 파이프라인 자체에서 생성하거나 만들 수도 있습니다.

저장소 내에 tbot.yaml을 만듭니다:

version: v2
proxy_server: example.teleport.sh:443
onboarding:
  join_method: gitlab
  token: example-bot
oneshot: true
storage:
  type: memory
# services will be filled in during the completion of an access guide.
services: []

교체:

  • example.teleport.sh를 Teleport Proxy 또는 Auth Service의 주소로 교체합니다. Teleport Proxy의 주소를 사용하는 것이 좋습니다.
  • example-bot을 두 번째 단계에서 만든 토큰의 이름으로 교체합니다.

이제 GitLab CI 파이프라인을 정의할 수 있습니다. 파이프라인이 tbot을 사용하기 전에 환경 내에서 tbot을 사용할 수 있어야 합니다. 이 예시에서는 CI 단계의 일부로 tbot을 다운로드하는 방법을 보여주지만, 프로덕션 구현에서는 Teleport CDN에 의존하지 않도록 이 바이너리를 포함하는 docker 이미지를 구축하는 것이 좋습니다.

저장소 내에 .gitlab-ci.yml을 만듭니다:

stages:
  - deploy

deploy-job:
  stage: deploy
  # id_tokens configures ID Tokens that GitLab will automatically inject into
  # the environment of your GitLab run.
  #
  # See https://docs.gitlab.com/ee/ci/secrets/id_token_authentication.html
  # for further explanation of the id_tokens configuration in GitLab.
  id_tokens:
    TBOT_GITLAB_JWT:
      # aud for TBOT_GITLAB_JWT must be configured with the name of your
      # Teleport cluster. This is not necessarily the address of your Teleport
      # cluster and will not include a port or scheme (http/https)
      #
      # This helps the Teleport Auth Service know that the token is intended for
      # it, and not a different service or Teleport cluster.
      aud: example.teleport.sh
  script:
    - curl "https://example.teleport.sh:443/scripts/install.sh" | bash
    - 'TELEPORT_ANONYMOUS_TELEMETRY=1 tbot start -c tbot.yaml'

교체:

  • audexample.teleport.sh를 Teleport 클러스터의 이름으로 교체합니다. 이는 Teleport 클러스터의 주소일 필요는 없으며 포트나 스킴(예: http/https)을 포함하지 않습니다.
  • example.teleport.sh를 Teleport Proxy Service의 주소로 교체합니다.

TELEPORT_ANONYMOUS_TELEMETRY는 익명 사용 텔레메트리 제출을 활성화합니다. 이는 tbot의 향후 개발 방향을 정하는 데 도움이 됩니다. 이 값을 생략하면 이 기능을 비활성화할 수 있습니다.

이 두 파일을 저장소에 커밋하고 푸시합니다.

GitLab CI 상태를 확인하고, 커밋의 로그 결과에서 실패가 없는지 검사합니다.

추가 단계#

이제 tbot의 기본 설정을 준비했습니다. 이 시점에서 tbot은 Teleport 클러스터에 자신을 식별시키고 자체 자격 증명을 갱신하지만, 다른 애플리케이션이 사용할 수 있는 자격 증명은 출력하지 않습니다.

GitLab CI에 tbot 배포

Teleport v18.9
원문 보기
요약

이 가이드에서는 Teleport 머신 및 워크로드 아이덴티티를 사용하여 GitLab 파이프라인이 장기 시크릿 없이 Teleport SSH 노드에 안전하게 연결할 수 있도록 합니다. GitLab용 머신 및 워크로드 아이덴티티는 GitLab의 클라우드 호스팅 옵션과 자체 호스팅 GitLab 설치와 함께 작동합니다.

이 가이드에서는 Teleport 머신 및 워크로드 아이덴티티를 사용하여 GitLab 파이프라인이 장기 시크릿 없이 Teleport SSH 노드에 안전하게 연결할 수 있도록 합니다.

GitLab용 머신 및 워크로드 아이덴티티는 GitLab의 클라우드 호스팅 옵션과 자체 호스팅 GitLab 설치와 함께 작동합니다. 최소 지원 GitLab 버전은 15.7입니다.

이는 GitLab 조직에서 비밀번호 또는 SSH 개인 키와 같은 장기 시크릿이 유출되는 위험을 완화하고 감사 및 세밀한 접근 제어와 같은 Teleport의 여러 다른 이점을 제공합니다.

사전 요구사항#

  • 실행 중인 Teleport 클러스터. Teleport를 시작하려면 무료 체험판에 가입하거나 데모 환경을 구성하세요.

  • tctl and tsh clients.

    Installing `tctl` and `tsh` clients
    1. Teleport 클러스터의 버전을 확인합니다. tctl and tsh clients는 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')"
      
    2. 사용 중인 플랫폼에 대한 지침에 따라 tctl and tsh clients를 설치합니다:

Mac

     `tctl` and `tsh` clients가 포함된, 서명된 Teleport macOS .pkg 설치 프로그램을 다운로드합니다:
 
     ```code
     $ curl -O https://cdn.teleport.dev/teleport-${TELEPORT_VERSION?}.pkg
     ```

     Finder에서 `pkg` 파일을 더블 클릭하여 설치를 시작합니다.
 
     
Warning
       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 명령을 실행할 수도 있습니다.

  • Teleport에 연결할 GitLab 프로젝트. GitLab의 클라우드 호스팅 서비스(gitlab.com) 또는 자체 호스팅 GitLab 인스턴스에 있을 수 있습니다. 자체 호스팅 GitLab 인스턴스를 사용하는 경우 Teleport Auth Service가 GitLab 인스턴스에 연결할 수 있어야 하고 GitLab 인스턴스에 유효한 TLS 인증서가 설정되어 있어야 합니다.

1단계/3단계. 봇 만들기#

다음으로 Bot을 생성해야 합니다. Bot은 머신 또는 머신 그룹을 위한 Teleport identity입니다. 사용자와 마찬가지로 bot에는 무엇에 액세스할 수 있는지 정의하는 role 및 trait 집합이 있습니다.

bot.yaml을 생성합니다:

kind: bot
version: v1
metadata:
  # name is a unique identifier for the Bot in the cluster.
  name: example
spec:
  # roles is a list of roles to grant to the Bot. Don't worry if you don't know
  # what roles you need to specify here, the Access Guides will walk you through
  # creating and assigning roles to the already created Bot.
  roles: []

example을 Bot에 대한 고유하고 설명적인 이름으로 반드시 교체하십시오.

tctl을 사용하여 이 파일을 적용합니다:

$ tctl create bot.yaml

2단계/3단계. 조인 토큰 만들기#

GitLab CI가 Teleport 클러스터에 인증할 수 있도록 하려면 먼저 조인 토큰을 만들어야 합니다. GitLab 조인 토큰에는 Teleport 클러스터에 조인하기 위해 해당 토큰을 사용할 수 있는 파이프라인을 설명하는 허용 규칙이 포함됩니다. 규칙에는 여러 필드가 포함될 수 있으며, 단일 규칙 내의 모든 필드와 일치하는 모든 파이프라인에 접근이 허용됩니다.

이 예시에서는 특정 GitLab 프로젝트 내의 모든 GitLab CI 작업에 접근을 허용하는 규칙이 있는 토큰을 만듭니다. GitLab 프로젝트의 정규화된 경로를 확인합니다. 여기에는 사용자명(또는 그룹)과 프로젝트 이름이 포함됩니다(예: my-user/my-project).

bot-token.yaml 파일을 만듭니다. 이 예시의 주석에서 제안한 대로 모든 값을 교체합니다:

kind: token
version: v2
metadata:
  name: example-bot
spec:
  # The Bot role indicates that this token grants access to a bot user, rather
  # than allowing a node to join. This role is built in to Teleport.
  roles: [Bot]
  join_method: gitlab
  # The bot_name indicates which bot user this token grants access to. This
  # should match the name of the bot that you created in step 1.
  bot_name: example
  gitlab:
    # domain should be the domain of your GitLab instance. If you are using
    # GitLab's cloud hosted offering, omit this field entirely.
    domain: gitlab.example.com
    # allow specifies rules that control which GitLab tokens will be accepted
    # by Teleport. Tokens not matching any allow rule will be denied.
    allow:
        # project_path should be the fully qualified path of your GitLab
        # project that you determined earlier. This will grant access to any
        # GitLab CI run in that project.
      - project_path: my-user/my-project

GitLab 조인에 대한 토큰 설정 옵션 전체 목록은 조인 토큰 레퍼런스 페이지에서 확인할 수 있습니다.

tctl을 사용하여 이것을 Teleport 클러스터에 적용합니다:

$ tctl create -f bot-token.yaml

3단계/3단계. GitLab 파이프라인 설정#

봇과 조인 토큰이 만들어지면 이를 사용하도록 tbot을 설정하는 GitLab 파이프라인을 이제 설정할 수 있습니다.

tbot을 설정하기 위해 YAML 파일이 사용됩니다. 이 예시에서는 저장소 자체 내에 이 파일을 저장하지만, CI 파이프라인 자체에서 생성하거나 만들 수도 있습니다.

저장소 내에 tbot.yaml을 만듭니다:

version: v2
proxy_server: example.teleport.sh:443
onboarding:
  join_method: gitlab
  token: example-bot
oneshot: true
storage:
  type: memory
# services will be filled in during the completion of an access guide.
services: []

교체:

  • example.teleport.sh를 Teleport Proxy 또는 Auth Service의 주소로 교체합니다. Teleport Proxy의 주소를 사용하는 것이 좋습니다.
  • example-bot을 두 번째 단계에서 만든 토큰의 이름으로 교체합니다.

이제 GitLab CI 파이프라인을 정의할 수 있습니다. 파이프라인이 tbot을 사용하기 전에 환경 내에서 tbot을 사용할 수 있어야 합니다. 이 예시에서는 CI 단계의 일부로 tbot을 다운로드하는 방법을 보여주지만, 프로덕션 구현에서는 Teleport CDN에 의존하지 않도록 이 바이너리를 포함하는 docker 이미지를 구축하는 것이 좋습니다.

저장소 내에 .gitlab-ci.yml을 만듭니다:

stages:
  - deploy

deploy-job:
  stage: deploy
  # id_tokens configures ID Tokens that GitLab will automatically inject into
  # the environment of your GitLab run.
  #
  # See https://docs.gitlab.com/ee/ci/secrets/id_token_authentication.html
  # for further explanation of the id_tokens configuration in GitLab.
  id_tokens:
    TBOT_GITLAB_JWT:
      # aud for TBOT_GITLAB_JWT must be configured with the name of your
      # Teleport cluster. This is not necessarily the address of your Teleport
      # cluster and will not include a port or scheme (http/https)
      #
      # This helps the Teleport Auth Service know that the token is intended for
      # it, and not a different service or Teleport cluster.
      aud: example.teleport.sh
  script:
    - curl "https://example.teleport.sh:443/scripts/install.sh" | bash
    - 'TELEPORT_ANONYMOUS_TELEMETRY=1 tbot start -c tbot.yaml'

교체:

  • audexample.teleport.sh를 Teleport 클러스터의 이름으로 교체합니다. 이는 Teleport 클러스터의 주소일 필요는 없으며 포트나 스킴(예: http/https)을 포함하지 않습니다.
  • example.teleport.sh를 Teleport Proxy Service의 주소로 교체합니다.

TELEPORT_ANONYMOUS_TELEMETRY는 익명 사용 텔레메트리 제출을 활성화합니다. 이는 tbot의 향후 개발 방향을 정하는 데 도움이 됩니다. 이 값을 생략하면 이 기능을 비활성화할 수 있습니다.

이 두 파일을 저장소에 커밋하고 푸시합니다.

GitLab CI 상태를 확인하고, 커밋의 로그 결과에서 실패가 없는지 검사합니다.

추가 단계#

이제 tbot의 기본 설정을 준비했습니다. 이 시점에서 tbot은 Teleport 클러스터에 자신을 식별시키고 자체 자격 증명을 갱신하지만, 다른 애플리케이션이 사용할 수 있는 자격 증명은 출력하지 않습니다.