Skip to content

Commit dfc4348

Browse files
authored
Merge pull request #120406 from marcosmyh/cosmos-db-update
Update Azure Cosmos DB Emulator instructions for python
2 parents 919ec1c + 1bcd936 commit dfc4348

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

articles/cosmos-db/emulator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Every request made against the emulator must be authenticated using a key over T
5151
5252
## Import emulator certificate
5353

54-
In some cases, you may wish to manually import the TLS/SS certificate from the emulator's running container into your host machine. This step avoids bad practices like disabling TLS/SSL validation in the SDK. For more information, see [import certificate](how-to-develop-emulator.md#export-the-emulators-tlsssl-certificate).
54+
In some cases, you may wish to manually import the TLS/SS certificate from the emulator's running container into your host machine. This step avoids bad practices like disabling TLS/SSL validation in the SDK. For more information, see [import certificate](how-to-develop-emulator.md#import-the-emulators-tlsssl-certificate).
5555

5656
## Next step
5757

articles/cosmos-db/how-to-develop-emulator.md

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ The Docker (Windows) container image doesn't support the API for MongoDB.
351351
352352
::: zone-end
353353
354-
## Export the emulator's TLS/SSL certificate
354+
## Import the emulator's TLS/SSL certificate
355355

356-
Export the certificate for the emulator to use the emulator with your preferred developer SDK without disable TLS/SSL on the client.
356+
Import the emulator's TLS/SSL certificate to use the emulator with your preferred developer SDK without disabling TLS/SSL on the client.
357357
358358
::: zone pivot="api-apache-cassandra,api-apache-gremlin,api-table"
359359
@@ -371,7 +371,7 @@ The Windows local installation of the emulator automatically imports the TLS/SSL
371371

372372
### [Docker (Linux container)](#tab/docker-linux)
373373

374-
The certificate for the emulator is available in the `_explorer/emulator.pem` path on the running container. Use `curl` to download the certificate from the running container to your local machine.
374+
The certificate for the emulator is available at the path `_explorer/emulator.pem` on the running container. Use `curl` to download the certificate from the running container to your local machine.
375375

