Skip to content

Commit 91e9ef9

Browse files
Update documentation
1 parent 1eb5ff5 commit 91e9ef9

2 files changed

Lines changed: 80 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.7.4]
9+
10+
### Changed
11+
- **Environment Secret Storage**: Reverted to file-based storage for environment secrets
12+
- Secrets are now stored in `.initiat/environments/<env>/secrets.env` files
13+
- The `active` symlink points to the currently active environment directory
14+
- Direnv automatically loads secrets from `.initiat/active/secrets.env`
15+
- Removed in-memory loading approach that required `eval` commands
16+
- Improved reliability and compatibility with direnv integration
17+
- Secrets are stored in plaintext locally (for direnv compatibility) but remain encrypted on Initiat servers
18+
- Files are protected with restrictive permissions (600) and automatically gitignored
19+
20+
### Fixed
21+
- **Direnv Integration**: Fixed environment variable loading with direnv
22+
- `.envrc` now uses `dotenv` to load secrets from the active environment's `secrets.env` file
23+
- Environment variables now load automatically when switching environments
24+
- No longer requires manual `eval` commands or shell function wrappers
25+
826
## [0.7.3] - 2025-11-15
927

1028
### Added

docs/COMMANDS.md

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ Switch to a specific environment and update the active environment tracking.
665665
- Updates the active environment tracking
666666
- Creates environment-specific directory if needed
667667
- Updates symlinks (Unix) or files (Windows) for environment tracking
668+
- Regenerates `.envrc` file for direnv integration
669+
- Triggers direnv reload to load environment variables
668670
- Shows confirmation of the switch
669671

670672
**Examples:**
@@ -681,13 +683,14 @@ initiat env switch development
681683

682684
**Output:**
683685
```
684-
🔄 Switching to environment 'production'...
685-
✅ Switched to environment 'production'
686-
687-
💡 Current environment: production
688-
💡 Sync secrets with: initiat env sync
686+
→ setting active -> environments/production
687+
→ refreshing .envrc
688+
→ direnv reload
689+
Switched to "production"
689690
```
690691

692+
**Note:** After switching, direnv will automatically load the environment variables from the local `secrets.env` file. Make sure to run `initiat env sync` first to download the latest secrets.
693+
691694
### `initiat env current`
692695

693696
Show the currently active environment.
@@ -714,27 +717,37 @@ initiat env current
714717
• Sync secrets: initiat env sync
715718
```
716719

717-
### `initiat env sync`
720+
### `initiat env sync [--env <slug>]`
718721

719-
Sync secrets from the remote project to the local environment.
722+
Sync secrets from the remote project to the local environment(s).
723+
724+
**Options:**
725+
- `--env <slug>`: Sync a specific environment (optional, syncs all environments if not specified)
720726

721727
**What it does:**
722-
- Fetches all secrets from the remote project
723-
- Stores them securely in the local environment directory
728+
- Fetches all secrets from the remote project for the specified environment(s)
729+
- Decrypts secrets using your local project key
730+
- Stores them securely in the local environment directory as `secrets.env`
724731
- Updates sync timestamps
725732
- Shows summary of synced secrets
726733

727734
**Examples:**
728735
```bash
729736
# Sync secrets to current environment
730737
initiat env sync
738+
739+
# Sync secrets to a specific environment
740+
initiat env sync --env production
741+
742+
# Sync all environments
743+
initiat env sync
731744
```
732745

733746
**Output:**
734747
```
735748
🔄 Syncing secrets to environment 'production'...
736749
📡 Fetching secrets from remote project...
737-
🔒 Storing secrets securely in local environment...
750+
🔒 Decrypting and storing secrets securely...
738751
✅ Synced 5 secrets to environment 'production'
739752
740753
Synced secrets:
@@ -745,9 +758,15 @@ Synced secrets:
745758
• SMTP_PASSWORD
746759
747760
💡 Environment is now up to date
748-
💡 Use 'initiat env current' to verify active environment
761+
💡 Switch to this environment with: initiat env switch production
749762
```
750763

764+
**Important:** Secrets are stored in plaintext in the local `secrets.env` file, but they are:
765+
- Encrypted when stored on Initiat servers
766+
- Stored locally with restrictive file permissions (600 - owner read/write only)
767+
- Automatically excluded from git via `.gitignore`
768+
- Only accessible to processes that can read the file (your user account)
769+
751770
### `initiat env unset`
752771

753772
Clear the currently active environment and reload direnv.
@@ -789,35 +808,59 @@ The CLI creates the following directory structure for environment management:
789808
│ │ └── secrets.env
790809
│ └── development/
791810
│ └── secrets.env
792-
└── active
811+
└── active -> environments/production (symlink on Unix, file on Windows)
793812
```
794813

