Skip to content

Commit b87df77

Browse files
committed
add configs
1 parent 1473968 commit b87df77

File tree

17 files changed

+478
-15
lines changed

17 files changed

+478
-15
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ In order to start the environments you will need:
3939

4040
### Usage
4141

42+
#### With docker-compose
43+
4244
Each setup has its own folder and `docker-compose.yaml` file.
4345

4446
A `docker-compose.yaml` file defines a set of services that will be started as docker containers and how that will happen: from which image, what command, environment variables and files to mount from host, how will be exposed to the network.
@@ -57,6 +59,33 @@ docker-compose -f sharded/docker-compose.yaml up
5759

5860
Please also refer to the official documentation ([Getting Started](https://docs.docker.com/compose/gettingstarted/), [Cli Reference](https://docs.docker.com/compose/reference/), [YAML Reference](https://docs.docker.com/compose/compose-file/)) and the many other resources online for details on how to use `docker-compose`.
5961

62+
#### Programmatically
63+
64+
``` js
65+
const createTestEnvironments = require('@mongodb-js/devtools-docker-test-envs');
66+
67+
const {
68+
community: communityTestEnv
69+
} = createTestEnvironments();
70+
71+
before(async() => {
72+
await Promise.all([
73+
communityTestEnv.start()
74+
]
75+
});
76+
77+
it('can connect', () => {
78+
const { connectionString } = communityTestEnv.getConnectionOptions('community');
79+
await MongoClient.connect(connectionString);
80+
});
81+
82+
after(async() => {
83+
await Promise.all([
84+
communityTestEnv.stop()
85+
]
86+
});
87+
```
88+
6089
#### How to connect to the environments
6190
6291
Informations on how to connect are available for each setup.

docker/community/index.js renamed to docker/community/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22

33
module.exports = {
44
dockerCompose: {
5-
projectName: 'community',
5+
projectName: path.basename(__dirname),
66
yamlPath: path.resolve(__dirname, 'docker-compose.yaml')
77
},
88
waitOn: [

docker/enterprise/config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
dockerCompose: {
5+
projectName: path.basename(__dirname),
6+
yamlPath: path.resolve(__dirname, 'docker-compose.yaml')
7+
},
8+
waitOn: [
9+
'tcp:27021'
10+
],
11+
connections: {
12+
enterprise: {
13+
connectionString: 'mongodb://localhost:27021/test'
14+
}
15+
}
16+
};

docker/kerberos/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Make sure you have this line in your `/etc/hosts`:
66

77
``` conf
8-
127.0.0.1 mongodb-kerberos-1.example.com mongodb-kerberos-2.example.com mongodb-kerberos-3.examplewrong.com
8+
127.0.0.1 mongodb-kerberos-1.example.com mongodb-kerberos-2.example.com mongodb-kerberos-3.examplecrossrealm.com
99
```
1010

1111
Make sure you have this in `/etc/krb5.conf` (note the `domain_realm` section to configure cross-realm):
@@ -23,7 +23,7 @@ Make sure you have this in `/etc/krb5.conf` (note the `domain_realm` section to
2323
}
2424
2525
[domain_realm]
26-
.examplewrong.com = EXAMPLE2.COM
26+
.examplecrossrealm.com = EXAMPLE2.COM
2727
```
2828

2929
Start the docker environment:
@@ -58,7 +58,7 @@ All servers are configured with the same set of users.
5858

5959
`mongodb-kerberos-1.example.com` is configured with the default `gssapiServiceName` (`mongodb`), while `mongodb-kerberos-2.example.com` is configured with `gssapiServiceName=alternate`. These two servers are in the Kerberos Realm `EXAMPLE.COM`.
6060

61-
The server `mongodb-kerberos-3.examplewrong.com` has the default `gssapiServiceName` (`mongodb`) but is located in a different Kerberos Realm `EXAMPLE2.COM`.
61+
The server `mongodb-kerberos-3.examplecrossrealm.com` has the default `gssapiServiceName` (`mongodb`) but is located in a different Kerberos Realm `EXAMPLE2.COM`.
6262

6363
##### Available users
6464

docker/kerberos/config.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const path = require('path');
2+
const execa = require('execa');
3+
4+
const {default: ConnectionString} = require('mongodb-connection-string-url');
5+
6+
const principal = 'mongodb.user';
7+
const defaultConnectionString = new ConnectionString('mongodb://mongodb-kerberos-1.example.com:29017');
8+
defaultConnectionString.username = principal;
9+
defaultConnectionString.searchParams.set('authMechanism', 'GSSAPI');
10+
11+
const alternateConnectionString = new ConnectionString('mongodb://mongodb-kerberos-2.example.com:29018');
12+
alternateConnectionString.username = principal;
13+
alternateConnectionString.searchParams.set('authMechanism', 'GSSAPI');
14+
alternateConnectionString.searchParams.set('authMechanismProperties', 'SERVICE_NAME:alternate');
15+
16+
const crossRealmConnectionString = new ConnectionString('mongodb://mongodb-kerberos-3.examplecrossrealm.com:29019');
17+
crossRealmConnectionString.username = principal;
18+
crossRealmConnectionString.searchParams.set('authMechanism', 'GSSAPI');
19+
20+
module.exports = {
21+
dockerCompose: {
22+
projectName: path.basename(__dirname),
23+
yamlPath: path.resolve(__dirname, 'docker-compose.yaml')
24+
},
25+
waitOn: [
26+
'tcp:29017',
27+
'tcp:29018',
28+
'tcp:29019'
29+
],
30+
hosts: [
31+
'mongodb-kerberos-1.example.com',
32+
'mongodb-kerberos-2.example.com',
33+
'mongodb-kerberos-3.examplecrossrealm.com'
34+
],
35+
setup: async() => {
36+
try { // hemdal
37+
await execa('kinit',
38+
['--password-file=STDIN', principal], {input: 'password'});
39+
} catch (e) { // mit
40+
await execa(
41+
'kinit', [principal], {input: 'password'});
42+
}
43+
},
44+
teardown: async() => {
45+
try {
46+
await execa('kdestroy', ['-p', principal]);
47+
} catch (e) {
48+
//
49+
}
50+
},
51+
connections: {
52+
default: {
53+
connectionString: defaultConnectionString.href
54+
},
55+
alternate: {
56+
connectionString: alternateConnectionString.href
57+
},
58+
crossRealm: {
59+
connectionString: crossRealmConnectionString.href
60+
}
61+
}
62+
};

docker/kerberos/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ services:
106106
MONGO_INITDB_ROOT_PASSWORD: root
107107
MONGO_INITDB_DATABASE: admin
108108
KRB5_KTNAME: "/etc/krb5-keytabs/mongodb.keytab"
109-
hostname: mongodb-kerberos-3.examplewrong.com
109+
hostname: mongodb-kerberos-3.examplecrossrealm.com
110110
depends_on:
111111
- kdc-kadmin2
112112
ports:

docker/kerberos/kdc/kadmin-example2/add_principals.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [[ "x${TRUST_PRINCIPAL}" != "x" && "x${TRUST_REALM}" != "x" ]]; then
1818
echo ""
1919
fi
2020

21-
kadmin.local -q "delete_principal -force mongodb/mongodb-kerberos-3.examplewrong.com@$REALM"
22-
kadmin.local -q "addprinc -randkey mongodb/mongodb-kerberos-3.examplewrong.com@$REALM"
21+
kadmin.local -q "delete_principal -force mongodb/mongodb-kerberos-3.examplecrossrealm.com@$REALM"
22+
kadmin.local -q "addprinc -randkey mongodb/mongodb-kerberos-3.examplecrossrealm.com@$REALM"
2323

24-
kadmin.local -q "ktadd -k /mongodb.keytab mongodb/mongodb-kerberos-3.examplewrong.com@$REALM"
24+
kadmin.local -q "ktadd -k /mongodb.keytab mongodb/mongodb-kerberos-3.examplecrossrealm.com@$REALM"

docker/ldap/config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const path = require('path');
2+
3+
const {default: ConnectionString} = require('mongodb-connection-string-url');
4+
5+
const connectionString = new ConnectionString('mongodb://localhost:30017');
6+
connectionString.username = 'writer';
7+
connectionString.password = 'Password1!';
8+
connectionString.searchParams.set('authMechanism', 'PLAIN');
9+
10+
module.exports = {
11+
dockerCompose: {
12+
projectName: path.basename(__dirname),
13+
yamlPath: path.resolve(__dirname, 'docker-compose.yaml')
14+
},
15+
waitOn: [
16+
'tcp:30017'
17+
],
18+
connections: {
19+
default: {
20+
connectionString: connectionString.href
21+
}
22+
}
23+
};
24+

docker/replica-set/config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
dockerCompose: {
5+
projectName: path.basename(__dirname),
6+
yamlPath: path.resolve(__dirname, 'docker-compose.yaml')
7+
},
8+
waitOn: [
9+
'tcp:28001',
10+
'tcp:28002',
11+
'tcp:28003',
12+
'tcp:28004'
13+
],
14+
hosts: [
15+
'mongodb-rs-1',
16+
'mongodb-rs-2',
17+
'mongodb-rs-3'
18+
],
19+
connections: {
20+
default: {
21+
connectionString: 'mongodb://root:password123@mongodb-rs-1:28001,mongodb-rs-2:28002,mongodb-rs-3:28003/db1?authSource=admin&replicaSet=replicaset'
22+
},
23+
anaylticsNode: {
24+
connectionString: 'mongodb://root:password123@mongodb-rs-1:28001,mongodb-rs-2:28002,mongodb-rs-3:28003/db1?authSource=admin&replicaSet=replicaset&readPreference=secondary&readPreferenceTags=nodeType:ANALYTICS'
25+
},
26+
privateNode: {
27+
connectionString: 'mongodb://root:password123@localhost:28004/db1?authSource=admin'
28+
}
29+
}
30+
};
31+

docker/scram/config.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const path = require('path');
2+
3+
function buildConnectionString(auth, authenticationMechanism, authenticationDatabase) {
4+
const uri = `mongodb://${auth}@localhost:28006/db1?authSource=${authenticationDatabase}`;
5+
if (authenticationMechanism) {
6+
return `${uri}&${authenticationMechanism}`;
7+
}
8+
9+
return uri;
10+
}
11+
12+
module.exports = {
13+
dockerCompose: {
14+
projectName: path.basename(__dirname),
15+
yamlPath: path.resolve(__dirname, 'docker-compose.yaml')
16+
},
17+
waitOn: [
18+
'tcp:28006'
19+
],
20+
connections: {
21+
readWriteAnyDatabase: {
22+
connectionString: buildConnectionString('user1:password', 'admin')
23+
},
24+
readWriteAnyDatabaseScramSha1: {
25+
connectionString: buildConnectionString('user1:password', 'admin', 'SCRAM-SHA-1')
26+
},
27+
readWriteAnyDatabaseScramSha256: {
28+
connectionString: buildConnectionString('user1:password', 'admin', 'SCRAM-SHA-256')
29+
},
30+
onlyScramSha1: {
31+
connectionString: buildConnectionString('scramSha1:password', 'admin', 'SCRAM-SHA-1')
32+
},
33+
onlyScramSha256: {
34+
connectionString: buildConnectionString('scramSha256:password', 'admin', 'SCRAM-SHA-256')
35+
},
36+
encodedPassword: {
37+
connectionString: buildConnectionString('randomPassword:C;Ib86n5b8{AnExew[TU%XZy,)E6G!dk', 'admin')
38+
},
39+
privilegesOnNonExistingDatabases: {
40+
connectionString: buildConnectionString('user2:password', 'admin')
41+
},
42+
privilegesOnNonExistingCollections: {
43+
connectionString: buildConnectionString('customRole:password', 'admin')
44+
},
45+
alternateAuthDb: {
46+
connectionString: buildConnectionString('authDb:password', 'authDb')
47+
}
48+
}
49+
};
50+

0 commit comments

Comments
 (0)