Teleport 사용자 가장하기
때로는 사용자가 비대화형 사용자(예: CI/CD 시스템)를 위한 단기 인증서를 생성해야 합니다. 대화형 사용자 Alice가 비대화형 CI/CD 사용자 Jenkins와 보안 스캐너를 위한 자격 증명을 생성하는 방법을 살펴보겠습니다.
때로는 사용자가 비대화형 사용자(예: CI/CD 시스템)를 위한 단기 인증서를 생성해야 합니다. Teleport와 상호작용하는 프로그램도 자체 인증을 생성해야 할 수 있습니다. Teleport의 가장(Impersonation) 기능은 사용자와 로봇이 다른 사용자 및 역할을 위한 단기 인증서를 생성할 수 있도록 합니다.
대화형 사용자 Alice가 비대화형 CI/CD 사용자 Jenkins와 보안 스캐너를 위한 자격 증명을 생성하는 방법을 살펴보겠습니다.
작동 방식#
Teleport 역할은 Teleport 사용자가 다른 역할이나 사용자를 가장할 수 있게 해줍니다. Teleport 사용자가 가장을 허용하는 역할로 인증하면 tctl auth sign 명령을 실행하여 Teleport Auth 서비스에게 다른 Teleport 사용자를 위한 인증서에 서명하도록 지시할 수 있습니다. 모든 Teleport 사용자 인증서와 마찬가지로 tctl auth sign이 작성한 인증서에는 Teleport 사용자 이름과 해당 사용자의 역할 이름이 포함됩니다. TLS 또는 SSH 클라이언트는 인증서를 로드하여 가장된 사용자로 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
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.
1/3단계: CI/CD 사용자 및 해당 역할 생성#
먼저 jenkins라는 역할을 생성합니다. 이 역할을 가진 사용자에게 발급된 인증서 기간을 제한하는 max_session_ttl 매개변수에 주목하세요. 일반적으로 TTL이 짧을수록 더 좋습니다.
jenkins라는 사용자도 생성하고 역할을 사용자에게 할당합니다.
이 파일을 jenkins.yaml로 저장합니다:
kind: role
version: v5
metadata:
name: jenkins
spec:
# 사용자 세션에 사용되는 SSH 옵션
options:
# max_session_ttl은 이 역할을 가진 사용자에게 발급된
# SSH 인증서의 TTL(유효 기간)을 정의합니다.
max_session_ttl: 240h
# allow 섹션은 이 역할의 사용자에게 허용된
# 리소스/동사 조합 목록을 선언합니다. 기본적으로 아무것도 허용되지 않습니다.
allow:
logins: ['jenkins']
node_labels:
'*': '*'
---
kind: user
version: v2
metadata:
name: jenkins
spec:
roles: ['jenkins']
리소스를 생성합니다:
$ tctl create -f jenkins.yaml
2/3단계: 가장자 역할 생성#
다음으로 impersonator라는 역할을 생성합니다. 이 역할을 가진 사용자는 jenkins 사용자와 역할을 가장할 수 있게 됩니다.
이 역할 정의를 impersonator.yaml로 저장합니다:
kind: role
version: v5
metadata:
name: impersonator
spec:
# 사용자 세션에 사용되는 SSH 옵션
options:
# max_session_ttl은 이 역할을 가진 사용자에게 발급된
# SSH 인증서의 TTL(유효 기간)을 정의합니다.
max_session_ttl: 10h
# allow 섹션은 이 역할의 사용자에게 허용된
# 리소스/동사 조합 목록을 선언합니다. 기본적으로 아무것도 허용되지 않습니다.
allow:
impersonate:
users: ['jenkins']
roles: ['jenkins']
role 리소스를 생성합니다:
$ tctl create -f impersonator.yaml
다음으로 alice라는 대화형 사용자를 생성하고 가장자 역할을 할당하여 alice가 jenkins를 가장할 수 있도록 합니다.
참고 - 접근 역할: Alice의 편의를 위해 사용자가 클러스터에 접근할 수 있게 하는 사전 설정
access역할도 할당합니다.
$ tctl users add alice --roles=impersonator,access
3/3단계: 가장을 사용하여 인증서 발급#
Alice는 tsh로 로그인하고 jenkins를 위한 인증서를 발급할 수 있습니다:
$ tsh login --proxy=proxy.example.com --user=alice --auth=local
$ tctl auth sign --user=jenkins --format=openssh --out=jenkins --ttl=240h
$ tsh login --proxy=mytenant.teleport.sh --user=alice --auth=local
$ tctl auth sign --user=jenkins --format=openssh --out=jenkins --ttl=240h
다음은 Alice가 키를 사용하는 방법의 예입니다:
# 이 세션을 위한 새 SSH 에이전트 시작
$ eval $(ssh-agent)
# 에이전트에 인증서 추가
$ ssh-add jenkins
# jenkins로 노드에 SSH 연결
$ ssh -J jenkins@teleport.localhost:3023 -p 3022 jenkins@127.0.0.1
참고 - 감사: Teleport의
session.start이벤트는jenkins를 가장하는alice가 수행한 작업을 캡처합니다.session.start event:session.start impersonator:alice login:jenkins user:jenkins
jenkins에 발급된 SSH 인증서에는 가장자alice에 대한 정보가 포함됩니다.
고급#
가장 규칙#
의도치 않은 결과를 방지하기 위해 Teleport는 다음 가장 규칙을 정의합니다:
- Alice의
max_session_ttl이 10시간이더라도jenkins역할이 허용하기 때문에 240시간의 더 긴 TTL로 인증서를 발급할 수 있습니다. 가장을 사용하여 발급된 인증서의 TTL은 가장되는 역할의 최대 TTL로 연장됩니다. jenkins역할이 다른 역할을 가장할 수 있더라도 Alice는 이 권한을 사용할 수 없습니다. Teleport는 재귀적 가장을 방지합니다.- Alice는 동일한 TTL로 새
jenkins인증서를 받을 수 있지만 메타데이터가 업데이트됩니다(예: 다른 Teleport 리프 클러스터를 가리키도록). Teleport는 가장된 사용자가 축소된 인증서 범위로 인증서를 갱신할 수 있도록 허용합니다.
동적 가장#
시스템에서 생성될 역할을 미리 알 수 없는 경우가 있습니다.
where 조건을 사용하여 레이블 매칭을 기반으로 하나의 역할이 다른 역할을 가장하도록 허용할 수 있습니다.
예를 들어 group: security 레이블을 가진 사용자나 역할의 가장을 허용하는 security-impersonator 역할을 정의하려는 경우 다음 역할 정의로 수행할 수 있습니다:
kind: role
version: v5
metadata:
name: security-impersonator
spec:
options:
max_session_ttl: 10h
# security-impersonator는 'group: security' 레이블을 가진 모든 사용자나 역할을 가장할 수 있습니다
allow:
impersonate:
users: ['*']
roles: ['*']
where: >
equals(impersonate_role.metadata.labels["group"], "security") &&
equals(impersonate_user.metadata.labels["group"], "security")
리소스를 생성합니다:
$ tctl create -f security-impersonator.yaml
$ tctl users update alice --set-roles=security-impersonator,access
Alice는 이제 group: security 레이블을 가진 모든 역할과 사용자를 가장할 수 있습니다.
이제 보안 스캔 도구를 위한 또 다른 머신 사용자를 생성해야 한다고 가정합니다. 다음 템플릿을 사용하여 security-scanner 사용자와 역할을 생성합니다:
kind: role
version: v5
metadata:
name: security-scanner
labels:
group: security
spec:
options:
max_session_ttl: 10h
allow:
logins: ['root']
node_labels:
'*': '*'
---
kind: user
version: v2
metadata:
name: security-scanner
labels:
group: security
spec:
roles: ['security-scanner']
이 역할이 Alice의 사용자가 구성된 후에 생성되었더라도 Alice는 group: security 레이블이 붙어 있으므로 security-scanner 사용자를 위한 인증서를 발급할 수 있습니다.
$ tctl auth sign --user=security-scanner --format=openssh --out=security-scanner --ttl=10h
사용자 특성 매칭#
사용자 특성 매칭으로 가장 규칙을 정의할 수도 있습니다.
여기서는 가장하려는 역할 및/또는 사용자의 레이블과 동일한 값을 group 사용자 특성이 포함하는 경우 다른 사용자나 역할의 가장을 허용하도록 security-impersonator 역할을 업데이트했습니다:
kind: role
version: v5
metadata:
name: security-impersonator
spec:
options:
max_session_ttl: 10h
allow:
impersonate:
users: ['*']
roles: ['*']
where: >
contains(user.spec.traits["group"], impersonate_role.metadata.labels["group"]) &&
contains(user.spec.traits["group"], impersonate_user.metadata.labels["group"])
사용자 특성은 일반적으로 외부 아이덴티티 공급자에서 오지만 특성을 사용하여 Alice의 계정을 수동으로 업데이트하여 로컬 사용자 alice로 테스트할 수 있습니다.
kind: user
version: v2
metadata:
name: alice
spec:
traits:
group: ['security', 'devops']
roles:
- security-impersonator
- access
Alice의 group 특성에 security가 포함되어 있고 security-scanner 사용자에 group: security 레이블이 있으므로 Alice는 보안 스캐너를 가장할 수 있습니다.
Alice는 새로 업데이트된 특성을 받기 위해 다시 로그인해야 합니다:
# Alice가 다시 로그인하면 업데이트된 역할로 새 인증서를 받습니다.
$ tsh login --proxy=teleport.example.com --user=alice --auth=local
# Alice는 이제 보안 스캐너를 위한 인증서를 받을 수 있습니다
$ tctl auth sign --user=security-scanner --format=openssh --out=security-scanner --ttl=10h
# Alice가 다시 로그인하면 업데이트된 역할로 새 인증서를 받습니다.
$ tsh login --proxy=mytenant.teleport.sh --user=alice --auth=local
# Alice는 이제 보안 스캐너를 위한 인증서를 받을 수 있습니다
$ tctl auth sign --user=security-scanner --format=openssh --out=security-scanner --ttl=10h
필터 필드#
다음은 이 가이드의 where 조건에서 사용된 필드에 대한 설명입니다.
| 필드 | 설명 |
|---|---|
user.spec.traits["group"] |
group 특성이 일반적으로 외부 아이덴티티 공급자에서 오는 로컬 또는 SSO 사용자의 특성 목록 |
impersonate_role.metadata.labels["<label key>"] |
가장할 역할의 레이블 key에 지정된 레이블 값 |
impersonate_user.metadata.labels["<label key>"] |
가장할 사용자의 레이블 key에 지정된 레이블 값 |
언어에 대한 더 깊은 설명은 술어 언어 가이드를 참조하세요.
