#!/bin/bash # Script to create a custom user for Kibana login # This runs after Elasticsearch is up and creates the user defined in service.env # Wait for Elasticsearch to be ready echo "Waiting for Elasticsearch to be ready..." until curl -s -u elastic:${ELASTIC_PASSWORD} http://localhost:9200/_cluster/health | grep -q '"status":"yellow"\|"status":"green"'; do sleep 5 done echo "Creating user '${KIBANA_USERNAME}'..." # Create the custom user with superuser role curl -X POST -u elastic:${ELASTIC_PASSWORD} \ -H "Content-Type: application/json" \ http://localhost:9200/_security/user/${KIBANA_USERNAME} \ -d '{ "password" : "'${KIBANA_USER_PASSWORD}'", "roles" : [ "superuser" ], "full_name" : "Admin User", "email" : "admin@example.com" }' if [ $? -eq 0 ]; then echo "" echo "User '${KIBANA_USERNAME}' created successfully!" echo "You can now log in to Kibana with:" echo " Username: ${KIBANA_USERNAME}" echo " Password: ${KIBANA_USER_PASSWORD}" else echo "Note: User might already exist or there was an error" fi