env-secrets 0.1.10 → 0.2.0

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.
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "Node.js Development",
3
+ "image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye",
4
+ "features": {
5
+ "ghcr.io/devcontainers/features/git:1": {},
6
+ "ghcr.io/devcontainers/features/github-cli:1": {}
7
+ },
8
+ "customizations": {
9
+ "vscode": {
10
+ "extensions": [
11
+ "dbaeumer.vscode-eslint",
12
+ "esbenp.prettier-vscode",
13
+ "ms-vscode.vscode-typescript-next",
14
+ "eamodio.gitlens",
15
+ "streetsidesoftware.code-spell-checker",
16
+ "orta.vscode-jest"
17
+ ],
18
+ "settings": {
19
+ "editor.formatOnSave": true,
20
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
21
+ "editor.codeActionsOnSave": {
22
+ "source.fixAll.eslint": true
23
+ }
24
+ }
25
+ }
26
+ },
27
+ "postCreateCommand": "yarn install",
28
+ "remoteUser": "node"
29
+ }
@@ -3,6 +3,16 @@ name: Release and Publish
3
3
 
4
4
  on:
5
5
  workflow_dispatch:
6
+ inputs:
7
+ release_type:
8
+ description: 'Release type (patch/minor/major)'
9
+ type: choice
10
+ options:
11
+ - patch
12
+ - minor
13
+ - major
14
+ default: 'patch'
15
+ required: true
6
16
 
7
17
  permissions:
8
18
  contents: write
@@ -37,7 +47,7 @@ jobs:
37
47
  run: yarn build
38
48
 
39
49
  - name: Github release
40
- run: yarn release patch --ci
50
+ run: yarn release ${{ inputs.release_type }} --ci
41
51
  env:
42
52
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
43
53
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -9,12 +9,12 @@ on:
9
9
  - main
10
10
 
11
11
  jobs:
12
- build:
12
+ unit-tests:
13
13
  runs-on: ubuntu-latest
14
14
 
15
15
  strategy:
16
16
  matrix:
17
- node-version: [16.x, 18.x, 20.x]
17
+ node-version: [18.x, 20.x, 22.x, 24.x]
18
18
 
19
19
  steps:
20
20
  - name: Checkout repository
@@ -26,13 +26,82 @@ jobs:
26
26
  node-version: ${{ matrix.node-version }}
27
27
 
28
28
  - name: Install dependencies
29
- run: yarn
29
+ run: yarn --ignore-scripts --frozen-lockfile
30
30
 
31
31
  - name: Build
32
32
  run: yarn build
33
33
 
34
34
  - name: Run the tests
35
- run: yarn test --coverage
35
+ run: yarn test:unit
36
+
37
+ - name: Notify failures
38
+ if: failure()
39
+ uses: rtCamp/action-slack-notify@v2
40
+ env:
41
+ SLACK_LINK_NAMES: true
42
+ SLACK_MESSAGE:
43
+ # prettier-ignore
44
+ "hey @${{ github.actor }}, @mark, sorry to let you know you broke the build"
45
+ SLACK_CHANNEL: feed-github
46
+ SLACK_COLOR: ${{ job.status }}
47
+
48
+ coverage:
49
+ runs-on: ubuntu-latest
50
+
51
+ steps:
52
+ - name: Checkout repository
53
+ uses: actions/checkout@v4
54
+
55
+ - name: Set up Node.js ${{ matrix.node-version }}
56
+ uses: actions/setup-node@v4
57
+ with:
58
+ node-version: 24.x
59
+
60
+ - name: Install dependencies
61
+ run: yarn --ignore-scripts --frozen-lockfile
62
+
63
+ - name: Build
64
+ run: yarn build
65
+
66
+ - name: Run the tests
67
+ run: yarn test:unit:coverage
68
+
69
+ - name: Upload coverage reports to Codecov
70
+ uses: codecov/codecov-action@v5
71
+ with:
72
+ token: ${{ secrets.CODECOV_TOKEN }}
73
+
74
+ - name: Notify failures
75
+ if: failure()
76
+ uses: rtCamp/action-slack-notify@v2
77
+ env:
78
+ SLACK_LINK_NAMES: true
79
+ SLACK_MESSAGE:
80
+ # prettier-ignore
81
+ "hey @${{ github.actor }}, @mark, sorry to let you know you broke the build"
82
+ SLACK_CHANNEL: feed-github
83
+ SLACK_COLOR: ${{ job.status }}
84
+
85
+ e2e:
86
+ runs-on: ubuntu-latest
87
+
88
+ steps:
89
+ - name: Checkout repository
90
+ uses: actions/checkout@v4
91
+
92
+ - name: Set up Node.js ${{ matrix.node-version }}
93
+ uses: actions/setup-node@v4
94
+ with:
95
+ node-version: 24.x
96
+
97
+ - name: Install dependencies
98
+ run: yarn --ignore-scripts --frozen-lockfile
99
+
100
+ - name: Build
101
+ run: yarn build
102
+
103
+ - name: Run the tests
104
+ run: yarn test:e2e
36
105
 
