Skip to content

Commit 9b5cd34

Browse files
committed
PHPC-144: MO first-user changes
MO now creates an initial user that collides with the user and certificate we used for this. MO really needs to generate a different internal user as most people will do as we did - take the user+cert from mongo jstests - rather then mucking around and create the chain ourself. To work around this, we create a bogus user (to trigger MO to create its user) but use the internal MO user as it is the one we want
1 parent 17e4f3e commit 9b5cd34

File tree

3 files changed

+5
-66
lines changed

3 files changed

+5
-66
lines changed

scripts/presets/standalone-x509.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
{
22
"name": "mongod",
33
"id" : "STANDALONE-X509",
4-
"auth_key": "secret",
5-
"login": "root",
6-
"password": "toor",
4+
"authSource": "$external",
5+
"login": "C=US,ST=California,L=Palo Alto,O=MongoDB,OU=phongo,CN=localhost",
76
"procParams": {
87
"dbpath": "/tmp/standalone-x509/",
98
"ipv6": true,
109
"logappend": true,
1110
"logpath": "/tmp/standalone-x509/m.log",
1211
"journal": true,
1312
"port": 2300,
14-
"setParameter": {"enableTestCommands": 1}
13+
"setParameter": {"enableTestCommands": 1, "authenticationMechanisms": "MONGODB-X509"}
1514
},
1615
"sslParams": {
17-
"clusterAuthMode": "x509",
1816
"sslMode": "requireSSL",
1917
"sslCAFile": "/phongo/scripts/ssl/ca.pem",
2018
"sslPEMKeyFile": "/phongo/scripts/ssl/server.pem",

tests/connect/standalone-x509-0001.phpt

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $opts = array(
1717
"cafile" => $SSL_DIR . "/ca.pem", /* Defaults to openssl.cafile */
1818
"capath" => $SSL_DIR, /* Defaults to openssl.capath */
1919
"local_cert" => $SSL_DIR . "/client.pem",
20-
"passphrase" => "Very secretive client.pem passphrase",
20+
"passphrase" => "qwerty",
2121
"CN_match" => "server",
2222
"verify_depth" => 5,
2323
"ciphers" => "HIGH:!EXPORT:!aNULL@STRENGTH",
@@ -30,28 +30,9 @@ $opts = array(
3030
);
3131
$context = stream_context_create($opts);
3232

33-
$parsed = parse_url(MONGODB_STANDALONE_X509_URI);
34-
$adminuser = "root";
35-
$adminpass = "toor";
36-
$dsn = sprintf("mongodb://%s:%s@%s:%d/admin?ssl=true", $adminuser, $adminpass, $parsed["host"], $parsed["port"]);
37-
$adminmanager = new MongoDB\Driver\Manager($dsn, array(), array("context" => $context));
38-
3933
$certusername = "C=US,ST=New York,L=New York City,O=MongoDB,OU=KernelUser,CN=client";
4034

4135

42-
$cmd = array(
43-
"createUser" => $certusername,
44-
"roles" => [["role" => "readWrite", "db" => DATABASE_NAME]],
45-
);
46-
47-
try {
48-
$command = new MongoDB\Driver\Command($cmd);
49-
$result = $adminmanager->executeCommand('$external', $command);
50-
echo "User Created\n";
51-
} catch(Exception $e) {
52-
echo get_class($e), ": ", $e->getMessage(), "\n";
53-
}
54-
5536
try {
5637
$parsed = parse_url(MONGODB_STANDALONE_X509_URI);
5738
$dsn = sprintf("mongodb://%s@%s:%d/%s?ssl=true&authMechanism=MONGODB-X509", $certusername, $parsed["host"], $parsed["port"], DATABASE_NAME);
@@ -72,20 +53,10 @@ try {
7253
echo get_class($e), ": ", $e->getMessage(), "\n";
7354
}
7455

75-
try {
76-
$command = new MongoDB\Driver\Command(array("dropUser" => $certusername));
77-
$result = $adminmanager->executeCommand('$external', $command);
78-
echo "User dropped\n";
79-
} catch(Exception $e) {
80-
echo get_class($e), ": ", $e->getMessage(), "\n";
81-
}
82-
8356

8457
?>
8558
===DONE===
8659
<?php exit(0); ?>
8760
--EXPECTF--
88-
User Created
8961
string(9) "important"
90-
User dropped
9162
===DONE===

tests/connect/standalone-x509-0002.phpt

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $opts = array(
1717
"cafile" => $SSL_DIR . "/ca.pem", /* Defaults to openssl.cafile */
1818
"capath" => $SSL_DIR, /* Defaults to openssl.capath */
1919
"local_cert" => $SSL_DIR . "/client.pem",
20-
"passphrase" => "Very secretive client.pem passphrase",
20+
"passphrase" => "qwerty",
2121
"CN_match" => "server",
2222
"verify_depth" => 5,
2323
"ciphers" => "HIGH:!EXPORT:!aNULL@STRENGTH",
@@ -30,28 +30,9 @@ $opts = array(
3030
);
3131
$context = stream_context_create($opts);
3232

33-
$parsed = parse_url(MONGODB_STANDALONE_X509_URI);
34-
$adminuser = "root";
35-
$adminpass = "toor";
36-
$dsn = sprintf("mongodb://%s:%s@%s:%d/admin?ssl=true", $adminuser, $adminpass, $parsed["host"], $parsed["port"]);
37-
$adminmanager = new MongoDB\Driver\Manager($dsn, array(), array("context" => $context));
38-
3933
$certusername = "C=US,ST=New York,L=New York City,O=MongoDB,OU=KernelUser,CN=client";
4034

4135

42-
$cmd = array(
43-
"createUser" => $certusername,
44-
"roles" => [["role" => "readWrite", "db" => DATABASE_NAME]],
45-
);
46-
47-
try {
48-
$command = new MongoDB\Driver\Command($cmd);
49-
$result = $adminmanager->executeCommand('$external', $command);
50-
echo "User Created\n";
51-
} catch(Exception $e) {
52-
echo get_class($e), ": ", $e->getMessage(), "\n";
53-
}
54-
5536
try {
5637
/* mongoc will pull the username of the certificate */
5738
$parsed = parse_url(MONGODB_STANDALONE_X509_URI);
@@ -73,20 +54,9 @@ try {
7354
echo get_class($e), ": ", $e->getMessage(), "\n";
7455
}
7556

76-
try {
77-
$command = new MongoDB\Driver\Command(array("dropUser" => $certusername));
78-
$result = $adminmanager->executeCommand('$external', $command);
79-
echo "User dropped\n";
80-
} catch(Exception $e) {
81-
echo get_class($e), ": ", $e->getMessage(), "\n";
82-
}
83-
84-
8557
?>
8658
===DONE===
8759
<?php exit(0); ?>
8860
--EXPECTF--
89-
User Created
9061
string(9) "important"
91-
User dropped
9262
===DONE===

0 commit comments

Comments
 (0)