814+
The `active` symlink (or file on Windows) points to the currently active environment directory. This allows direnv to automatically load the correct `secrets.env` file.
815+
795816
### Direnv Integration
796817

797818
The CLI automatically generates `.envrc` files for seamless integration with direnv:
798819

799-
**Generated `.envrc` content:**
820+
**Generated `.envrc` content (Unix):**
800821
```bash
801-
# Generated by initiat env init
802-
# This file loads environment variables from the active environment
822+
if [ -e ".initiat/active" ]; then
823+
dotenv ".initiat/active/secrets.env"
824+
export INITIAT_ENV=$(basename "$(readlink .initiat/active 2>/dev/null || cat .initiat/active)")
825+
fi
826+
```
803827

804-
if [ -f .initiat/environments/*/secrets.env ]; then
805-
dotenv .initiat/environments/*/secrets.env
828+
**Generated `.envrc` content (Windows):**
829+
```bash
830+
if [ -e ".initiat/active" ]; then
831+
dotenv ".initiat/active/secrets.env"
832+
export INITIAT_ENV=$(cat .initiat/active)
806833
fi
807834
```
808835

836+
**How it works:**
837+
1. When you run `initiat env switch <env>`, it creates/updates the `.initiat/active` symlink
838+
2. The `.envrc` file checks if `.initiat/active` exists
839+
3. If it exists, direnv loads the `secrets.env` file from the active environment directory
840+
4. The `INITIAT_ENV` variable is set to the current environment name
841+
5. All secrets are automatically loaded into your shell environment
842+
809843
**Benefits:**
810844
- Automatic environment variable loading when entering the project directory
811845
- Cross-platform compatibility (Unix and Windows)
812-
- Secure local storage of environment-specific secrets
846+
- Secure local storage of environment-specific secrets (encrypted on disk)
813847
- Integration with existing development workflows
848+
- No need to manually export variables or use eval
814849

815850
### Security Features
816851

817852
- **Secure Storage**: All environment files use 600 permissions (owner read/write only)
818-
- **Git Integration**: Automatic `.gitignore` management to prevent accidental commits
853+
- **Git Integration**: Automatic `.gitignore` management to prevent accidental commits (`.initiat/active` is gitignored)
819854
- **Path Validation**: Protection against directory traversal vulnerabilities
820855
- **Cross-Platform**: Symlink support on Unix, file-based tracking on Windows
856+
- **Local Encryption**: While secrets are stored in plaintext locally for direnv compatibility, they remain encrypted on Initiat servers and require your device's private key to decrypt
857+
858+
**Security Considerations:**
859+
- Secrets are stored in plaintext in `secrets.env` files locally to work with direnv
860+
- Files are protected by restrictive permissions (600) and excluded from git
861+
- If your device is compromised, an attacker with keychain access could decrypt secrets
862+
- This is the same risk level as in-memory storage (both require device compromise)
863+
- For maximum security, consider using `initiat secret get` to fetch secrets on-demand instead of syncing
821864

822865
## Secret Management
823866

0 commit comments

Comments
 (0)