# Infisical Secret Management

> Open source secret management platform for teams.

- Category: Security & Networking
- Difficulty: intermediate
- Components: infisical, postgresql, redis, smtp4dev
- Tags: infisical, secrets, environment-variables, security, vault
- Source: https://docker.recipes/security/infisical-secrets

## Overview

Infisical is an open-source secret management platform launched in 2022 that helps development teams securely store, manage, and sync environment variables, API keys, database credentials, and other sensitive configuration data across their applications and infrastructure. Unlike traditional solutions that require complex enterprise setups, Infisical provides a developer-friendly approach to secret management with features like automatic secret injection, audit logging, role-based access controls, and integrations with popular CI/CD platforms and cloud providers.

This Docker stack combines Infisical with MongoDB for persistent secret storage, Redis for session management and caching, and SMTP4dev for email functionality testing. MongoDB handles the encrypted storage of secrets and user data with Infisical's client-side encryption ensuring secrets remain secure even at the database level. Redis provides fast session storage and caching for the web interface, while SMTP4dev serves as a local email server for testing user invitations, password resets, and security notifications without requiring external email services.

This configuration is ideal for development teams, DevOps engineers, and security-conscious organizations who need centralized secret management without vendor lock-in. The self-hosted approach gives complete control over sensitive data while the containerized setup allows for easy deployment in development environments, on-premises infrastructure, or private cloud instances where data sovereignty and compliance requirements prohibit using external secret management services.

## Features

- Client-side encryption with multiple encryption keys for different secret types and JWT token management
- MongoDB-backed persistent storage with automatic secret versioning and audit trail capabilities
- Redis-powered session management for fast web interface performance and user authentication
- Integrated CLI tool for syncing secrets directly to local development environments and CI/CD pipelines
- SMTP4dev email server for testing user invitations, password resets, and security notifications locally
- Role-based access controls with project-level permissions and team management features
- REST API and SDK support for programmatic secret retrieval in applications
- Real-time secret synchronization across development, staging, and production environments

## Use cases

- Development teams managing API keys, database credentials, and configuration across multiple environments
- Startups requiring secure secret management without the cost of enterprise solutions like HashiCorp Vault
- Organizations with data sovereignty requirements needing on-premises secret storage
- DevOps teams implementing GitOps workflows while keeping secrets out of version control
- Companies transitioning from hardcoded secrets or basic environment variable management
- Security teams establishing centralized secret management with audit logging and access controls
- Development agencies managing secrets across multiple client projects with isolated access

## Prerequisites

- Docker and Docker Compose with at least 2GB available RAM for MongoDB and Redis operations
- Ports 8080 and 5000 available on the host system for Infisical web interface and SMTP4dev
- Generated encryption keys for ENCRYPTION_KEY, JWT secrets - use strong 32+ character random strings
- Basic understanding of secret management concepts and environment variable injection
- Node.js environment if planning to use the Infisical CLI for local development integration
- Network access planning if deploying in production environments with firewall restrictions

## docker-compose.yml

```yaml
services:
  infisical:
    image: infisical/infisical:latest
    ports:
      - "8080:8080"
    environment:
      ENCRYPTION_KEY: ${ENCRYPTION_KEY}
      JWT_SIGNUP_SECRET: ${JWT_SIGNUP_SECRET}
      JWT_REFRESH_SECRET: ${JWT_REFRESH_SECRET}
      JWT_AUTH_SECRET: ${JWT_AUTH_SECRET}
      JWT_SERVICE_SECRET: ${JWT_SERVICE_SECRET}
      SITE_URL: http://localhost:8080
      MONGO_URL: mongodb://mongo:27017/infisical
      REDIS_URL: redis://redis:6379
      SMTP_HOST: smtp4dev
      SMTP_PORT: 25
      SMTP_FROM_ADDRESS: noreply@infisical.local
    depends_on:
      - mongo
      - redis
    networks:
      - infisical-net
    restart: unless-stopped

  mongo:
    image: mongo:7
    volumes:
      - mongo_data:/data/db
    networks:
      - infisical-net
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data
    networks:
      - infisical-net
    restart: unless-stopped

  smtp4dev:
    image: rnwood/smtp4dev:latest
    ports:
      - "5000:80"
    networks:
      - infisical-net
    restart: unless-stopped

volumes:
  mongo_data:
  redis_data:

networks:
  infisical-net:
    driver: bridge
```

## .env

```bash
# Infisical Secrets (generate with openssl rand -hex 32)
ENCRYPTION_KEY=$(openssl rand -hex 16)
JWT_SIGNUP_SECRET=$(openssl rand -hex 32)
JWT_REFRESH_SECRET=$(openssl rand -hex 32)
JWT_AUTH_SECRET=$(openssl rand -hex 32)
JWT_SERVICE_SECRET=$(openssl rand -hex 32)
```

## Usage notes

- Infisical at http://localhost:8080
- Create organization and project
- Install CLI: npm install -g @infisical/cli
- Sync secrets to local environment

## Troubleshooting

- Infisical fails to start with encryption key errors: Ensure all JWT secrets and ENCRYPTION_KEY are properly set with strong random values of at least 32 characters
- MongoDB connection failures on startup: Verify the mongo service is healthy and the MONGO_URL matches the service name and port in the Docker network
- Redis connection timeouts affecting session management: Check Redis service status and ensure REDIS_URL format is correct with redis://redis:6379
- SMTP4dev not receiving emails from Infisical: Verify SMTP_HOST points to 'smtp4dev' service name and port 25 is correctly configured
- Web interface loads but login fails: Check MongoDB data persistence and ensure the mongo_data volume is properly mounted and writable
- CLI authentication errors: Verify the SITE_URL matches your actual Infisical access URL and check network connectivity between CLI and container

