how to setup kibana user credentials with docker elk stack

13,241

For setting kibana user credentials for docker elk stack, we have to set xpack.security.enabled: true either in elasticsearch.yml or pass this as a environment variable in docker-compose.yml file.

Pass username & password as environment variable in docker-compose.yml like below:

version: '3.3'

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
    ports:
      - "9200:9200"
      - "9300:9300"
    configs:
      - source: elastic_config
        target: /usr/share/elasticsearch/config/elasticsearch.yml
    environment:
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
      ELASTIC_USERNAME: "elastic"
      ELASTIC_PASSWORD: "MyPw123"
      http.cors.enabled: "true"
      http.cors.allow-origin: "*"
      xpack.security.enabled: "true"
    networks:
      - elk
    deploy:
      mode: replicated
      replicas: 1

  logstash:
    image: docker.elastic.co/logstash/logstash:6.6.1
    ports:
      - "5044:5044"
      - "9600:9600"
    configs:
      - source: logstash_config
        target: /usr/share/logstash/config/logstash.yml:rw
      - source: logstash_pipeline
        target: /usr/share/logstash/pipeline/logstash.conf
    environment:
      LS_JAVA_OPTS: "-Xmx256m -Xms256m"
      xpack.monitoring.elasticsearch.url: "elasticsearch:9200"
      xpack.monitoring.elasticsearch.username: "elastic"
      xpack.monitoring.elasticsearch.password: "MyPw123"
    networks:
      - elk
    deploy:
      mode: replicated
      replicas: 1

  kibana:
    image: docker.elastic.co/kibana/kibana:6.6.1
    ports:
      - "5601:5601"
    configs:
      - source: kibana_config
        target: /usr/share/kibana/config/kibana.yml
    networks:
      - elk
    deploy:
      mode: replicated
      replicas: 1

configs:
  elastic_config:
    file: ./elasticsearch/config/elasticsearch.yml
  logstash_config:
    file: ./logstash/config/logstash.yml
  logstash_pipeline:
    file: ./logstash/pipeline/logstash.conf
  kibana_config:
    file: ./kibana/config/kibana.yml

networks:
  elk:
    driver: overlay

Then add this following lines to kibana.yml:

elasticsearch.username: "elastic"
elasticsearch.password: "MyPw123" 
Share:
13,241
James Taylor
Author by

James Taylor

Updated on June 21, 2022

Comments

  • James Taylor
    James Taylor almost 2 years

    How to setup login credentials for kibana gui with docker elk stack containers.

    What arguments and environmental variables must be passed in docker-compose.yaml file to get this working.

  • Vincent Decaux
    Vincent Decaux about 3 years
    Just in case, elasticsearch.url became elasticsearch.hosts and expects an array of URL
  • ynux
    ynux about 2 years
    This will work. Note, however, that this is using the most powerful "elastic" user for all tasks, while there is a sophisticated role concept giving kibana and logstash just the privileges they need.
  • Mohsenasm
    Mohsenasm about 2 years
    Is there any way without using configs or custom Dockerfiles? (i.e. just using environments)