mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-07-30 10:23:15 +03:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ab4dc55b2e | |||
| e394527e23 | |||
| 29150a8fd2 | |||
| 38c189f087 | |||
| 3747195c5f | |||
| 0104a02854 | |||
| c81d6f1774 | |||
| da9a93f3f5 | |||
| 6784ab3896 | |||
| 609488b35d | |||
| 42871c7c42 | |||
| 9c822dc25c | |||
| bb5aae504b | |||
| 6adb719ae2 | |||
| 54b24ddb30 | |||
| fbe0bd395b |
@@ -0,0 +1,144 @@
|
|||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Use Node.js 10.x
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 10.x
|
||||||
|
- name: setup npm cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
- name: npm install
|
||||||
|
run: npm ci
|
||||||
|
- name: npm build
|
||||||
|
run: npm run build
|
||||||
|
- name: npm run test
|
||||||
|
run: npm run test
|
||||||
|
|
||||||
|
integration:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
services:
|
||||||
|
vaultBasic:
|
||||||
|
image: vault:1.2.3
|
||||||
|
ports:
|
||||||
|
- 8200/tcp
|
||||||
|
env:
|
||||||
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
|
options: --cap-add=IPC_LOCK
|
||||||
|
vaultEnterprise:
|
||||||
|
image: hashicorp/vault-enterprise:1.3.0_ent
|
||||||
|
ports:
|
||||||
|
- 8200/tcp
|
||||||
|
env:
|
||||||
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
|
options: --cap-add=IPC_LOCK
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Use Node.js 10.x
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 10.x
|
||||||
|
- name: setup npm cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
- name: npm install
|
||||||
|
run: npm ci
|
||||||
|
- name: npm build
|
||||||
|
run: npm run build
|
||||||
|
- name: npm run test:integration:basic
|
||||||
|
run: npm run test:integration:basic
|
||||||
|
env:
|
||||||
|
VAULT_HOST: localhost
|
||||||
|
VAULT_PORT: ${{ job.services.vaultBasic.ports[8200] }}
|
||||||
|
CI: true
|
||||||
|
- name: npm run test:integration:enterprise
|
||||||
|
run: npm run test:integration:enterprise
|
||||||
|
env:
|
||||||
|
VAULT_HOST: localhost
|
||||||
|
VAULT_PORT: ${{ job.services.vaultEnterprise.ports[8200] }}
|
||||||
|
CI: true
|
||||||
|
|
||||||
|
e2e:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
services:
|
||||||
|
vault:
|
||||||
|
image: vault:1.3.0
|
||||||
|
ports:
|
||||||
|
- 8200/tcp
|
||||||
|
env:
|
||||||
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
|
options: --cap-add=IPC_LOCK
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Use Node.js 10.x
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 10.x
|
||||||
|
- name: setup npm cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
- name: npm install
|
||||||
|
run: npm ci
|
||||||
|
- name: npm build
|
||||||
|
run: npm run build
|
||||||
|
- name: setup vault
|
||||||
|
run: node ./integrationTests/e2e/setup.js
|
||||||
|
env:
|
||||||
|
VAULT_HOST: localhost
|
||||||
|
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
||||||
|
- name: use vault action
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: http://localhost:${{ job.services.vault.ports[8200] }}
|
||||||
|
token: testtoken
|
||||||
|
secrets: |
|
||||||
|
test secret ;
|
||||||
|
test secret | NAMED_SECRET ;
|
||||||
|
nested/test otherSecret ;
|
||||||
|
- name: verify
|
||||||
|
run: npm run test:e2e
|
||||||
|
|
||||||
|
publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build, integration, e2e]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Use Node.js 10.x
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 10.x
|
||||||
|
- name: setup npm cache
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
- name: npm install
|
||||||
|
run: npm ci
|
||||||
|
- name: release
|
||||||
|
if: success() && endsWith(github.ref, 'master')
|
||||||
|
run: npx semantic-release
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
name: Test
|
|
||||||
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
unit:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js 10.x
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: 10.x
|
|
||||||
- name: npm install and test
|
|
||||||
run: |
|
|
||||||
npm ci
|
|
||||||
npm test
|
|
||||||
env:
|
|
||||||
CI: true
|
|
||||||
|
|
||||||
integration:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
services:
|
|
||||||
vault:
|
|
||||||
image: vault:1.2.3
|
|
||||||
ports:
|
|
||||||
- 8200/tcp
|
|
||||||
env:
|
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
|
||||||
options: --cap-add=IPC_LOCK
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js 10.x
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: 10.x
|
|
||||||
- name: npm install
|
|
||||||
run: npm ci
|
|
||||||
- name: npm run test:integration
|
|
||||||
run: npm run test:integration
|
|
||||||
env:
|
|
||||||
VAULT_HOST: localhost
|
|
||||||
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
|
||||||
|
|
||||||
e2e:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
services:
|
|
||||||
vault:
|
|
||||||
image: vault:1.2.3
|
|
||||||
ports:
|
|
||||||
- 8200/tcp
|
|
||||||
env:
|
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
|
||||||
options: --cap-add=IPC_LOCK
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Use Node.js 10.x
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: 10.x
|
|
||||||
- name: npm install
|
|
||||||
run: npm ci
|
|
||||||
- name: setup vault
|
|
||||||
run: node ./e2e/setup.js
|
|
||||||
env:
|
|
||||||
VAULT_HOST: localhost
|
|
||||||
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
|
||||||
- name: use vault action
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
url: http://localhost:${{ job.services.vault.ports[8200] }}
|
|
||||||
token: testtoken
|
|
||||||
secrets: |
|
|
||||||
test secret ;
|
|
||||||
test secret | NAMED_SECRET ;
|
|
||||||
nested/test otherSecret ;
|
|
||||||
- name: verify
|
|
||||||
run: npm run test:e2e
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# vault-action
|
# vault-action
|
||||||
|
|
||||||
A helper action for easily pulling secrets from the v2 K/V backend of vault.
|
A helper action for easily pulling secrets from the default v2 K/V backend of vault.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
@@ -68,11 +68,30 @@ This action can take multi-line input, so say you had your AWS keys stored in a
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
with:
|
with:
|
||||||
keys: |
|
secrets: |
|
||||||
ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
||||||
ci/aws secretKey | AWS_SECRET_ACCESS_KEY
|
ci/aws secretKey | AWS_SECRET_ACCESS_KEY
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Namespace
|
||||||
|
|
||||||
|
This action could be use with namespace Vault Enterprise feature. You can specify namespace in request :
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
# ...
|
||||||
|
- name: Import Secrets
|
||||||
|
uses: RichiCoder1/vault-action
|
||||||
|
with:
|
||||||
|
url: https://vault-enterprise.mycompany.com:8200
|
||||||
|
token: ${{ secrets.VaultToken }}
|
||||||
|
namespace: ns1
|
||||||
|
secrets: |
|
||||||
|
ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
||||||
|
ci/aws secretKey | AWS_SECRET_ACCESS_KEY ;
|
||||||
|
ci npm_token
|
||||||
|
```
|
||||||
|
|
||||||
## Masking
|
## Masking
|
||||||
|
|
||||||
This action uses Github Action's built in masking, so all variables will automatically be masked if printed to the console or to logs.
|
This action uses Github Action's built in masking, so all variables will automatically be masked if printed to the console or to logs.
|
||||||
|
|||||||
@@ -5,17 +5,23 @@ const got = require('got');
|
|||||||
async function exportSecrets() {
|
async function exportSecrets() {
|
||||||
const vaultUrl = core.getInput('url', { required: true });
|
const vaultUrl = core.getInput('url', { required: true });
|
||||||
const vaultToken = core.getInput('token', { required: true });
|
const vaultToken = core.getInput('token', { required: true });
|
||||||
|
const vaultNamespace = core.getInput('namespace', { required: false });
|
||||||
|
|
||||||
const secretsInput = core.getInput('secrets', { required: true });
|
const secretsInput = core.getInput('secrets', { required: true });
|
||||||
const secrets = parseSecretsInput(secretsInput);
|
const secrets = parseSecretsInput(secretsInput);
|
||||||
|
|
||||||
for (const secret of secrets) {
|
for (const secret of secrets) {
|
||||||
const { secretPath, outputName, secretKey } = secret;
|
const { secretPath, outputName, secretKey } = secret;
|
||||||
const result = await got(`${vaultUrl}/v1/secret/data/${secretPath}`, {
|
const requestOptions = {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': vaultToken
|
'X-Vault-Token': vaultToken
|
||||||
}
|
}};
|
||||||
});
|
|
||||||
|
if (vaultNamespace != null){
|
||||||
|
requestOptions.headers["X-Vault-Namespace"] = vaultNamespace
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await got(`${vaultUrl}/v1/secret/data/${secretPath}`, requestOptions);
|
||||||
|
|
||||||
const parsedResponse = JSON.parse(result.body);
|
const parsedResponse = JSON.parse(result.body);
|
||||||
const vaultKeyData = parsedResponse.data;
|
const vaultKeyData = parsedResponse.data;
|
||||||
@@ -91,4 +97,4 @@ module.exports = {
|
|||||||
exportSecrets,
|
exportSecrets,
|
||||||
parseSecretsInput,
|
parseSecretsInput,
|
||||||
normalizeOutputKey
|
normalizeOutputKey
|
||||||
};
|
};
|
||||||
|
|||||||
+8
-2
@@ -1,4 +1,4 @@
|
|||||||
name: 'Vault'
|
name: 'Vault Secrets'
|
||||||
description: 'A Github Action that allows you to consume the v2 K/V backend of HashiCorp Vault as secure environment variables'
|
description: 'A Github Action that allows you to consume the v2 K/V backend of HashiCorp Vault as secure environment variables'
|
||||||
inputs:
|
inputs:
|
||||||
url:
|
url:
|
||||||
@@ -10,6 +10,12 @@ inputs:
|
|||||||
secrets:
|
secrets:
|
||||||
description: 'A semicolon-separated list of secrets to retrieve. These will automatically be converted to environmental variable keys. See README for more details'
|
description: 'A semicolon-separated list of secrets to retrieve. These will automatically be converted to environmental variable keys. See README for more details'
|
||||||
required: true
|
required: true
|
||||||
|
namespace:
|
||||||
|
description: 'The Vault namespace from which to query secrets. Vault Enterprise only, unset by default'
|
||||||
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'index.js'
|
main: 'dist/index.js'
|
||||||
|
branding:
|
||||||
|
icon: 'unlock'
|
||||||
|
color: 'gray-dark'
|
||||||
|
|||||||
Vendored
+4751
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
|||||||
|
# Start vault server locally for the purposes of integration tests.
|
||||||
|
version: "3.0"
|
||||||
|
services:
|
||||||
|
vault:
|
||||||
|
image: vault:1.3.0
|
||||||
|
environment:
|
||||||
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
|
ports:
|
||||||
|
- 8200:8200
|
||||||
|
privileged: true
|
||||||
|
vault-enterprise:
|
||||||
|
image: hashicorp/vault-enterprise:1.3.0_ent
|
||||||
|
environment:
|
||||||
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
|
ports:
|
||||||
|
- 8201:8201
|
||||||
|
privileged: true
|
||||||
@@ -5,51 +5,52 @@ const core = require('@actions/core');
|
|||||||
const got = require('got');
|
const got = require('got');
|
||||||
const { when } = require('jest-when');
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
const { exportSecrets } = require('../action');
|
const { exportSecrets } = require('../../action');
|
||||||
|
|
||||||
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
|
|
||||||
describe('integration', () => {
|
describe('integration', () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
// Verify Connection
|
// Verify Connection
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/config`, {
|
await got(`${vaultUrl}/v1/secret/config`, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/test`, {
|
await got(`${vaultUrl}/v1/secret/data/test`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
secret: "SUPERSECRET",
|
secret: 'SUPERSECRET',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await got(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}/v1/secret/data/nested/test`, {
|
await got(`${vaultUrl}/v1/secret/data/nested/test`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
otherSecret: "OTHERSUPERSECRET",
|
otherSecret: 'OTHERSUPERSECRET',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url')
|
.calledWith('url')
|
||||||
.mockReturnValue(`http://${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`);
|
.mockReturnValue(`${vaultUrl}`);
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('token')
|
.calledWith('token')
|
||||||
@@ -63,7 +64,7 @@ describe('integration', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('get simple secret', async () => {
|
it('get simple secret', async () => {
|
||||||
mockInput('test secret')
|
mockInput('test secret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('re-map secret', async () => {
|
it('re-map secret', async () => {
|
||||||
mockInput('test secret | TEST_KEY')
|
mockInput('test secret | TEST_KEY');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -79,7 +80,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('get nested secret', async () => {
|
it('get nested secret', async () => {
|
||||||
mockInput('nested/test otherSecret')
|
mockInput('nested/test otherSecret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -100,4 +101,4 @@ describe('integration', () => {
|
|||||||
expect(core.exportVariable).toBeCalledWith('NAMED_SECRET', 'SUPERSECRET');
|
expect(core.exportVariable).toBeCalledWith('NAMED_SECRET', 'SUPERSECRET');
|
||||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET');
|
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# e2e tests
|
||||||
|
|
||||||
|
This test suite runs `vault-action` as a GitHub Action in the context of a live build, and then verifies that the appropriate environmental variables are set.
|
||||||
|
These tests are intended to mostly be very simple smoke tests to verify that the action is being compiled and run correctly in context.
|
||||||
@@ -16,7 +16,7 @@ const got = require('got');
|
|||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
secret: "SUPERSECRET",
|
secret: 'SUPERSECRET',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
@@ -29,7 +29,7 @@ const got = require('got');
|
|||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
data: {
|
data: {
|
||||||
otherSecret: "OTHERSUPERSECRET",
|
otherSecret: 'OTHERSUPERSECRET',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: true,
|
json: true,
|
||||||
@@ -38,4 +38,4 @@ const got = require('got');
|
|||||||
console.log(error);
|
console.log(error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
jest.mock('@actions/core');
|
||||||
|
jest.mock('@actions/core/lib/command');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
const got = require('got');
|
||||||
|
const { when } = require('jest-when');
|
||||||
|
|
||||||
|
const { exportSecrets } = require('../../action');
|
||||||
|
|
||||||
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`;
|
||||||
|
|
||||||
|
describe('integration', () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
// Verify Connection
|
||||||
|
await got(`${vaultUrl}/v1/secret/config`, {
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': 'testtoken',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create namespace
|
||||||
|
await got(`${vaultUrl}/v1/sys/namespaces/ns1`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': 'testtoken',
|
||||||
|
},
|
||||||
|
json: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Enable secret engine
|
||||||
|
await got(`${vaultUrl}/v1/sys/mounts/secret`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': 'testtoken',
|
||||||
|
'X-Vault-Namespace': 'ns1',
|
||||||
|
},
|
||||||
|
body: { path: 'secret', type: 'kv', config: {}, options: { version: 2 }, generate_signing_key: true },
|
||||||
|
json: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`${vaultUrl}/v1/secret/data/test`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': 'testtoken',
|
||||||
|
'X-Vault-Namespace': 'ns1',
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
data: {
|
||||||
|
secret: 'SUPERSECRET_IN_NAMESPACE',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
json: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`${vaultUrl}/v1/secret/data/nested/test`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': 'testtoken',
|
||||||
|
'X-Vault-Namespace': 'ns1',
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
data: {
|
||||||
|
otherSecret: 'OTHERSUPERSECRET_IN_NAMESPACE',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
json: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('url')
|
||||||
|
.mockReturnValue(`${vaultUrl}`);
|
||||||
|
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('token')
|
||||||
|
.mockReturnValue('testtoken');
|
||||||
|
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('namespace')
|
||||||
|
.mockReturnValue('ns1');
|
||||||
|
});
|
||||||
|
|
||||||
|
function mockInput(secrets) {
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('secrets')
|
||||||
|
.mockReturnValue(secrets);
|
||||||
|
}
|
||||||
|
|
||||||
|
it('get simple secret', async () => {
|
||||||
|
mockInput('test secret');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET_IN_NAMESPACE');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('re-map secret', async () => {
|
||||||
|
mockInput('test secret | TEST_KEY');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('TEST_KEY', 'SUPERSECRET_IN_NAMESPACE');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get nested secret', async () => {
|
||||||
|
mockInput('nested/test otherSecret');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET_IN_NAMESPACE');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get multiple secrets', async () => {
|
||||||
|
mockInput(`
|
||||||
|
test secret ;
|
||||||
|
test secret | NAMED_SECRET ;
|
||||||
|
nested/test otherSecret ;`);
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledTimes(3);
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET_IN_NAMESPACE');
|
||||||
|
expect(core.exportVariable).toBeCalledWith('NAMED_SECRET', 'SUPERSECRET_IN_NAMESPACE');
|
||||||
|
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET_IN_NAMESPACE');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
verbose: true
|
||||||
|
};
|
||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integration/', '<rootDir>/e2e/'],
|
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integrationTests/'],
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+5611
-3
File diff suppressed because it is too large
Load Diff
+49
-36
@@ -1,38 +1,51 @@
|
|||||||
{
|
{
|
||||||
"name": "vault-action",
|
"name": "vault-action",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "A Github Action that allows you to consume vault secrets as secure environment variables.",
|
"description": "A Github Action that allows you to consume vault secrets as secure environment variables.",
|
||||||
"main": "index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest",
|
"build": "ncc build index.js -o dist",
|
||||||
"test:integration": "jest -c integration/jest.config.js",
|
"test": "jest",
|
||||||
"test:e2e": "jest -c e2e/jest.config.js"
|
"test:integration:basic": "jest -c integrationTests/basic/jest.config.js",
|
||||||
},
|
"test:integration:enterprise": "jest -c integrationTests/enterprise/jest.config.js",
|
||||||
"repository": {
|
"test:e2e": "jest -c integrationTests/e2e/jest.config.js"
|
||||||
"type": "git",
|
},
|
||||||
"url": "git+https://github.com/RichiCoder1/vault-action.git"
|
"release": {
|
||||||
},
|
"branch": "master",
|
||||||
"keywords": [
|
"plugins": [
|
||||||
"hashicorp",
|
"@semantic-release/commit-analyzer",
|
||||||
"vault",
|
"@semantic-release/release-notes-generator",
|
||||||
"github",
|
"@semantic-release/github"
|
||||||
"actions",
|
],
|
||||||
"github-actions",
|
"ci": false
|
||||||
"javascript"
|
},
|
||||||
],
|
"repository": {
|
||||||
"author": "Richard Simpson <richardsimpson@outlook.com>",
|
"type": "git",
|
||||||
"license": "MIT",
|
"url": "git+https://github.com/RichiCoder1/vault-action.git"
|
||||||
"bugs": {
|
},
|
||||||
"url": "https://github.com/RichiCoder1/vault-action/issues"
|
"keywords": [
|
||||||
},
|
"hashicorp",
|
||||||
"homepage": "https://github.com/RichiCoder1/vault-action#readme",
|
"vault",
|
||||||
"dependencies": {
|
"github",
|
||||||
"@actions/core": "^1.1.1",
|
"actions",
|
||||||
"got": "^9.6.0"
|
"github-actions",
|
||||||
},
|
"javascript"
|
||||||
"devDependencies": {
|
],
|
||||||
"@types/jest": "^24.0.18",
|
"author": "Richard Simpson <richardsimpson@outlook.com>",
|
||||||
"jest": "^24.9.0",
|
"license": "MIT",
|
||||||
"jest-when": "^2.7.0"
|
"bugs": {
|
||||||
}
|
"url": "https://github.com/RichiCoder1/vault-action/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/RichiCoder1/vault-action#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.1.1",
|
||||||
|
"got": "^9.6.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jest": "^24.0.18",
|
||||||
|
"@zeit/ncc": "^0.20.5",
|
||||||
|
"jest": "^24.9.0",
|
||||||
|
"jest-when": "^2.7.0",
|
||||||
|
"semantic-release": "^15.13.24"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user