You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/COMMANDS.md
+62-19Lines changed: 62 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -665,6 +665,8 @@ Switch to a specific environment and update the active environment tracking.
665
665
- Updates the active environment tracking
666
666
- Creates environment-specific directory if needed
667
667
- Updates symlinks (Unix) or files (Windows) for environment tracking
668
+
- Regenerates `.envrc` file for direnv integration
669
+
- Triggers direnv reload to load environment variables
668
670
- Shows confirmation of the switch
669
671
670
672
**Examples:**
@@ -681,13 +683,14 @@ initiat env switch development
681
683
682
684
**Output:**
683
685
```
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"
689
690
```
690
691
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
+
691
694
### `initiat env current`
692
695
693
696
Show the currently active environment.
@@ -714,27 +717,37 @@ initiat env current
714
717
• Sync secrets: initiat env sync
715
718
```
716
719
717
-
### `initiat env sync`
720
+
### `initiat env sync [--env <slug>]`
718
721
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)
720
726
721
727
**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`
724
731
- Updates sync timestamps
725
732
- Shows summary of synced secrets
726
733
727
734
**Examples:**
728
735
```bash
729
736
# Sync secrets to current environment
730
737
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
731
744
```
732
745
733
746
**Output:**
734
747
```
735
748
🔄 Syncing secrets to environment 'production'...
736
749
📡 Fetching secrets from remote project...
737
-
🔒 Storing secrets securely in local environment...
750
+
🔒 Decrypting and storing secrets securely...
738
751
✅ Synced 5 secrets to environment 'production'
739
752
740
753
Synced secrets:
@@ -745,9 +758,15 @@ Synced secrets:
745
758
• SMTP_PASSWORD
746
759
747
760
💡 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
749
762
```
750
763
764
+
**Important:** Secrets are stored in plaintext in the local `secrets.env` file, but they are:
- Automatically excluded from git via `.gitignore`
768
+
- Only accessible to processes that can read the file (your user account)
769
+
751
770
### `initiat env unset`
752
771
753
772
Clear the currently active environment and reload direnv.
@@ -789,35 +808,59 @@ The CLI creates the following directory structure for environment management:
789
808
│ │ └── secrets.env
790
809
│ └── development/
791
810
│ └── secrets.env
792
-
└── active
811
+
└── active -> environments/production (symlink on Unix, file on Windows)
793
812
```
794
813
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
+
795
816
### Direnv Integration
796
817
797
818
The CLI automatically generates `.envrc` files for seamless integration with direnv:
798
819
799
-
**Generated `.envrc` content:**
820
+
**Generated `.envrc` content (Unix):**
800
821
```bash
801
-
# Generated by initiat env init
802
-
# This file loads environment variables from the active environment
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)
806
833
fi
807
834
```
808
835
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
+
809
843
**Benefits:**
810
844
- Automatic environment variable loading when entering the project directory
811
845
- 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)
813
847
- Integration with existing development workflows
848
+
- No need to manually export variables or use eval
814
849
815
850
### Security Features
816
851
817
852
-**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)
819
854
-**Path Validation**: Protection against directory traversal vulnerabilities
820
855
-**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
0 commit comments