X.509 인증서를 사용하여 자체 관리 배포서버에서 클라이언트 인증하기
The following procedure sets up X.509 certificate authentication for
client authentication on a standalone mongod
instance.
This is also known as Mutual TLS or mTLS.
To use X.509 authentication for replica sets or sharded clusters, see 자체 관리형 MongoDB의 멤버십 인증에 x.509 인증서 사용.
전제 조건
TLS/SSL, PKI(공개 키 인프라) 인증서, 특히 X.509 인증서 및 인증 기관에 대한 전체 설명은 이 문서 의 범위를 벗어납니다. 이 튜토리얼에서는 TLS/SSL에 대한 사전 지식이 있고 유효한 X.509 인증서에 액세스 가정합니다.
Certificate Authority
프로덕션 용도의 경우 MongoDB deployment는 동일한 인증 기관에서 생성하고 서명한 유효한 인증서를 사용해야 합니다. 귀하 또는 귀하의 조직은 독립적인 인증 기관을 생성 및 유지 관리하거나 타사 TLS 공급업체에서 생성한 인증서를 사용할 수 있습니다. 인증서를 얻고 관리하는 것은 이 문서의 범위를 벗어납니다.
X.509 인증 사용하려면 --tlsCertificateSelector
또는 --net.tls.certificateSelector
를 사용하지 않는 한 --tlsCAFile
또는 net.tls.CAFile
를 지정해야 합니다.
Client X.509 Certificate
You must have valid X.509 certificates. The client X.509 certificates must meet the client certificate requirements.
--tlsAllowInvalidCertificates
또는 net.tls.allowInvalidCertificates: true
를 지정하는 경우 잘못된 인증서로 TLS 연결을 설정할 수는 있지만 인증에는 충분하지 않습니다.
절차
Deploy with X.509 Authentication
You can configure a mongod
instance for X.509
authentication from the command-line.
To configure a standalone mongod
instance, run
the following command:
mongod --tlsMode requireTLS \ --tlsCertificateKeyFile <path to TLS/SSL certificate and key PEM file> \ --tlsCAFile <path to root CA PEM file> --bind_ip <hostnames>
Include additional options as required for your configuration.
The X.509 configuration requires:
옵션 | 참고 사항 |
---|---|
| |
Specify the instance's X.509 certificate to present to clients. | |
Specify the Certificate Authority file to verify the certificates presented to the instance. |
You can configure a mongod
for X.509
authentication in the 구성 파일.
To configure a standalone mongod
instance, add
the following configuration options to your configuration
file:
net: tls: mode: requireTLS certificateKeyFile: <path to TLS/SSL certificate and key PEM file> CAFile: <path to root CA PEM file>
Include additional options as required for your configuration.
The X.509 configuration requires:
옵션 | 참고 사항 |
---|---|
| |
Specify the instance's X.509 certificate to present to clients. | |
Specify the Certificate Authority file to verify the certificates presented to the instance. |
To set up X.509 authentication for replica sets or sharded clusters, see 자체 관리형 MongoDB의 멤버십 인증에 x.509 인증서 사용.
Add X.509 Certificate subject
as a User
To authenticate with a client certificate, you must first add the value
of the subject
from the client certificate as a MongoDB user to the
$external
database. Each unique X.509 client certificate
corresponds to a single MongoDB user. You cannot use a single client
certificate to authenticate more than one MongoDB user.
참고
Username Requirements
$external
인증 사용자(Kerberos, LDAP 또는 X.509 사용자)와 함께 클라이언트 세션 및 인과적 일관성 보장을 사용하려면 사용자 이름이 10KB보다 클 수 없습니다.
The RDNs in the
subject
string must be compatible with the RFC2253 standard.
You can retrieve the
RFC2253
formattedsubject
from the client certificate with the following command:openssl x509 -in <pathToClientPEM> -inform PEM -subject -nameopt RFC2253 The command returns the
subject
string and the certificate:subject= CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry -----BEGIN CERTIFICATE----- # ... -----END CERTIFICATE----- Add the
RFC2253
compliant value of thesubject
as a user. Omit spaces as needed.The following example adds a user and grants the user
readWrite
role in thetest
database and theuserAdminAnyDatabase
role:db.getSiblingDB("$external").runCommand( { createUser: "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry", roles: [ { role: "readWrite", db: "test" }, { role: "userAdminAnyDatabase", db: "admin" } ], writeConcern: { w: "majority" , wtimeout: 5000 } } ) See 자체 관리 배포에서 사용자 및 역할 관리 for details on adding a user with roles.
Authenticate with a X.509 Certificate
After you have added the X.509 client certificate subject as a corresponding MongoDB user, you can authenticate with the client certificate:
To authenticate during connection, run the following command:
mongosh --tls --tlsCertificateKeyFile <path to client PEM file> \ --tlsCAFile <path to root CA PEM file> \ --authenticationDatabase '$external' \ --authenticationMechanism MONGODB-X509
옵션 | 참고 사항 |
---|---|
Specify the client's X.509 file. | |
Specify the Certificate Authority file to verify the
certificate presented by the | |
| |
|
You can connect without authentication and use the
db.auth()
method to authenticate after
connection.
For example, if using mongosh
,
mongosh --tls --tlsCertificateKeyFile <path to client PEM file> \ --tlsCAFile <path to root CA PEM file> 옵션참고 사항Specify the client's X.509 file.
To authenticate, use the
db.auth()
method in the$external
database. For themechanism
field, specify"MONGODB-X509"
.db.getSiblingDB("$external").auth( { mechanism: "MONGODB-X509" } )
다음 단계
To use X.509 authentication for replica sets or sharded clusters, see 자체 관리형 MongoDB의 멤버십 인증에 x.509 인증서 사용.