You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cat /proc/version
Linux version 5.15.0-1023-aws (buildd@bos02-arm64-076) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.38) #27-Ubuntu SMP Thu Oct 20 16:46:19 UTC 2022
lsb_release -r
Release: 22.04
mongosh --tls --host localhost --tlsCertificateKeyFile /etc/mongo-certs/mongo-rwadmin-user-cert-and-key.pem --tlsCAFile /etc/mongo-certs/mongo-ca-cert.pem --authenticationDatabase '$external' --authenticationMechanism MONGODB-X509 --eval "db.version()"
Current Mongosh Log ID: 6387f46f68b9c93944b9c978
Connecting to: mongodb://localhost:27017/?directConnection=true&serverSelectionTimeoutMS=2000&tls=true&tlsCertificateKeyFile=%2Fetc%2Fmongo-certs%2Fmongo-rwadmin-user-cert-and-key.pem&tlsCAFile=%2Fetc%2Fmongo-certs%2Fmongo-ca-cert.pem&authSource=%24external&authMechanism=MONGODB-X509&appName=mongosh+1.6.0
Using MongoDB: 6.0.3
Using Mongosh: 1.6.0
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2022-11-30T17:58:03.060+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
------
6.0.3
Controller host:
Macos 13.0.1 (22A400) arm64
STEPS TO REPRODUCE
#!/usr/bin/env ansible-playbook
- name: Check replica set status for all replica set nodes are in a healthy statehosts: mongogather_facts: notasks:
- name: check mongo replica set statebecome: truecommunity.mongodb.mongodb_status:
login_host: localhostreplica_set: rs0auth_mechanism: "MONGODB-X509"tls: truetlsCAFile: /etc/mongo-certs/mongo-ca-cert.pemtlsCertificateKeyFile: /etc/mongo-certs/mongo-rwadmin-user-cert-and-key.pemlogin_database: "$external"# this tlsAllowInvalidHostnames option is needed or the ansible community mongo ansible collection wont work with x509# must be a defect, works correctly with mongosh#connection_options:# - "tlsAllowInvalidHostnames=true"
# mongosh --tls --host localhost --tlsCertificateKeyFile /etc/mongo-certs/mongo-rwadmin-user-cert-and-key.pem --tlsCAFile /etc/mongo-certs/mongo-ca-cert.pem --authenticationDatabase '$external' --authenticationMechanism MONGODB-X509 admin
Current Mongosh Log ID: 6387f52f3e68e0f7ec7a7caa
Connecting to: mongodb://localhost:27017/admin?directConnection=true&serverSelectionTimeoutMS=2000&tls=true&tlsCertificateKeyFile=%2Fetc%2Fmongo-certs%2Fmongo-rwadmin-user-cert-and-key.pem&tlsCAFile=%2Fetc%2Fmongo-certs%2Fmongo-ca-cert.pem&authSource=%24external&authMechanism=MONGODB-X509&appName=mongosh+1.6.0
Using MongoDB: 6.0.3
Using Mongosh: 1.6.0
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2022-11-30T17:58:03.060+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
------
rs0 [direct: primary] admin> db.getSiblingDB("$external").auth({mechanism: "MONGODB-X509", user: "[email protected],CN=rwadmin,OU=mongo-user.dw.dev.stealthsoft.io,O=StealthMode Inc,L=Austin,ST=Texas,C=US"})
{ ok: 1 }
rs0 [direct: primary] admin> db.getSiblingDB("$external").getUsers();
{
users: [
{
_id: '[email protected],CN=rwadmin,OU=mongo-user.dw.dev.stealthsoft.io,O=StealthMode Inc,L=Austin,ST=Texas,C=US',
userId: new UUID("8599dc7b-8eb6-42c2-82ec-d6babd85c590"),
user: '[email protected],CN=rwadmin,OU=mongo-user.dw.dev.stealthsoft.io,O=StealthMode Inc,L=Austin,ST=Texas,C=US',
db: '$external',
roles: [ { role: 'root', db: 'admin' } ],
mechanisms: [ 'external' ]
},
{
_id: '[email protected],CN=rwapp,OU=mongo-user.dw.dev.stealthsoft.io,O=StealthMode Inc,L=Austin,ST=Texas,C=US',
userId: new UUID("f64f84c2-a6d4-441b-b1d8-7d236851c471"),
user: '[email protected],CN=rwapp,OU=mongo-user.dw.dev.stealthsoft.io,O=StealthMode Inc,L=Austin,ST=Texas,C=US',
db: '$external',
roles: [ { role: 'readWrite', db: 'rwsecure' } ],
mechanisms: [ 'external' ]
}
],
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1669854524, i: 1 }),
signature: {
hash: Binary(Buffer.from("0398d62ed09262dce376cd4aac40801db40a7445", "hex"), 0),
keyId: Long("7171583554449571845")
}
},
operationTime: Timestamp({ t: 1669854524, i: 1 })
}
rs0 [direct: primary] admin>
./mongo-status.yml
PLAY [Check replica set status for all replica set nodes are in a healthy state]
TASK [check mongo replica set state]
fatal: [mgo-wj-a]: FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"msg": "Unable to determine if auth is enabled: Traceback (most recent call last):\n File \"/tmp/ansible_community.mongodb.mongodb_status_payload_qsf9hv51/ansible_community.mongodb.mongodb_status_payload.zip/ansible_collections/community/mongodb/plugins/module_utils/mongodb_common.py\", line 279, in is_auth_enabled\n myclient['admin'].command('listDatabases', 1.0)\n File \"/usr/local/lib/python3.10/dist-packages/pymongo/_csot.py\", line 105, in csot_wrapper\n return func(self, *args, **kwargs)\n File \"/usr/local/lib/python3.10/dist-packages/pymongo/database.py\", line 805, in command\n with self.__client._socket_for_reads(read_preference, session) as (\n File \"/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py\", line 1296, in _socket_for_reads\n server = self._select_server(read_preference, session)\n File \"/usr/local/lib/python3.10/dist-packages/pymongo/mongo_client.py\", line 1257, in _select_server\n server = topology.select_server(server_selector)\n File \"/usr/local/lib/python3.10/dist-packages/pymongo/topology.py\", line 272, in select_server\n server = self._select_server(selector, server_selection_timeout, address)\n File \"/usr/local/lib/python3.10/dist-packages/pymongo/topology.py\", line 261, in _select_server\n servers = self.select_servers(selector, server_selection_timeout, address)\n File \"/usr/local/lib/python3.10/dist-packages/pymongo/topology.py\", line 223, in select_servers\n server_descriptions = self._select_servers_loop(selector, server_timeout, address)\n File \"/usr/local/lib/python3.10/dist-packages/pymongo/topology.py\", line 238, in _select_servers_loop\n raise ServerSelectionTimeoutError(\npymongo.errors.ServerSelectionTimeoutError: not enough values to unpack (expected 2, got 1), Timeout: 30s, Topology Description: <TopologyDescription id: 6387f1fed957c5ccc26eada3, topology_type: Single, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=ValueError('not enough values to unpack (expected 2, got 1)')>]>\n"
}
The text was updated successfully, but these errors were encountered:
Thank you for the very detailed report. Can you also tell us how you generate your certs? Does it work if you use the hostname, i.e. mgo-wj-b.dw.dev.stealthsoft.io?
@fischerscode Have you experienced any issues around this?
Even if it is not the best solution, I overcame this by adding localhost into the list of SAN(s) in the csr.
To say it in openssl words the outcome is the following: openssl req -new -newkey rsa:2048 -nodes -keyout replica.key -out replica.csr -addext "extendedKeyUsage = serverAuth, clientAuth" -addext "subjectAltName = DNS:<node1-fqdn>, DNS:<node2-fqdn>, DNS:<node3-fqdn>, DNS:localhost.
SUMMARY
x509 auth always fails unless:
connection_options: - tlsAllowInvalidHostnames=true
ISSUE TYPE
COMPONENT NAME
x509 auth handling with pymongo
ANSIBLE VERSION
From mysql replica set primary node:
From controller host:
Pymongo version on replica set master node
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
mysql replica set primary node:
Controller host:
Macos 13.0.1 (22A400) arm64
STEPS TO REPRODUCE
EXPECTED RESULTS
It should work like mongosh
ACTUAL RESULTS
It fails unless I include these lines in the playbook yaml
The text was updated successfully, but these errors were encountered: