GitLab을 SSO 프로바이더로 사용한 인증
이 가이드는 특정 사용자 그룹에게 자격 증명을 발급하도록 GitLab을 구성하는 방법을 다룹니다. You can register your Teleport cluster as an application with GitLab, then create an authentication connector resource that provides Teleport with ...
이 가이드는 특정 사용자 그룹에게 자격 증명을 발급하도록 GitLab을 구성하는 방법을 다룹니다. 역할 기반 접근 제어(RBAC)와 함께 사용하면 관리자가 다음과 같은 정책을 정의할 수 있습니다:
- "DBA" 그룹의 구성원만 PostgreSQL 데이터베이스에 접근할 수 있습니다.
- "ProductionKubernetes"의 구성원만 프로덕션 Kubernetes 클러스터에 접근할 수 있습니다.
- 개발자는 프로덕션 서버에 절대 SSH 접근을 하면 안 됩니다.
작동 방식#
You can register your Teleport cluster as an application with GitLab, then create an authentication connector resource that provides Teleport with information about your application. When a user signs in to Teleport, GitLab executes its own authentication flow, then sends an HTTP request to your Teleport cluster to indicate that authentication has completed.
Teleport authenticates users to your infrastructure by issuing short-lived certificates. After a user completes an SSO authentication flow, Teleport issues short-lived TLS and SSH certificates to the user. Teleport also creates a temporary user on the Auth Service backend.
Teleport roles are encoded in the user's certificates. To assign Teleport roles to the user, the Auth Service inspects the role mapping within the authentication connector, which associates user data on GitLab with the names of one or more Teleport roles.
사전 요구 사항#
- 사용자가 할당된 최소 두 개의 GitLab 그룹. 아래 예제에서는 두 개의 서브그룹
admin과dev가 있는company라는 그룹을 가정합니다. oidc리소스를 유지 관리할 수 있는 접근 권한이 있는 Teleport 역할. 기본editor역할에서 사용 가능합니다.
-
A running Teleport Enterprise 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단계. GitLab 구성#
Teleport 역할에 매핑할 GitLab 그룹이 하나 이상 구성되어 있어야 합니다. 이 예제에서는 devs와 admins라는 이름을 사용합니다. 각 그룹에 사용자를 할당합니다.
-
GitLab OAuth 프로바이더로 Teleport를 사용할 수 있도록 하는 애플리케이션을 그룹 중 하나에 만듭니다(Group overview -> Settings -> Applications).
을 Teleport Proxy Service의 공개 주소에 할당합니다. 여러 공개 주소를 가진 셀프 호스팅 클러스터가 있는 경우 이 주소가 첫 번째로 나열된 것을 가리키도록 합니다.
설정:
- 리다이렉트 URL:
https:///v1/webapi/oidc/callback. Confidential,openid,profile,email체크.

