InfoGrab Docs

MongoDB 자동 사용자 프로비저닝

요약

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.

전제 조건#

  • Teleport 클러스터.
  • Teleport 클러스터에 등록된 셀프 호스팅 MongoDB 데이터베이스. 데이터베이스를 등록하는 방법은 Teleport 문서를 참조하세요. MongoDB 데이터베이스는 구성 파일에서 security.authorizationenabled로 설정하여 역할 기반 접근 제어(RBAC)가 활성화되어 있어야 합니다.
  • 대상 데이터베이스에 연결하고 사용자 계정을 생성할 수 있는 권한.
지원되는 서비스

자동 사용자 프로비저닝은 MongoDB Atlas와 호환되지 않습니다.

1/3단계. 데이터베이스 관리자 구성#

Teleport는 관리자 사용자로 연결할 때 일반 사용자 연결과 동일한 인증 메커니즘(X.509)을 사용합니다.

관리자 사용자는 데이터베이스 내에서 사용자를 생성하고 권한을 부여할 수 있는 권한이 있어야 합니다. 또한 사용자 연결을 모니터링할 수 있는 권한도 있어야 합니다.

먼저 다음 권한으로 admin 데이터베이스에 역할을 생성합니다:

db.getSiblingDB("admin").runCommand({
    createRole: "teleport-admin-role",
    privileges: [
        { resource: { cluster: true }, actions: [ "inprog" ] },
        { resource: { db: "", collection: "" }, actions: [ "grantRole", "revokeRole" ] },
        { resource: { db: "$external", "collection": "" }, actions: [ "createUser", "updateUser", "dropUser", "viewUser", "setAuthenticationRestriction", "changeCustomData"] },
    ],
    roles: [],
})
grantRole 액션을 특정 데이터베이스로 제한 위 예시에서 `grantRole` 권한은 `admin` 데이터베이스를 포함한 모든 데이터베이스에서 관리자 사용자에게 부여되어 자동 프로비저닝된 사용자에게 모든 데이터베이스의 역할을 할당할 수 있습니다.

최소 권한 원칙을 적용하기 위해 자동 프로비저닝된 사용자에게 할당할 역할을 소유한 데이터베이스로만 grantRole을 제한할 수 있습니다:

db.getSiblingDB("admin").runCommand({
    createRole: "teleport-admin-role",
    privileges: [
        { resource: { cluster: true }, actions: [ "inprog" ] },
        { resource: { db: "", collection: "" }, actions: [ "revokeRole" ] },
        { resource: { db: "$external", "collection": "" }, actions: [ "createUser", "updateUser", "dropUser", "viewUser", "setAuthenticationRestriction", "changeCustomData"] },
        { resource: { db: "<db1>", collection: "" }, actions: [ "grantRole" ] },
        { resource: { db: "<db2>", collection: "" }, actions: [ "grantRole" ] },
        ...
    ],
    roles: [],
})

이제 이 역할로 관리자 사용자를 생성합니다:

db.getSiblingDB("$external").runCommand({
  createUser: "CN=teleport-admin",
  roles: [ { role: 'teleport-admin-role', db: 'admin' } ],
})

Next, configure the database admin user in the Teleport database configuration:

kind: db
version: v3
metadata:
  name: example
spec:
  protocol: "mongodb"
  uri: "localhost:27017"
  admin_user:
    name: "teleport-admin"

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.

2/3단계. Teleport 역할 구성#

사용자가 데이터베이스 내에서 할당받아야 할 데이터베이스 역할을 지정하려면 db_roles 역할 옵션을 사용합니다:

kind: role
version: v7
metadata:
  name: auto-db-users
spec:
  options:
    # create_db_user_mode는 일치하는 데이터베이스에 대한 자동 사용자 프로비저닝을 활성화합니다
    create_db_user_mode: keep
  allow:
    db_labels:
      "*": "*"
    db_names:
    - "*"
    # db_roles는 데이터베이스 사용자에게 할당될 역할 목록입니다
    db_roles:
    - "readAnyDatabase@admin"
    - "readWrite@db1"
    - "myCustomRole@db2"
    - "{{internal.db_roles}}"
    - "{{external.db_roles}}"

With automatic user provisioning, users always connect to the database with their Teleport username so the db_users role field is ignored for roles that have database user provisioning enabled.

The available provisioning modes are:

  • off: Disables user provisioning.

  • keep: Enables user provisioning and disables users at session end. The user will be stripped of all roles and the user account will be locked.

  • best_effort_drop: Enables user provisioning and, when the session ends, drops the user if no resources depend on it. In cases where any resource depends on the user, it falls back to disabling the user, mirroring the behavior of keep mode.

데이터베이스 내에서 생성된 사용자는 다음과 같이 설정됩니다:

  • 인증된 Teleport 사용자와 동일한 사용자 이름을 갖습니다.
  • 사용자의 customDatateleport-auto-usertrue로 설정됩니다.
  • 데이터베이스와 일치하는 Teleport 사용자의 역할 집합에서 모든 역할이 할당됩니다. 역할 이름은 유효하고 데이터베이스에 존재해야 합니다.

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 myCustomRole@db2 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.

다음 단계#

