env-secrets 0.1.9 → 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,10 +47,10 @@ 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
- GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
53
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44
54
 
45
55
  - name: Notify failures
46
56
  if: failure()
@@ -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,57 +1,90 @@
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)
7
7
  [![test](https://img.shields.io/github/actions/workflow/status/markcallen/env-secrets/unittests.yaml)](https://github.com/markcallen/env-secrets/tree/main)
8
- ![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/markcallen/env-secrets)
9
8
  [![Downloads/week](https://img.shields.io/npm/dw/env-secrets.svg)](https://npmjs.org/package/env-secrets)
10
9
  [![License](https://img.shields.io/npm/l/env-secrets.svg)](https://github.com/markcallen/env-secrets/blob/main/LICENSE)
11
10
 
12
- ## Setup
11
+ ## Features
13
12
 
14
- 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)
15
45
 
16
46
  ## Installation
17
47
 
18
- Globally
48
+ ### Global Installation
19
49
 
20
- ```
50
+ ```bash
21
51
  npm install -g env-secrets
22
52
  ```
23
53
 
24
- Project specific
54
+ ### Project-Specific Installation
25
55
 
26
- ```
56
+ ```bash
27
57
  npm install env-secrets
28
58
  ```
29
59
 
30
- when using project specific run using npx
60
+ When using project-specific installation, run using `npx`:
31
61
 
32
- ```
62
+ ```bash
33
63
  npx env-secrets ...
34
64
  ```
35
65
 
36
66
  ## Usage
37
67
 
38
- AWS
68
+ ### AWS Secrets Manager
39
69
 
40
- ```
41
- env-secrets aws -s <secret name> -r <region> -p <profile> -- <program to run>
42
- ```
70
+ Retrieve secrets from AWS Secrets Manager and inject them as environment variables:
43
71
 
44
- `<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
+ ```
45
75
 
46
- `<region>` is the region where the secret to stored. It is optional, the AWS_DEFAULT_REGION environment variable will be used instead.
76
+ #### Parameters
47
77
 
48
- `<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
49
82
 
50
- example:
83
+ #### Examples
51
84
 
52
- Create a Secret using AWS cli
85
+ 1. **Create a secret using AWS CLI:**
53
86
 
54
- ```
87
+ ```bash
55
88
  aws secretsmanager create-secret \
56
89
  --region us-east-1 \
57
90
  --profile marka \
@@ -60,75 +93,190 @@ aws secretsmanager create-secret \
60
93
  --secret-string "{\"user\":\"marka\",\"password\":\"mypassword\"}"
61
94
  ```
62
95
 
63
- List the secret using AWS cli
96
+ 2. **List the secret using AWS CLI:**
64
97
 
65
- ```
98
+ ```bash
66
99
  aws secretsmanager get-secret-value \
67
100
  --region us-east-1 \
68
101
  --profile marka \
69
- --secret-id local/sample \
102
+ --secret-id local/sample \
70
103
  --query SecretString
71
104
  ```
72
105
 
73
- ```
106
+ 3. **Run a command with injected secrets:**
107
+
108
+ ```bash
74
109
  env-secrets aws -s local/sample -r us-east-1 -p marka -- echo \${user}/\${password}
75
110
  ```
76
111
 
77
- ## Development
78
-
79
- Setup node using [nvm](https://github.com/nvm-sh/nvm). Or use node 20 (LTS).
112
+ 4. **Run a Node.js application with secrets:**
80
113
 
114
+ ```bash
115
+ env-secrets aws -s my-app-secrets -r us-west-2 -- node app.js
81
116
  ```
82
- 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)"
83
122
  ```
84
123
 
85
- Install yarn
124
+ 6. **Use with Docker containers:**
86
125
 
126
+ ```bash
127
+ env-secrets aws -s docker-secrets -r us-east-1 -- docker run -e DATABASE_URL -e API_KEY my-app
87
128
  ```
88
- 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
89
175
  ```
90
176
 
91
- Setup
177
+ ## Development
178
+
179
+ ### Setup
92
180
 
181
+ 1. **Install Node.js using nvm (recommended):**
182
+
183
+ ```bash
184
+ nvm use
93
185
  ```
186
+
187
+ Or use Node.js 20 (LTS) directly.
188
+
189
+ 2. **Install dependencies:**
190
+
191
+ ```bash
192
+ npm install -g yarn
94
193
  yarn
95
194
  ```
96
195
 
97
- Run
196
+ ### Running in Development
98
197
 
99
- ```
198
+ ```bash
100
199
  npx ts-node src/index.ts aws -s local/sample -r us-east-1 -p marka -- env
101
200
  ```
102
201
 
103
- ### Debug
202
+ ### Debugging
104
203
 
105
- Uses debug-js to show debug logs by passing in env-secrets for the main application
106
- 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:
107
205
 
108
- ```
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
109
211
  DEBUG=env-secrets,env-secrets:secretsmanager npx ts-node src/index.ts aws -s local/sample -r us-east-1 -p marka -- env
110
212
  ```
111
213
 
112
- ## Publishing
214
+ ### Devpod Setup
113
215
 
114
- Login into npm
216
+ Create a devpod using Kubernetes provider:
115
217
 
218
+ ```bash
219
+ devpod up --id env-secretes-dev --provider kubernetes --ide cursor git@github.com:markcallen/env-secrets.git
116
220
  ```
117
- 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
118
238
  ```
119
239
 
120
- Try a dry run:
240
+ ## Publishing
121
241
 
242
+ 1. **Login to npm:**
243
+
244
+ ```bash
245
+ npm login
122
246
  ```
247
+
248
+ 2. **Dry run release:**
249
+
250
+ ```bash
123
251
  npm run release -- patch --dry-run
124
252
  ```
125
253
 
126
- Run:
254
+ 3. **Publish release:**
127
255
 
128
- ```
256
+ ```bash
129
257
  npm run release -- patch
130
258
  ```
131
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
+
132
280
  ## License
133
281
 
134
282
  Distributed under the MIT License. See `LICENSE` for more information.
@@ -138,3 +286,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
138
286
  Mark C Allen - [@markcallen](https://www.linkedin.com/in/markcallen/)
139
287
 
140
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
+ }