PortGate

Blueprints · Docker & Databases

Beginner 10 min · Meilisearch

Meilisearch localhost bind and master key

Binds Meilisearch to 127.0.0.1 and refuses to start while the master key is still the placeholder.

Why this should not be public

Without a master key Meilisearch accepts any request, including deleting indexes and adding documents. Even with a key, the admin key belongs on the server; browsers should only ever see a search-only key.

Live config

Baked-in protections

Step 1 · yaml

Compose file

/opt/meilisearch/compose.yaml

The master key is read from an env file the writer creates.

services:
  meilisearch:
    image: getmeili/meilisearch:v1.11
    env_file:
      - ./meili.env
    environment:
      MEILI_ENV: production
      MEILI_HTTP_ADDR: 0.0.0.0:7700
    ports:
      - "127.0.0.1:7700:7700"
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped

Step 2 · bash

Env file and start script

/root/portgate-blueprints/meili-write.sh

The start script is written and not executed.

#!/bin/sh
set -eu
install -d -m 755 "/opt/meilisearch"
umask 077
printf 'MEILI_MASTER_KEY=%s\n' "change-me" > "/opt/meilisearch/meili.env"
chmod 600 "/opt/meilisearch/meili.env"
cat > "/opt/meilisearch/up.sh" <<'EOF'
#!/bin/sh
set -eu
if grep -q '^MEILI_MASTER_KEY=change-me$' "/opt/meilisearch/meili.env"; then
  echo "Set MEILI_MASTER_KEY before starting." >&2
  exit 1
fi
cd "/opt/meilisearch"
docker compose up -d
EOF
chmod 755 "/opt/meilisearch/up.sh"
echo "Start script written. It was not run."