MongoDB 자동 사용자 프로비저닝

원문 보기
요약

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.

전제 조건#

  • Teleport 클러스터.
  • Teleport 클러스터에 등록된 셀프 호스팅 MongoDB 데이터베이스. 데이터베이스를 등록하는 방법은 Teleport 문서를 참조하세요. MongoDB 데이터베이스는 구성 파일에서 security.authorizationenabled로 설정하여 역할 기반 접근 제어(RBAC)가 활성화되어 있어야 합니다.
  • 대상 데이터베이스에 연결하고 사용자 계정을 생성할 수 있는 권한.
지원되는 서비스

자동 사용자 프로비저닝은 MongoDB Atlas와 호환되지 않습니다.

1/3단계. 데이터베이스 관리자 구성#

Teleport는 관리자 사용자로 연결할 때 일반 사용자 연결과 동일한 인증 메커니즘(X.509)을 사용합니다.

관리자 사용자는 데이터베이스 내에서 사용자를 생성하고 권한을 부여할 수 있는 권한이 있어야 합니다. 또한 사용자 연결을 모니터링할 수 있는 권한도 있어야 합니다.

먼저 다음 권한으로 admin 데이터베이스에 역할을 생성합니다:

db.getSiblingDB("admin").runCommand({
    createRole: "teleport-admin-role",
    privileges: [
        { resource: { cluster: true }, actions: [ "inprog" ] },
        { resource: { db: "", collection: "" }, actions: [ "grantRole", "revokeRole" ] },
        { resource: { db: "$external", "collection": "" }, actions: [ "createUser", "updateUser", "dropUser", "viewUser", "setAuthenticationRestriction", "changeCustomData"] },
    ],
    roles: [],
})
grantRole 액션을 특정 데이터베이스로 제한 위 예시에서 `grantRole` 권한은 `admin` 데이터베이스를 포함한 모든 데이터베이스에서 관리자 사용자에게 부여되어 자동 프로비저닝된 사용자에게 모든 데이터베이스의 역할을 할당할 수 있습니다.

최소 권한 원칙을 적용하기 위해 자동 프로비저닝된 사용자에게 할당할 역할을 소유한 데이터베이스로만 grantRole을 제한할 수 있습니다:

db.getSiblingDB("admin").runCommand({
    createRole: "teleport-admin-role",
    privileges: [
        { resource: { cluster: true }, actions: [ "inprog" ] },
        { resource: { db: "", collection: "" }, actions: [ "revokeRole" ] },
        { resource: { db: "$external", "collection": "" }, actions: [ "createUser", "updateUser", "dropUser", "viewUser", "setAuthenticationRestriction", "changeCustomData"] },
        { resource: { db: "<db1>", collection: "" }, actions: [ "grantRole" ] },
        { resource: { db: "<db2>", collection: "" }, actions: [ "grantRole" ] },
        ...
    ],
    roles: [],
})

이제 이 역할로 관리자 사용자를 생성합니다:

db.getSiblingDB("$external").runCommand({
  createUser: "CN=teleport-admin",
  roles: [ { role: 'teleport-admin-role', db: 'admin' } ],
})

Next, configure the database admin user in the Teleport database configuration:

kind: db
version: v3
metadata:
  name: example
spec:
  protocol: "mongodb"
  uri: "localhost:27017"
  admin_user:
    name: "teleport-admin"

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.

2/3단계. Teleport 역할 구성#

사용자가 데이터베이스 내에서 할당받아야 할 데이터베이스 역할을 지정하려면 db_roles 역할 옵션을 사용합니다:

kind: role
version: v7
metadata:
  name: auto-db-users
spec:
  options:
    # create_db_user_mode는 일치하는 데이터베이스에 대한 자동 사용자 프로비저닝을 활성화합니다
    create_db_user_mode: keep
  allow:
    db_labels:
      "*": "*"
    db_names:
    - "*"
    # db_roles는 데이터베이스 사용자에게 할당될 역할 목록입니다
    db_roles:
    - "readAnyDatabase@admin"
    - "readWrite@db1"
    - "myCustomRole@db2"
    - "{{internal.db_roles}}"
    - "{{external.db_roles}}"

With automatic user provisioning, users always connect to the database with their Teleport username so the db_users role field is ignored for roles that have database user provisioning enabled.

The available provisioning modes are:

  • off: Disables user provisioning.

  • keep: Enables user provisioning and disables users at session end. The user will be stripped of all roles and the user account will be locked.

  • best_effort_drop: Enables user provisioning and, when the session ends, drops the user if no resources depend on it. In cases where any resource depends on the user, it falls back to disabling the user, mirroring the behavior of keep mode.

데이터베이스 내에서 생성된 사용자는 다음과 같이 설정됩니다:

  • 인증된 Teleport 사용자와 동일한 사용자 이름을 갖습니다.
  • 사용자의 customDatateleport-auto-usertrue로 설정됩니다.
  • 데이터베이스와 일치하는 Teleport 사용자의 역할 집합에서 모든 역할이 할당됩니다. 역할 이름은 유효하고 데이터베이스에 존재해야 합니다.

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 myCustomRole@db2 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.

다음 단계#