Why can't i connect kibana with Elasticsearch?

Yeah...no worries... its weekend.... i will take a look see what I can figure out

Have a good weekend... maybe I will have something for you...

good / bad I seem to be seeing same thing....

EDIT : Found it ... tricky has to do with the order things are created.....

You bring the components up...
Then you are creating the token...
But by the time you do that Kibana is already up...
You need to delete the Kibana container and then "up" / recreate it again...
Then ENV vars are only read once on startup.

Let me see if I can figure out the right way....

The problem that I see is the ENV vars are read at container creation time, but you don't have the token yet... when you paste in the token after it is not read...

You can see that by running

$ docker inspect kibana you will see the new token is not taken.

OK this worked.... without fancy scripting...

  1. Comment out the whole kibana section in your compose

  2. $ docker compose -f discuss-compose-service-token.yml up

  3. Let it come up....

  4. In another window run

  5. $ docker exec -it elastic /usr/share/elasticsearch/bin/elasticsearch-service-tokens create elastic/kibana kibana-service-token

  6. Get the token

  7. Stop docker up...

  8. Uncomment the kibana section and put in the token

  9. $ docker compose -f discuss-compose-service-token.yml up

Everything works...

As an alternate...
If you want a better way to do this, I suggest looking at this.., you can trim the compose down to a single node if you like

Thank you so much for the follow up @stephenb in the line:

  1. $ Docker compose -f discuss-compose-service-token.yml up
    Could you please tell me where do i get the file discuss-compose-service-token.yml ?
    Sorry for my late reply, you know a lot of work bro :slight_smile:

That is a file I created basically the same as your but I took out a few things...

$ cat discuss-compose-service-token.yml

---
services:
  elastic:
    container_name: elastic
    image: docker.elastic.co/elasticsearch/elasticsearch:8.18.0
    ports:
      - 9200:9200
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=true
      #- xpack.security.http.ssl.enabled=true
      - ELASTIC_PASSWORD=Cu213lona1993
      #- xpack.security.http.ssl.keystore.path=/usr/share/elasticsearch/config/certs/elastic.keystore.jks
      #- xpack.security.http.ssl.keystore.password=changeit
    healthcheck:
      test: ["CMD-SHELL", "curl -s -k -u elastic:Cu213lona1993 http://localhost:9200 | grep -q 'cluster_name'"]
      interval: 10s
      timeout: 5s
      retries: 10
    volumes:
      - ./certs:/usr/share/elasticsearch/config/certs  
  kibana:
    container_name: kibana
    image: docker.elastic.co/kibana/kibana:8.18.0
    ports:
      - 5601:5601
    environment:
      - ELASTICSEARCH_HOSTS=http://elastic:9200
      - ELASTICSEARCH_SERVICEACCOUNTTOKEN=AAEAAWVsYXN0aWMva2liYW5hL2tpYmFuYS1zZXJ2aWNlLXRva2VuOktpZENtc1RwVGJDR1c5YVdENFVseXc
      - SERVER_SSL_ENABLED=false
      - SERVER_PUBLICBASEURL=http://localhost:5601
      - ELASTICSEARCH_SSL_VERIFICATIONMODE=none  # Para ignorar el certificado autofirmado
    depends_on:
      elastic:
        condition: service_healthy  

I ran these from th kibana container to check

curl -s -k -H "Authorization: Bearer AAEAAWVsYXN0aWMva2liYW5hL2tpYmFuYS1zZXJ2aWNlLXRva2VuOkhXOTEzQnh5U3ZXUGtwTjc3X01Kamc" http://elastic:9200/_cat/health?v

curl -k -H "Authorization: Bearer AAEAAWVsYXN0aWMva2liYW5hL2tpYmFuYS1zZXJ2aWNlLXRva2VuOkhXOTEzQnh5U3ZXUGtwTjc3X01Kamc" http://elastic:9200/_nodes?filter_path=nodes.*.version%2Cnodes.*.http.publish_address%2Cnodes.*.ip

Can I ask what you are actually trying to do?

If you just want Elastic and Kibana to Run and play with it... there are plenty of compose out there

You are just complicating things with the service token.

well, actually my porpouse is to learn about elasticsearch and at the same time with kibana. I must tell you that i already achieve. I just create 2 containers following the documentation and making a small change in the security configuration BUT this time i really took care of data is displayed when ES container is created the first time:

Datos de configuración de seguridad en Elasticsearch:

:white_check_mark: Elasticsearch security features have been automatically configured!
:white_check_mark: Authentication is enabled and cluster connections are encrypted.

:information_source: Password for the elastic user (reset with bin/elasticsearch-reset-password -u elastic):
lq67VKk3a5fLRAv3e+5n

:information_source: HTTP CA certificate SHA-256 fingerprint:
10c9a75c3ab28fed209f3830aed9136b9fc1cb14a9f6fe1bef076198bda56dc4

:information_source: Configure Kibana to use this cluster:
• Run Kibana and click the configuration link in the terminal when Kibana starts.
• Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTcyLjE5LjAuMjo5MjAwIl0sImZnciI6IjEwYzlhNzVjM2FiMjhmZWQyMDlmMzgzMGFlZDkxMzZiOWZjMWNiMTRhOWY2ZmUxYmVmMDc2MTk4YmRhNTZkYzQiLCJrZXkiOiJVSHlpdlpjQklrTWRCam1DWlBYNDp6NDJ2ZGdGN2tqRDRWLWFxVHhLaG1nIn0=

:information_source: Configure other nodes to join this cluster:
• Copy the following enrollment token and start new Elasticsearch nodes with bin/elasticsearch --enrollment-token <token> (valid for the next 30 minutes):
eyJ2ZXIiOiI4LjE0LjAiLCJhZHIiOlsiMTcyLjE5LjAuMjo5MjAwIl0sImZnciI6IjEwYzlhNzVjM2FiMjhmZWQyMDlmMzgzMGFlZDkxMzZiOWZjMWNiMTRhOWY2ZmUxYmVmMDc2MTk4YmRhNTZkYzQiLCJrZXkiOiJVbnlpdlpjQklrTWRCam1DWlBYLTpTek5BNVhJcnpVVk9obkEybWpiOHlnIn0=

If you're running in Docker, copy the enrollment token and run:
`docker run -e "ENROLLMENT_TOKEN=" docker.elastic.co/elasticsearch/elasticsearch:8.1

You did it great, the issue is that if i remove the lines:

#- xpack.security.http.ssl.keystore.path=/usr/share/elasticsearch/config/certs/elastic.keystore.jks
      #- xpack.security.http.ssl.keystore.password=changeit

i couldn't connect ES with my spring boot app

But mission accomplished. ES and kibana is up and running with security enabled. :slight_smile:

Hope you can keep on giving me the further support if needed @stephenb

1 Like