Hi, everybody.
I have a problem with elasticsearch 8 and docker, which I am sitting on last 3-4 hours.
I have next docker compose configuration which consist of php symfony application and elasticsearch single node with security enabled options.
version: '2.2'
services:
php_symfony_application:
build: ./ci/php
container_name: "php_symfony_application"
volumes:
- .:/var/www/php_symfony_application
setup:
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
container_name: "udemy_phpes_setup"
volumes:
- certs:/usr/share/elasticsearch/config/certs
user: "0"
command: >
bash -c '
if [ x${ELASTIC_PASSWORD} == x ]; then
echo "Set the ELASTIC_PASSWORD environment variable in the .env file";
exit 1;
fi;
if [ ! -f certs/ca.zip ]; then
echo "Creating CA";
bin/elasticsearch-certutil ca --silent --pem -out config/certs/ca.zip;
unzip config/certs/ca.zip -d config/certs;
fi;
if [ ! -f certs/certs.zip ]; then
echo "Creating certs";
echo -ne \
"instances:\n"\
" - name: elasticsearch8\n"\
" dns:\n"\
" - elasticsearch8\n"\
" - localhost\n"\
" ip:\n"\
" - 127.0.0.1\n"\
> config/certs/instances.yml;
bin/elasticsearch-certutil cert --silent --pem -out config/certs/certs.zip --in config/certs/instances.yml --ca-cert config/certs/ca/ca.crt --ca-key config/certs/ca/ca.key;
unzip config/certs/certs.zip -d config/certs;
fi;
echo "Setting file permissions"
chown -R root:root config/certs;
find . -type d -exec chmod 750 \{\} \;;
find . -type f -exec chmod 640 \{\} \;;
echo "Waiting for Elasticsearch availability";
until curl -s --cacert config/certs/ca/ca.crt https://elasticsearch8:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
echo "All done!";
'
healthcheck:
test: [ "CMD-SHELL", "[ -f config/certs/elasticsearch8/elasticsearch8.crt ]" ]
interval: 1s
timeout: 5s
retries: 120
elasticsearch8:
depends_on:
setup:
condition: service_healthy
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
container_name: "elasticsearch8"
volumes:
- certs:/usr/share/elasticsearch/config/certs
- ./ci/data/es/db:/usr/share/elasticsearch/data
ports:
- ${ES_PORT}:9200
expose:
- ${ES_PORT}
environment:
- node.name=elasticsearch8
- cluster.name=${CLUSTER_NAME}
- cluster.initial_master_nodes=elasticsearch8
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
- bootstrap.memory_lock=true
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=certs/elasticsearch8/elasticsearch8.key
- xpack.security.http.ssl.certificate=certs/elasticsearch8/elasticsearch8.crt
- xpack.security.http.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.http.ssl.verification_mode=certificate
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.key=certs/elasticsearch8/elasticsearch8.key
- xpack.security.transport.ssl.certificate=certs/elasticsearch8/elasticsearch8.crt
- xpack.security.transport.ssl.certificate_authorities=certs/ca/ca.crt
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.license.self_generated.type=${LICENSE}
ulimits:
memlock:
soft: -1
hard: -1
healthcheck:
test:
[
"CMD-SHELL",
"curl -s --cacert config/certs/ca/ca.crt https://localhost:9200 | grep -q 'missing authentication credentials'",
]
interval: 10s
timeout: 10s
retries: 120
volumes:
certs:
driver: local
I can connect from local machine with curl using certificate:
curl --cacert path/to/ca.crt -u elastic:test1234 https://localhost:9202/_cluster/health?prett
All works in that case as it should be.
But while being inside php application container and running the curl with certificate:
curl --cacert path/to/ca.crt -u elastic:test1234 https://elasticsearch8:9200/_cluster/health?pretty
I am getting the error:
curl: (35) error:14094417:SSL routines:ssl3_read_bytes:sslv3 alert illegal parameter
As result (at least I suppose it is the reason) while trying to connect to the cluster via elasticsearch-php client with next code:
$client = ClientBuilder::create()
->setHosts(['https://elasticsearch8:9200'])
->setBasicAuthentication('elastic', 'test1234')
->setCABundle('path/to/http_ca.crt')
->build();
I am getting the error: "No alive nodes. All the 1 nodes seem to be down."
Seems it is some issue related to the docker,dns and certificates altogether. I completely stuck with that and have no more ideas how to resolve the problem.
Can anybody save my day? I would be very grateful for any ideas.
Thanks