Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(oidc): add docker compose configuration that uses mock oidc provider #23

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about using a different port than the default? That way it won't conflict with other testing environments we have. Maybe 27096?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense (and your other comment too), let me update that!

--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
Loading