mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-07-26 00:13:16 +03:00
Compare commits
20 Commits
v2.7.4
...
update-jsonata
| Author | SHA1 | Date | |
|---|---|---|---|
| 3027ac711e | |||
| 77efb36ae3 | |||
| a727ce205a | |||
| d1720f055e | |||
| 92626383ce | |||
| 9c2d817b85 | |||
| b477844b5f | |||
| 9f522b8598 | |||
| efab57ede0 | |||
| d523bb05b2 | |||
| 11845b19f6 | |||
| 7a6258bb0b | |||
| a0b66b1cc3 | |||
| c616aba63e | |||
| e3d5714d59 | |||
| 00bce0da9c | |||
| 6853090cd9 | |||
| 45dc5344f1 | |||
| 2fb925f14c | |||
| caba6efd0e |
@@ -8,7 +8,6 @@ Relates OR Closes #0000
|
||||
|
||||
### Checklist
|
||||
- [ ] Added [CHANGELOG](https://github.com/hashicorp/vault-action/blob/master/CHANGELOG.md) entry (only for user-facing changes)
|
||||
- [ ] Did not commit changes to `dist/index.js` (This is only done for releases by vault-action maintainers)
|
||||
|
||||
|
||||
### Community Note
|
||||
|
||||
@@ -10,7 +10,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||
with:
|
||||
node-version: '16.14.0'
|
||||
node-version: '20.9.0'
|
||||
|
||||
- name: Setup NPM Cache
|
||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||
@@ -40,7 +40,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||
with:
|
||||
node-version: '16.14.0'
|
||||
node-version: '20.9.0'
|
||||
|
||||
- name: Setup NPM Cache
|
||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||
@@ -76,7 +76,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||
with:
|
||||
node-version: '16.14.0'
|
||||
node-version: '20.9.0'
|
||||
|
||||
- name: Setup NPM Cache
|
||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||
@@ -110,7 +110,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||
with:
|
||||
node-version: '16.14.0'
|
||||
node-version: '20.9.0'
|
||||
|
||||
- name: Setup NPM Cache
|
||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||
@@ -207,7 +207,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||
with:
|
||||
node-version: '16.14.0'
|
||||
node-version: '20.9.0'
|
||||
|
||||
- name: Setup NPM Cache
|
||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||
with:
|
||||
node-version: '16.14.0'
|
||||
node-version: '20.9.0'
|
||||
|
||||
- name: NPM Install
|
||||
run: npm ci
|
||||
@@ -48,14 +48,26 @@ jobs:
|
||||
token: testtoken
|
||||
secrets: |
|
||||
secret/data/test-json-string jsonString;
|
||||
secret/data/test-json-data jsonData;
|
||||
|
||||
- name: Check Secrets
|
||||
run: |
|
||||
touch secrets.json
|
||||
echo "${{ steps.import-secrets.outputs.jsonString }}" >> secrets.json
|
||||
- uses: actions/github-script@v7
|
||||
with:
|
||||
github-token: "foobar"
|
||||
script: |
|
||||
const { JSONSTRING, JSONDATA } = process.env
|
||||
|
||||
- name: Check json file format
|
||||
run: |
|
||||
echo
|
||||
cat secrets.json
|
||||
jq -c . < secrets.json
|
||||
console.log(`string ${JSONSTRING}`)
|
||||
console.log(`data ${JSONDATA}`)
|
||||
const str = JSONDATA
|
||||
|
||||
let valid = true
|
||||
try {
|
||||
JSON.parse(str)
|
||||
} catch (e) {
|
||||
valid = false
|
||||
}
|
||||
if (valid) {
|
||||
console.log("valid json")
|
||||
} else {
|
||||
console.log("not valid json")
|
||||
}
|
||||
|
||||
+36
-1
@@ -1,6 +1,41 @@
|
||||
## Unreleased
|
||||
|
||||
* Add changes here
|
||||
Features:
|
||||
|
||||
* `secretId` is no longer required for approle to support advanced use cases like machine login when `bind_secret_id` is false. [GH-522](https://github.com/hashicorp/vault-action/pull/522)
|
||||
|
||||
## 3.0.0 (February 15, 2024)
|
||||
|
||||
Improvements:
|
||||
|
||||
* Bump node runtime from node16 to node20 [GH-529](https://github.com/hashicorp/vault-action/pull/529)
|
||||
|
||||
## 2.8.1 (February 15, 2024)
|
||||
|
||||
Bugs:
|
||||
|
||||
* Revert [GH-509](https://github.com/hashicorp/vault-action/pull/509) which made a backwards incompatible bump of the node runtime from node16 to node20 [GH-527](https://github.com/hashicorp/vault-action/pull/527)
|
||||
|
||||
## 2.8.0 (February 1, 2024)
|
||||
|
||||
Features:
|
||||
|
||||
* Add `ignoreNotFound` input (default: false) to prevent the action from failing when a secret does not exist [GH-518](https://github.com/hashicorp/vault-action/pull/518)
|
||||
|
||||
Improvements:
|
||||
|
||||
* bump jsrsasign from 10.8.6 to 11.0.0 [GH-513](https://github.com/hashicorp/vault-action/pull/513)
|
||||
* bump @actions/core from 1.10.0 to 1.10.1 [GH-489](https://github.com/hashicorp/vault-action/pull/489)
|
||||
* bump jest-when from 3.5.2 to 3.6.0 [GH-484](https://github.com/hashicorp/vault-action/pull/484)
|
||||
* bump jest from 29.5.0 to 29.7.0 [GH-490](https://github.com/hashicorp/vault-action/pull/490)
|
||||
* bump @vercel/ncc from 0.36.1 to 0.38.1 [GH-503](https://github.com/hashicorp/vault-action/pull/503)
|
||||
|
||||
## 2.7.5 (January 30, 2024)
|
||||
|
||||
Improvements:
|
||||
|
||||
* Bump node runtime from node16 to node20 [GH-509](https://github.com/hashicorp/vault-action/pull/509)
|
||||
* Bump got from 11.8.5 to 11.8.6 [GH-492](https://github.com/hashicorp/vault-action/pull/492)
|
||||
|
||||
## 2.7.4 (October 26, 2023)
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
A helper action for easily pulling secrets from HashiCorp Vault™.
|
||||
|
||||
Note: The Vault Github Action is a read-only action, and in general
|
||||
is not meant to modify Vault’s state.
|
||||
|
||||
<!-- TOC -->
|
||||
|
||||
- [Vault GitHub Action](#vault-github-action)
|
||||
@@ -22,6 +25,7 @@ A helper action for easily pulling secrets from HashiCorp Vault™.
|
||||
- [Userpass](#userpass)
|
||||
- [Ldap](#ldap)
|
||||
- [Other Auth Methods](#other-auth-methods)
|
||||
- [Custom Path](#custom-path-name)
|
||||
- [Key Syntax](#key-syntax)
|
||||
- [Simple Key](#simple-key)
|
||||
- [Set Output Variable Name](#set-output-variable-name)
|
||||
@@ -297,6 +301,20 @@ with:
|
||||
If any other method is specified and you provide an `authPayload`, the action will
|
||||
attempt to `POST` to `auth/${method}/login` with the provided payload and parse out the client token.
|
||||
|
||||
### Custom Path Name
|
||||
|
||||
Auth methods at custom path names can be configured using the [`path`](#path) parameter
|
||||
|
||||
```yaml
|
||||
with:
|
||||
url: https://vault.mycompany.com:8200
|
||||
caCertificate: ${{ secrets.VAULT_CA_CERT }}
|
||||
path: my-custom-path
|
||||
method: userpass
|
||||
username: ${{ secrets.VAULT_USERNAME }}
|
||||
password: ${{ secrets.VAULT_PASSWORD }}
|
||||
```
|
||||
|
||||
## Key Syntax
|
||||
|
||||
The `secrets` parameter is a set of multiple secret requests separated by the `;` character.
|
||||
@@ -631,6 +649,13 @@ Base64 encoded client key the action uses to authenticate with Vault when mTLS i
|
||||
|
||||
When set to true, disables verification of server certificates when testing the action.
|
||||
|
||||
### `ignoreNotFound`
|
||||
|
||||
**Type: `string`**\
|
||||
**Default: `false`**
|
||||
|
||||
When set to true, prevents the action from failing when a secret does not exist.
|
||||
|
||||
## Masking - Hiding Secrets from Logs
|
||||
|
||||
This action uses GitHub Action's built-in masking, so all variables will automatically be masked (aka hidden) if printed to the console or to logs.
|
||||
|
||||
+6
-2
@@ -1,4 +1,4 @@
|
||||
name: 'Vault Secrets'
|
||||
name: 'HashiCorp Vault'
|
||||
description: 'A Github Action that allows you to consume HashiCorp Vault™ secrets as secure environment variables'
|
||||
inputs:
|
||||
url:
|
||||
@@ -89,8 +89,12 @@ inputs:
|
||||
secretEncodingType:
|
||||
description: 'The encoding type of the secret to decode. If not specified, the secret will not be decoded. Supported values: base64, hex, utf8'
|
||||
required: false
|
||||
ignoreNotFound:
|
||||
description: 'Whether or not the action should exit successfully if some requested secrets were not found.'
|
||||
required: false
|
||||
default: 'false'
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
branding:
|
||||
icon: 'unlock'
|
||||
|
||||
Vendored
+9050
-13696
File diff suppressed because one or more lines are too long
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
const core = require('@actions/core');
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
const got = require('got');
|
||||
const { when } = require('jest-when');
|
||||
vi.mock('@actions/core');
|
||||
import core from '@actions/core';
|
||||
|
||||
const { exportSecrets } = require('../../src/action');
|
||||
import got from 'got';
|
||||
import { when } from 'jest-when'
|
||||
|
||||
import { exportSecrets } from '../../src/action.js';
|
||||
|
||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||
@@ -102,7 +103,7 @@ describe('authenticate with approle', () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('method', expect.anything())
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
const core = require('@actions/core');
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
const got = require('got');
|
||||
const { when } = require('jest-when');
|
||||
vi.mock('@actions/core');
|
||||
import core from '@actions/core';
|
||||
|
||||
const { exportSecrets } = require('../../src/action');
|
||||
import got from 'got';
|
||||
import { when } from 'jest-when'
|
||||
|
||||
import { exportSecrets } from '../../src/action.js';
|
||||
|
||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||
@@ -107,7 +108,7 @@ describe('integration', () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('url', expect.anything())
|
||||
@@ -124,12 +125,34 @@ describe('integration', () => {
|
||||
.mockReturnValueOnce(secrets);
|
||||
}
|
||||
|
||||
function mockIgnoreNotFound(shouldIgnore) {
|
||||
when(core.getInput)
|
||||
.calledWith('ignoreNotFound', expect.anything())
|
||||
.mockReturnValueOnce(shouldIgnore);
|
||||
}
|
||||
|
||||
|
||||
it('prints a nice error message when secret not found', async () => {
|
||||
mockInput(`secret/data/test secret ;
|
||||
secret/data/test secret | NAMED_SECRET ;
|
||||
secret/data/notFound kehe | NO_SIR ;`);
|
||||
|
||||
expect(exportSecrets()).rejects.toEqual(Error(`Unable to retrieve result for "secret/data/notFound" because it was not found: {"errors":[]}`));
|
||||
await expect(exportSecrets()).rejects.toEqual(Error(`Unable to retrieve result for "secret/data/notFound" because it was not found: {"errors":[]}`));
|
||||
})
|
||||
|
||||
it('does not error when secret not found and ignoreNotFound is true', async () => {
|
||||
mockInput(`secret/data/test secret ;
|
||||
secret/data/test secret | NAMED_SECRET ;
|
||||
secret/data/notFound kehe | NO_SIR ;`);
|
||||
|
||||
mockIgnoreNotFound("true");
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportVariable).toBeCalledTimes(2);
|
||||
|
||||
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET');
|
||||
expect(core.exportVariable).toBeCalledWith('NAMED_SECRET', 'SUPERSECRET');
|
||||
})
|
||||
|
||||
it('get simple secret', async () => {
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
verbose: true
|
||||
};
|
||||
@@ -1,17 +1,18 @@
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
const core = require('@actions/core');
|
||||
const rsasign = require('jsrsasign');
|
||||
const {
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
vi.mock('@actions/core');
|
||||
import core from '@actions/core';
|
||||
import rsasign from 'jsrsasign';
|
||||
import {
|
||||
privateRsaKey,
|
||||
privateRsaKeyBase64,
|
||||
publicRsaKey
|
||||
} = require('./rsa_keys');
|
||||
} from './rsa_keys.js';
|
||||
|
||||
const got = require('got');
|
||||
const { when } = require('jest-when');
|
||||
import got from 'got';
|
||||
import { when } from 'jest-when'
|
||||
|
||||
const { exportSecrets } = require('../../src/action');
|
||||
import { exportSecrets } from '../../src/action.js';
|
||||
|
||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||
@@ -139,7 +140,7 @@ describe('jwt auth', () => {
|
||||
|
||||
describe('authenticate with private key', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('url', expect.anything())
|
||||
@@ -189,7 +190,7 @@ describe('jwt auth', () => {
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('url', expect.anything())
|
||||
|
||||
@@ -42,7 +42,7 @@ LrJEY9tZaRF8xraMZiOcBcyAt6S/TS29HttJ6+zlhcWx34fItEZ8jA5gzhTmspOY
|
||||
-----END PUBLIC KEY-----
|
||||
`;
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
privateRsaKey,
|
||||
privateRsaKeyBase64,
|
||||
publicRsaKey
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
const core = require('@actions/core');
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
const got = require('got');
|
||||
const { when } = require('jest-when');
|
||||
vi.mock('@actions/core');
|
||||
import core from '@actions/core';
|
||||
|
||||
const { exportSecrets } = require('../../src/action');
|
||||
import got from 'got';
|
||||
import { when } from 'jest-when'
|
||||
|
||||
import { exportSecrets } from '../../src/action.js';
|
||||
|
||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||
@@ -84,7 +85,7 @@ describe('authenticate with userpass', () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('method', expect.anything())
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { defineConfig, configDefaults } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
// required to make jest-when work with vitest
|
||||
globals: true,
|
||||
include: [
|
||||
'**/integrationTests/basic/**.{test,spec}.?(c|m)[jt]s?(x)',
|
||||
],
|
||||
},
|
||||
})
|
||||
@@ -1,3 +1,5 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
|
||||
describe('e2e-tls', () => {
|
||||
it('verify', () => {
|
||||
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
verbose: true
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
const got = require('got');
|
||||
const core = require('@actions/core');
|
||||
import got from 'got';
|
||||
import core from '@actions/core';
|
||||
|
||||
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
||||
const caCertificateRaw = `${process.env.VAULTCA}`;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { defineConfig, configDefaults } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
// required to make jest-when work with vitest
|
||||
globals: true,
|
||||
include: [
|
||||
'**/integrationTests/e2e-tls/**.{test,spec}.?(c|m)[jt]s?(x)',
|
||||
],
|
||||
},
|
||||
})
|
||||
@@ -1,3 +1,5 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
|
||||
describe('e2e', () => {
|
||||
it('verify', () => {
|
||||
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
verbose: true
|
||||
};
|
||||
@@ -1,4 +1,4 @@
|
||||
const got = require('got');
|
||||
import got from 'got';
|
||||
|
||||
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
||||
const vaultToken = `${process.env.VAULT_TOKEN}` === undefined ? `${process.env.VAULT_TOKEN}` : "testtoken";
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { defineConfig, configDefaults } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
// required to make jest-when work with vitest
|
||||
globals: true,
|
||||
include: [
|
||||
'**/integrationTests/e2e/**.{test,spec}.?(c|m)[jt]s?(x)',
|
||||
],
|
||||
},
|
||||
})
|
||||
@@ -1,11 +1,12 @@
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
const core = require('@actions/core');
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
const got = require('got');
|
||||
const { when } = require('jest-when');
|
||||
vi.mock('@actions/core');
|
||||
import core from '@actions/core';
|
||||
|
||||
const { exportSecrets } = require('../../src/action');
|
||||
import got from 'got';
|
||||
import { when } from 'jest-when'
|
||||
|
||||
import { exportSecrets } from '../../src/action.js';
|
||||
|
||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`;
|
||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||
@@ -41,7 +42,7 @@ describe('integration', () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('url', expect.anything())
|
||||
@@ -238,7 +239,7 @@ describe('authenticate with approle', () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('method', expect.anything())
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
verbose: true
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import { defineConfig, configDefaults } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
// required to make jest-when work with vitest
|
||||
globals: true,
|
||||
include: [
|
||||
'**/integrationTests/enterprise/**.{test,spec}.?(c|m)[jt]s?(x)',
|
||||
],
|
||||
},
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
module.exports = {
|
||||
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integrationTests/'],
|
||||
};
|
||||
+1
-1
@@ -7,4 +7,4 @@
|
||||
"compilerOptions": {
|
||||
"target": "es2018"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+4849
-2085
File diff suppressed because it is too large
Load Diff
+14
-16
@@ -2,14 +2,15 @@
|
||||
"name": "vault-action",
|
||||
"version": "0.1.0",
|
||||
"description": "A Github Action that allows you to consume vault secrets as secure environment variables.",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "ncc build src/entry.js -o dist",
|
||||
"test": "jest",
|
||||
"test:integration:basic": "jest -c integrationTests/basic/jest.config.js",
|
||||
"test:integration:enterprise": "jest -c integrationTests/enterprise/jest.config.js",
|
||||
"test:integration:e2e": "jest -c integrationTests/e2e/jest.config.js",
|
||||
"test:integration:e2e-tls": "jest -c integrationTests/e2e-tls/jest.config.js"
|
||||
"test": "vitest run",
|
||||
"test:integration:basic": "vitest run -c integrationTests/basic/vitest.config.js",
|
||||
"test:integration:enterprise": "vitest run -c integrationTests/enterprise/vitest.config.js",
|
||||
"test:integration:e2e": "vitest run -c integrationTests/e2e/vitest.config.js",
|
||||
"test:integration:e2e-tls": "vitest run -c integrationTests/e2e-tls/vitest.config.js"
|
||||
},
|
||||
"files": [
|
||||
"src/**/*",
|
||||
@@ -34,18 +35,15 @@
|
||||
},
|
||||
"homepage": "https://github.com/hashicorp/vault-action#readme",
|
||||
"dependencies": {
|
||||
"got": "^11.8.5",
|
||||
"jsonata": "^2.0.3",
|
||||
"jsrsasign": "^10.8.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@actions/core": ">=1 <2"
|
||||
"@actions/core": "^1.10.1",
|
||||
"got": "^14.2.1",
|
||||
"jsonata": "^2.0.4",
|
||||
"jsrsasign": "^11.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"jest": "^29.5.0",
|
||||
"jest-when": "^3.5.2",
|
||||
"mock-http-server": "^1.4.5"
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"jest-when": "^3.6.0",
|
||||
"mock-http-server": "^1.4.5",
|
||||
"vitest": "^1.3.1"
|
||||
}
|
||||
}
|
||||
|
||||
+12
-11
@@ -1,12 +1,14 @@
|
||||
// @ts-check
|
||||
const core = require('@actions/core');
|
||||
const command = require('@actions/core/lib/command');
|
||||
const got = require('got').default;
|
||||
const jsonata = require('jsonata');
|
||||
const { normalizeOutputKey } = require('./utils');
|
||||
const { WILDCARD } = require('./constants');
|
||||
import core from '@actions/core';
|
||||
import got from 'got';
|
||||
|
||||
const { auth: { retrieveToken }, secrets: { getSecrets } } = require('./index');
|
||||
import { normalizeOutputKey } from './utils.js';
|
||||
import { WILDCARD } from './constants.js';
|
||||
import { retrieveToken } from './auth.js';
|
||||
import { getSecrets } from './secrets.js';
|
||||
|
||||
// ncc doesn't compile jsonata imports properly, so we must use our own custom require
|
||||
import require from "./cjs-require.js";
|
||||
const jsonata = require('jsonata');
|
||||
|
||||
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes', 'ldap', 'userpass'];
|
||||
const ENCODING_TYPES = ['base64', 'hex', 'utf8'];
|
||||
@@ -219,9 +221,8 @@ function parseHeadersInput(inputKey, inputOptions) {
|
||||
}, new Map());
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
exportSecrets,
|
||||
parseSecretsInput,
|
||||
parseHeadersInput,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,17 +1,17 @@
|
||||
jest.mock('got');
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
const command = require('@actions/core/lib/command');
|
||||
const core = require('@actions/core');
|
||||
const got = require('got');
|
||||
const {
|
||||
vi.mock('got');
|
||||
vi.mock('@actions/core');
|
||||
|
||||
import core from '@actions/core';
|
||||
import got from 'got';
|
||||
import {
|
||||
exportSecrets,
|
||||
parseSecretsInput,
|
||||
parseHeadersInput
|
||||
} = require('./action');
|
||||
} from './action.js';
|
||||
|
||||
const { when } = require('jest-when');
|
||||
import { when } from 'jest-when'
|
||||
|
||||
describe('parseSecretsInput', () => {
|
||||
it('parses simple secret', () => {
|
||||
@@ -132,7 +132,7 @@ describe('parseHeaders', () => {
|
||||
|
||||
describe('exportSecrets', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('url', expect.anything())
|
||||
|
||||
+6
-6
@@ -1,8 +1,8 @@
|
||||
// @ts-check
|
||||
const core = require('@actions/core');
|
||||
const rsasign = require('jsrsasign');
|
||||
const fs = require('fs');
|
||||
const { default: got } = require('got');
|
||||
import core from '@actions/core';
|
||||
import * as fs from 'fs';
|
||||
import got from 'got';
|
||||
import rsasign from 'jsrsasign';
|
||||
|
||||
const defaultKubernetesTokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token'
|
||||
/***
|
||||
@@ -17,7 +17,7 @@ async function retrieveToken(method, client) {
|
||||
switch (method) {
|
||||
case 'approle': {
|
||||
const vaultRoleId = core.getInput('roleId', { required: true });
|
||||
const vaultSecretId = core.getInput('secretId', { required: true });
|
||||
const vaultSecretId = core.getInput('secretId', { required: false });
|
||||
return await getClientToken(client, method, path, { role_id: vaultRoleId, secret_id: vaultSecretId });
|
||||
}
|
||||
case 'github': {
|
||||
@@ -154,6 +154,6 @@ async function getClientToken(client, method, path, payload) {
|
||||
* }} auth
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
retrieveToken,
|
||||
};
|
||||
|
||||
+15
-17
@@ -1,22 +1,20 @@
|
||||
jest.mock('got');
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/core/lib/command');
|
||||
jest.mock('fs', () => ({
|
||||
stat: jest.fn().mockResolvedValue(null),
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
vi.mock('got');
|
||||
vi.mock('@actions/core');
|
||||
vi.mock('fs', () => ({
|
||||
stat: vi.fn().mockResolvedValue(null),
|
||||
promises: {
|
||||
access: jest.fn().mockResolvedValue(null),
|
||||
access: vi.fn().mockResolvedValue(null),
|
||||
}
|
||||
}));
|
||||
|
||||
const core = require('@actions/core');
|
||||
const got = require('got');
|
||||
const fs = require("fs")
|
||||
const { when } = require('jest-when');
|
||||
import core from '@actions/core';
|
||||
import got from 'got'
|
||||
import * as fs from 'fs';
|
||||
import { when } from 'jest-when'
|
||||
|
||||
|
||||
const {
|
||||
retrieveToken
|
||||
} = require('./auth');
|
||||
import { retrieveToken } from './auth.js';
|
||||
|
||||
|
||||
function mockInput(name, key) {
|
||||
@@ -27,7 +25,7 @@ function mockInput(name, key) {
|
||||
|
||||
function mockApiResponse() {
|
||||
const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } }
|
||||
got.post = jest.fn()
|
||||
got.post = vi.fn()
|
||||
got.post.mockReturnValue(response)
|
||||
}
|
||||
const testToken = "testoken";
|
||||
@@ -35,7 +33,7 @@ const testToken = "testoken";
|
||||
describe("test retrival for token", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it("test retrival with approle", async () => {
|
||||
@@ -76,7 +74,7 @@ describe("test retrival for token", () => {
|
||||
mockInput("kubernetesTokenPath", testTokenPath)
|
||||
mockInput("role", testRole)
|
||||
mockInput("path", testPath)
|
||||
fs.readFileSync = jest.fn()
|
||||
fs.readFileSync = vi.fn()
|
||||
fs.readFileSync.mockReturnValueOnce(jwtToken)
|
||||
const token = await retrieveToken(method, got)
|
||||
expect(token).toEqual(testToken)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// This allows us to use `require` in our ECMAScript module
|
||||
// See: https://github.com/vercel/ncc/issues/791
|
||||
// https://nodejs.org/api/module.html#modulecreaterequirefilename
|
||||
import { createRequire } from "module";
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
export default require;
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
const WILDCARD = '*';
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
WILDCARD
|
||||
};
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
const core = require('@actions/core');
|
||||
const { exportSecrets } = require('./action');
|
||||
import core from '@actions/core';
|
||||
import { exportSecrets } from './action.js';
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
const auth = require('./auth');
|
||||
const secrets = require('./secrets');
|
||||
import auth from './auth.js';
|
||||
import secrets from './secrets.js';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
auth,
|
||||
secrets
|
||||
};
|
||||
};
|
||||
|
||||
+16
-14
@@ -1,17 +1,19 @@
|
||||
jest.mock('@actions/core');
|
||||
import { vi, describe, test, expect } from 'vitest';
|
||||
|
||||
const core = require('@actions/core');
|
||||
const ServerMock = require("mock-http-server");
|
||||
const { exportSecrets } = require("./action");
|
||||
const { when } = require('jest-when');
|
||||
vi.mock('@actions/core');
|
||||
|
||||
import core from '@actions/core';
|
||||
import ServerMock from 'mock-http-server';
|
||||
import { exportSecrets } from './action.js';
|
||||
import { when } from 'jest-when';
|
||||
|
||||
describe('exportSecrets retries', () => {
|
||||
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
||||
var calls = 0;
|
||||
|
||||
beforeEach((done) => {
|
||||
beforeEach(() => new Promise(done => {
|
||||
calls = 0;
|
||||
jest.resetAllMocks();
|
||||
vi.resetAllMocks();
|
||||
|
||||
when(core.getInput)
|
||||
.calledWith('token', expect.anything())
|
||||
@@ -28,11 +30,11 @@ describe('exportSecrets retries', () => {
|
||||
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
afterEach((done) => {
|
||||
afterEach(() => new Promise(done => {
|
||||
server.stop(done);
|
||||
});
|
||||
}));
|
||||
|
||||
function mockStatusCodes(statusCodes) {
|
||||
server.on({
|
||||
@@ -51,19 +53,19 @@ describe('exportSecrets retries', () => {
|
||||
});
|
||||
}
|
||||
|
||||
it('retries on 412 status code', (done) => {
|
||||
it('retries on 412 status code', () => new Promise(done => {
|
||||
mockStatusCodes([412, 200])
|
||||
exportSecrets().then(() => {
|
||||
expect(calls).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('retries on 500 status code', (done) => {
|
||||
it('retries on 500 status code', () => new Promise(done => {
|
||||
mockStatusCodes([500, 200])
|
||||
exportSecrets().then(() => {
|
||||
expect(calls).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
+19
-6
@@ -1,6 +1,12 @@
|
||||
const jsonata = require("jsonata");
|
||||
const { WILDCARD } = require("./constants");
|
||||
const { normalizeOutputKey } = require("./utils");
|
||||
import core from '@actions/core';
|
||||
import { WILDCARD } from './constants.js';
|
||||
import { normalizeOutputKey } from './utils.js';
|
||||
|
||||
// ncc doesn't compile jsonata imports properly, so we must use our own custom require
|
||||
import require from "./cjs-require.js";
|
||||
const jsonata = require('jsonata');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} SecretRequest
|
||||
* @property {string} path
|
||||
@@ -21,7 +27,7 @@ const { normalizeOutputKey } = require("./utils");
|
||||
* @param {import('got').Got} client
|
||||
* @return {Promise<SecretResponse<TRequest>[]>}
|
||||
*/
|
||||
async function getSecrets(secretRequests, client) {
|
||||
async function getSecrets(secretRequests, client, ignoreNotFound) {
|
||||
const responseCache = new Map();
|
||||
let results = [];
|
||||
|
||||
@@ -42,7 +48,14 @@ async function getSecrets(secretRequests, client) {
|
||||
} catch (error) {
|
||||
const {response} = error;
|
||||
if (response?.statusCode === 404) {
|
||||
throw Error(`Unable to retrieve result for "${path}" because it was not found: ${response.body.trim()}`)
|
||||
let notFoundMsg = `Unable to retrieve result for "${path}" because it was not found: ${response.body.trim()}`;
|
||||
const ignoreNotFound = (core.getInput('ignoreNotFound', { required: false }) || 'false').toLowerCase() != 'false';
|
||||
if (ignoreNotFound) {
|
||||
core.error(`✘ ${notFoundMsg}`);
|
||||
continue;
|
||||
} else {
|
||||
throw Error(notFoundMsg)
|
||||
}
|
||||
}
|
||||
throw error
|
||||
}
|
||||
@@ -156,7 +169,7 @@ const selectAndAppendResults = async (
|
||||
];
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
getSecrets,
|
||||
selectData
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,6 +14,6 @@ function normalizeOutputKey(dataKey, isEnvVar = false) {
|
||||
return outputKey;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
normalizeOutputKey
|
||||
export {
|
||||
normalizeOutputKey
|
||||
};
|
||||
|
||||
+1
-1
@@ -9,4 +9,4 @@
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { defineConfig, configDefaults } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
// required to make jest-when work with vitest
|
||||
globals: true,
|
||||
exclude:[
|
||||
...configDefaults.exclude,
|
||||
'**/integrationTests/**'
|
||||
]
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user