Skip to content

Commit 117bd57

Browse files
committed
Add cert gen scripts
1 parent eda9b97 commit 117bd57

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ venv/
4343
mongodb-datasource/
4444
grafana-storage/
4545

46-
mongo-docs/
46+
mongo-docs/
47+
certs/

scripts/cert-gen.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#/bin/bash
2+
# Generate keys and certs to test local MongoDB TLS connection
3+
4+
set -e
5+
6+
mkdir -p certs
7+
8+
# Generate a Certificate Authority (CA)
9+
openssl genrsa -out certs/ca.key 4096
10+
openssl req -x509 -new -nodes -key certs/ca.key -sha256 -days 365 -out certs/ca.pem -subj "/CN=localhost"
11+
12+
13+
# Generate a Server Key and Certificate Signing Request (CSR)
14+
# Passphrase is set to 123
15+
openssl genrsa -out certs/mongodb.key -passout pass:123 4096
16+
openssl req -new -key certs/mongodb.key -out certs/mongodb.csr -subj "/CN=localhost"
17+
18+
# Sign the Server Certificate with the CA
19+
openssl x509 -req -extfile <(printf "subjectAltName=DNS:localhost") -in certs/mongodb.csr -CA certs/ca.pem -CAkey certs/ca.key -CAcreateserial -out certs/mongodb.crt -days 365 -sha256
20+
21+
# Combine Server Key and Certificate
22+
cat certs/mongodb.key certs/mongodb.crt > certs/mongodb.pem

scripts/start-mongo.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#/bin/bash
2+
# Start MongoDB service with different configurations
3+
4+
# --tls
5+
if [ "$1" == "--tls" ]; then
6+
echo "Starting MongoDB with TLS..."
7+
docker run --rm --name mongodb-ds-mongo-tls -v ./mongod.conf:/etc/mongo/mongod.conf \
8+
-v ./certs:/certs -p 27017:27017 -d mongo --config /etc/mongo/mongod.conf
9+
# if no configuration is provided, start with default settings
10+
else
11+
echo "Starting MongoDB with default settings..."
12+
docker run --rm --name mongodb-ds-mongo -d mongo
13+
fi

0 commit comments

Comments
 (0)