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): start mongodb with auth enabled to ensure we're testing it correctly #26

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion docker/oidc/mock-oidc-provider/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM mongodb/mongodb-enterprise-server:latest
USER root
RUN apt-get update && apt-get install -y \
ca-certificates \
curl
curl jq netcat
ARG TARGETARCH
ARG NODE_VERSION=20.10.0
ARG NODE_PACKAGE=node-v$NODE_VERSION-linux-arm64
ARG NODE_HOME=/opt/$NODE_PACKAGE
Expand Down
27 changes: 26 additions & 1 deletion docker/oidc/mock-oidc-provider/start-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,35 @@ echo Waiting to make sure that oidc mock provider and proxy are running
until $(curl --output /dev/null --silent --head --fail http://localhost:$OIDC_PROVIDER_PROXY_PORT/.well-known/openid-configuration); do
sleep 0.3
done

echo Setting up user roles
# Start the server (without auth).
# This is original mongodb/mongodb-enterprise-server entrypoint
python3 /usr/local/bin/docker-entrypoint.py \
--setParameter authenticationMechanisms="MONGODB-OIDC" \
--setParameter enableTestCommands="true" \
--setParameter oidcIdentityProviders="$OIDC_IDENTITY_PROVIDERS" > /dev/null &

# Wait for the mongodb server to start.
until nc -z localhost 27017; do
sleep 1
done
# Creates the OIDC user role in the database.
mongosh "mongodb://localhost:27017/admin" --json --eval "(process.env.OIDC_TOKEN_PAYLOAD_GROUPS ?? 'testgroup').split(',').map(group => db.createRole({ role: 'dev/' + group, privileges: [ ], roles: [ \"readWriteAnyDatabase\" ] }));"

# Stop the no auth database (we re-start it with auth enabled next).
pkill mongod

# Wait for the mongodb server to shut down.
until ! nc -z localhost 27017; do
sleep 1
done

echo Starting server
OIDC_IDENTITY_PROVIDERS="[$(curl --fail http://localhost:29091/server-oidc-config)]"
# This is original mongodb/mongodb-enterprise-server entrypoint
python3 /usr/local/bin/docker-entrypoint.py \
--setParameter authenticationMechanisms="SCRAM-SHA-256,MONGODB-OIDC" \
--setParameter authenticationMechanisms="MONGODB-OIDC" \
--setParameter enableTestCommands="true" \
--auth \
--setParameter oidcIdentityProviders="$OIDC_IDENTITY_PROVIDERS"
Loading