Skip to content

Commit

Permalink
chore: add readme and allow env configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
gribnoysup committed Dec 1, 2023
1 parent 4fcae8c commit 2b26456
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 11 deletions.
20 changes: 20 additions & 0 deletions docker/oidc/mock-oidc-provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### MongoDB enterprise with mock OIDC provider auth enabled

```sh
docker-compose -f oidc/mock-oidc-provider/docker-compose.yaml up
```

#### How to connect

```sh
mongosh \
--host localhost \
--port 27017 \
--authenticationMechanism MONGODB-OIDC
```

Connection string:

```
mongodb://localhost:27017/?authMechanism=MONGODB-OIDC
```
21 changes: 21 additions & 0 deletions docker/oidc/mock-oidc-provider/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from 'path';

import ConnectionString from 'mongodb-connection-string-url';

const port = '27017';

const connectionString = new ConnectionString(`mongodb://localhost:${port}`);
connectionString.searchParams.set('authMechanism', 'MONGODB-OIDC');

export default {
dockerCompose: {
projectName: path.basename(__dirname),
yamlPath: path.resolve(__dirname, 'docker-compose.yaml'),
},
waitOn: [`tcp:${port}`],
connections: {
oidc: {
connectionString: connectionString.href,
},
},
};
13 changes: 13 additions & 0 deletions docker/oidc/mock-oidc-provider/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3'
services:
mongodb-server-with-mock-oidc-provider:
build: .
ports:
- '27017:27017'
- '29091:29091'
environment:
- OIDC_TOKEN_PAYLOAD_EXPIRES_IN
# comma-separated list
- OIDC_TOKEN_PAYLOAD_GROUPS
- OIDC_TOKEN_PAYLOAD_SUB
- OIDC_TOKEN_PAYLOAD_AUD
7 changes: 0 additions & 7 deletions docker/oidc/mock-oidc-provider/docker-compose.yml

This file was deleted.

12 changes: 8 additions & 4 deletions docker/oidc/mock-oidc-provider/oidc-mock-provider.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const { OIDCMockProvider } = require('@mongodb-js/oidc-mock-provider');

const DEFAULT_TOKEN_PAYLOAD = {
expires_in: 3600,
expires_in: process.env.OIDC_TOKEN_PAYLOAD_EXPIRES_IN
? Number(process.env.OIDC_TOKEN_PAYLOAD_EXPIRES_IN)
: 3600,
payload: {
// Define the user information stored inside the access tokens.
groups: ['testgroup'],
sub: 'testuser',
aud: 'resource-server-audience-value',
groups: process.env.OIDC_TOKEN_PAYLOAD_GROUPS
? process.env.OIDC_TOKEN_PAYLOAD_GROUPS.split(',')
: ['testgroup'],
sub: process.env.OIDC_TOKEN_PAYLOAD_SUB || 'testuser',
aud: process.env.OIDC_TOKEN_PAYLOAD_AUD || 'resource-server-audience-value',
},
};

Expand Down

0 comments on commit 2b26456

Please sign in to comment.