376376
```bash
377377
curl -k https://localhost:8081/_explorer/emulator.pem > ~/emulatorcert.crt
@@ -391,7 +391,7 @@ The Windows local installation of the emulator automatically imports the TLS/SSL
391391
392392
### [Docker (Linux container) / Docker (Windows container)](#tab/docker-linux+docker-windows)
393393
394-
The certificate for the emulator is available in the `_explorer/emulator.pem` path on the running container.
394+
The certificate for the emulator is available at the path `_explorer/emulator.pem` on the running container.
395395
396396
1. Use `curl` to download the certificate from the running container to your local machine.
397397
@@ -407,6 +407,20 @@ The certificate for the emulator is available in the `_explorer/emulator.pem` pa
407407
```bash
408408
cp ~/emulatorcert.crt /usr/local/share/ca-certificates/
409409
```
410+
1. Update CA certificates and regenerate the certificate bundle by using the appropriate command for your Linux distribution.
411+
412+
For **Debian-based** systems (e.g., Ubuntu), use:
413+
414+
```bash
415+
sudo update-ca-certificates
416+
```
417+
418+
For **Red Hat-based** systems (e.g., CentOS, Fedora), use:
419+
```bash
420+
sudo update-ca-trust
421+
```
422+
423+
For more detailed instructions, consult the documentation specific to your Linux distribution.
410424
411425
### [Windows (local)](#tab/windows)
412426
@@ -418,7 +432,7 @@ The Windows local installation of the emulator automatically imports the TLS/SSL
418432
419433
## Connect to the emulator from the SDK
420434
421-
Each SDK includes a client class typically used to connect the SDK to your Azure Cosmos DB account. Using the [emulator's credentials](emulator.md#authentication), you can connect the SDK to the emulator instance instead.
435+
Each SDK includes a client class typically used to connect the SDK to your Azure Cosmos DB account. By using the [emulator's credentials](emulator.md#authentication), you can connect the SDK to the emulator instance instead.
422436

423437
::: zone pivot="api-nosql"
424438

@@ -467,7 +481,7 @@ Use the [Azure Cosmos DB API for NoSQL .NET SDK](nosql/quickstart-dotnet.md) to
467481
```
468482
469483
> [!WARNING]
470-
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#export-the-emulators-tlsssl-certificate). To resolve this, configure the client's options to disable TLS/SSL validation before creating the client:
484+
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#import-the-emulators-tlsssl-certificate). To resolve this, configure the client's options to disable TLS/SSL validation before creating the client:
471485
>
472486
> ```csharp
473487
> CosmosClientOptions options = new ()
@@ -527,7 +541,7 @@ Use the [Azure Cosmos DB API for NoSQL Python SDK](nosql/quickstart-python.md) t
527541
```
528542
529543
> [!WARNING]
530-
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#export-the-emulators-tlsssl-certificate). To resolve this, configure the application to disable TLS/SSL validation before creating the client:
544+
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#import-the-emulators-tlsssl-certificate). To resolve this, configure the application to disable TLS/SSL validation before creating the client:
531545
>
532546
> ```python
533547
> import urllib3
@@ -536,6 +550,41 @@ Use the [Azure Cosmos DB API for NoSQL Python SDK](nosql/quickstart-python.md) t
536550
> ```
537551
>
538552
553+
If you are still facing SSL errors, it is possible that Python is retrieving the certificates from a different certificate store. To determine the path where Python is looking for the certificates, follow these steps:
554+
>[!IMPORTANT]
555+
>If you are using a Python **virtual environment** (venv) ensure it is **activated** before running the commands!
556+
1. Open a terminal
557+
1. Start the Python interpreter by typing python or python3, depending on your Python version.
558+
1. In the Python interpreter, run the following commands:
559+
```python
560+
from requests.utils import DEFAULT_CA_BUNDLE_PATH
561+
print(DEFAULT_CA_BUNDLE_PATH)
562+
```
563+
564+
**Inside a virtual environment**, the path may be (at least in Ubuntu):
565+
```bash
566+
path/to/venv/lib/pythonX.XX/site-packages/certifi/cacert.pem
567+
```
568+
569+
**Outside of a virtual environment**, the path may be (at least in Ubuntu):
570+
```bash
571+
/etc/ssl/certs/ca-certificates.crt
572+
```
573+
574+
1. Once you have identified the DEFAULT_CA_BUNDLE_PATH, open a **new terminal** and run the following commands to append the emulator certificate to the certificate bundle:
575+
> [!IMPORTANT]
576+
> If DEFAULT_CA_BUNDLE_PATH variable points to a **system directory**, you might encounter a **"Permission denied"** error. In this case, you will need to run the commands with elevated privileges (as root). Also, you will need to [update and regenerate the certificate bundle](#import-the-emulators-tlsssl-certificate) after executing the provided commands.
577+
578+
```bash
579+
# Add a new line to the certificate bundle
580+
echo >> /path/to/ca_bundle
581+
```
582+
583+
```bash
584+
# Append the emulator certificate to the certificate bundle
585+
cat /path/to/emulatorcert.crt >> /path/to/ca_bundle
586+
```
587+
539588
### [JavaScript / Node.js](#tab/javascript+nodejs)
540589
541590
Use the [Azure Cosmos DB API for NoSQL Node.js SDK](nosql/quickstart-nodejs.md) to connect to the emulator from a Node.js/JavaScript application.
@@ -579,7 +628,7 @@ Use the [Azure Cosmos DB API for NoSQL Node.js SDK](nosql/quickstart-nodejs.md)
579628
```
580629
581630
> [!WARNING]
582-
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#export-the-emulators-tlsssl-certificate). To resolve this, configure the application to disable TLS/SSL validation before creating the client:
631+
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#import-the-emulators-tlsssl-certificate). To resolve this, configure the application to disable TLS/SSL validation before creating the client:
583632
>
584633
> ```javascript
585634
> process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
@@ -715,7 +764,7 @@ Use the [MongoDB Node.js driver](mongodb/quickstart-nodejs.md) to connect to the
715764
```
716765
717766
> [!WARNING]
718-
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#export-the-emulators-tlsssl-certificate). To resolve this, configure the application to disable TLS/SSL validation before creating the client:
767+
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#import-the-emulators-tlsssl-certificate). To resolve this, configure the application to disable TLS/SSL validation before creating the client:
719768
>
720769
> ```javascript
721770
> const client = new MongoClient(
@@ -858,7 +907,7 @@ Use the [Apache Cassandra Node.js driver](cassandra/manage-data-nodejs.md) to us
858907
```
859908
860909
> [!WARNING]
861-
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#export-the-emulators-tlsssl-certificate). To resolve this, configure the client to disable TLS/SSL validation:
910+
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#import-the-emulators-tlsssl-certificate). To resolve this, configure the client to disable TLS/SSL validation:
862911
>
863912
> ```javascript
864913
> const client = new Client({
@@ -1136,7 +1185,7 @@ Use the [Azure Tables JavaScript SDK](cassandra/manage-data-nodejs.md) to use th
11361185
```
11371186
11381187
> [!WARNING]
1139-
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#export-the-emulators-tlsssl-certificate). To resolve this, configure the client to disable TLS/SSL validation:
1188+
> If you get a SSL error, you may need to disable TLS/SSL for your application. This commonly occurs if you are developing on your local machine, using the Azure Cosmos DB emulator in a container, and have not [imported the container's SSL certificate](#import-the-emulators-tlsssl-certificate). To resolve this, configure the client to disable TLS/SSL validation:
11401189
>
11411190
> ```javascript
11421191
> const client = TableClient.fromConnectionString(

0 commit comments

Comments
 (0)