자체 관리형 샤딩된 클러스터를 키 파일 인증으로 업데이트
이 페이지의 내용
개요
샤딩된 클러스터에서 액세스 제어를 적용하려면 다음을 구성해야 합니다.
내부 인증을 사용하는 클러스터 구성 요소 간 보안
Security between connecting clients and the cluster using 자체 관리형 배포서버의 역할 기반 액세스 제어.
이 튜토리얼에서는 샤딩된 클러스터의 각 노드가 동일한 내부 인증 메커니즘과 설정을 사용해야 합니다. 즉, 클러스터의 mongos
및 mongod
각각에 내부 인증을 시행해야 합니다.
다음 튜토리얼에서는 키 파일을 사용하여 내부 인증을 활성화합니다.
내부 인증 을 설정하면 사용자 액세스 제어도 강화됩니다. 복제본 세트 에 연결하려면 mongosh
와 같은 클라이언트는 사용자 계정 을 사용해야 합니다. 액세스 제어를 참조하세요.
CloudManager 및 OpsManager
If Cloud Manager or Ops Manager is managing your deployment, internal authentication is automatically enforced.
To configure Access Control on a
managed deployment, see: Configure Access Control for MongoDB Deployments
in the Cloud Manager manual
or in the Ops Manager manual.
고려 사항
중요
변경된 IP 주소로 인해 구성이 업데이트되는 것을 방지하려면 IP 주소 대신 DNS 호스트 이름을 사용하세요. 특히 복제본 세트 구성원 또는 샤딩된 클러스터 구성원을 구성할 때 IP 주소 대신 DNS 호스트 이름을 사용하는 것이 중요합니다.
IP 주소 대신 호스트 이름을 사용하여 스플릿 네트워크 호라이즌 전반에 걸쳐 클러스터를 구성하세요. MongoDB 5.0부터 IP 주소로만 구성된 노드는 스타트업 유효성 검사에 실패하며 시작되지 않습니다.
IP 바인딩
운영 체제
이 자습서에서는 주로 mongod
프로세스를 참조합니다. 윈도우 사용자는 mongod.exe
프로그램을 대신 사용해야 합니다.
키 파일 보안
키파일은 최소한의 보안 형태로 테스트 또는 개발 환경에 가장 적합합니다. 프로덕션 환경에서는 X.509 인증서를 사용하는 것이 좋습니다.
액세스 제어
이 자습서는 admin
데이터베이스에 최소한의 관리 사용자를 만드는 방법만 다룹니다. 사용자 인증에는 기본 SCRAM 인증 메커니즘을 사용합니다. 시도-응답 보안 메커니즘은 테스트 또는 개발 환경에 가장 적합합니다. 프로덕션 환경의 경우 x.509 인증서 또는 자체 관리형 LDAP 프록시 인증(MongoDB Enterprise에서만 사용 가능) 또는 자체 관리형 배포에서 Kerberos 인증(MongoDB Enterprise에서만 사용 가능)을 사용하는 것이 좋습니다.
특정 인증 메커니즘에 대한 사용자 생성에 대한 자세한 내용은 특정 인증 메커니즘 페이지를 참조하세요.
사용자 생성 및 관리에 대한 권장사항은 ➤ 역할 기반 액세스 제어 구성을 참조하세요.
사용자
일반적으로 샤딩된 클러스터에 대한 사용자를 생성하려면 mongos
에 연결하여 샤딩된 클러스터 사용자를 추가합니다.
그러나 일부 유지 관리 작업에는 샤딩된 클러스터의 특정 샤드에 대한 직접 연결이 필요합니다. 이러한 작업을 수행하려면 샤드에 직접 연결하고 샤드 로컬 관리 사용자로 인증해야 합니다.
샤드 로컬 사용자는 특정 샤드 에만 존재하며 샤드별 유지 관리 및 구성에만 사용해야 합니다. 샤드 로컬 사용자로는 mongos
에 연결할 수 없습니다.
자세한 내용은 자체 관리 배포서버의 사용자 보안 문서를 참조하세요.
중단 시간
Upgrading a sharded cluster to enforce access control requires downtime.
시작하기 전에
MongoDB 8.0 부터는 directShardOperations
역할 을 사용하여 샤드 에 대해 직접 명령을 실행해야 하는 유지 관리 작업을 수행할 수 있습니다.
경고
directShardOperations
역할 을 사용하여 명령을 실행하면 클러스터 가 올바르게 작동하지 않고 데이터가 손상될 수 있습니다. directShardOperations
역할 은 유지 관리 목적으로만 사용하거나 MongoDB 지원 의 지침 에 따라 사용하세요. 유지 관리 작업 수행이 완료되면 directShardOperations
역할 사용을 중지합니다.
절차
Enforce Keyfile Internal Authentication on Existing Sharded Cluster Deployment
키 파일을 생성합니다.
키 파일 인증을 사용하면 샤딩된 클러스터의 각 mongod
또는 mongos
인스턴스는 배포에서 다른 멤버를 인증하기 위한 공유 암호로 키 파일의 내용을 사용합니다. 올바른 키 파일을 가진 mongod
또는 mongos
인스턴스만 샤딩된 클러스터에 참여할 수 있습니다.
참고
내부 멤버십 인증을 위한 키파일은 YAML 형식을 사용해 키파일에 여러 키를 허용합니다. YAML 형식은 다음 중 하나를 허용합니다.
단일 키 문자열(이전 버전과 동일)
키 문자열의 순서
YAML 형식은 텍스트 파일 형식을 사용하는 기존의 단일 키 키파일과 호환됩니다.
키 길이는 6~1024자 사이여야 하며 base64 세트의 문자만 포함할 수 있습니다. 샤딩된 클러스터의 모든 멤버는 하나 이상의 공통 키를 공유해야 합니다.
참고
UNIX 시스템에서는 키 파일에 그룹 또는 월드 권한이 없어야 합니다. Windows 시스템에서는 키 파일 권한이 확인되지 않습니다.
원하는 방법을 사용하여 키 파일을 생성할 수 있습니다. 예를 들어 다음 작업에서는 openssl
사용하여 공유 암호로 사용할 복잡한 의사 난수 1024자 문자열을 생성합니다. 그런 다음 chmod
사용하여 파일 소유자에게만 읽기 권한을 제공하도록 파일 권한을 변경합니다.
openssl rand -base64 756 > <path-to-keyfile> chmod 400 <path-to-keyfile>
키파일 사용에 대한 추가 세부 정보 및 요구 사항은 키파일을 참조하세요.
Copy the keyfile to each component in the sharded cluster.
Every server hosting a mongod
or mongos
component
of the sharded cluster must contain a copy of the keyfile.
샤딩된 클러스터 멤버를 호스팅하는 각 서버에 키 파일을 복사합니다. mongod
또는 mongos
인스턴스를 실행하는 사용자가 파일의 소유자이며 키 파일에 액세스할 수 있도록 합니다.
USB 드라이브 또는 네트워크 연결 저장 장치와 같이 mongod
또는 mongos
인스턴스를 호스팅하는 하드웨어에서 쉽게 분리될 수 있는 저장 매체에 키 파일을 저장하지 마세요.
밸런서를 비활성화합니다.
sh.stopBalancer()
The balancer may not stop immediately if a migration is in progress.
The sh.stopBalancer()
method blocks the shell until the
balancer stops.
MongoDB 6.0.3부터 자동 청크 분할이 수행되지 않습니다. 이는 밸런싱 정책 개선 때문입니다. 자동 분할 명령이 여전히 존재하지만 작업을 수행하지 않습니다.
MongoDB 6.0.3 이전 버전에서 sh.stopBalancer()
는 샤딩된 클러스터에 대한 자동 분할도 비활성화합니다.
다음을 사용하세요. sh.getBalancerState()
to verify that the balancer has
stopped.
sh.getBalancerState()
중요
Do not proceed until the balancer has stopped running.
See 샤딩된 클러스터 밸런서 관리 for tutorials on configuring sharded cluster balancer behavior.
Shut down all mongos
instances for the sharded cluster.
연결 mongosh
to each mongos
and shut
them down.
Use the db.shutdownServer()
method on the admin
database
to safely shut down the mongos
:
db.getSiblingDB("admin").shutdownServer()
Repeat until all mongos
instances in the cluster
are offline.
Once this step is complete, all mongos
instances in the cluster
should be offline.
Shut down config server mongod
instances.
연결 mongosh
to each mongod
in the
config server deployment and shut them down.
For replica set config server deployments, shut down the 기본 member last.
Use the db.shutdownServer()
method on the admin
database
to safely shut down the mongod
:
db.getSiblingDB("admin").shutdownServer()
Repeat until all config servers are offline.
Shut down shard replica set mongod
instances.
For each shard replica set, connect mongosh
to each
mongod
member in the replica set and shut them down. Shut down
the 기본 member last.
Use the db.shutdownServer()
method on the admin
database
to safely shut down the mongod
:
db.getSiblingDB("admin").shutdownServer()
Repeat this step for each shard replica set until all mongod
instances in all shard replica sets are offline.
Once this step is complete, the entire sharded cluster should be offline.
Enforce Access Control on the Config Servers.
시작하기 each mongod
in the config server replica set.
Include the keyFile
setting. The keyFile
setting enforces
both 자체 관리형 내부/멤버십 인증 and
자체 관리형 배포서버의 역할 기반 액세스 제어.
구성 파일이나 명령줄을 통해 mongod
설정을 지정할 수 있습니다.
구성 파일
If using a 구성 파일, for a config server replica
set, set security.keyFile
to the keyfile's path,
sharding.clusterRole
to configsvr
, and
replication.replSetName
to the name of the config
server replica set.
security: keyFile: <path-to-keyfile> sharding: clusterRole: configsvr replication: replSetName: <setname> storage: dbpath: <path>
구성에 필요한 추가 옵션을 포함합니다. 예를 들어 원격 클라이언트가 배포에 연결하거나 배포 멤버가 다른 호스트에서 실행되도록 하려면 net.bindIp
설정을 지정하세요.
--config
옵션과 구성 파일 경로를 지정하여
mongod
를 시작합니다.
mongod --config <path-to-config>
명령줄
If using the command line parameters, for a config server replica
set, start the mongod
with the -keyFile
,
--configsvr
, and --replSet
parameters.
mongod --keyFile <path-to-keyfile> --configsvr --replSet <setname> --dbpath <path>
구성에 필요한 추가 옵션을 포함합니다. 예를 들어 원격 클라이언트를 배포에 연결하거나 배포 구성원이 다른 호스트에서 실행되도록 하려면 --bind_ip
를 지정합니다.
For more information on command line options, see the
mongod
reference page.
Make sure to use the original replica set name when restarting each member. You cannot change the name of a replica set.
Enforce Access Control for each Shard in the Sharded Cluster.
keyFile
매개 변수와 함께
mongod
를 실행하면 자체 관리 배포서버에서 자체 관리 내부/멤버십 인증 과 역할 기반 액세스 제어가 모두 적용됩니다.
구성 파일 또는 명령줄을 사용하여 복제본 세트의 각 mongod
를 시작합니다.
구성 파일
If using a 구성 파일, set the
security.keyFile
option to the keyfile's path and the
replication.replSetName
option to the original name
of the replica set.
security: keyFile: <path-to-keyfile> replication: replSetName: <setname> storage: dbPath: <path>
구성에 필요한 추가 옵션을 포함합니다. 예를 들어 원격 클라이언트가 배포에 연결하거나 배포 멤버가 다른 호스트에서 실행되도록 하려면 net.bindIp
설정을 지정하세요.
--config
옵션과 구성 파일 경로를 지정하여
mongod
를 시작합니다.
mongod --config <path-to-config-file>
명령줄
If using the command line parameters, start the mongod
and
specify the --keyFile
and --replSet
parameters.
mongod --keyfile <path-to-keyfile> --replSet <setname> --dbpath <path>
구성에 필요한 추가 옵션을 포함합니다. 예를 들어 원격 클라이언트를 배포에 연결하거나 배포 구성원이 다른 호스트에서 실행되도록 하려면 --bind_ip
를 지정합니다.
For more information on startup parameters,
see the mongod
reference page.
Make sure to use the original replica set name when restarting each member. You cannot change the name of a replica set.
Repeat this step until all shards in the cluster are online.
Create a Shard-Local User Administrator (Optional).
중요
The 자체 관리형 배포서버의 로컬 호스트 예외 allows clients connected over the
localhost interface to create users on a mongod
enforcing access control. After creating the first user,
the 자체 관리형 배포서버의 로컬 호스트 예외 closes.
첫 번째 사용자는 userAdminAnyDatabase
와 같은 다른 사용자를 만들 수 있는 권한이 있어야 합니다. 이렇게 하면 자체 관리형 배포의 Localhost 예외가 종료된 후 추가 사용자를 생성할 수 있습니다.
If at least one user does not have privileges to create users, once the localhost exception closes you may be unable to create or modify users with new privileges, and therefore unable to access certain functions or operations.
For each shard replica set in the cluster, connect
mongosh
to the 기본 member over the
localhost interface. You must run
mongosh
on the same machine as the target
mongod
to use the localhost interface.
Create a user with the userAdminAnyDatabase
role on the admin
database. This user can create
additional users for the shard replica set as necessary.
Creating this user also closes the 자체 관리형 배포서버의 로컬 호스트 예외.
The following example creates the shard-local user fred
on the
admin
database.
중요
시스템 보안을 보장하고 악의적인 액세스를 방지하거나 지연하려면 암호는 임의적이고 길며 복잡해야 합니다.
팁
메서드/명령 호출에서 암호를 직접 지정하는 대신 passwordPrompt()
메서드를 다양한 사용자 인증/관리 메서드/명령과 함께 사용하여 암호를 묻는 메시지를 표시할 수 있습니다. 그러나 이전 버전의 mongo
셸에서와 마찬가지로 비밀번호를 직접 지정할 수도 있습니다.
admin = db.getSiblingDB("admin") admin.createUser( { user: "fred", pwd: passwordPrompt(), // or cleartext password roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } )
Enforce Access Control for the mongos
servers.
keyFile
매개 변수와 함께
mongod
를 실행하면 자체 관리 배포서버에서 자체 관리 내부/멤버십 인증 과 역할 기반 액세스 제어가 모두 적용됩니다.
구성 파일 또는 명령줄을 사용하여 복제본 세트의 각 mongos
를 시작합니다.
구성 파일
If using a 구성 파일, set the
security.keyFile
to the keyfile`s path and the
sharding.configDB
to the replica set name and at least
one member of the replica set in <replSetName>/<host:port>
format.
security: keyFile: <path-to-keyfile> sharding: configDB: <configReplSetName>/cfg1.example.net:27019,cfg2.example.net:27019,...
구성에 필요한 추가 옵션을 포함합니다. 예를 들어 원격 클라이언트가 배포에 연결하거나 배포 멤버가 다른 호스트에서 실행되도록 하려면 net.bindIp
설정을 지정하세요.
--config
옵션과 구성 파일 경로를 지정하여
mongos
를 시작합니다.
mongos --config <path-to-config-file>
명령줄
명령줄 매개 변수를 사용하는 경우 mongos
를 시작하고 --keyFile
및 --configdb
매개 변수를 지정합니다.
mongos --keyFile <path-to-keyfile> --configdb <configReplSetName>/cfg1.example.net:27019,cfg2.example.net:27019,...
구성에 필요한 추가 옵션을 포함합니다. 예를 들어 원격 클라이언트를 배포에 연결하거나 배포 구성원이 다른 호스트에서 실행되도록 하려면 --bind_ip
를 지정합니다.
At this point, the entire sharded cluster is back online and can
communicate internally using the keyfile specified. However, external
programs like mongosh
need to use a correctly
provisioned user in order to read or write to the cluster.
Connect to the mongos
instance over the localhost interface.
localhost 인터페이스를 통해
mongosh
를
mongos
인스턴스 중 하나에 연결합니다. mongos
인스턴스와 동일한 물리적 컴퓨터에서
mongosh
를 실행해야 합니다.
배포를 위해 생성된 사용자가 없기 때문에 로컬 호스트 인터페이스를 사용할 수 있습니다. 첫 번째 사용자 생성 후 localhost 인터페이스는 닫힙니다.
사용자 관리자를 만듭니다.
중요
첫 번째 사용자를 만든 후에는 로컬 호스트 예외를 더 이상 사용할 수 없습니다.
첫 번째 사용자는 userAdminAnyDatabase
와 같은 다른 사용자를 만들 수 있는 권한이 있어야 합니다. 이렇게 하면 자체 관리형 배포의 Localhost 예외가 종료된 후 추가 사용자를 생성할 수 있습니다.
사용자를 생성할 권한이 없는 사용자가 한 명 이상인 경우, 로컬 호스트 예외가 종료되면 사용자를 생성하거나 수정할 수 없으므로 필요한 작업을 수행하지 못할 수 있습니다.
db.createUser()
메서드를 사용하여 사용자를 추가합니다. 사용자는 admin
데이터베이스에서 최소한
userAdminAnyDatabase
역할을 갖고 있어야 합니다.
중요
시스템 보안을 보장하고 악의적인 액세스를 방지하거나 지연하려면 암호는 임의적이고 길며 복잡해야 합니다.
다음 예시에서는 admin
데이터베이스에 사용자 fred
를 생성합니다.
팁
메서드/명령 호출에서 암호를 직접 지정하는 대신 passwordPrompt()
메서드를 다양한 사용자 인증/관리 메서드/명령과 함께 사용하여 암호를 묻는 메시지를 표시할 수 있습니다. 그러나 이전 버전의 mongo
셸에서와 마찬가지로 비밀번호를 직접 지정할 수도 있습니다.
admin = db.getSiblingDB("admin") admin.createUser( { user: "fred", pwd: passwordPrompt(), // or cleartext password roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } )
기본 제공 역할 및 데이터베이스 관리 작업과 관련된 역할의 전체 목록은 데이터베이스 사용자 역할에서 확인하세요.
사용자 관리자로 인증합니다.
db.auth()
를 사용하여 사용자 관리자로 인증해 추가 사용자를 생성합니다.
팁
메서드/명령 호출에서 암호를 직접 지정하는 대신 passwordPrompt()
메서드를 다양한 사용자 인증/관리 메서드/명령과 함께 사용하여 암호를 묻는 메시지를 표시할 수 있습니다. 그러나 이전 버전의 mongo
셸에서와 마찬가지로 비밀번호를 직접 지정할 수도 있습니다.
db.getSiblingDB("admin").auth("fred", passwordPrompt()) // or cleartext password
메시지가 표시되면 비밀번호를 입력합니다.
또는 -u <username>
,
-p <password>
및 --authenticationDatabase "admin"
매개변수를 사용하여 새 mongosh
세션을 대상 복제본 세트 멤버에 연결합니다. 에 연결하려면 자체 관리 배포서버에서 로컬 호스트 예외를
mongos
사용해야 합니다.
mongosh -u "fred" -p --authenticationDatabase "admin"
클러스터 관리를 위한 관리 사용자 생성
The cluster administrator user has the clusterAdmin
role
for the sharded cluster and not the shard-local cluster
administrator.
다음 예시에서는 admin
데이터베이스에 사용자 ravi
를 생성합니다.
중요
시스템 보안을 보장하고 악의적인 액세스를 방지하거나 지연하려면 암호는 임의적이고 길며 복잡해야 합니다.
팁
메서드/명령 호출에서 암호를 직접 지정하는 대신 passwordPrompt()
메서드를 다양한 사용자 인증/관리 메서드/명령과 함께 사용하여 암호를 묻는 메시지를 표시할 수 있습니다. 그러나 이전 버전의 mongo
셸에서와 마찬가지로 비밀번호를 직접 지정할 수도 있습니다.
db.getSiblingDB("admin").createUser( { "user" : "ravi", "pwd" : passwordPrompt(), // or cleartext password roles: [ { "role" : "clusterAdmin", "db" : "admin" } ] } )
복제본 세트 및 샤딩된 클러스터 작업과 관련된 기본 제공 역할의 전체 목록은 클러스터 관리 역할을 참조하세요.
Authenticate as cluster admin.
To perform sharding operations, authenticate as a
clusterAdmin
user with either the
db.auth()
method or a new mongosh
session
with the username
, password
, and authenticationDatabase
parameters.
참고
이는 샤딩된 클러스터의 클러스터 관리자이며, 샤드 로컬 클러스터 관리자가 아닙니다.
Start the balancer.
Start the balancer.
sh.startBalancer()
MongoDB 6.0.3부터 자동 청크 분할이 수행되지 않습니다. 이는 밸런싱 정책 개선 때문입니다. 자동 분할 명령이 여전히 존재하지만 작업을 수행하지 않습니다.
MongoDB 6.0.3 이전 버전에서 sh.startBalancer()
는 샤딩된 클러스터에 대한 자동 분할도 활성화합니다.
Use the sh.getBalancerState()
to verify the balancer has started.
See 샤딩된 클러스터 밸런서 관리 for tutorials on the sharded cluster balancer.
추가 사용자 만들기(선택 사항).
클라이언트가 샤딩된 클러스터 에 연결하고 액세스 할 수 있도록 사용자를 생성합니다. 및 와 read
같은 사용 가능한 내장 제공
readWrite
역할은 데이터베이스 사용자 역할 을 참조하세요. 추가 관리 사용자가 필요할 수도 있습니다. 사용자에 대한 자세한 내용 은 자체 관리 배포서버의 사용자를 참조하세요.
추가 사용자를 생성하려면 userAdminAnyDatabase
또는 userAdmin
역할을 가진 사용자로 인증해야 합니다.
X.509 내부 인증
내부 인증에 x.509를 사용하는 방법에 대한 자세한 내용은 자체 관리형 MongoDB의 멤버십 인증에 x.509 인증서 사용을 참조하세요.
키 파일 내부 인증에서 X.509 내부 인증으로 업그레이드 하려면 자체 관리형 MongoDB 키 파일 인증에서 X.509 인증으로 업그레이드를 참조하세요.
다음도 참조하세요.