MariaDB 자동 사용자 프로비저닝
Teleport can automatically create users in your database, removing the need for creating individual user accounts in advance or using the same set ...
Teleport can automatically create users in your database, removing the need for creating individual user accounts in advance or using the same set of shared database accounts for all users.
전제 조건#
- 셀프 호스팅 MariaDB 또는 RDS MariaDB 데이터베이스가 구성된 Teleport 클러스터.
- 대상 데이터베이스에 연결하고 사용자 계정을 생성할 수 있는 권한.
자동 사용자 프로비저닝은 MariaDB 버전 10.3.3 또는 10.2.11 미만과는 호환되지 않습니다.
1/3단계. 데이터베이스 관리자 구성#
Teleport should be able to connect to the database as a user that can create
other users and assign them roles. We recommend creating a separate user
designated specifically for Teleport automatic user provisioning. Let's call it
teleport-admin.
Teleport는 관리자 사용자로 연결할 때 일반 사용자 연결과 동일한 인증 메커니즘을 사용합니다: 셀프 호스팅 데이터베이스의 경우 X.509, RDS의 경우 AWS IAM.
관리자 사용자는 데이터베이스 내에서 사용자를 생성하고 권한을 부여할 수 있는 권한이 있어야 합니다. 또한 사용자 프로세스 및 역할 할당을 모니터링할 수 있는 권한도 있어야 합니다.
또한, 관리자 사용자가 기본적으로 로그인할 데이터베이스가 필요합니다. 이 데이터베이스는 사용자 정의 속성과 저장 프로시저를 저장하는 데도 사용됩니다.
RDS MariaDB 관리자 사용자는 IAM 인증을 허용하기 위해 AWSAuthenticationPlugin을 사용해야 합니다:
CREATE USER 'teleport-admin' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';
GRANT PROCESS, CREATE USER ON *.* TO 'teleport-admin';
GRANT SELECT ON mysql.roles_mapping TO 'teleport-admin';
GRANT UPDATE ON mysql.* TO 'teleport-admin'; -- SET DEFAULT ROLE FOR를 위해
GRANT SELECT ON *.* TO 'teleport-admin'; -- 자원을 소유한 사용자를 삭제하기 전 확인하는 best_effort_drop 모드 사용 시 필요.
CREATE DATABASE IF NOT EXISTS `teleport`;
GRANT ALL ON `teleport`.* TO 'teleport-admin' WITH GRANT OPTION;
Note that Teleport uses teleport as the name of the default database but the
name is configurable in the Teleport database definition. Replace the database
name in the last two lines if you wish to use another database name.
셀프 호스팅 MariaDB 관리자 사용자는 X.509 인증이 구성되어 있어야 합니다:
CREATE USER 'teleport-admin' REQUIRE SUBJECT '/CN=teleport-admin';
GRANT PROCESS, CREATE USER ON *.* TO 'teleport-admin';
GRANT SELECT ON mysql.roles_mapping TO 'teleport-admin';
GRANT UPDATE ON mysql.* TO 'teleport-admin'; -- SET DEFAULT ROLE FOR를 위해
GRANT SELECT ON *.* TO 'teleport-admin'; -- 자원을 소유한 사용자를 삭제하기 전 확인하는 best_effort_drop 모드 사용 시 필요.
CREATE DATABASE IF NOT EXISTS `teleport`;
GRANT ALL ON `teleport`.* TO 'teleport-admin' WITH GRANT OPTION;
Note that Teleport uses teleport as the name of the default database but the
name is configurable in the Teleport database definition. Replace the database
name in the last two lines if you wish to use another database name.
Teleport가 생성한 사용자는 데이터베이스에서 teleport-auto-user 역할이 할당되며, 해당 역할이 존재하지 않으면 자동으로 생성됩니다.
MariaDB 세션 중에는 한 번에 하나의 역할만 활성화될 수 있습니다. Teleport는 통합 역할 tp-role-<user>를 생성하여 생성된 사용자에게 할당합니다. 실제 역할은 이 통합 역할에 할당되고, 통합 역할은 기본 역할로 설정됩니다.
Next, configure the database admin user in the Teleport database configuration:
kind: db
version: v3
metadata:
name: example
spec:
protocol: "mysql"
uri: "localhost:3306"
admin_user:
name: "teleport-admin"
# Optional default database the admin user logs into. Default is
# 'teleport', if not specified.
# default_database: teleport
This example assumes that you have configured the database as a dynamic
resource. If you have configured your database using a static Teleport Database
Service configuration, edit the entry in your db_service.databases
configuration.
For auto-discovered cloud databases, the name of the admin user is taken from
the teleport.dev/db-admin label, and the default database is taken from the
teleport.dev/db-admin-default-database label.
2/3단계. Teleport 역할 구성#
To specify the database roles a user should be assigned within the database,
use the db_roles role option:
kind: role
version: v7
metadata:
name: auto-db-users
spec:
options:
# create_db_user_mode enables automatic user provisioning for matching databases
create_db_user_mode: keep
allow:
db_labels:
"*": "*"
db_names:
- "*"
# db_roles is a list of roles the database user will be assigned
db_roles:
- reader
- "{{internal.db_roles}}"
- "{{external.db_roles}}"
(!docs/pages/includes/database-access/auto-user-provisioning/db_users_ignored.mdx!)
(!docs/pages/includes/database-access/auto-user-provisioning/modes.mdx!)
데이터베이스 내에서 생성된 사용자는 다음과 같이 설정됩니다:
teleport-auto-user역할이 할당됩니다.- 데이터베이스와 일치하는 Teleport 사용자의 역할 집합에서 모든 역할이 할당됩니다. 역할 이름은 유효하고 데이터베이스에 존재해야 합니다. 관리자 사용자는 이러한 역할의 "관리자"여야 합니다. 자세한 내용은 위의 "역할 관리자" 섹션을 참조하세요.
MariaDB limits usernames to 80 characters. When the Teleport
username is within this limit, the user created within the database will have
the same name as the Teleport username. When the Teleport username is over the
80 character limit, the user created within the database will have the
name in the format of tp-<base64-sha1-teleport-username>.
이름 매핑 추적
원래 Teleport 사용자 이름은 기본 데이터베이스의 `user_attributes` 테이블에 사용자 속성으로 저장됩니다.데이터베이스 관리자는 다음과 같이 특정 Teleport 사용자 이름을 검색할 수 있습니다:
SELECT * FROM teleport.user_attributes WHERE JSON_VALUE(Attributes,"$.user") = "teleport-user-name";
또한, Teleport 사용자 이름이 80자를 초과하는 경우 "해시된" 데이터베이스 내 이름이 Teleport 감사 로그에서 데이터베이스 쿼리의 db_user로 기록됩니다.
Note that in case of a name conflict where a user with the same name already
exists in the database and is not managed by Teleport (i.e. not assigned the
teleport-auto-user role), the connection will be aborted.
3/3단계. 데이터베이스에 연결#
Now, log into your Teleport cluster and connect to the database:
$ tsh login --proxy=teleport.example.com
$ tsh db connect --db-name <database> example
To view the list of database roles that are allowed for each database, you can
use the command tsh db ls -v. By default, all database roles will be assigned
to your auto-provisioned database user. You can optionally select a subset of
the database roles with --db-roles:
$ tsh db connect --db-name <database> --db-roles reader example
문제 해결#
매핑된 원격 사용자 이름 오류 사용#
You may encounter the following error when connecting to a database in a remote cluster:
> tsh db connect --db-name <database> example
ERROR: please use your mapped remote username ("remote-<your-teleport-username>-<root-cluster-name>") to connect instead of "<database-user>"
When you access resources in a remote cluster, the remote cluster will receive
the name remote-<your-teleport-username>-<root-cluster-name> from the local
cluster. This is to prevent any naming collisions with users in the remote
cluster. Please use the username from the error message as the database
username for when connecting through tsh or GUI clients.
다음 단계#
- GUI 데이터베이스 클라이언트를 사용하여 연결합니다.
- 역할 템플릿에 대해 알아봅니다.
- 자동 사용자 프로비저닝 RFD를 읽어봅니다.
