This document describes how to integrate Infisical secrets management with the WordPress Docker deployments.
Infisical provides centralized secrets management, allowing you to:
- Store database credentials securely outside of version control
- Rotate credentials without redeploying infrastructure
- Audit access to sensitive values
- Sync secrets across multiple environments
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Developer │────▶│ Infisical │◀────│ Cloud-Init │
│ (local) │ │ (SaaS/Self) │ │ (bootstrap) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ .env file │
│ (on droplet) │
└─────────────────┘
│
▼
┌─────────────────┐
│ Docker Stack │
│ (WordPress) │
└─────────────────┘
- Log in to Infisical or your self-hosted instance
- Create a new project for your WordPress site
- Add the following secrets:
| Secret Name | Description | Example |
|---|---|---|
MYSQL_DATABASE |
WordPress database name | wordpress |
MYSQL_USER |
WordPress database user | wordpress |
MYSQL_PASSWORD |
WordPress database password | <strong-password> |
MYSQL_ROOT_PASSWORD |
MySQL root password | <strong-root-password> |
WP_IMAGE |
WordPress Docker image | reg.mini.dev/1923/wordpress-fluentsmtp:latest |
CADDY_IMAGE |
Caddy Docker image | reg.mini.dev/caddy:2 |
DOMAIN |
Site domain | example.com |
- Navigate to Project Settings → Machine Identities
- Create a new Machine Identity
- Add Universal Auth method
- Copy the Client ID and Client Secret
- Generate a token using the CLI:
export INFISICAL_UNIVERSAL_AUTH_CLIENT_ID=<client-id>
export INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET=<client-secret>
infisical login --method=universal-authIn terraform.tfvars:
infisical_client_id = "your-client-id"
infisical_client_secret = "your-client-secret"
infisical_project_id = "your-project-id"
infisical_environment = "prod"The cloud-init script will:
- Install the Infisical CLI (via artifacts-cli.infisical.com apt repo)
- Authenticate using the Machine Identity (Universal Auth)
- Rotate the bootstrap secret (Layer 2)
- Write
.infisical-auth.envfor the ansible playbook
runcmd:
# Install Infisical CLI
- curl -1sLf 'https://dl.cloudsmith.io/public/infisical/infisical-cli/setup.deb.sh' | sudo -E bash
- apt-get update && apt-get install -y infisical
# Export secrets to .env
- |
infisical export \
--token="${infisical_token}" \
--projectId="${infisical_project_id}" \
--env="${infisical_environment}" \
--format=dotenv > /opt/myproject/.env- Update the secret value in Infisical
- SSH to the droplet and re-export:
infisical export \
--token="$INFISICAL_TOKEN" \
--projectId="$PROJECT_ID" \
--env="prod" \
--format=dotenv > /opt/myproject/.env
cd /opt/myproject
docker compose down && docker compose up -d#!/usr/bin/env bash
# rotate-credentials.sh
set -euo pipefail
APP_DIR="/opt/myproject"
INFISICAL_TOKEN="${INFISICAL_TOKEN:-}"
PROJECT_ID="${PROJECT_ID:-}"
# Re-export secrets
infisical export \
--token="$INFISICAL_TOKEN" \
--projectId="$PROJECT_ID" \
--env="prod" \
--format=dotenv > "$APP_DIR/.env"
# Restart containers with new credentials
cd "$APP_DIR"
docker compose down
docker compose up -d
echo "Credentials rotated successfully"- Token Scope: Use minimal scopes for Machine Identity tokens
- Token Rotation: Rotate Infisical tokens periodically
- Audit Logs: Enable and review Infisical audit logs
- IP Allowlist: Restrict token usage to droplet IP if possible
- Environment Isolation: Use separate Infisical environments for staging/prod
# Verify token is valid
infisical login --method=universal-auth --token="$INFISICAL_TOKEN"
# Check token permissions
infisical projects list# Manual export with debug output
infisical export \
--token="$INFISICAL_TOKEN" \
--projectId="$PROJECT_ID" \
--env="prod" \
--format=dotenv \
--debug# Force recreate containers
docker compose down
docker compose up -d --force-recreate