37
106
  - name: Notify failures
38
107
  if: failure()
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # env-secrets
2
2
 
3
- Get secrets from a vault and inject them as environment variables
3
+ A Node.js CLI tool that retrieves secrets from vaults and injects them as environment variables into your running applications.
4
4
 
5
5
  [![Version](https://img.shields.io/npm/v/env-secrets.svg)](https://npmjs.org/package/env-secrets)
6
6
  [![build](https://img.shields.io/github/actions/workflow/status/markcallen/env-secrets/build-main.yml)](https://github.com/markcallen/env-secrets/tree/main)
@@ -8,49 +8,83 @@ Get secrets from a vault and inject them as environment variables
8
8
  [![Downloads/week](https://img.shields.io/npm/dw/env-secrets.svg)](https://npmjs.org/package/env-secrets)
9
9
  [![License](https://img.shields.io/npm/l/env-secrets.svg)](https://github.com/markcallen/env-secrets/blob/main/LICENSE)
10
10
 
11
- ## Setup
11
+ ## Features
12
12
 
13
- Install node
13
+ - 🔐 Retrieve secrets from AWS Secrets Manager
14
+ - 🌍 Inject secrets as environment variables
15
+ - 🚀 Run any command with injected secrets
16
+ - 🔍 Debug logging support
17
+ - 📦 Works globally or project-specific
18
+ - 🛡️ Secure credential handling
19
+ - 🔄 JSON secret parsing
20
+
21
+ ## Quick Start
22
+
23
+ 1. **Install the tool:**
24
+
25
+ ```bash
26
+ npm install -g env-secrets
27
+ ```
28
+
29
+ 2. **Run a command with secrets:**
30
+
31
+ ```bash
32
+ env-secrets aws -s my-secret-name -r us-east-1 -- echo "Hello, ${USER_NAME}!"
33
+ ```
34
+
35
+ 3. **Run your application with secrets:**
36
+ ```bash
37
+ env-secrets aws -s my-app-secrets -r us-west-2 -- node app.js
38
+ ```
39
+
40
+ ## Prerequisites
41
+
42
+ - Node.js 18.0.0 or higher
43
+ - AWS CLI (for AWS Secrets Manager integration)
44
+ - AWS credentials configured (via AWS CLI, environment variables, or IAM roles)
14
45
 
15
46
  ## Installation
16
47
 
17
- Globally
48
+ ### Global Installation
18
49
 
19
- ```
50
+ ```bash
20
51
  npm install -g env-secrets
21
52
  ```
22
53
 
23
- Project specific
54
+ ### Project-Specific Installation
24
55
 
25
- ```
56
+ ```bash
26
57
  npm install env-secrets
27
58
  ```
28
59
 
29
- when using project specific run using npx
60
+ When using project-specific installation, run using `npx`:
30
61
 
31
- ```
62
+ ```bash
32
63
  npx env-secrets ...
33
64
  ```
34
65
 
35
66
  ## Usage
36
67
 
37
- AWS
68
+ ### AWS Secrets Manager
38
69
 
39
- ```
40
- env-secrets aws -s <secret name> -r <region> -p <profile> -- <program to run>
41
- ```
70
+ Retrieve secrets from AWS Secrets Manager and inject them as environment variables:
42
71
 
43
- `<secret name>` is the name of the secret in Secrets Manager
72
+ ```bash
73
+ env-secrets aws -s <secret-name> -r <region> -p <profile> -- <program-to-run>
74
+ ```
44
75
 
45
- `<region>` is the region where the secret to stored. It is optional, the AWS_DEFAULT_REGION environment variable will be used instead.
76
+ #### Parameters
46
77
 
47
- `<profile>` is the local aws profile to use. It is optional, the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables will be used instead.
78
+ - `-s, --secret <secret-name>` (required): The name of the secret in AWS Secrets Manager
79
+ - `-r, --region <region>` (optional): AWS region where the secret is stored. If not provided, uses `AWS_DEFAULT_REGION` environment variable
80
+ - `-p, --profile <profile>` (optional): Local AWS profile to use. If not provided, uses `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables
81
+ - `-- <program-to-run>`: The program to run with the injected environment variables
48
82
 
49
- example:
83
+ #### Examples
50
84
 
51
- Create a Secret using AWS cli
85
+ 1. **Create a secret using AWS CLI:**
52
86
 
53
- ```
87
+ ```bash
54
88
  aws secretsmanager create-secret \
55
89
  --region us-east-1 \
56
90
  --profile marka \
@@ -59,75 +93,190 @@ aws secretsmanager create-secret \
59
93
  --secret-string "{\"user\":\"marka\",\"password\":\"mypassword\"}"
60
94
  ```
61
95
 
62
- List the secret using AWS cli
96
+ 2. **List the secret using AWS CLI:**
63
97
 
64
- ```
98
+ ```bash
65
99
  aws secretsmanager get-secret-value \
66
100
  --region us-east-1 \
67
101
  --profile marka \
68
- --secret-id local/sample \
102
+ --secret-id local/sample \
69
103
  --query SecretString
70
104
  ```
71
105
 
72
- ```
106
+ 3. **Run a command with injected secrets:**
107
+
108
+ ```bash
73
109
  env-secrets aws -s local/sample -r us-east-1 -p marka -- echo \${user}/\${password}
74
110
  ```
75
111
 
76
- ## Development
77
-
78
- Setup node using [nvm](https://github.com/nvm-sh/nvm). Or use node 20 (LTS).
112
+ 4. **Run a Node.js application with secrets:**
79
113
 
114
+ ```bash
115
+ env-secrets aws -s my-app-secrets -r us-west-2 -- node app.js
80
116
  ```
81
- nvm use
117
+
118
+ 5. **Check environment variables:**
119
+
120
+ ```bash
121
+ env-secrets aws -s local/sample -r us-east-1 -p marka -- env | grep -E "(user|password)"
82
122
  ```
83
123
 
84
- Install yarn
124
+ 6. **Use with Docker containers:**
85
125
 
126
+ ```bash
127
+ env-secrets aws -s docker-secrets -r us-east-1 -- docker run -e DATABASE_URL -e API_KEY my-app
86
128
  ```
87
- npm install -y yarn
129
+
130
+ ## Security Considerations
131
+
132
+ - 🔐 **Credential Management**: The tool respects AWS credential precedence (environment variables, IAM roles, profiles)
133
+ - 🛡️ **Secret Exposure**: Secrets are only injected into the child process environment, not logged
134
+ - 🔒 **Network Security**: Uses AWS SDK's built-in security features for API calls
135
+ - 📝 **Audit Trail**: AWS CloudTrail logs all Secrets Manager API calls
136
+ - 🚫 **No Persistence**: Secrets are not stored locally or cached
137
+
138
+ ## Troubleshooting
139
+
140
+ ### Common Issues
141
+
142
+ 1. **"Unable to connect to AWS"**
143
+
144
+ - Verify AWS credentials are configured correctly
145
+ - Check if the specified region is valid
146
+ - Ensure network connectivity to AWS services
147
+
148
+ 2. **"Secret not found"**
149
+
150
+ - Verify the secret name exists in the specified region
151
+ - Check if you have permissions to access the secret
152
+ - Ensure the secret name is correct (case-sensitive)
153
+
154
+ 3. **"ConfigError"**
155
+
156
+ - Verify AWS profile configuration in `~/.aws/credentials`
157
+ - Check if environment variables are set correctly
158
+ - Ensure IAM role permissions if using EC2/ECS
159
+
160
+ 4. **Environment variables not injected**
161
+ - Verify the secret contains valid JSON
162
+ - Check if the secret is accessible
163
+ - Use debug mode to troubleshoot: `DEBUG=env-secrets env-secrets aws ...`
164
+
165
+ ### Debug Mode
166
+
167
+ Enable debug logging to troubleshoot issues:
168
+
169
+ ```bash
170
+ # Debug main application
171
+ DEBUG=env-secrets env-secrets aws -s my-secret -r us-east-1 -- env
172
+
173
+ # Debug vault-specific operations
174
+ DEBUG=env-secrets,env-secrets:secretsmanager env-secrets aws -s my-secret -r us-east-1 -- env
88
175
  ```
89
176
 
90
- Setup
177
+ ## Development
178
+
179
+ ### Setup
91
180
 
181
+ 1. **Install Node.js using nvm (recommended):**
182
+
183
+ ```bash
184
+ nvm use
92
185
  ```
186
+
187
+ Or use Node.js 20 (LTS) directly.
188
+
189
+ 2. **Install dependencies:**
190
+
191
+ ```bash
192
+ npm install -g yarn
93
193
  yarn
94
194
  ```
95
195
 
96
- Run
196
+ ### Running in Development
97
197
 
98
- ```
198
+ ```bash
99
199
  npx ts-node src/index.ts aws -s local/sample -r us-east-1 -p marka -- env
100
200
  ```
101
201
 
102
- ### Debug
202
+ ### Debugging
103
203
 
104
- Uses debug-js to show debug logs by passing in env-secrets for the main application
105
- and env-secrets:{vault} for vault specific debugging
204
+ The application uses `debug-js` for logging. Enable debug logs by setting the `DEBUG` environment variable:
106
205
 
107
- ```
206
+ ```bash
207
+ # Debug main application
208
+ DEBUG=env-secrets npx ts-node src/index.ts aws -s local/sample -r us-east-1 -p marka -- env
209
+
210
+ # Debug vault-specific operations
108
211
  DEBUG=env-secrets,env-secrets:secretsmanager npx ts-node src/index.ts aws -s local/sample -r us-east-1 -p marka -- env
109
212
  ```
110
213
 
111
- ## Publishing
214
+ ### Devpod Setup
112
215
 
113
- Login into npm
216
+ Create a devpod using Kubernetes provider:
114
217
 
218
+ ```bash
219
+ devpod up --id env-secretes-dev --provider kubernetes --ide cursor git@github.com:markcallen/env-secrets.git
115
220
  ```
116
- npm login
221
+
222
+ ## Testing
223
+
224
+ Run the test suite:
225
+
226
+ ```bash
227
+ # Run all tests
228
+ npm test
229
+
230
+ # Run unit tests only
231
+ npm run test:unit
232
+
233
+ # Run unit tests with coverage
234
+ npm run test:unit:coverage
235
+
236
+ # Run end-to-end tests
237
+ npm run test:e2e
117
238
  ```
118
239
 
119
- Try a dry run:
240
+ ## Publishing
120
241
 
242
+ 1. **Login to npm:**
243
+
244
+ ```bash
245
+ npm login
121
246
  ```
247
+
248
+ 2. **Dry run release:**
249
+
250
+ ```bash
122
251
  npm run release -- patch --dry-run
123
252
  ```
124
253
 
125
- Run:
254
+ 3. **Publish release:**
126
255
 
127
- ```
256
+ ```bash
128
257
  npm run release -- patch
129
258
  ```
130
259
 
260
+ ## Contributing
261
+
262
+ We welcome contributions! Please follow these steps:
263
+
264
+ 1. Fork the repository
265
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
266
+ 3. Make your changes
267
+ 4. Add tests for new functionality
268
+ 5. Run the test suite (`npm test`)
269
+ 6. Commit your changes (`git commit -m 'Add amazing feature'`)
270
+ 7. Push to the branch (`git push origin feature/amazing-feature`)
271
+ 8. Open a Pull Request
272
+
273
+ ### Development Guidelines
274
+
275
+ - Follow the existing code style (ESLint + Prettier)
276
+ - Add tests for new functionality
277
+ - Update documentation for new features
278
+ - Ensure all tests pass before submitting
279
+
131
280
  ## License
132
281
 
133
282
  Distributed under the MIT License. See `LICENSE` for more information.
@@ -137,3 +286,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
137
286
  Mark C Allen - [@markcallen](https://www.linkedin.com/in/markcallen/)
138
287
 
139
288
  Project Link: [https://github.com/markcallen/env-secrets](https://github.com/markcallen/env-secrets)
289
+
290
+ ## Changelog
291
+
292
+ See [GitHub Releases](https://github.com/markcallen/env-secrets/releases) for a complete changelog.
@@ -0,0 +1,37 @@
1
+ import * as path from 'path';
2
+ import { exec } from 'child_process';
3
+
4
+ type Cli = {
5
+ code: number;
6
+ error: Error;
7
+ stdout: any;
8
+ stderr: any;
9
+ };
10
+
11
+ describe('CLI tests', () => {
12
+ test('general help', async () => {
13
+ const result = await cli(['-h'], '.');
14
+ expect(result.code).toBe(0);
15
+ });
16
+ test('aws help', async () => {
17
+ const result = await cli(['aws -h'], '.');
18
+ expect(result.code).toBe(0);
19
+ });
20
+ });
21
+
22
+ function cli(args, cwd): Promise<Cli> {
23
+ return new Promise((resolve) => {
24
+ exec(
25
+ `node ${path.resolve('./dist/index')} ${args.join(' ')}`,
26
+ { cwd },
27
+ (error, stdout, stderr) => {
28
+ resolve({
29
+ code: error && error.code ? error.code : 0,
30
+ error: error || new Error(),
31
+ stdout,
32
+ stderr
33
+ });
34
+ }
35
+ );
36
+ });
37
+ }