Overview
Infisical is a secure secret management platform that GAIA uses to centrally manage environment variables and API keys. Instead of storing sensitive information in .env
files, Infisical allows you to:
Centrally manage secrets across multiple environments
Secure access controls with role-based permissions
Audit logging for secret access and changes
Automatic secret rotation capabilities
Team collaboration with shared secret access
When Infisical is configured, it will override any local environment variables with the same names from your Infisical project.
How Infisical Works with GAIA
GAIA’s backend automatically loads secrets from Infisical during startup using the inject_infisical_secrets()
function. Here’s the process:
Authentication : Uses machine identity credentials to authenticate with Infisical
Secret Retrieval : Fetches all secrets from your Infisical project
Environment Injection : Overwrites local environment variables with Infisical secrets
Application Startup : GAIA starts with the combined environment configuration
Setting Up Infisical
Step 1: Create an Infisical Account
Visit app.infisical.com
Sign up for a free account
Create a new project for GAIA
Step 2: Create a Machine Identity
Machine identities allow GAIA to authenticate with Infisical automatically:
Go to Project Settings → Access Control → Machine Identities
Click Create Identity
Configure the identity:
Name : gaia-backend
Role : Admin or Developer (with read access to secrets)
Note down the Client ID and Client Secret
Step 3: Add Secrets to Infisical
Navigate to your project’s Secrets section and add all your environment variables:
Core Application ENV = production
DEBUG = false
HOST = https://api.heygaia.io
FRONTEND_URL = https://heygaia.io
Database URLs POSTGRES_URL = postgresql://user:pass@host:5432/db
MONGO_DB = mongodb://user:pass@host:27017/gaia
REDIS_URL = redis://user:pass@host:6379
AI API Keys OPENAI_API_KEY = sk-your-openai-key
GEMINI_API_KEY = your-gemini-key
HUGGINGFACE_API_KEY = hf_your-hf-token
Integration APIs GOOGLE_CLIENT_ID = your-google-client-id
GOOGLE_CLIENT_SECRET = your-google-secret
BING_API_KEY = your-bing-key
Add the Infisical configuration to your backend .env
file:
# Infisical Configuration
INFISICAL_PROJECT_ID = your-project-id-from-infisical
INFISICAL_MACHINE_INDENTITY_CLIENT_ID = your-client-id
INFISICAL_MACHINE_INDENTITY_CLIENT_SECRET = your-client-secret
# Optional: Set environment (defaults to 'production')
ENV = development
The INFISICAL_PROJECT_ID
, INFISICAL_MACHINE_INDENTITY_CLIENT_ID
, and INFISICAL_MACHINE_INDENTITY_CLIENT_SECRET
must be set in your local .env
file - they cannot be stored in Infisical itself since they’re needed to authenticate with Infisical.
Environment Priority
GAIA loads environment variables in this order (later sources override earlier ones):
System environment variables
Local .env
file variables
Infisical secrets (highest priority)
This means:
✅ Infisical secrets will override local .env
variables
✅ You can use local .env
for development and Infisical for production
✅ Critical secrets are managed centrally through Infisical
Development vs Production
Development Setup
For local development, you can choose between:
Option A: Use Infisical (Recommended for teams)
# backend/.env
ENV = development
INFISICAL_PROJECT_ID = your-dev-project-id
INFISICAL_MACHINE_INDENTITY_CLIENT_ID = your-client-id
INFISICAL_MACHINE_INDENTITY_CLIENT_SECRET = your-client-secret
Option B: Use Local Environment Variables
# backend/.env
ENV = development
# Add all your environment variables here
OPENAI_API_KEY = your-local-dev-key
# ... other variables
Production Setup
For production, always use Infisical :
# backend/.env (production)
ENV = production
INFISICAL_PROJECT_ID = your-prod-project-id
INFISICAL_MACHINE_INDENTITY_CLIENT_ID = your-prod-client-id
INFISICAL_MACHINE_INDENTITY_CLIENT_SECRET = your-prod-client-secret
Troubleshooting
Common Issues
InfisicalConfigError: INFISICAL_PROJECT_ID is missing
Solution : Add the INFISICAL_PROJECT_ID
to your .env
file. You can find this in your Infisical project settings.
Solution :
Verify your INFISICAL_MACHINE_INDENTITY_CLIENT_ID
and INFISICAL_MACHINE_INDENTITY_CLIENT_SECRET
Ensure the machine identity has proper permissions
Check that the identity is enabled
Solution :
Verify the environment slug matches (development/production)
Check that secrets exist in the correct Infisical project
Ensure the machine identity has read access to secrets
Local variables not being overridden
Solution : This is expected behavior. Infisical secrets have the highest priority and will override local variables with the same name.
Debug Mode
To debug Infisical integration, check the application logs during startup. The backend will log any Infisical connection issues.
Security Best Practices
Access Control
Use separate machine identities for different environments
Grant minimal required permissions
Regularly audit access logs
Secret Management
Use different secrets for dev/staging/production
Rotate secrets regularly
Never commit Infisical credentials to version control
Environment Separation
Use separate Infisical projects for each environment
Implement proper CI/CD secret injection
Monitor secret access patterns
Backup Strategy
Export secrets regularly for backup
Document secret recovery procedures
Have fallback authentication methods
Next Steps
Responses are generated using AI and may contain mistakes.