2017-07-20 11 views
1

背景 完全なssl検証を有効にして、同じ方法でローカルでmongoを実行しようとしています。 Mongoは証明書が自己署名されていると不平を言っていますが、検証するためにルート証明書として扱うべきだと思うca.crtファイルを指定しています。それが合理的であれば、私のmongo configかcert生成が正しくないと思います。私は、次のdev envをmongo + sslで実行しています

#!/bin/sh 

# Generate self signed root CA cert 
openssl req -nodes -x509 -newkey rsa:2048 -keyout ca.key -out ca.crt -subj "/[email protected]" 


# Generate server cert to be signed 
openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj "/[email protected]" 

# Sign the server cert 
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt 

# Create server PEM file 
cat server.key server.crt > server.pem 


# Generate client cert to be signed 
openssl req -nodes -newkey rsa:2048 -keyout client.key -out client.csr -subj "/[email protected]" 

# Sign the client cert 
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAserial ca.srl -out client.crt 

# Create client PEM file 
cat client.key client.crt > client.pem 

モンゴDBの設定 私はその後、(ドッカ内)で実行しているモンゴの設定を実行しているSSLのものを作成するには

SSLキー/本命/ PEM 以下の通りです。 (/ data/mongoは上に生成された場所です)。

をモンゴへの接続
mongo --config config/location 

経由

net: 
    port: 27017 
    ssl: 
    mode: requireSSL 
    CAFile: /data/mongo/ca.crt 
    PEMKeyFile: /data/mongo/server.pem 
    allowInvalidHostnames: true 
setParameter: 
    enableLocalhostAuthBypass: true 

と実行している私は、次のようにMongoのコマンドラインを使用してサーバーに接続しよう。

mongo --ssl --sslPEMKeyFile /data/mongo/client.pem --sslCAFile /data/mongo/ca.crt 

そして

MongoDB shell version: 3.2.14 
connecting to: test 
2017-07-19T20:12:31.456+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60516 #1 (1 connection now open) 
2017-07-19T20:12:31.461+0000 E NETWORK [conn1] SSL peer certificate validation failed: self signed certificate 
2017-07-19T20:12:31.461+0000 I NETWORK [conn1] end connection 127.0.0.1:60516 (0 connections now open) 
2017-07-19T20:12:31.461+0000 E NETWORK [thread1] SSL peer certificate validation failed: self signed certificate 
2017-07-19T20:12:31.461+0000 E QUERY [thread1] Error: socket exception [CONNECT_ERROR] for SSL peer certificate validation failed: self signed certificate : 
[email protected]/mongo/shell/mongo.js:229:14 
@(connect):1:6 

exception: connect failed 
+1

これはちょっと変です。 MongoDBのドキュメントでは、MongoDBが自己署名証明書のホスト名を検証しないことを示しています。* "[[自己署名証明書を使用する場合]]サーバIDの検証は行われません。マニュアルの[mongodとmongosのTLS/SSLの設定](https://docs.mongodb.com/manual/tutorial/configure-ssl/)を参照してください。 – jww

+1

*** 'CN = www.example.com' ***はおそらく間違っています。ホスト名は常に* SAN *に入ります。 * CN *内に存在する場合は、* SAN *にも存在する必要があります(この場合は2回リストする必要があります)。詳細なルールと理由については、[証明機関との証明書署名要求の署名方法](http://stackoverflow.com/a/21340898/608639)および[opensslによる自己署名証明書の作成方法]( http://stackoverflow.com/q/10175812/608639)また、自己署名証明書を適切なトラストストアに配置する必要があります。 – jww

+0

私はこれを行う方法を完全に理解しているとは思わない?それはsubj argsのそれぞれに入っていますか? – jimmiebtlr

答えて

0

がそれを手に入れた次のような出力を得ます!基本的には、件名にもっと多くのデータが必要でした。あるいは、CAのROOTCAが必要でした。なぜ評価されるべきかについてコメントできる人。誰もが同様のトラブルを抱えている場合

回答が見つかった/

https://www.mongodb.com/blog/post/secure-mongodb-with-x-509-authentication https://raw.githubusercontent.com/tjworks/mongoscripts/master/x509/setup-x509.sh

から取られた鉱山とほぼ同じスタック交換券もで見つけることができます

#!/bin/sh 
prefix="/C=CN/ST=GD/L=city/O=company" 

# Generate self signed root CA cert 
openssl req -nodes -x509 -newkey rsa:2048 -keyout ca.key -out ca.crt -subj "${prefix}/CN=ROOTCA" 


# Generate server cert to be signed 
openssl req -nodes -newkey rsa:2048 -keyout server.key -out server.csr -subj "${prefix}/CN=127.0.0.1" 

# Sign the server cert 
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt 

# Create server PEM file 
cat server.key server.crt > server.pem 


# Generate client cert to be signed 
openssl req -nodes -newkey rsa:2048 -keyout client.key -out client.csr -subj "${prefix}/CN=127.0.0.1" 

# Sign the client cert 
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAserial ca.srl -out client.crt 

# Create client PEM file 
cat client.key client.crt > client.pem 

いくつかの関連リソース

https://dba.stackexchange.com/questions/151251/mongodb-error-self-signed-certificate-in-certificate-chain?newreg=20bca440682842c085a8764dd7c91e96

関連する問題