Bitbucket Pipelines에 tbot 배포
이 가이드에서는 Bitbucket Pipelines 워크플로 내에서 머신 및 워크로드 아이덴티티의 에이전트 tbot을 실행하도록 설정합니다. bitbucket 조인 방법은 공유 시크릿을 사용하지 않고 머신 및 워크로드 아이덴티티 봇이 Teleport Auth Service에 인증할 수 있는 안전한 방법입니다.
이 가이드에서는 Bitbucket Pipelines 워크플로 내에서 머신 및 워크로드 아이덴티티의 에이전트 tbot을 실행하도록 설정합니다. 봇은 장기 시크릿의 필요성을 제거하기 위해 bitbucket 위임 조인 방법을 사용하도록 설정됩니다.
작동 방식#
bitbucket 조인 방법은 공유 시크릿을 사용하지 않고 머신 및 워크로드 아이덴티티 봇이 Teleport Auth Service에 인증할 수 있는 안전한 방법입니다. 대신 Bitbucket Pipelines이 작업 환경에 주입하는 OpenID Connect 토큰을 사용합니다.
이 토큰은 Teleport Auth Service로 전송되며, Bitbucket의 아이덴티티 공급자를 신뢰하도록 설정되어 있고 모든 아이덴티티 어설션이 일치하면 인증 시도가 성공합니다.
사전 조건#
-
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.
- 푸시할 수 있는 Bitbucket 저장소.
1단계/4단계. Bitbucket 설정 확인#
Bitbucket 조인에는 저장소 설정에서 찾을 수 있는 여러 설정 파라미터가 필요합니다. Bitbucket 저장소에서 "Repository settings"로 이동한 후 사이드바의 "Pipelines" 아래에서 "OpenID Connect"를 선택합니다.
이 페이지에서 다음 값을 기록합니다:
- 아이덴티티 공급자 URL ()
- Audience ()
- 중괄호를 포함한 Workspace UUID ()
- 중괄호를 포함한 Repository UUID ()
2단계/4단계. 봇 만들기#
Next, you need to create a Bot. A Bot is a Teleport identity for a machine or group of machines. Like users, bots have a set of roles and traits which define what they can access.
Create 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: []
Make sure you replace example with a unique, descriptive name for your Bot.
Use tctl to apply this file:
$ tctl create bot.yaml
3단계/4단계. Bitbucket Pipelines용 조인 토큰 만들기#
Pipelines 워크플로가 Teleport 클러스터에 인증할 수 있도록 하려면 먼저 조인 토큰을 만들어야 합니다. 이 토큰은 Auth Service가 봇 또는 노드의 조인을 허용할지 여부를 결정하는 기준을 설정합니다.
bot-token.yaml 파일을 만들고 identity_provider_url, audience, workspace_uuid, repository_uuid를 1단계의 값으로 교체합니다.
kind: token
version: v2
metadata:
name: example-bot
spec:
roles: [Bot]
join_method: bitbucket
bot_name: example
bitbucket:
identity_provider_url: name="identity-provider-url" />
audience: name="audience" />
# allow는 Auth Service가 `tbot`의 조인 허용 여부를 결정하는 규칙을 지정합니다.
allow:
- workspace_uuid: ''
repository_uuid: ''
토큰 리소스의 필드를 자세히 살펴봅니다:
metadata.name은 토큰의 이름을 정의합니다. 이 값은 나중에 설정의 다른 부분에서 사용해야 합니다.spec.bot_name은 이 토큰이 접근을 허용할 Machine ID 봇의 이름입니다. 이 값은 나중에 설정의 다른 부분에서 사용해야 합니다.spec.roles는 이 토큰이 접근을 허용할 역할을 정의합니다.[Bot]값은 이 토큰이 머신 및 워크로드 아이덴티티 봇에 대한 접근을 허용함을 나타냅니다.spec.join_method는 토큰이 적용 가능한 조인 방법을 정의합니다. 이 가이드는 Bitbucket Pipelines에만 초점을 맞추므로bitbucket으로 설정합니다.spec.bitbucket.identity_provider_url은 Pipelines 및 OpenID Connect 아래 Bitbucket 저장소 설정에 표시되는 아이덴티티 공급자 URL입니다.spec.bitbucket.audience는 Pipelines 및 OpenID Connect 아래 Bitbucket 저장소 설정에 표시되는 audience 값입니다.spec.bitbucket.allow는 토큰을 사용하여 인증할 수 있는 Bitbucket Pipelines 실행에 대한 규칙을 설정하는 데 사용됩니다.
유효한 필드의 전체 목록은 토큰 레퍼런스를 참조하세요.
tctl을 사용하여 이 파일을 Teleport 클러스터에 적용합니다:
$ tctl create -f bot-token.yaml
4단계/4단계. Bitbucket Pipelines 워크플로 설정#
봇과 조인 토큰이 만들어지면 Teleport에 인증할 수 있는 워크플로를 설정할 수 있습니다.
이 예시 워크플로는 "Pipelines" 또는 "Branches" 뷰에서 수동으로 트리거할 수 있는 "custom" 파이프라인을 정의합니다:
image: atlassian/default-image:3
pipelines:
custom:
run-tbot:
- step:
oidc: true
script:
# Teleport 설치
- curl "https://example.teleport.sh"/>:443/scripts/install.sh" | bash
# SSH 접근을 위한 아이덴티티 모드로 `tbot` 실행
- tbot start identity --destination=./tbot-user --join-method=bitbucket --proxy-server= name="example.teleport.sh"/>:443 --token=bot-bitbucket --oneshot
# 생성된 SSH 자격 증명 사용
- ssh -F ./tbot-user/ssh_config user@node.example.teleport.sh echo "hello world"
를 Teleport Proxy Service의 주소로 교체합니다.
이 예시는 SSH 자격 증명을 생성하기 위해 아이덴티티 모드로 tbot을 시작합니다. 데이터베이스, 애플리케이션, Kubernetes 접근과 같은 다른 모드 사용에 대한 자세한 내용은 tbot 문서를 참조하세요.
기존 워크플로를 수정하는 경우 다음 단계에 주의하세요:
- 단계 속성에
oidc: true를 설정하여 해당 단계에 토큰이 발급되도록 합니다. - 클러스터의 설치 스크립트에서 Teleport를 설치합니다.
--join-method=bitbucket,--token=example-bot(또는 3단계에서 설정한 이름),--oneshot과 함께tbot을 실행합니다.
Bitbucket Pipelines에서는 artifacts를 사용하여 저장된 모든 것이 CI 실행이 완료된 후에도 다운로드 가능하게 남아 있으므로 단계 간에 출력을 안전하게 공유할 수 없습니다.
이 제한으로 인해 Teleport 자격 증명을 사용하는 모든 작업은 동일한 단계의 일부로 수행해야 합니다. 필요한 경우 여러 단계에서 자격 증명이 필요하면 여기에 표시된 스크립트를 복제하여 주어진 실행에서 tbot을 여러 번 다운로드하고 실행할 수 있습니다.
추가 단계#
- 접근 가이드를 따라 환경에 맞게
tbot을 마저 설정합니다. - 사용 가능한 모든 설정 옵션을 확인하려면 설정 레퍼런스를 읽으세요.
- Bitbucket Pipelines 자체에 대한 자세한 내용은 Bitbucket 문서를 읽으세요.
