I'm unable to connect to the MongoDB with Tls Allow Invalid Certificate option with the Rust driver.
let uri = "MongoDB://user:pwd#host:port/database_name?tls=true&tlsAllowInvalidCertificates=true"
let client_options = ClientOptions::parse(uri)?;
let client = Client::with_options(client_options).expect("");
let db = client.database("database_name");
I can see that the client_options has correctly parsed the uri with:
tls: Some(Enabled(TlsOptions{allow_invalid_certificates: Some(true) ...}))
However I get the following non-recoverable error:
Error: invalid peer certificate contents: invalid peer certificate: UnsupportedCertVersion
Server MongoDB: 4.2.18
Client Mongosh: 1.5.0
Rust Driver: 2.3.0
P.s. I'm able to connect to MongoDB by the mongosh shell with the following command:
mongosh server_dns:server_port/database_name -u username -p --tls --tlsAllowInvalidCertificates
(It's also possible to connect with described options with pymongo)
What solved the issue was to add the feature "openssl-tls" to Cargo.toml
[dependencies.mongodb]
version = "2.3.0"
default-features = false
features = ["openssl-tls"]
Related
I'm working on JDK8 and using mongo-java-driver(v3.5.0) to connect MongoDB(v3.6.3).
I've enabled SSL by following this article. I don't have /etc/mongod.conf file, instead I've /etc/mongodb.conf file; so I've updated the SSL settings in that file:
# SSL options
# Enable SSL on normal ports
sslOnNormalPorts = true
# SSL Key file and password
sslPEMKeyFile = /etc/ssl/mongodb.pem
sslPEMKeyPassword = PASSWORD
I'm able to access mongo via mongo shell using:
mongo --ssl --sslCAFile /etc/ssl/rootCA.pem --sslPEMKeyFile /etc/ssl/mongodb.pem --host localhost
I want to connect MongoDB using Java driver. I initially tried the following JDBC connection string:
mongodb://USER:PASSWORD#localhost:27017/?ssl=true&sslAllowInvalidCertificates=true&sslPEMKeyFile=/etc/ssl/mongodb.pem
but as per documentation, there are no such options available. Also, I get error:
The connection string contains an invalid host 'localhost:27017/?ssl=true&sslAllowInvalidCertificates=true&sslPEMKeyFile=/etc/ssl'. The port '27017/?ssl=true&sslAllowInvalidCertificates=true&sslPEMKeyFile=/etc/ssl' is not a valid, it must be an integer between 0 and 65535
And when I try with the following connection string:
url=mongodb://USER:PASSWORD#localhost:27017/?ssl=true
I get following error:
com.mongodb.MongoSocketWriteException: Exception sending message
at com.mongodb.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:445) ~[mongo-java-driver-3.5.0.jar:?]
.
...
Caused by: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
.
...
Here's the code that I've used:
String url = "mongodb://USER:PASSWORD#localhost/?authSource=admin&ssl=true"
MongoClientURI connectionURI = new MongoClientURI(url)
mongoClient = new MongoClient(connectionURI)
Could someone help me with what JDBC connection string I need to configure to connect successfully. Thank you.
I have a default Teiid 12.2 installation on RHEL 8.
Now I'm trying to configure an ODBC connection that would be used by PHP.
This always results in an error "[unixODBC]received invalid response to GSSAPI negotiation: R"
This is my ODBC configuration
[TEIID12]
Driver = PostgreSQL
Trace = No
Description = PostgreSQL Data Source
Servername = servername
Port = 35432
Protocol = 7.4-1
UserName = someusername
Password = xxxx
Database = vdb
ReadOnly = no
ServerType = Postgres
ConnSettings =
UseServerSidePrepare=1
Debug=0
Fetch = 10000
A regular isql command also fails with the same information
isql -v TEIID12 someusername xxxx
Results in:
[08001][unixODBC]received invalid response to GSSAPI negotiation: R
[ISQL]ERROR: Could not SQLConnect
Additional information:
The same configuration used to work on a different Linux Distro (Ubuntu) but on this machine, kerberos was not configured. So I assume that this is influincing some sort of "preference".
The standalone-teiid.xml configuration has <ssl mode="disabled" /> for the odbc transport. And yet the GSS API errors occur.
In combination with the later, is it possible that the postgresql ODBC driver is requiring GSS to be used? Is there a setting in odbc.ini where this can be disabled?
On Ubuntu the driver version was 10.01, on RHEL it is 10.03
A solution that worked was to set the environment variable PGGSSENCMODE=disable in /etc/profile.
I have symfony 3.4 and used Doctrine MongoDB Bundle
"doctrine/mongodb-odm": "1.1",
"doctrine/mongodb-odm-bundle": "3.4",
I have locally installed mongo and used with below configuration working fine.
mongodb_server: 'mongodb://mongo:27017'
mongodb_collection: test
doctrine_mongodb:
connections:
default:
server: "%mongodb_server%"
options: {}
default_database: "%mongodb_collection%"
but now i try to access mongodb atlas cluster at this time i have getting below error.
MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known
i have trying to access using actual credentials as demo given
mongodb_server: 'mongodb+srv://<username>:<password>#clustertesting.osnmb.mongodb.net/<dbname>?retryWrites=true&w=majority'
mongodb_collection: test
I'm trying to write a MongoDB script as part of automating customer data deletion in accordance with GDPR (current process is manual), but I'm having problems authenticating from the script. Authentication works perfectly from the command line, but not from a script.
I'm not certain which mechanism I should use, but since there are only two that don't require external files (which I don't use in the command line), I figured I'd try both.
When running from the command line, this is the command I use:
$ mongo -u [adminusr] -p '[adminpwd]' --authenticationDatabase admin
This script:
var host = '127.0.0.1';
var port = '27017';
var user = 'admin';
var pwd = 'secrets';
var authDB = 'admin';
try {
var conn = new Mongo('mongodb://' + host + ':' + port + '/' + authDB);
conn.auth({
user: user,
pwd: pwd,
mechanism: 'SCRAM-SHA-1',
digest: false
});
// deletion commands...
} catch (e) {
print(e);
}
gives this error:
$ mongo erasure.js
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Error: Authentication failed.
Changing the auth part to this:
conn.auth({
user: user,
pwd: pwd,
mechanism: 'MONGODB-CR',
db: authDB,
digest: false
});
gives me this error:
$ mongo erasure.js
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.10
Error: auth failed
The official documentation on writing MongoDB scripts and authentication is also very scarce on how to do this.
How can I get the auth to work?
Thanks.
I tried to much posibilities that I found searching for this error without success.
I can connect to my mongo with the CLI typing mongo --port myPort -u myUser ...
But I need to connect my app (in the same host) by URI.
This is what I get:
mongo mongodb://username:password#localhost:myPort/myDb
MongoDB shell version: 2.6.10
connecting to: mongodb://username:password#localhost:myPort/myDb
2017-05-19T23:34:33.568+0200 Assertion failure _setName.size() src/mongo/client/dbclientinterface.h 231
2017-05-19T23:34:33.569+0200 0x6b75c9 0x659e9f 0x636a32 0x5013b8 0x4fa7f1 0x6006fd 0x5eb869 0x7fdcdff35d76 0x1ebf47506362
mongo(_ZN5mongo15printStackTraceERSo+0x39) [0x6b75c9]
mongo(_ZN5mongo10logContextEPKc+0x21f) [0x659e9f]
mongo(_ZN5mongo12verifyFailedEPKcS1_j+0x142) [0x636a32]
mongo(_ZN5mongo16ConnectionStringC1ENS0_14ConnectionTypeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES9_+0x208) [0x5013b8]
mongo(_ZN5mongo16ConnectionString5parseERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS6_+0x201) [0x4fa7f1]
mongo(_ZN5mongo17mongoConsExternalEPNS_7V8ScopeERKN2v89ArgumentsE+0x11d) [0x6006fd]
mongo(_ZN5mongo7V8Scope10v8CallbackERKN2v89ArgumentsE+0xa9) [0x5eb869]
/usr/lib/libv8.so.3.14.5(+0x99d76) [0x7fdcdff35d76]
[0x1ebf47506362]
2017-05-19T23:34:33.570+0200 Error: assertion src/mongo/client/dbclientinterface.h:231 at src/mongo/shell/mongo.js:148
exception: connect failed
Any idea? :\ Thanks
Solved upgrading mongod from 2.6 to 3.0.15
If you don't want to upgrade to a newer version of MongoDB you can also just drop the mongodb:// from the beginning. For example change:
mongo mongodb://username:password#localhost:myPort/myDb
to:
mongo username:password#localhost:myPort/myDb
Ref: https://jira.mongodb.org/browse/SERVER-15739?focusedCommentId=1000536&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-1000536