- 리다이렉트 URL:
-
애플리케이션에서
Application ID와Secret을 수집합니다. Teleport OIDC 인증 커넥터에서 사용됩니다:
-
GitLab 발급자 주소를 확인합니다.
GitLab.com의 경우 발급자 주소는
https://gitlab.com입니다. 이를 통해 Teleport가https://gitlab.com/.well-known/openid-configuration에서 Open-ID 구성에 접근할 수 있습니다. 셀프 호스팅의 경우 발급자 주소는 GitLab 인스턴스의 경로입니다.
2/3단계. GitLab을 Teleport에 연결#
이 섹션에서는 Teleport가 GitLab과 OIDC 메시지를 교환하고 사용자에게 인증서를 발급하는 데 필요한 정보를 제공하는 인증 커넥터를 만듭니다.
역할 매핑 할당#
When a user authenticates to Teleport, the Teleport Auth Service issues SSH and TLS certificates to the user that contain the user's Teleport roles.
For SSO authentication connectors, the Auth Service determines which roles to encode in the certificate by reading the authentication connector's role mapping. The role mapping indicates which Teleport roles to assign based on data that your identity provider stores about the user.
When you configure an authentication connector using the tctl CLI, a role
mapping takes the following format:
<claim_name>,<claim_value>,<teleport_role_1>,<teleport_role_2>,...,<teleport_role_n>
For example, the following role mapping means that any user with the claim
groups with the value admins receives the Teleport roles auditor and
editor:
groups,admins,auditor,editor
For the purpose of this guide, assign two separate role mappings:
- A more permissive role mapping:
- A more restrictive role mapping:
OIDC 커넥터 구성#
tctl을 사용하여 OIDC 커넥터 리소스를 만듭니다.
워크스테이션에서 클라이언트 시크릿만 포함된 client-secret.txt 파일을 만듭니다.
GitLab의 애플리케이션 ID와 시크릿으로 교체합니다:
$ tctl sso configure oidc --preset gitlab \
--id
콜백 주소 변경
The callback address can be changed if calling back to a remote machine
instead of the local machine is required:
# --bind-addr sets the host and port tsh will listen on, and --callback changes
# what link is displayed to the user
$ tsh login --proxy=proxy.example.com --auth=github --bind-addr=localhost:1234 --callback https://remote.machine:1234
For this to work the hostname or CIDR of the remote machine that will be used for
the callback will need to be allowed via your auth connector's client_redirect_settings:
kind: oidc
metadata:
name: example-connector
spec:
client_redirect_settings:
# a list of hostnames allowed for HTTPS client redirect URLs
# can be a regex pattern
allowed_https_hostnames:
- remote.machine
- '*.app.github.dev'
- '^\d+-[a-zA-Z0-9]+\.foo.internal$'
# a list of CIDRs allowed for HTTP or HTTPS client redirect URLs
insecure_allowed_cidr_ranges:
- '192.168.1.0/24'
- '2001:db8::/96'
커넥터 테스트#
파일을 tctl sso test에 파이프하여 커넥터 리소스를 테스트합니다:
$ cat oidc.yaml | tctl sso test
GitLab에서 애플리케이션을 인증한 후 웹 브라우저에 Login Successful 메시지가 표시되어야 합니다. 그렇지 않으면 명령의 출력을 참고하여 진단합니다.
커넥터 만들기#
tctl 도구를 사용하여 커넥터를 만듭니다:
$ tctl create -f oidc.yaml
이제 웹 UI에 새 버튼 "Login with GitLab"이 있습니다. CLI는 이전과 동일합니다:
$ tsh --proxy= login
이 명령은 SSO 로그인 URL을 출력합니다(그리고 브라우저에서 자동으로 열려고 합니다).
팁
Teleport는 여러 OIDC/SAML 커넥터를 사용할 수 있습니다. 이 경우 커넥터 이름은 tsh login --auth=connector_name으로 전달할 수 있습니다.
중요
Teleport는 OIDC Connect에 대해 전송자 주도 플로우만 지원합니다. 즉, 아이덴티티 프로바이더에서 로그인을 시작할 수 없으며 Teleport 웹 UI 또는 CLI에서 로그인을 시작해야 합니다.
3/3단계. 인증 기본 설정 구성#
Edit your cluster authentication preferences so you can make the authentication
connector you configured in this guide the default authentication method for
your Teleport cluster.
Open the Teleport Web UI. From the left sidebar, navigate to Zero Trust
Access > Auth Connectors. Find the connector you would like to make the
default and, from its three-dot menu, select Set as default.
If you are managing your Teleport resources as configuration files, you can
choose a default authentication connector using a dynamic resource. In this
case, use tctl to edit the cluster_auth_preference value:
$ tctl edit cluster_auth_preference
Set the value of spec.type to oidc:
kind: cluster_auth_preference
metadata:
...
name: cluster-auth-preference
spec:
...
type: oidc
...
version: v2
After you save and exit the editor, tctl will update the resource:
cluster auth preference has been updated
Additional ways to edit cluster auth preferences
The cluster auth preference is available as a Teleport Terraform provider
resource. Find a list of configuration options in the Cluster Auth Preferences
Resource
Reference.
If you self-host Teleport, you can edit your Teleport Auth Service configuration
file to include the following:
# Snippet from /etc/teleport.yaml
auth_service:
authentication:
type: oidc
If you need to log in again before configuring your identity provider, use the
flag --auth=local .
다음 단계#
Now that you have connected Teleport to your identity provider, you can
customize the way Teleport includes IdP data in Teleport roles.
With role templates, you can include user data from your IdP directly in
Teleport roles. If you use the external template variable in the value of a
role field, Teleport passes that value from your IdP. In this example, all of
the role options you can use for allowing users to assume certain principals on
remote systems come from your IdP:
kind: role
version: v7
metadata:
name: sso-users
spec:
allow:
logins: ['{{external.logins}}']
aws_role_arns: ['{{external.aws_role_arns}}']
azure_identities: ['{{external.azure_identities}}']
db_names: ['{{external.db_names}}']
db_roles: ['{{external.db_roles}}']
db_users: ['{{external.db_users}}']
desktop_groups: ['{{external.desktop_groups}}']
gcp_service_accounts: ['{{external.gcp_service_accounts}}']
host_groups: ['{{external.host_groups}}']
host_sudoers: ['{{external.host_sudoers}}']
kubernetes_groups: ['{{external.kubernetes_groups}}']
kubernetes_users: ['{{external.kubernetes_users}}']
windows_desktop_logins: ['{{external.windows_desktop_logins}}']
For more information on using the external template variable, see Role
Templates.
For an explanation of the fields listed above, see the Role
Reference.
If you need to transform your IdP user data before you include it in Teleport
roles, you can do so using Login Rules. Login Rules allow you to include
external traits within Teleport roles even if your IdP provides user data in a
different format than the one expected by Teleport. Read more about Login
Rules.
문제 해결#
Note이 섹션의 내용은 원문 문서를 참조하세요. (oidc-login-troubleshooting.mdx)
