Docs Menu

키 파일 인증으로 자체 관리 복제본 세트 업데이트(다운타임 없음)

To secure against unauthorized access, enforce 인증 for your deployments. Authentication for replica sets consists of internal authentication among the replica set members, and user access control for clients connecting to the replica set.

If your deployment does not currently enforce authentication, you can use the --transitionToAuth option to enforce authentication without downtime.

This tutorial uses the keyfile internal authentication mechanism for internal security, and SCRAM-based role-based access controls for client connections.

Cloud Manager 또는 Ops Manager를 사용하여 배포를 관리하는 경우, 인증을 시행하려면 해당 Cloud Manager 매뉴얼 또는 Ops Manager 매뉴얼을 확인하세요.

This tutorial assumes that your replica set can elect a new 기본 after stepping down the existing primary replica set member. This requires:

a mongod running with --transitionToAuth accepts both authenticated and non-authenticated connections. Clients connected to the mongod during this transition state can perform read, write, and administrative operations on any database.

At the end of the following procedure, the replica set rejects any client attempting to make a non-authenticated connection. The procedure creates users for client applications to use when connecting to the replica set.

See ➤ Configure Role-Based Access Control for user creation and management best practices.

2} 및mongod mongos MongoDB localhost 바이너리는 기본적으로 에 바인딩됩니다.

중요

시스템 보안을 보장하고 악의적인 액세스를 방지하거나 지연하려면 암호는 임의적이고 길며 복잡해야 합니다.

중요

변경된 IP 주소로 인해 구성이 업데이트되는 것을 방지하려면 IP 주소 대신 DNS 호스트 이름을 사용하세요. 특히 복제본 세트 구성원 또는 샤딩된 클러스터 구성원을 구성할 때 IP 주소 대신 DNS 호스트 이름을 사용하는 것이 중요합니다.

IP 주소 대신 호스트 이름을 사용하여 스플릿 네트워크 호라이즌 전반에 걸쳐 클러스터를 구성하세요. MongoDB 5.0부터 IP 주소로만 구성된 노드는 스타트업 유효성 검사에 실패하며 시작되지 않습니다.

1

Connect to the 기본 to create a user with userAdminAnyDatabase role. The userAdminAnyDatabase role grants access to user creation on any database in the deployment.

다음 예에서는 admin 데이터베이스에 userAdminAnyDatabase 역할을 가진 fred 사용자를 만듭니다.

중요

시스템 보안을 보장하고 악의적인 액세스를 방지하거나 지연하려면 암호는 임의적이고 길며 복잡해야 합니다.

메서드/명령 호출에서 암호를 직접 지정하는 대신 passwordPrompt() 메서드를 다양한 사용자 인증/관리 메서드/명령과 함께 사용하여 암호를 묻는 메시지를 표시할 수 있습니다. 그러나 이전 버전의 mongo 셸에서와 마찬가지로 비밀번호를 직접 지정할 수도 있습니다.

