Vault & Variables
Comprehensive guide on how to use vault and variables
The vault system in Migraine provides secure variable management with scope awareness. This section covers how to use and manage variables in your workflows.
Overview
The vault system allows you to store, manage, and use variables in your workflows. It provides a secure way to handle sensitive data like API keys, passwords, and other configuration values.
Security Notice
⚠️ IMPORTANT: The current vault implementation stores variables in an unencrypted SQLite database. While the variables are stored locally and not transmitted over networks, they are not encrypted at rest. We are actively working on adding encryption support to the vault system in an upcoming release to enhance security. For now, we recommend avoiding storing highly sensitive information like production API keys in the vault until encryption is implemented.
Variable Scopes
Migraine supports three variable scopes:
- Global - Available to all workflows
- Project - Available to workflows in the same project
- Workflow - Specific to one workflow
Managing Variables
Setting Variables
Listing Variables
Getting Variables
Deleting Variables
Using Variables in Workflows
Configuration
When use_vault: true
is set in a workflow:
- Variables are resolved from the vault according to scope precedence
- Fallback to environment files if vault doesn't contain the variable
- Prompt for missing variables if no fallback exists
When use_vault: false
:
- Variables are loaded from environment files (
.env
or workflow-specific files) - Prompt for missing variables
Variable Resolution Order
When a workflow runs, variables are resolved in this order:
- Command-line flags:
migraine run workflow -v var=value
- Workflow scope (in vault)
- Project scope (in vault)
- Global scope (in vault)
- Environment files (
.env
,./env/[workflow].env
) - Prompt user for missing variables
WORKING_DIR Feature
As of recent updates, Migraine automatically stores the working directory of each workflow as a vault variable:
- The
WORKING_DIR
variable is stored with workflow scope - This enables the
migraine workflow pre-checks <workflow_name>
command to run pre-checks from the stored directory - The system changes to the stored directory, executes the pre-checks, then restores the original directory
Practical Examples
Example 1: Storing and Using API Keys
Example 2: Environment-Specific Variables
Advanced Features
Variable Transformations
You can apply transformations to variables in the workflow configuration:
Validation in Workflows
Use pre-checks to validate that required variables are provided:
Best Practices
1. Use Appropriate Scoping
- Use global variables for values needed across all workflows
- Use project variables for values specific to a project
- Use workflow variables for values specific to a single workflow
2. Secure Handling
- Avoid storing highly sensitive information until encryption is implemented
- Use environment variables for production secrets when possible
- Regularly audit stored variables
3. Documentation
- Document the purpose of variables in comments
- Use descriptive variable names
- Maintain consistency in naming conventions
4. Validation
- Validate required variables in pre-checks
- Use transformations to ensure proper formatting
- Test workflows with different variable values