envcraft-cli 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,351 @@
1
- # Temporary Holding Version
1
+ # envman - Environment Variables Management CLI
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A comprehensive Node.js CLI tool for managing environment variables safely. Features include:
4
+ - File-based management (development)
5
+ - **Encrypted database storage** (production)
6
+ - Secure key management with audit trails
7
+
8
+ ## Features
9
+
10
+ ### 📁 File-Based Management
11
+ - Set, get, delete environment variables
12
+ - Multiple output formats (JSON, table, shell)
13
+ - Load, save, copy, validate files
14
+ - Merge and diff files
15
+ - Export in shell format
16
+
17
+ ### 🔐 Secure Storage (NEW!)
18
+ - **AES-256-GCM encryption** at rest
19
+ - **Access audit logging** - track who accessed what
20
+ - **Integrity verification** - detect tampering
21
+ - **Key rotation** support
22
+ - **Export/import** with encryption
23
+ - Production-ready security
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ npm install
29
+ npm install sqlite3 # For secure storage
30
+ chmod +x src/cli.js
31
+ chmod +x src/cli-store.js
32
+ ```
33
+
34
+ ## Quick Start - Secure Storage
35
+
36
+ For safe production storage, see [QUICKSTART_SECURE.md](./instructions/QUICKSTART_SECURE.md):
37
+
38
+ ```bash
39
+ # Generate encryption key
40
+ node src/cli-store.js generate-key
41
+
42
+ # Store a secret
43
+ export ENCRYPTION_KEY="your-key-here"
44
+ node src/cli-store.js set API_KEY "secret-value" --description "API Key"
45
+
46
+ # Retrieve it
47
+ node src/cli-store.js get API_KEY
48
+
49
+ # View access logs
50
+ node src/cli-store.js logs --all
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ ### 📄 File-Based Management (Development)
56
+
57
+ #### Set a variable
58
+ ```bash
59
+ node src/cli.js set API_KEY "secret123"
60
+ node src/cli.js set DB_HOST "localhost" --file .env.local
61
+ ```
62
+
63
+ #### Get a variable
64
+ ```bash
65
+ node src/cli.js get API_KEY
66
+ ```
67
+
68
+ #### List all variables
69
+ ```bash
70
+ node src/cli.js list
71
+ node src/cli.js list --format json
72
+ node src/cli.js list --format shell
73
+ node src/cli.js list --prefix DB_ # Filter by prefix
74
+ ```
75
+
76
+ #### Delete a variable
77
+ ```bash
78
+ node src/cli.js delete API_KEY
79
+ node src/cli.js del SECRET_TOKEN
80
+ node src/cli.js rm PASSWORD
81
+ ```
82
+
83
+ ### File Operations
84
+
85
+ #### Load variables from a file
86
+ ```bash
87
+ node src/cli.js load .env.example
88
+ ```
89
+
90
+ #### Save variables to a file
91
+ ```bash
92
+ node src/cli.js save .env.backup
93
+ ```
94
+
95
+ #### Copy a file
96
+ ```bash
97
+ node src/cli.js copy .env .env.local
98
+ ```
99
+
100
+ #### Validate a file
101
+ ```bash
102
+ node src/cli.js validate .env
103
+ ```
104
+
105
+ #### Merge two files
106
+ ```bash
107
+ node src/cli.js merge .env.defaults .env.local
108
+ node src/cli.js merge file1 file2 --format json
109
+ ```
110
+
111
+ #### Compare two files
112
+ ```bash
113
+ node src/cli.js diff .env .env.example
114
+ ```
115
+
116
+ #### Export in shell format
117
+ ```bash
118
+ node src/cli.js export
119
+ node src/cli.js export | bash # Load into shell
120
+ ```
121
+
122
+ ## Usage
123
+
124
+ ### Basic Commands
125
+
126
+ #### Set a variable
127
+ ```bash
128
+ node src/cli.js set API_KEY "secret123"
129
+ node src/cli.js set DB_HOST "localhost" --file .env.local
130
+ ```
131
+
132
+ #### Get a variable
133
+ ```bash
134
+ node src/cli.js get API_KEY
135
+ ```
136
+
137
+ #### List all variables
138
+ ```bash
139
+ node src/cli.js list
140
+ node src/cli.js list --format json
141
+ node src/cli.js list --format shell
142
+ node src/cli.js list --prefix DB_ # Filter by prefix
143
+ ```
144
+
145
+ #### Delete a variable
146
+ ```bash
147
+ node src/cli.js delete API_KEY
148
+ node src/cli.js del SECRET_TOKEN
149
+ node src/cli.js rm PASSWORD
150
+ ```
151
+
152
+ ### File Operations
153
+
154
+ #### Load variables from a file
155
+ ```bash
156
+ node src/cli.js load .env.example
157
+ ```
158
+
159
+ #### Save variables to a file
160
+ ```bash
161
+ node src/cli.js save .env.backup
162
+ ```
163
+
164
+ #### Copy a file
165
+ ```bash
166
+ node src/cli.js copy .env .env.local
167
+ ```
168
+
169
+ #### Validate a file
170
+ ```bash
171
+ node src/cli.js validate .env
172
+ ```
173
+
174
+ #### Merge two files
175
+ ```bash
176
+ node src/cli.js merge .env.defaults .env.local
177
+ node src/cli.js merge file1 file2 --format json
178
+ ```
179
+
180
+ #### Compare two files
181
+ ```bash
182
+ node src/cli.js diff .env .env.example
183
+ ```
184
+
185
+ #### Export in shell format
186
+ ```bash
187
+ node src/cli.js export
188
+ node src/cli.js export | bash # Load into shell
189
+ ```
190
+
191
+ ## Options
192
+
193
+ | Option | Short | Description |
194
+ |--------|-------|-------------|
195
+ | `--file <path>` | `-f` | Target .env file (default: .env) |
196
+ | `--format <format>` | | Output format: `json`, `table`, `shell` (default: table) |
197
+ | `--prefix <prefix>` | | Filter variables by prefix |
198
+ | `--global` | `-g` | Use environment variables instead of file |
199
+ | `--help` | `-h` | Show help message |
200
+ | `--version` | `-v` | Show version |
201
+
202
+ ## Examples
203
+
204
+ ```bash
205
+ # Set production API key in specific file
206
+ node src/cli.js set API_KEY "prod-key-123" --file .env.production
207
+
208
+ # List all database variables as JSON
209
+ node src/cli.js list --prefix DB_ --format json
210
+
211
+ # Validate configuration
212
+ node src/cli.js validate .env
213
+
214
+ # Generate shell exports
215
+ node src/cli.js export > env.sh
216
+ source env.sh
217
+
218
+ # Compare development and production configs
219
+ node src/cli.js diff .env.development .env.production
220
+
221
+ # Merge multiple environment files
222
+ node src/cli.js merge .env.defaults .env.local
223
+
224
+ # Use global environment variables
225
+ node src/cli.js get PATH --global
226
+ node src/cli.js list --global --format json
227
+ ```
228
+
229
+ ## File Format
230
+
231
+ The tool supports standard `.env` file format:
232
+
233
+ ```
234
+ # Comments start with #
235
+ API_KEY=secret123
236
+ DB_HOST=localhost
237
+ DB_PORT=5432
238
+ LONG_VALUE="value with spaces"
239
+ MULTILINE="line1\nline2"
240
+ ```
241
+
242
+ ## Features
243
+
244
+ - ✅ Set, get, delete environment variables
245
+ - ✅ List variables in multiple formats (table, JSON, shell)
246
+ - ✅ Load and save `.env` files
247
+ - ✅ Validate `.env` files
248
+ - ✅ Merge and diff files
249
+ - ✅ Export in shell format
250
+ - ✅ Filter by prefix
251
+ - ✅ Work with global environment variables
252
+ - ✅ Support for quoted values and special characters
253
+
254
+ ## 🔐 Secure Storage Features
255
+
256
+ - ✅ **AES-256-GCM encryption** for all secrets
257
+ - ✅ **Audit logging** - track every access with who/what/when
258
+ - ✅ **Integrity verification** using PBKDF2 hashes
259
+ - ✅ **Multiple database backends** - SQLite, PostgreSQL, Firebase Firestore
260
+ - ✅ **Key management** - separate from encrypted data
261
+ - ✅ **Export/import** with encryption
262
+ - ✅ **Access control** - user tracking
263
+
264
+ ## 📊 Database Options
265
+
266
+ Choose based on your needs:
267
+
268
+ | Database | Use Case | Setup | Cost |
269
+ |----------|----------|-------|------|
270
+ | **SQLite** | Development, MVP | < 1 min | Free |
271
+ | **SSH File** | Remote server storage | 5 min | Server cost |
272
+ | **PostgreSQL** | Production, teams | 15 min | $20-100/mo |
273
+ | **Firebase** | Fast deployment, scaling | 10 min | $0-50/mo |
274
+ | **DynamoDB** | AWS ecosystem | 10 min | $50-200/mo |
275
+
276
+ See [DB_OPTIONS.md](./instructions/DB_OPTIONS.md) for detailed comparison.
277
+
278
+ ## Documentation
279
+
280
+ | Document | Purpose |
281
+ |----------|---------|
282
+ | [QUICKSTART_SECURE.md](./instructions/QUICKSTART_SECURE.md) | Get started with secure storage in 5 minutes |
283
+ | [SAFE_STORAGE_GUIDE.md](./instructions/SAFE_STORAGE_GUIDE.md) | How secure storage works, why it matters |
284
+ | [SECURITY.md](./instructions/SECURITY.md) | Detailed security practices and best practices |
285
+ | [STORAGE_COMPARISON.md](./instructions/STORAGE_COMPARISON.md) | Compare .env files vs database vs external KMS |
286
+ | [DB_OPTIONS.md](./instructions/DB_OPTIONS.md) | Database backends: SQLite, PostgreSQL, Firebase, DynamoDB |
287
+ | [FIREBASE_SETUP.md](./instructions/FIREBASE_SETUP.md) | Firebase Firestore setup and integration guide |
288
+ | [SSH_SETUP.md](./instructions/SSH_SETUP.md) | SSH file storage on remote server (134.185.111.151) |
289
+ | [DATABASE_COMPARISON.md](./instructions/DATABASE_COMPARISON.md) | Complete database comparison matrix |
290
+
291
+ ## Development
292
+
293
+ ```bash
294
+ # Run file-based CLI
295
+ node src/cli.js --help
296
+
297
+ # Run secure storage CLI
298
+ node src/cli-store.js --help
299
+
300
+ # Run example
301
+ node examples/secure-storage.js
302
+
303
+ # Test
304
+ npm test
305
+ ```
306
+
307
+ ## Architecture
308
+
309
+ ```
310
+ Development → Staging/Production → Enterprise
311
+ .env files Encrypted DB Vault/KMS
312
+ (simple) (balanced security) (full compliance)
313
+ ```
314
+
315
+ ## Example: Development vs Production
316
+
317
+ ### Development (quick & easy)
318
+ ```bash
319
+ # Use .env files
320
+ node src/cli.js set API_KEY "dev-key"
321
+ node src/cli.js list
322
+ ```
323
+
324
+ ### Production (secure & audited)
325
+ ```bash
326
+ # Use encrypted database
327
+ export ENCRYPTION_KEY=$(aws secretsmanager get-secret-value ...)
328
+ node src/cli-store.js set API_KEY "prod-key" --user automation
329
+ node src/cli-store.js logs --all # Audit trail
330
+ ```
331
+
332
+ ## Security Summary
333
+
334
+ **Secure Storage protects against:**
335
+ - ✓ Accidental exposure (encrypted at rest)
336
+ - ✓ Unauthorized access (audit logs detect it)
337
+ - ✓ Data tampering (PBKDF2 verification)
338
+ - ✓ Key compromise (separate key management)
339
+ - ✓ Compliance violations (audit trail)
340
+
341
+ See [SAFE_STORAGE_GUIDE.md](./instructions/SAFE_STORAGE_GUIDE.md) for details.
342
+
343
+ ## SSH Access
344
+
345
+ Connect to the remote storage server with the private key (keep the key file private, mode `400`):
346
+
347
+ ```bash
348
+ ssh -i ~/.ssh/id_rsa ubuntu@134.185.111.151
349
+ ```
350
+
351
+ See [SSH_SETUP.md](./instructions/SSH_SETUP.md) for server setup details.
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "envcraft-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "Environment variables management CLI tool with secure storage",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "bin": {
8
+ "envman": "src/cli.js",
9
+ "envman-store": "src/cli-store.js"
10
+ },
11
+ "files": [
12
+ "src",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "start": "node src/cli.js",
18
+ "store": "node src/cli-store.js",
19
+ "show": "node src/cli.js list",
20
+ "vm": "node src/cli.js vm fetch",
21
+ "example":"node examples/secure-storage.js",
22
+ "example:firebase": "node examples/firebase-storage.js",
23
+ "test": "node --test tests/**/*.test.js"
24
+ },
25
+ "keywords": [
26
+ "env",
27
+ "environment",
28
+ "cli",
29
+ "dotenv",
30
+ "secrets",
31
+ "encryption",
32
+ "security"
33
+ ],
34
+ "author": "",
35
+ "license": "MIT",
36
+ "dependencies": {
37
+ "sqlite3": "^5.1.6"
38
+ },
39
+ "devDependencies": {}
40
+ }
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Secure secret storage CLI
5
+ * Manages encrypted storage of environment variables
6
+ */
7
+
8
+ import { SecureEnvDB } from './storage/db.js';
9
+ import { SecureEncryption } from './storage/encryption.js';
10
+ import { parseArgs } from './utils/parser.js';
11
+ import { logError, logSuccess, logInfo, table } from './utils/logger.js';
12
+ import fs from 'fs';
13
+
14
+ async function main() {
15
+ try {
16
+ const args = parseArgs(process.argv.slice(2));
17
+ const dbFile = args.options.db || args.options.d || 'env-secrets.db';
18
+ const encryptionKey = process.env.ENCRYPTION_KEY;
19
+
20
+ if (!encryptionKey) {
21
+ throw new Error('ENCRYPTION_KEY environment variable is required');
22
+ }
23
+
24
+ if (!args.command || args.options.help || args.options.h) {
25
+ showHelp();
26
+ return;
27
+ }
28
+
29
+ if (args.options.version || args.options.v) {
30
+ console.log('envman-store 1.0.0');
31
+ return;
32
+ }
33
+
34
+ const db = new SecureEnvDB(dbFile, encryptionKey);
35
+ await db.init();
36
+
37
+ const user = args.options.user || process.env.USER || 'system';
38
+
39
+ switch (args.command) {
40
+ case 'set':
41
+ if (args.params.length < 2) throw new Error('Usage: set <key> <value>');
42
+ const description = args.options.description || args.options.d || '';
43
+ await db.set(args.params[0], args.params[1], user, description);
44
+ logSuccess(`Secret stored: ${args.params[0]}`);
45
+ break;
46
+
47
+ case 'get':
48
+ if (args.params.length < 1) throw new Error('Usage: get <key>');
49
+ const value = await db.get(args.params[0], user);
50
+ if (value) {
51
+ console.log(value);
52
+ } else {
53
+ throw new Error(`Secret not found: ${args.params[0]}`);
54
+ }
55
+ break;
56
+
57
+ case 'list':
58
+ case 'ls':
59
+ const keys = await db.listKeys();
60
+ if (keys.length === 0) {
61
+ console.log('No secrets found');
62
+ } else {
63
+ const formatted = keys.map(k => ({
64
+ 'Key': k.key,
65
+ 'Created': new Date(k.created_at).toLocaleString(),
66
+ 'Updated': new Date(k.updated_at).toLocaleString(),
67
+ 'By': k.created_by,
68
+ 'Description': k.description || '-'
69
+ }));
70
+ table(Object.fromEntries(
71
+ formatted.map((f, i) => [`${i + 1}. ${f.Key}`, f.Description])
72
+ ));
73
+ }
74
+ break;
75
+
76
+ case 'delete':
77
+ case 'del':
78
+ case 'rm':
79
+ if (args.params.length < 1) throw new Error('Usage: delete <key>');
80
+ const deleted = await db.delete(args.params[0], user);
81
+ if (deleted) {
82
+ logSuccess(`Secret deleted: ${args.params[0]}`);
83
+ } else {
84
+ throw new Error(`Secret not found: ${args.params[0]}`);
85
+ }
86
+ break;
87
+
88
+ case 'verify':
89
+ if (args.params.length < 2) throw new Error('Usage: verify <key> <value>');
90
+ const isValid = await db.verify(args.params[0], args.params[1]);
91
+ if (isValid) {
92
+ logSuccess('Secret verified - integrity OK');
93
+ } else {
94
+ logError('Secret verification failed - value mismatch');
95
+ }
96
+ break;
97
+
98
+ case 'logs':
99
+ if (args.options.all || args.options.a) {
100
+ const allLogs = await db.getAllAccessLogs(
101
+ parseInt(args.options.limit || 100)
102
+ );
103
+ const logTable = allLogs.map(l => ({
104
+ 'Time': l.timestamp,
105
+ 'Action': l.action,
106
+ 'Secret': l.key,
107
+ 'User': l.user
108
+ }));
109
+ console.log('Access Logs:');
110
+ logTable.forEach(l => {
111
+ console.log(` ${l.Time} | ${l.Action} | ${l.Secret} | ${l.User}`);
112
+ });
113
+ } else if (args.params.length >= 1) {
114
+ const key = args.params[0];
115
+ const secretLogs = await db.getAccessLogs(
116
+ key,
117
+ parseInt(args.options.limit || 50)
118
+ );
119
+ console.log(`Access logs for '${key}':`);
120
+ secretLogs.forEach(l => {
121
+ console.log(` ${l.timestamp} | ${l.action} by ${l.user}`);
122
+ });
123
+ } else {
124
+ throw new Error('Usage: logs <key> | logs --all');
125
+ }
126
+ break;
127
+
128
+ case 'export':
129
+ if (args.params.length < 1) throw new Error('Usage: export <filename>');
130
+ const exportKey = args.options.key || SecureEncryption.generateKey();
131
+ const exported = await db.exportToFile(args.params[0], exportKey);
132
+ fs.writeFileSync(args.params[0], exported.encryptedExport);
133
+ logSuccess(`Exported ${Object.keys(exported.secrets).length} secrets to ${args.params[0]}`);
134
+ console.log(`Export key (save this safely): ${exportKey}`);
135
+ break;
136
+
137
+ case 'import':
138
+ if (args.params.length < 1) throw new Error('Usage: import <filename>');
139
+ if (!args.options.key) throw new Error('--key required for import');
140
+ const encryptedData = fs.readFileSync(args.params[0], 'utf-8');
141
+ const imported = await db.importFromFile(encryptedData, args.options.key, user);
142
+ logSuccess(`Imported ${imported} secrets from ${args.params[0]}`);
143
+ break;
144
+
145
+ case 'generate-key':
146
+ const newKey = SecureEncryption.generateKey();
147
+ console.log('New encryption key:');
148
+ console.log(newKey);
149
+ console.log('\nSet as environment variable:');
150
+ console.log(`export ENCRYPTION_KEY="${newKey}"`);
151
+ break;
152
+
153
+ case 'help':
154
+ showHelp();
155
+ break;
156
+
157
+ default:
158
+ throw new Error(`Unknown command: ${args.command}`);
159
+ }
160
+
161
+ await db.close();
162
+
163
+ } catch (error) {
164
+ logError(error.message);
165
+ process.exit(1);
166
+ }
167
+ }
168
+
169
+ function showHelp() {
170
+ console.log(`
171
+ envman-store - Secure Secrets Storage CLI
172
+
173
+ Usage:
174
+ envman-store <command> [options]
175
+
176
+ Commands:
177
+ set <key> <value> Store a secret
178
+ get <key> Retrieve and decrypt a secret
179
+ list (ls) List all stored secret keys
180
+ delete <key> (del, rm) Delete a secret
181
+ verify <key> <value> Verify secret integrity
182
+ logs [key] View access logs
183
+ export <file> Export secrets (encrypted)
184
+ import <file> Import secrets (encrypted)
185
+ generate-key Generate new encryption key
186
+ help Show this help
187
+
188
+ Options:
189
+ --db, -d <path> Database file (default: env-secrets.db)
190
+ --user <name> User name for access logs (default: $USER)
191
+ --description, -d <text> Description for set command
192
+ --key <key> Encryption key for export/import
193
+ --all, -a Show all logs (with logs command)
194
+ --limit <number> Limit results (default: 50 for logs, 100 for --all)
195
+ --help, -h Show help
196
+ --version, -v Show version
197
+
198
+ Environment Variables:
199
+ ENCRYPTION_KEY Master encryption key (required)
200
+ USER Default user name
201
+
202
+ Examples:
203
+ # Set a secret with description
204
+ envman-store set DATABASE_URL "postgresql://..." --description "Prod DB"
205
+
206
+ # Get a secret
207
+ envman-store get DATABASE_URL
208
+
209
+ # List all secrets
210
+ envman-store list
211
+
212
+ # Check access logs
213
+ envman-store logs DATABASE_URL
214
+ envman-store logs --all --limit 50
215
+
216
+ # Export and import
217
+ envman-store export backup.enc --key <export-key>
218
+ envman-store import backup.enc --key <export-key>
219
+
220
+ # Generate encryption key
221
+ envman-store generate-key
222
+
223
+ Security:
224
+ ✓ All secrets encrypted with AES-256-GCM
225
+ ✓ Each access logged for audit trail
226
+ ✓ Integrity verification with PBKDF2 hashes
227
+ ✓ Never logs secret values
228
+
229
+ See instructions/SECURITY.md for detailed security documentation.
230
+ `);
231
+ }
232
+
233
+ main();