diff --git a/.github/workflows/test-docs.yml b/.github/workflows/test-docs.yml index 0bbbddfd5..4aaad8de3 100644 --- a/.github/workflows/test-docs.yml +++ b/.github/workflows/test-docs.yml @@ -8,6 +8,7 @@ on: - 'docs/operator-public-documentation/**' - '.github/scripts/check_doc_links*.py' - '.github/workflows/*docs.yml' + - 'documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts/**' push: branches: [main] paths: @@ -16,6 +17,7 @@ on: - 'docs/operator-public-documentation/**' - '.github/scripts/check_doc_links*.py' - '.github/workflows/*docs.yml' + - 'documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts/**' workflow_dispatch: permissions: @@ -32,10 +34,15 @@ jobs: - uses: actions/setup-python@v5 with: python-version: 3.x + - uses: actions/setup-node@v4 + with: + node-version: '22' - name: Install documentation dependencies run: pip install "mkdocs-material==9.5.19" "mike==2.1.3" "mkdocs-redirects==1.2.2" - name: Test link checker run: python -m unittest discover -s .github/scripts -p '*_test.py' + - name: Test deployment diagnostic credentials + run: python -m unittest discover -s documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts -p 'test_*.py' - name: Build and check candidate entrypoints run: | mkdocs build diff --git a/docs/operator-public-documentation/v1/getting-started/connecting-to-documentdb.md b/docs/operator-public-documentation/v1/getting-started/connecting-to-documentdb.md index 6c43e9132..278981059 100644 --- a/docs/operator-public-documentation/v1/getting-started/connecting-to-documentdb.md +++ b/docs/operator-public-documentation/v1/getting-started/connecting-to-documentdb.md @@ -134,7 +134,9 @@ documentdb-service-my-documentdb.documentdb-ns.svc.cluster.local:10260 ## Connect with mongosh ```bash -mongosh "mongodb://dev_user:DevPassword123@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" +# Enter the password from your credentials Secret when prompted. +mongosh "mongodb://127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" \ + --username dev_user --password ``` Or use individual flags: @@ -142,7 +144,7 @@ Or use individual flags: ```bash mongosh 127.0.0.1:10260 \ -u dev_user \ - -p DevPassword123 \ + --password \ --authenticationMechanism SCRAM-SHA-256 \ --tls --tlsAllowInvalidCertificates ``` @@ -156,9 +158,11 @@ The [DocumentDB for VS Code](https://marketplace.visualstudio.com/items?itemName 3. Select **Add Connection** and enter your connection string: ```text - mongodb://dev_user:DevPassword123@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0 + mongodb://:@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0 ``` + Replace the placeholders with credentials from your Secret, percent-encoding any reserved URI characters. + 4. Browse databases, collections, and documents. You can also use the built-in playground to run queries interactively. !!! tip @@ -169,11 +173,18 @@ The [DocumentDB for VS Code](https://marketplace.visualstudio.com/items?itemName All examples below assume: - DocumentDB is accessible at `127.0.0.1:10260` (via port-forward or LoadBalancer) -- Credentials: username `dev_user`, password `DevPassword123` +- Credentials supplied through `DOCUMENTDB_USERNAME` and `DOCUMENTDB_PASSWORD` - Self-signed TLS (certificate validation skipped) For production deployments with trusted certificates, see [TLS configuration](../configuration/tls.md). +Read credentials from the same Secret used by your cluster rather than embedding them in the examples: + +```bash +export DOCUMENTDB_USERNAME="$(kubectl get secret documentdb-credentials -n documentdb-ns -o jsonpath='{.data.username}' | base64 -d)" +export DOCUMENTDB_PASSWORD="$(kubectl get secret documentdb-credentials -n documentdb-ns -o jsonpath='{.data.password}' | base64 -d)" +``` + ### Python (PyMongo) Install the driver: @@ -183,13 +194,15 @@ pip install pymongo ``` ```python title="connect_documentdb.py" +import os + from pymongo import MongoClient client = MongoClient( host="127.0.0.1", port=10260, - username="dev_user", - password="DevPassword123", + username=os.environ["DOCUMENTDB_USERNAME"], + password=os.environ["DOCUMENTDB_PASSWORD"], authSource="admin", authMechanism="SCRAM-SHA-256", tls=True, @@ -224,12 +237,20 @@ npm install mongodb ```javascript title="connect_documentdb.js" const { MongoClient } = require("mongodb"); +const username = process.env.DOCUMENTDB_USERNAME; +const password = process.env.DOCUMENTDB_PASSWORD; +if (!username || !password) { + throw new Error("DOCUMENTDB_USERNAME and DOCUMENTDB_PASSWORD are required"); +} + const uri = - "mongodb://dev_user:DevPassword123@127.0.0.1:10260/" + - "?directConnection=true&authMechanism=SCRAM-SHA-256" + + "mongodb://127.0.0.1:10260/" + + "?directConnection=true" + "&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0"; const client = new MongoClient(uri, { + auth: { username, password }, + authMechanism: "SCRAM-SHA-256", // Connection pool settings maxPoolSize: 50, minPoolSize: 5, @@ -273,6 +294,7 @@ import ( "crypto/tls" "fmt" "log" + "os" "time" "go.mongodb.org/mongo-driver/bson" @@ -284,8 +306,13 @@ func main() { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - uri := "mongodb://dev_user:DevPassword123@127.0.0.1:10260/" + - "?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true" + username, password := os.Getenv("DOCUMENTDB_USERNAME"), os.Getenv("DOCUMENTDB_PASSWORD") + if username == "" || password == "" { + log.Fatal("DOCUMENTDB_USERNAME and DOCUMENTDB_PASSWORD are required") + } + + uri := "mongodb://127.0.0.1:10260/" + + "?directConnection=true&tls=true" // For self-signed certificates, skip verification. // For trusted CAs, load the CA cert into a tls.Config instead. @@ -293,6 +320,7 @@ func main() { clientOpts := options.Client(). ApplyURI(uri). + SetAuth(options.Credential{AuthMechanism: "SCRAM-SHA-256", Username: username, Password: password, AuthSource: "admin"}). SetTLSConfig(tlsConfig). SetMaxPoolSize(50). // Maximum connections in the pool SetMinPoolSize(5). // Minimum idle connections @@ -345,6 +373,7 @@ Add the dependency to your `pom.xml`: ```java title="ConnectDocumentDB.java" import com.mongodb.ConnectionString; import com.mongodb.MongoClientSettings; +import com.mongodb.MongoCredential; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; @@ -359,8 +388,14 @@ import java.util.concurrent.TimeUnit; public class ConnectDocumentDB { public static void main(String[] args) throws Exception { - String uri = "mongodb://dev_user:DevPassword123@127.0.0.1:10260/" - + "?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true"; + String username = System.getenv("DOCUMENTDB_USERNAME"); + String password = System.getenv("DOCUMENTDB_PASSWORD"); + if (username == null || username.isEmpty() || password == null || password.isEmpty()) { + throw new IllegalArgumentException("DOCUMENTDB_USERNAME and DOCUMENTDB_PASSWORD are required"); + } + + String uri = "mongodb://127.0.0.1:10260/" + + "?directConnection=true&tls=true"; // For self-signed certificates, create a trust-all SSLContext. // For trusted CAs, configure a proper TrustStore instead. @@ -376,6 +411,7 @@ public class ConnectDocumentDB { MongoClientSettings settings = MongoClientSettings.builder() .applyConnectionString(new ConnectionString(uri)) + .credential(MongoCredential.createScramSha256Credential(username, "admin", password.toCharArray())) .applyToSslSettings(builder -> builder .enabled(true) .context(sslContext)) @@ -438,7 +474,8 @@ When using `CertManager` or `Provided` mode with a trusted CA, remove `tlsAllowI === "mongosh" ```bash - mongosh "mongodb://dev_user:DevPassword123@:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&replicaSet=rs0" \ + mongosh "mongodb://:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&replicaSet=rs0" \ + --username "$DOCUMENTDB_USERNAME" --password \ --tlsCAFile /path/to/ca.crt ``` @@ -448,8 +485,8 @@ When using `CertManager` or `Provided` mode with a trusted CA, remove `tlsAllowI client = MongoClient( host="", port=10260, - username="dev_user", - password="DevPassword123", + username=os.environ["DOCUMENTDB_USERNAME"], + password=os.environ["DOCUMENTDB_PASSWORD"], authSource="admin", authMechanism="SCRAM-SHA-256", tls=True, diff --git a/docs/operator-public-documentation/v1/getting-started/quickstart-k3s.md b/docs/operator-public-documentation/v1/getting-started/quickstart-k3s.md index 404cc8b4b..eb61d340b 100644 --- a/docs/operator-public-documentation/v1/getting-started/quickstart-k3s.md +++ b/docs/operator-public-documentation/v1/getting-started/quickstart-k3s.md @@ -186,8 +186,9 @@ In another terminal, get the connection string and connect: # View the connection string from the DocumentDB cluster status kubectl get documentdb my-documentdb -n documentdb-ns -o jsonpath='{.status.connectionString}' -# Connect with mongosh (substitute your credentials) -mongosh "mongodb://dev_user:DevPassword123@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" +# Enter the password from your credentials Secret when prompted. +mongosh "mongodb://127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" \ + --username dev_user --password ``` ### Option 2: K3s built-in load balancer @@ -238,7 +239,8 @@ my-documentdb Cluster in healthy state mongodb://...@192.168.1.100:10260/... Connect with `mongosh` using the external IP: ```bash -mongosh "mongodb://dev_user:DevPassword123@192.168.1.100:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" +mongosh "mongodb://192.168.1.100:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" \ + --username dev_user --password ``` For more connection options including application drivers, see [Connecting to DocumentDB](connecting-to-documentdb.md). diff --git a/docs/operator-public-documentation/v1/getting-started/quickstart-kind.md b/docs/operator-public-documentation/v1/getting-started/quickstart-kind.md index cacdfb367..c7d8db48a 100644 --- a/docs/operator-public-documentation/v1/getting-started/quickstart-kind.md +++ b/docs/operator-public-documentation/v1/getting-started/quickstart-kind.md @@ -176,14 +176,15 @@ In a new terminal, retrieve the connection string from the DocumentDB cluster st kubectl get documentdb my-documentdb -n documentdb-ns -o jsonpath='{.status.connectionString}' ``` -Use `mongosh` with the resolved credentials: +Use `mongosh` with your username, and enter the password from the credentials Secret when prompted: ```bash -mongosh "mongodb://dev_user:DevPassword123@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" +mongosh "mongodb://127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" \ + --username dev_user --password ``` !!! tip - The `CONNECTION STRING` column in `kubectl get documentdb` output contains embedded `kubectl` commands that extract the username and password from the credentials Secret at runtime. You can copy and `eval` the full string, or substitute your known credentials directly as shown above. + The `CONNECTION STRING` column in `kubectl get documentdb` output contains embedded `kubectl` commands that extract the username and password from the credentials Secret at runtime. The command above keeps the password out of the URI and shell history. Try inserting and querying data: diff --git a/docs/operator-public-documentation/v1/index.md b/docs/operator-public-documentation/v1/index.md index 3b7a53353..76f40f25b 100644 --- a/docs/operator-public-documentation/v1/index.md +++ b/docs/operator-public-documentation/v1/index.md @@ -201,7 +201,7 @@ kubectl port-forward svc/documentdb-service-documentdb-preview 10260:10260 -n do ```bash mongosh 127.0.0.1:10260 \ -u k8s_secret_user \ - -p K8sSecret100 \ + --password \ --authenticationMechanism SCRAM-SHA-256 \ --tls --tlsAllowInvalidCertificates ``` @@ -209,9 +209,12 @@ mongosh 127.0.0.1:10260 \ Or use a connection string: ```bash -mongosh "mongodb://k8s_secret_user:K8sSecret100@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" +mongosh "mongodb://127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0" \ + --username k8s_secret_user --password ``` +Enter the password from your credentials Secret when prompted. + #### Option 2: LoadBalancer service (for cloud deployments) For direct external access in cloud environments (AKS, EKS, GKE), deploy with a `LoadBalancer` service type: diff --git a/docs/operator-public-documentation/v1/multi-region-deployment/failover-procedures.md b/docs/operator-public-documentation/v1/multi-region-deployment/failover-procedures.md index 24dc4d0a3..314b3025a 100644 --- a/docs/operator-public-documentation/v1/multi-region-deployment/failover-procedures.md +++ b/docs/operator-public-documentation/v1/multi-region-deployment/failover-procedures.md @@ -182,8 +182,9 @@ Confirm the new primary accepts writes: kubectl --context new-primary port-forward \ -n documentdb-preview-ns svc/documentdb-preview 10260:10260 & -# Connect with mongosh -mongosh "mongodb://admin:password@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true" +# Connect with your username and enter its password when prompted. +mongosh "mongodb://localhost:10260/?tls=true&tlsAllowInvalidCertificates=true" \ + --username "" --password # Test write operation db.testCollection.insertOne({ @@ -328,7 +329,8 @@ kubectl --context new-primary get documentdb documentdb-preview \ kubectl --context new-primary port-forward \ -n documentdb-preview-ns svc/documentdb-preview 10260:10260 & -mongosh "mongodb://admin:password@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true" +mongosh "mongodb://localhost:10260/?tls=true&tlsAllowInvalidCertificates=true" \ + --username "" --password db.testCollection.insertOne({message: "DR failover test"}) ``` diff --git a/documentdb-playground/aks-setup/README.md b/documentdb-playground/aks-setup/README.md index 7c50db69f..1de250361 100644 --- a/documentdb-playground/aks-setup/README.md +++ b/documentdb-playground/aks-setup/README.md @@ -249,7 +249,7 @@ kubectl get secret documentdb-credentials -n documentdb-instance-ns -o jsonpath= kubectl get secret documentdb-credentials -n documentdb-instance-ns -o jsonpath='{.data.password}' | base64 -d # Connection string format -mongodb://username:password@EXTERNAL-IP:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0 +mongodb://:@:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true&replicaSet=rs0 ``` ### Common Issues diff --git a/documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts/create-cluster.sh b/documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts/create-cluster.sh index 2b6a41f51..f5e5ee63e 100755 --- a/documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts/create-cluster.sh +++ b/documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts/create-cluster.sh @@ -818,10 +818,33 @@ diagnose_documentdb() { # 5. Ping test via in-cluster mongosh (validate endpoint independently of app code) log "Testing DocumentDB connectivity via in-cluster mongosh..." - if kubectl run mongosh-diag-$RANDOM --rm -i --restart=Never --quiet \ - --image=mongo:7 -n documentdb-instance-ns -- \ - mongosh "mongodb://docdbadmin:SecurePassword123!@documentdb-service-sample-documentdb:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true" \ - --quiet --eval "db.runCommand({ping: 1})" 2>/dev/null | grep -q "ok.*1"; then + local diagnostic_pod="mongosh-diag-$RANDOM" + local diagnostic_overrides + diagnostic_overrides=$(cat </dev/null | grep -q "ok.*1"; then success "DocumentDB ping succeeded" else warn "DocumentDB ping failed -- see troubleshooting guide in summary" @@ -880,7 +903,7 @@ print_summary() { echo " - Check DocumentDB: kubectl get documentdb -n documentdb-instance-ns" echo " - Check service status: kubectl get svc -n documentdb-instance-ns" echo " - Wait for LoadBalancer IP: kubectl get svc documentdb-service-sample-documentdb -n documentdb-instance-ns -w" - echo " - Once IP is assigned, connect: mongodb://docdbadmin:SecurePassword123!@:10260/" + echo " - Once IP is assigned, connect using credentials from the documentdb-credentials Secret" echo "" echo "🔎 Troubleshooting (adapted from DocumentDB troubleshooting best practices):" echo "" @@ -909,7 +932,7 @@ print_summary() { echo "" echo " 6. Validate the endpoint independently of your application code:" echo " kubectl port-forward -n documentdb-instance-ns svc/documentdb-service-sample-documentdb 10260:10260 &" - echo " mongosh \"mongodb://docdbadmin:SecurePassword123!@localhost:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true\"" + echo " mongosh \"mongodb://localhost:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true\" --username '' --password" echo "" echo " 7. TLS / certificate errors:" echo " - For self-signed certs (default): keep tlsAllowInvalidCertificates=true in the connection string" @@ -962,4 +985,6 @@ main() { } # Run main function -main "$@" +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + main "$@" +fi diff --git a/documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts/test_create_cluster.py b/documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts/test_create_cluster.py new file mode 100644 index 000000000..9e28f2d42 --- /dev/null +++ b/documentdb-playground/contrib/telemetry-and-cost-optimized-eks/scripts/test_create_cluster.py @@ -0,0 +1,107 @@ +import json +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +class DiagnosticCredentialsTests(unittest.TestCase): + def test_diagnostic_reads_credentials_from_secret(self): + script = Path(__file__).with_name("create-cluster.sh") + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + for name in ("aws", "eksctl", "kubectl", "helm", "curl"): + stub = root / name + stub.write_text("#!/bin/sh\nexit 99\n") + stub.chmod(0o755) + capture = root / "arguments" + environment = dict( + os.environ, + DEPLOY_INSTANCE="true", + PATH=str(root) + os.pathsep + os.environ["PATH"], + DIAGNOSTIC_ARGUMENTS=str(capture), + ) + result = subprocess.run( + ["bash", "-c", """ +script="$1" +shift +source "$script" +kubectl() { + if [[ "$1" == run ]]; then + printf '%s\\0' "$@" > "$DIAGNOSTIC_ARGUMENTS" + printf '{ ok: 1 }\\n' + fi +} +diagnose_documentdb +""", "test", str(script)], + env=environment, capture_output=True, text=True, + ) + self.assertEqual(result.returncode, 0, result.stderr) + arguments = capture.read_bytes().decode().strip("\0").split("\0") + overrides = json.loads(next( + value.split("=", 1)[1] for value in arguments + if value.startswith("--overrides=") + )) + container = overrides["spec"]["containers"][0] + self.assertEqual(container["name"], arguments[1]) + self.assertEqual(container["command"], ["mongosh"]) + self.assertEqual(container["image"], "mongo:7") + for variable, key in ( + ("DOCUMENTDB_USERNAME", "username"), + ("DOCUMENTDB_PASSWORD", "password"), + ): + env = next(entry for entry in container["env"] if entry["name"] == variable) + self.assertEqual(env["valueFrom"], { + "secretKeyRef": {"name": "documentdb-credentials", "key": key} + }) + self.assertNotIn("value", env) + self.assertEqual(container["args"][0].split("://")[1].split("/")[0], + "documentdb-service-sample-documentdb:10260") + self.assertNotIn("authMechanism=", container["args"][0]) + self.check_authentication(container["args"][-1]) + + def check_authentication(self, javascript): + node = shutil.which("node") + self.assertIsNotNone(node, "Node.js is required to exercise the mongosh diagnostic JavaScript") + harness = r""" +const vm = require("node:vm"); +const assert = require("node:assert/strict"); +const code = process.argv[1]; +for (const authenticated of [true, false]) { + let pinged = false; + const credentials = { DOCUMENTDB_USERNAME: "test @ user", DOCUMENTDB_PASSWORD: "test : / ? & value" }; + const admin = { + auth(options) { + assert.equal(options.user, credentials.DOCUMENTDB_USERNAME); + assert.equal(options.pwd, credentials.DOCUMENTDB_PASSWORD); + assert.equal(options.mechanism, "SCRAM-SHA-256"); + return { ok: authenticated ? 1 : 0 }; + }, + runCommand(command) { + assert.equal(command.ping, 1); + pinged = true; + return { ok: 1 }; + } + }; + const context = { + process: { env: credentials }, + db: { getSiblingDB(name) { assert.equal(name, "admin"); return admin; } } + }; + if (authenticated) { + assert.equal(vm.runInNewContext(code, context).ok, 1); + } else { + assert.throws(() => vm.runInNewContext(code, context), /Authentication failed/); + } + assert.equal(pinged, authenticated); +} +""" + result = subprocess.run( + [node, "-e", harness, javascript], text=True, capture_output=True, + ) + self.assertEqual(result.returncode, 0, result.stderr) + + +if __name__ == "__main__": + unittest.main() diff --git a/documentdb-playground/multi-cloud-deployment/README.md b/documentdb-playground/multi-cloud-deployment/README.md index c2fee4714..a92011a05 100644 --- a/documentdb-playground/multi-cloud-deployment/README.md +++ b/documentdb-playground/multi-cloud-deployment/README.md @@ -201,9 +201,12 @@ mongosh "mongodb+srv://docdb:@./?tls=true&tlsA Example: ```bash -mongosh "mongodb+srv://docdb:mypassword@documentdb-aks-fleet-rg.multi-cloud.pgmongo-dev.cosmos.windows-int.net/?tls=true&tlsAllowInvalidCertificates=true&authMechanism=SCRAM-SHA-256" +mongosh "mongodb+srv://documentdb-aks-fleet-rg.multi-cloud.pgmongo-dev.cosmos.windows-int.net/?tls=true&tlsAllowInvalidCertificates=true&authMechanism=SCRAM-SHA-256" \ + --username docdb --password ``` +Enter the password from the cluster's credentials Secret when prompted. + ### Observability and Telemetry The `telemetry` folder contains configuration files for setting up a comprehensive observability stack across your multi-cloud DocumentDB deployment: diff --git a/documentdb-playground/sync_service/README.md b/documentdb-playground/sync_service/README.md index 9f8925842..4a2e541d5 100644 --- a/documentdb-playground/sync_service/README.md +++ b/documentdb-playground/sync_service/README.md @@ -97,14 +97,14 @@ Edit `config.yaml` and fill in the following required fields: | `target.uri` | Connection string to your target [Azure DocumentDB (with MongoDB compatibility)][azure-documentdb] | | `watch.collections` | List of collections to sync, in `database.collection` format | -Example: +Example (replace the placeholders with your credentials, percent-encoding reserved URI characters; do not commit the configured file): ```yaml source: - uri: "mongodb://k8s_secret_user:K8sSecret100@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true" + uri: "mongodb://:@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true" target: - uri: "mongodb+srv://admin:MyP%40ss@target-cluster.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000" + uri: "mongodb+srv://:@target-cluster.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000" watch: collections: @@ -147,12 +147,14 @@ This walkthrough uses three terminals side by side. | Terminal | Purpose | Connect with [mongosh][mongosh] | |----------|---------|----------------------------------| -| **Source** | On-premise DocumentDB on Kubernetes | `mongosh "mongodb://k8s_secret_user:K8sSecret100@127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true"` | +| **Source** | On-premise DocumentDB on Kubernetes | `mongosh "mongodb://127.0.0.1:10260/?directConnection=true&authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true" --username k8s_secret_user --password` | | **Target** | [Azure DocumentDB][azure-documentdb] | `mongosh ""` | | **Sync service** | Runs the Python sync service | — | > You can also use the [DocumentDB for VS Code][vscode-documentdb] extension instead of mongosh. +Enter the source password from its credentials Secret when prompted. + In **both** the source and target shells, switch to the demo database: ```javascript diff --git a/documentdb-playground/sync_service/sync.py b/documentdb-playground/sync_service/sync.py index 7bfb4a37f..a17c83389 100644 --- a/documentdb-playground/sync_service/sync.py +++ b/documentdb-playground/sync_service/sync.py @@ -78,10 +78,10 @@ def extract_cluster_name(uri: str) -> str: Extract cluster name from MongoDB connection URI. Examples: - mongodb+srv://user:pass@my-cluster.mongocluster.cosmos.azure.com/... + mongodb+srv://:@my-cluster.mongocluster.cosmos.azure.com/... -> my-cluster - mongodb://user:pass@localhost:27017/... + mongodb://:@localhost:27017/... -> localhost """ try: