elastic / elasticsearch-labs

Notebooks & Example Apps for Search & AI Applications with Elasticsearch
https://www.elastic.co/search-labs
Apache License 2.0
616 stars 151 forks source link

chatbot-rag-app does not work for self-signed (local development) #138

Open liu-xiao-guo opened 9 months ago

liu-xiao-guo commented 9 months ago

For self-signed environment, the code does not work. we need to set the certificate in order to establish a connection with Elasticsearch. There are two places to change:

1) index_data.py

ELASTCSEARCH_CERT_PATH = "/usr/share/certs/http_ca.crt"

if ELASTICSEARCH_URL:
    elasticsearch_client = Elasticsearch(
        hosts=[ELASTICSEARCH_URL], 
        ca_certs = ELASTCSEARCH_CERT_PATH, 
        verify_certs = True
    )
This adds the certificate info into the connection.

2) elasticsearch-client.py

ELASTCSEARCH_CERT_PATH = "/usr/share/certs/http_ca.crt"

if ELASTICSEARCH_URL:
    elasticsearch_client = Elasticsearch(
        hosts=[ELASTICSEARCH_URL], 
        ca_certs = ELASTCSEARCH_CERT_PATH, 
        verify_certs = True
    )

We can index the data using the command like:

docker run \
  --volume="$PWD/http_ca.crt:/usr/share/certs/http_ca.crt:ro" \
  --rm --env-file .env chatbot-rag-app flask create-index

and we can run the frondend like:

docker run \
  --volume="$PWD/http_ca.crt:/usr/share/certs/http_ca.crt:ro" \
  --rm -p 4000:4000 --env-file .env -d chatbot-rag-app
joemcelroy commented 9 months ago

Thanks! For now we have focused on two scenarios: cloud + local instance with security turned off.

An incremental improvement will be to add a heading for when you need to use the self-signed cert and allow the developer to customise the code to accommodate it. Happy for you to add that heading to the readme in a PR.

Will keep this issue open in case there are more developers who want this support. If you do, please react / comment on the issue!