admin = db.getSiblingDB("admin")
admin.createUser(
{
user: "fred",
pwd: " passwordPrompt(), // or cleartext password
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)

At the completion of this procedure, any client that administers users in the replica set must authenticate as this user, or a user with similar permissions.

기본 제공 역할 및 데이터베이스 관리 작업과 관련된 역할의 전체 목록은 데이터베이스 사용자 역할에서 확인하세요.

2

Connect to the 기본 to create a user with clusterAdmin role. The clusterAdmin role grants access to replication operations, such as configuring the replica set.

다음 예에서는 admin 데이터베이스에 clusterAdmin 역할을 가진 ravi 사용자를 만듭니다.

중요

시스템 보안을 보장하고 악의적인 액세스를 방지하거나 지연하려면 암호는 임의적이고 길며 복잡해야 합니다.

메서드/명령 호출에서 암호를 직접 지정하는 대신 passwordPrompt() 메서드를 다양한 사용자 인증/관리 메서드/명령과 함께 사용하여 암호를 묻는 메시지를 표시할 수 있습니다. 그러나 이전 버전의 mongo 셸에서와 마찬가지로 비밀번호를 직접 지정할 수도 있습니다.

db.getSiblingDB("admin").createUser(
{
"user" : "ravi",
"pwd" : passwordPrompt(), // or cleartext password
roles: [ { "role" : "clusterAdmin", "db" : "admin" } ]
}
)

At the completion of this procedure, any client that administrates or maintains the replica set must authenticate as this user, or a user with similar permissions.

복제본 세트 작업과 관련된 기본 제공 역할의 전체 목록은 클러스터 관리 역할에서 확인하세요.

3

Create users to allow client application to connect and interact with the replica set. At the completion of this tutorial, clients must authenticate as a configured user to connect to the replica set.

See 데이터베이스 사용자 역할 for basic built-in roles to use in creating read-only and read-write users.

The following creates a user with read and write permissions on the foo database.

중요

시스템 보안을 보장하고 악의적인 액세스를 방지하거나 지연하려면 암호는 임의적이고 길며 복잡해야 합니다.

Create a user with the readWrite role in the foo database.

메서드/명령 호출에서 암호를 직접 지정하는 대신 passwordPrompt() 메서드를 다양한 사용자 인증/관리 메서드/명령과 함께 사용하여 암호를 묻는 메시지를 표시할 수 있습니다. 그러나 이전 버전의 mongo 셸에서와 마찬가지로 비밀번호를 직접 지정할 수도 있습니다.

db.getSiblingDB("foo").createUser(
{
"user" : "joe",
"pwd" : passwordPrompt(), // or cleartext password
roles: [ { "role" : "readWrite", "db" : "foo" } ]
}
)

Clients authenticating as this user can perform read and write operations against the foo database. See 자체 관리형 배포로 사용자 인증 for more on creating an authenticated connection to the replica set.

사용자 추가에 대한 자세한 내용은 사용자 추가 튜토리얼을 참조하세요. 새 사용자를 추가할 때는 보안 권장 사항을 고려하세요.

4

At this point in the procedure, the replica set does not enforce authentication. However, client applications can still specify auth credentials and connect to the replica set.

Update client applications to authenticate to the replica set using a configured user. Authenticated connections require a username, password, and the authentication database. See 자체 관리형 배포로 사용자 인증.

For example, the following connects to a replica set named mongoRepl and authenticates as the user joe.

mongosh -u joe -password -authenticationDatabase foo --host mongoRepl/mongo1.example.net:27017, mongo2.example.net:27017, mongo3.example.net:27017

-p 명령줄 옵션에 비밀번호를 지정하지 않으면 mongosh(이)가 비밀번호를 묻는 메시지를 표시합니다.

If your application uses a MongoDB driver, see the associated 드라이버 documentation for instructions on creating an authenticated connection.

At the completion of this tutorial, the replica set rejects non-authenticated client connections. Performing this step now ensures clients can connect to the replica set before and after the transition.

5

키 파일 인증을 사용하면 복제본 세트의 각 mongod 인스턴스는 배포서버에서 다른 멤버를 인증하기 위한 공유 암호로 키 파일의 내용을 사용합니다. 올바른 키 파일을 가진 mongod 인스턴스만 복제본 세트에 참여할 수 있습니다.

참고

내부 멤버십 인증을 위한 키파일은 YAML 형식을 사용해 키파일에 여러 키를 허용합니다. YAML 형식은 다음 중 하나를 허용합니다.

  • 단일 키 문자열(이전 버전과 동일)

  • 키 문자열의 순서

YAML 형식은 텍스트 파일 형식을 사용하는 기존의 단일 키 키파일과 호환됩니다.

키 길이는 6~1024자 사이여야 하며, base64 세트의 문자만 포함할 수 있습니다. 복제본 세트의 모든 멤버는 하나 이상의 공통 키를 공유해야 합니다.

참고

UNIX 시스템에서는 키 파일에 그룹 또는 월드 권한이 없어야 합니다. Windows 시스템에서는 키 파일 권한이 확인되지 않습니다.

원하는 방법을 사용하여 키 파일을 생성할 수 있습니다. 예를 들어 다음 작업에서는 openssl 사용하여 공유 암호로 사용할 복잡한 의사 난수 1024자 문자열을 생성합니다. 그런 다음 chmod 사용하여 파일 소유자에게만 읽기 권한을 제공하도록 파일 권한을 변경합니다.

openssl rand -base64 756 > <path-to-keyfile>
chmod 400 <path-to-keyfile>

키파일 사용에 대한 추가 세부 정보 및 요구 사항은 키파일을 참조하세요.

6

복제본 세트 멤버를 호스팅하는 각 서버에 키 파일을 복사합니다. mongod 인스턴스를 실행하는 사용자가 파일의 소유자이며 키 파일에 액세스할 수 있도록 합니다.

USB 드라이브 또는 네트워크 연결 저장 장치와 같이 mongod 인스턴스를 호스팅하는 하드웨어에서 쉽게 분리될 수 있는 저장 매체에 키 파일을 저장하지 마세요.

7

Restart each 보조 or 중재자 member in the replica set, including in the configuration:

You must restart each member one at a time to ensure a majority of members in the replica set remain online.

From a mongosh session that is connected to the secondary or arbiter, issue the db.shutdownServer() against the admin database.

admin = db.getSiblingDB("admin")
admin.shutdownServer()

Specify the following settings in your 구성 파일.

mongodmongos 는 기본적으로 로컬 호스트에 바인딩됩니다. 배포 구성원이 다른 호스트에서 실행되거나 원격 클라이언트를 배포에 연결하려는 경우 net.bindIp 설정을 지정해야 합니다.

security:
keyFile: <path-to-keyfile>
transitionToAuth: true
replication:
replSetName: <replicaSetName>

Specify the --config option with the path to the configuration file when starting the mongod.

mongod --config <path-to-config-file>

구성 파일에 대한 자세한 내용은 구성 옵션을 참조하세요.

Alternatively, you can use the equivalent mongod command-line options (e.g. --transitionToAuth and --keyFile) when starting your mongod. See the mongod reference page for a complete list of options.

배포에 적합한 추가 설정을 포함하세요.

At the end of this step, all secondaries and arbiters should be up and running with security.transitionToAuth set to true.

8

Step down the 기본 member in the replica set and restart the member, including in its configuration:

Connect to the primary using mongosh and step down the primary using the rs.stepDown() method.

rs.stepDown()

Once the primary steps down and the replica set elects a new primary, shut down the old primary mongod.

From a mongosh session that is connected to the old primary, issue the db.shutdownServer() on the admin database.

admin = db.getSiblingDB("admin")
admin.shutdownServer()

Specify the following settings in your 구성 파일.

구성에 필요한 추가 옵션을 포함합니다. 예를 들어 원격 클라이언트가 배포에 연결하거나 배포 멤버가 다른 호스트에서 실행되도록 하려면 net.bindIp 설정을 지정하세요.

security:
keyFile: <path-to-keyfile>
transitionToAuth: true
replication:
replSetName: <replicaSetName>

Start the mongod using the configuration file.

mongod --config <path-to-config-file>

구성 파일에 대한 자세한 내용은 구성 옵션을 참조하세요.

Alternatively, you can use the equivalent mongod command-line options (e.g. --transitionToAuth and --keyFile) when starting your mongod. See the mongod reference page for a complete list of options.

배포에 적합한 추가 설정을 포함하세요.

At the end of this step, all members of the replica set should be up and running with security.transitionToAuth set to true and security.keyFile set to the keyfile path.

9

Restart each 보조 or 중재자 member in the replica set, removing the security.transitionToAuth option on restart. You must do this one at a time to ensure a majority of members in the replica set remain online.

If the majority of replica set members are offline at the same time, the replica set may go into read-only mode.

연결 mongosh to the secondary or arbiter, and issue the db.shutdownServer() on the admin database.

admin = db.getSiblingDB("admin")
admin.shutdownServer()

Restart the mongod, this time without the security.transitionToAuth option but with internal authentication mechanism such as security.keyFile.

Specify the following settings in your 구성 파일.

구성에 필요한 추가 옵션을 포함합니다. 예를 들어 원격 클라이언트가 배포에 연결하거나 배포 멤버가 다른 호스트에서 실행되도록 하려면 net.bindIp 설정을 지정하세요.

security:
keyFile: <path-to-keyfile>
replication:
replSetName: <replicaSetName>

구성 파일을 사용하여 mongod를 시작합니다.

mongod --config <path-to-config-file>

구성 파일에 대한 자세한 내용은 구성 옵션을 참조하세요.

You can also use the equivalent mongod options when starting your mongod. See the mongod reference page for a complete list of options.

배포에 적합한 추가 설정을 포함하세요.

At the end of this step, all secondaries and arbiters should be up and running with internal authentication configured, but without security.transitionToAuth. Clients can only connect to these mongod instances by using the configured client authentication mechanism.

10

Step down the 기본 member in the replica set, then restart it without the security.transitionToAuth option.

중요

At the end of this step, clients not connecting with auth cannot connect to the replica set. Update clients to connect with authentication before completing this step to avoid loss of connectivity.

Connect to the primary using mongosh and step down the primary using the rs.stepDown() method.

rs.stepDown()

Once the primary steps down and the replica set elects a new primary, shut down the old primary mongod.

From a mongosh session that is connected to the old primary, issue the db.shutdownServer() on the admin database.

admin = db.getSiblingDB("admin")
admin.shutdownServer()

Restart the mongod, this time without the security.transitionToAuth option but with the internal authentication mechanism such as security.keyFile.

Specify the following settings in your 구성 파일.

security:
keyFile: <path-to-keyfile>
replication:
replSetName: <replicaSetName>

구성 파일을 사용하여 mongod를 시작합니다.

mongod --config <path-to-config-file>

구성 파일에 대한 자세한 내용은 구성 옵션을 참조하세요.

You can also use the equivalent mongod options when starting your mongod. See the mongod reference page for a complete list of options.

배포에 적합한 추가 설정을 포함하세요.

At the end of this step, all members of the replica set should be up and running with authentication enforced. Clients can only connect to these mongod instances by using the configured client authentication mechanism.

내부 인증 에 X. 를 사용하는 방법에 대한509 자세한 내용은 자체 관리형 MongoDB 통한 멤버십 인증을 위한 X. 인증서 사용을 참조하세요.509

키 파일 내부 인증 에서 X.509 내부 인증 으로 업그레이드 하려면 자체 관리형 MongoDB 키 파일 인증에서 X. 인증으로509 업그레이드를 참조하세요.