mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-07-26 00:13:16 +03:00
Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e27b45646f | |||
| 76ca623af3 | |||
| c8b383ee4e | |||
| a214c8c65a | |||
| f7f0d5a289 | |||
| 633de935e7 | |||
| 5de67274a5 | |||
| e031fa076e | |||
| e5ef6c9c11 | |||
| 6cf013b5c0 | |||
| 098ee568ed | |||
| e055dfd1a4 | |||
| b3a02289e7 | |||
| 683c9b2557 | |||
| e59c94afbe | |||
| cd01494ae2 | |||
| a2d854da53 | |||
| d1321fc438 | |||
| 5fb792e09f | |||
| c63c61cd7e | |||
| 944a2bea12 | |||
| 2f554c06ec | |||
| 25ecb3dd46 | |||
| 734d76c388 | |||
| 22e3f3e09e | |||
| 727494f451 | |||
| fa68886b06 | |||
| a7527a3e8a | |||
| 9878eba70a | |||
| 83d944ba1a | |||
| 567ec72c33 | |||
| 5c464962be | |||
| ea29244204 | |||
| 5de02d5a14 | |||
| 8845b5c724 | |||
| c80d0b130c | |||
| 01bb0f9bc9 | |||
| 5a70924133 | |||
| b5fdbf352b | |||
| 268a32f886 | |||
| f2b4d0b645 | |||
| 675d33e3da | |||
| 50ece41861 | |||
| ed8303ca53 | |||
| 0e719ef42a | |||
| 795c9eddca | |||
| 9e8c0bad27 | |||
| 751a3d19ad | |||
| cc7ceeef06 | |||
| fa23030c10 | |||
| 4561f9e26e | |||
| cb2908ac94 | |||
| 198a7ed7d2 | |||
| 4ab6f6070f | |||
| bef2eb0b90 | |||
| 0ece1da433 | |||
| 7fb0d673d1 |
@@ -1 +0,0 @@
|
|||||||
ko_fi: richicoder
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: "[BUG] "
|
||||||
|
labels: bug
|
||||||
|
assignees: RichiCoder1
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
The yaml of the `vault-action` step, with any sensitive information masked or removed.
|
||||||
|
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Log Output**
|
||||||
|
For the most verbose logs, [add a secret called `ACTIONS_STEP_DEBUG` with the value `true`](https://github.com/actions/toolkit/blob/master/docs/action-debugging.md). Then, re-run the workflow if possible and post the *raw logs* for the step here with any sensitive information masked or removed.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: "[FEAT] "
|
||||||
|
labels: enhancement
|
||||||
|
assignees: RichiCoder1
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
+214
-97
@@ -3,169 +3,286 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Use Node.js 10.x
|
|
||||||
uses: actions/setup-node@v1
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 10.x
|
node-version: ''
|
||||||
- name: setup npm cache
|
|
||||||
|
- name: Setup NPM Cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
path: ~/.npm
|
path: ~/.npm
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-node-
|
${{ runner.os }}-node-
|
||||||
- name: npm install
|
|
||||||
|
- name: NPM Install
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: npm build
|
|
||||||
|
- name: NPM Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: npm run test
|
|
||||||
|
- name: NPM Run Test
|
||||||
run: npm run test
|
run: npm run test
|
||||||
|
|
||||||
integration:
|
integrationOSS:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
services:
|
steps:
|
||||||
vaultBasic:
|
- uses: actions/checkout@v1
|
||||||
image: vault:1.2.3
|
|
||||||
ports:
|
- name: Run docker-compose
|
||||||
- 8200/tcp
|
run: docker-compose up -d vault
|
||||||
env:
|
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
- uses: actions/setup-node@v1
|
||||||
options: --cap-add=IPC_LOCK
|
with:
|
||||||
vaultEnterprise:
|
node-version: ''
|
||||||
image: hashicorp/vault-enterprise:1.3.0_ent
|
|
||||||
ports:
|
- name: Setup NPM Cache
|
||||||
- 8200/tcp
|
uses: actions/cache@v1
|
||||||
env:
|
with:
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
path: ~/.npm
|
||||||
options: --cap-add=IPC_LOCK
|
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: 8200
|
||||||
|
CI: true
|
||||||
|
|
||||||
|
integrationEnterprise:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Use Node.js 10.x
|
|
||||||
uses: actions/setup-node@v1
|
- name: Run docker-compose
|
||||||
with:
|
run: docker-compose up -d vault-enterprise
|
||||||
node-version: 10.x
|
|
||||||
- name: setup npm cache
|
- uses: actions/setup-node@v1
|
||||||
uses: actions/cache@v1
|
with:
|
||||||
with:
|
node-version: ''
|
||||||
path: ~/.npm
|
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
- name: Setup NPM Cache
|
||||||
restore-keys: |
|
uses: actions/cache@v1
|
||||||
${{ runner.os }}-node-
|
with:
|
||||||
- name: npm install
|
path: ~/.npm
|
||||||
run: npm ci
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
- name: npm build
|
restore-keys: |
|
||||||
run: npm run build
|
${{ runner.os }}-node-
|
||||||
- name: npm run test:integration:basic
|
|
||||||
run: npm run test:integration:basic
|
- name: NPM Install
|
||||||
env:
|
run: npm ci
|
||||||
VAULT_HOST: localhost
|
|
||||||
VAULT_PORT: ${{ job.services.vaultBasic.ports[8200] }}
|
- name: NPM Build
|
||||||
CI: true
|
run: npm run build
|
||||||
- name: npm run test:integration:enterprise
|
|
||||||
run: npm run test:integration:enterprise
|
- name: NPM Run test:intergration:enterprise
|
||||||
env:
|
run: npm run test:integration:enterprise
|
||||||
VAULT_HOST: localhost
|
env:
|
||||||
VAULT_PORT: ${{ job.services.vaultEnterprise.ports[8200] }}
|
VAULT_HOST: localhost
|
||||||
CI: true
|
VAULT_PORT: 8200
|
||||||
|
CI: true
|
||||||
|
|
||||||
e2e:
|
e2e:
|
||||||
runs-on: ubuntu-latest
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Use Node.js 10.x
|
|
||||||
uses: actions/setup-node@v1
|
- name: Run docker-compose
|
||||||
|
run: docker-compose up -d vault
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 10.x
|
node-version: ''
|
||||||
- name: setup npm cache
|
|
||||||
|
- name: Setup NPM Cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
path: ~/.npm
|
path: ~/.npm
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-node-
|
${{ runner.os }}-node-
|
||||||
- name: npm install
|
|
||||||
|
- name: NPM Install
|
||||||
run: npm ci
|
run: npm ci
|
||||||
- name: npm build
|
|
||||||
|
- name: NPM Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
- name: setup vault
|
|
||||||
|
- name: Setup Vault
|
||||||
run: node ./integrationTests/e2e/setup.js
|
run: node ./integrationTests/e2e/setup.js
|
||||||
env:
|
env:
|
||||||
VAULT_HOST: localhost
|
VAULT_HOST: localhost
|
||||||
VAULT_PORT: ${{ job.services.vault.ports[8200] }}
|
VAULT_PORT: 8200
|
||||||
- name: use vault action (default K/V version 2)
|
|
||||||
|
- name: Test Vault Action (default KV V2)
|
||||||
uses: ./
|
uses: ./
|
||||||
id: kv-secrets
|
id: kv-secrets
|
||||||
with:
|
with:
|
||||||
url: http://localhost:${{ job.services.vault.ports[8200] }}
|
url: http://localhost:8200
|
||||||
token: testtoken
|
token: testtoken
|
||||||
secrets: |
|
secrets: |
|
||||||
test secret ;
|
secret/data/test secret ;
|
||||||
test secret | NAMED_SECRET ;
|
secret/data/test secret | NAMED_SECRET ;
|
||||||
nested/test otherSecret ;
|
secret/data/nested/test otherSecret ;
|
||||||
- name: use vault action (custom K/V version 1)
|
|
||||||
|
- name: Test Vault Action (default KV V1)
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
url: http://localhost:${{ job.services.vault.ports[8200] }}
|
url: http://localhost:8200
|
||||||
token: testtoken
|
token: testtoken
|
||||||
path: my-secret
|
|
||||||
kv-version: 1
|
|
||||||
secrets: |
|
secrets: |
|
||||||
test altSecret ;
|
my-secret/test altSecret ;
|
||||||
test altSecret | NAMED_ALTSECRET ;
|
my-secret/test altSecret | NAMED_ALTSECRET ;
|
||||||
nested/test otherAltSecret ;
|
my-secret/nested/test otherAltSecret ;
|
||||||
- name: use vault action (using cubbyhole engine)
|
|
||||||
|
- name: Test Vault Action (cubbyhole)
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
url: http://localhost:${{ job.services.vault.ports[8200] }}
|
url: http://localhost:8200
|
||||||
token: testtoken
|
token: testtoken
|
||||||
secrets: |
|
secrets: |
|
||||||
/cubbyhole/test foo ;
|
/cubbyhole/test foo ;
|
||||||
/cubbyhole/test zip | NAMED_CUBBYSECRET ;
|
/cubbyhole/test zip | NAMED_CUBBYSECRET ;
|
||||||
- name: verify
|
|
||||||
|
- name: Verify Vault Action Outputs
|
||||||
run: npm run test:e2e
|
run: npm run test:e2e
|
||||||
env:
|
env:
|
||||||
OTHER_SECRET_OUTPUT: ${{ steps.kv-secrets.outputs.otherSecret }}
|
OTHER_SECRET_OUTPUT: ${{ steps.kv-secrets.outputs.otherSecret }}
|
||||||
|
|
||||||
publish:
|
e2e-tls:
|
||||||
if: github.event_name == 'push' && contains(github.ref, 'master')
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [build, integration, e2e]
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: Use Node.js 10.x
|
|
||||||
uses: actions/setup-node@v1
|
- name: Run docker-compose
|
||||||
|
run: docker-compose up -d vault-tls
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: 10.x
|
node-version: ''
|
||||||
- name: setup npm cache
|
|
||||||
|
- name: Setup NPM Cache
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
path: ~/.npm
|
path: ~/.npm
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-node-
|
${{ runner.os }}-node-
|
||||||
- name: npm install
|
|
||||||
run: npm ci
|
- name: NPM Install
|
||||||
- name: release
|
run: npm ci
|
||||||
if: success() && endsWith(github.ref, 'master')
|
|
||||||
run: npx semantic-release
|
- name: NPM Build
|
||||||
env:
|
run: npm run build
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
- name: Setup Vault
|
||||||
|
run: node ./integrationTests/e2e-tls/setup.js
|
||||||
|
env:
|
||||||
|
VAULT_HOST: localhost
|
||||||
|
VAULT_PORT: 8200
|
||||||
|
VAULTCA: ${{ secrets.VAULTCA }}
|
||||||
|
VAULT_CLIENT_CERT: ${{ secrets.VAULT_CLIENT_CERT }}
|
||||||
|
VAULT_CLIENT_KEY: ${{ secrets.VAULT_CLIENT_KEY }}
|
||||||
|
|
||||||
|
- name: Test Vault Action (default KV V2)
|
||||||
|
uses: ./
|
||||||
|
id: kv-secrets
|
||||||
|
with:
|
||||||
|
url: https://localhost:8200
|
||||||
|
token: ${{ env.VAULT_TOKEN }}
|
||||||
|
caCertificate: ${{ secrets.VAULTCA }}
|
||||||
|
clientCertificate: ${{ secrets.VAULT_CLIENT_CERT }}
|
||||||
|
clientKey: ${{ secrets.VAULT_CLIENT_KEY }}
|
||||||
|
secrets: |
|
||||||
|
secret/data/test secret ;
|
||||||
|
secret/data/test secret | NAMED_SECRET ;
|
||||||
|
secret/data/nested/test otherSecret ;
|
||||||
|
|
||||||
|
- name: Test Vault Action (tlsSkipVerify)
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: https://localhost:8200
|
||||||
|
token: ${{ env.VAULT_TOKEN }}
|
||||||
|
tlsSkipVerify: true
|
||||||
|
clientCertificate: ${{ secrets.VAULT_CLIENT_CERT }}
|
||||||
|
clientKey: ${{ secrets.VAULT_CLIENT_KEY }}
|
||||||
|
secrets: |
|
||||||
|
secret/data/tlsSkipVerify skip ;
|
||||||
|
|
||||||
|
- name: Test Vault Action (default KV V1)
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: https://localhost:8200
|
||||||
|
token: ${{ env.VAULT_TOKEN }}
|
||||||
|
caCertificate: ${{ secrets.VAULTCA }}
|
||||||
|
clientCertificate: ${{ secrets.VAULT_CLIENT_CERT }}
|
||||||
|
clientKey: ${{ secrets.VAULT_CLIENT_KEY }}
|
||||||
|
secrets: |
|
||||||
|
my-secret/test altSecret ;
|
||||||
|
my-secret/test altSecret | NAMED_ALTSECRET ;
|
||||||
|
my-secret/nested/test otherAltSecret ;
|
||||||
|
|
||||||
|
- name: Test Vault Action (cubbyhole)
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: https://localhost:8200
|
||||||
|
token: ${{ env.VAULT_TOKEN }}
|
||||||
|
secrets: |
|
||||||
|
/cubbyhole/test foo ;
|
||||||
|
/cubbyhole/test zip | NAMED_CUBBYSECRET ;
|
||||||
|
caCertificate: ${{ secrets.VAULTCA }}
|
||||||
|
clientCertificate: ${{ secrets.VAULT_CLIENT_CERT }}
|
||||||
|
clientKey: ${{ secrets.VAULT_CLIENT_KEY }}
|
||||||
|
|
||||||
|
- name: Verify Vault Action Outputs
|
||||||
|
run: npm run test:e2e-tls
|
||||||
|
env:
|
||||||
|
OTHER_SECRET_OUTPUT: ${{ steps.kv-secrets.outputs.otherSecret }}
|
||||||
|
|
||||||
|
# Removing publish step for now.
|
||||||
|
# publish:
|
||||||
|
# if: github.event_name == 'push' && contains(github.ref, 'master')
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# needs: [build, integration, e2e]
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v1
|
||||||
|
# - uses: actions/setup-node@v1
|
||||||
|
# with:
|
||||||
|
# node-version: ''
|
||||||
|
# - 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 }}
|
||||||
|
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
|
|||||||
Vendored
+35
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"name": "vscode-jest-tests",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"--runInBand"
|
||||||
|
],
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"disableOptimisticBPs": true,
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"name": "vscode-integration-tests",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"--runInBand",
|
||||||
|
"--config=${workspaceFolder}/integrationTests/basic/jest.config.js"
|
||||||
|
],
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen",
|
||||||
|
"disableOptimisticBPs": true,
|
||||||
|
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"markdown-toc.depthFrom": 2
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
## Unreleased
|
||||||
|
|
||||||
|
## 2.0.0 (August 24th, 2020)
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
* Added TLS and mTLS support [GH-97](https://github.com/hashicorp/vault-action/pull/97)
|
||||||
|
|
||||||
|
Improvements:
|
||||||
|
|
||||||
|
* Breaking change: removed KV specific parameters and generalized secret UX [GH-102](https://github.com/hashicorp/vault-action/pull/102)
|
||||||
|
|
||||||
|
Bugs:
|
||||||
@@ -1,8 +1,31 @@
|
|||||||
# vault-action
|
# Vault GitHub Action
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Please note**: We take Vault's security and our users' trust very seriously. If you believe you have found a security issue in Vault or this Vault Action, _please responsibly disclose_ by contacting us at [security@hashicorp.com](mailto:security@hashicorp.com).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
A helper action for easily pulling secrets from HashiCorp Vault™.
|
A helper action for easily pulling secrets from HashiCorp Vault™.
|
||||||
|
|
||||||
By default, this action pulls from [Version 2](https://www.vaultproject.io/docs/secrets/kv/kv-v2/) of the K/V Engine. See examples below for how to [use v1](#using-kv-version-1) as well as [other non-K/V engines](#other-secret-engines).
|
<!-- TOC -->
|
||||||
|
|
||||||
|
- [Example Usage](#example-usage)
|
||||||
|
- [Authentication method](#authentication-method)
|
||||||
|
- [Key Syntax](#key-syntax)
|
||||||
|
- [Simple Key](#simple-key)
|
||||||
|
- [Set Output Variable Name](#set-output-variable-name)
|
||||||
|
- [Multiple Secrets](#multiple-secrets)
|
||||||
|
- [Nested Secrets](#nested-secrets)
|
||||||
|
- [Other Secret Engines](#other-secret-engines)
|
||||||
|
- [Adding Extra Headers](#adding-extra-headers)
|
||||||
|
- [Vault Enterprise Features](#vault-enterprise-features)
|
||||||
|
- [Namespace](#namespace)
|
||||||
|
- [Reference](#reference)
|
||||||
|
- [Masking - Hiding Secrets from Logs](#masking---hiding-secrets-from-logs)
|
||||||
|
- [Normalization](#normalization)
|
||||||
|
|
||||||
|
<!-- /TOC -->
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
@@ -13,29 +36,31 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
# ...
|
# ...
|
||||||
- name: Import Secrets
|
- name: Import Secrets
|
||||||
uses: RichiCoder1/vault-action
|
uses: hashicorp/vault-action
|
||||||
with:
|
with:
|
||||||
url: https://vault.mycompany.com:8200
|
url: https://vault.mycompany.com:8200
|
||||||
token: ${{ secrets.VaultToken }}
|
token: ${{ secrets.VaultToken }}
|
||||||
|
caCertificate: ${{ secrets.VAULTCA }}
|
||||||
secrets: |
|
secrets: |
|
||||||
ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
secret/data/ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
||||||
ci/aws secretKey | AWS_SECRET_ACCESS_KEY ;
|
secret/data/ci/aws secretKey | AWS_SECRET_ACCESS_KEY ;
|
||||||
ci npm_token
|
secret/data/ci npm_token
|
||||||
# ...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
## Authentication method
|
## Authentication method
|
||||||
|
|
||||||
While most workflows will likely use a vault token, you can also use an `approle` to authenticate with vaule. You can configure which by using the `method` parameter:
|
While most workflows will likely use a vault token, you can also use an `approle` to authenticate with Vault. You can configure which by using the `method` parameter:
|
||||||
|
|
||||||
- **token**: (by default) you must provide a token parameter
|
- **token**: (by default) you must provide a `token` parameter
|
||||||
```yaml
|
```yaml
|
||||||
...
|
...
|
||||||
with:
|
with:
|
||||||
url: https://vault.mycompany.com:8200
|
url: https://vault.mycompany.com:8200
|
||||||
token: ${{ secrets.VaultToken }}
|
token: ${{ secrets.VaultToken }}
|
||||||
|
caCertificate: ${{ secrets.VAULTCA }}
|
||||||
```
|
```
|
||||||
- **approle**: you must provide a roleId & secretId parameter
|
- **approle**: you must provide a `roleId` & `secretId` parameter
|
||||||
```yaml
|
```yaml
|
||||||
...
|
...
|
||||||
with:
|
with:
|
||||||
@@ -43,25 +68,37 @@ with:
|
|||||||
method: approle
|
method: approle
|
||||||
roleId: ${{ secrets.roleId }}
|
roleId: ${{ secrets.roleId }}
|
||||||
secretId: ${{ secrets.secretId }}
|
secretId: ${{ secrets.secretId }}
|
||||||
|
caCertificate: ${{ secrets.VAULTCA }}
|
||||||
```
|
```
|
||||||
|
- **github**: you must provide the github token as `githubToken`
|
||||||
|
```yaml
|
||||||
|
...
|
||||||
|
with:
|
||||||
|
url: https://vault.mycompany.com:8200
|
||||||
|
method: github
|
||||||
|
githubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
caCertificate: ${{ secrets.VAULTCA }}
|
||||||
|
```
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
## Key Syntax
|
## Key Syntax
|
||||||
|
|
||||||
The `secrets` parameter is a set of multiple secret requests separated by the `;` character.
|
The `secrets` parameter is a set of multiple secret requests separated by the `;` character.
|
||||||
|
|
||||||
Each secret request is comprised of the `path` and the `key` of the desired secret, and optionally the desired Env Var output name.
|
Each secret request consists of the `path` and the `key` of the desired secret, and optionally the desired Env Var output name.
|
||||||
|
|
||||||
```raw
|
```raw
|
||||||
{{ Secret Path }} {{ Secret Key }} | {{ Output Variable Name }}
|
{{ Secret Path }} {{ Secret Key or Selector }} | {{ Env/Output Variable Name }}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Simple Key
|
### Simple Key
|
||||||
|
|
||||||
To retrieve a key `npmToken` from path `ci` that has value `somelongtoken` from vault you could do:
|
To retrieve a key `npmToken` from path `secret/data/ci` that has value `somelongtoken` from vault you could do:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
with:
|
with:
|
||||||
secrets: ci npmToken
|
secrets: secret/data/ci npmToken
|
||||||
```
|
```
|
||||||
|
|
||||||
`vault-action` will automatically normalize the given secret selector key, and set the follow as environment variables for the following steps in the current job:
|
`vault-action` will automatically normalize the given secret selector key, and set the follow as environment variables for the following steps in the current job:
|
||||||
@@ -70,7 +107,7 @@ with:
|
|||||||
NPMTOKEN=somelongtoken
|
NPMTOKEN=somelongtoken
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also access the secret via ouputs:
|
You can also access the secret via outputs:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
@@ -83,13 +120,15 @@ steps:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
_**Note:** If you'd like to only use outputs and disable automatic environment variables, you can set the `exportEnv` option to `false`._
|
||||||
|
|
||||||
### Set Output Variable Name
|
### Set Output Variable Name
|
||||||
|
|
||||||
However, if you want to set it to a specific name, say `NPM_TOKEN`, you could do this instead:
|
However, if you want to set it to a specific name, say `NPM_TOKEN`, you could do this instead:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
with:
|
with:
|
||||||
secrets: ci npmToken | NPM_TOKEN
|
secrets: secret/data/ci npmToken | NPM_TOKEN
|
||||||
```
|
```
|
||||||
|
|
||||||
With that, `vault-action` will now use your requested name and output:
|
With that, `vault-action` will now use your requested name and output:
|
||||||
@@ -116,50 +155,18 @@ This action can take multi-line input, so say you had your AWS keys stored in a
|
|||||||
```yaml
|
```yaml
|
||||||
with:
|
with:
|
||||||
secrets: |
|
secrets: |
|
||||||
ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
secret/data/ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
||||||
ci/aws secretKey | AWS_SECRET_ACCESS_KEY
|
secret/data/ci/aws secretKey | AWS_SECRET_ACCESS_KEY
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using K/V version 1
|
## Other Secret Engines
|
||||||
|
|
||||||
By default, `vault-action` expects a K/V engine using [version 2](https://www.vaultproject.io/docs/secrets/kv/kv-v2.html).
|
Vault Action currently supports retrieving secrets from any engine where secrets
|
||||||
|
are retrieved via `GET` requests. This means secret engines such as PKI are currently
|
||||||
|
not supported due to their requirement of sending parameters along with the request
|
||||||
|
(such as `common_name`).
|
||||||
|
|
||||||
In order to work with a [v1 engine](https://www.vaultproject.io/docs/secrets/kv/kv-v1/), the `kv-version` parameter may be passed:
|
For example, to request a secret from the `cubbyhole` secret engine:
|
||||||
|
|
||||||
```yaml
|
|
||||||
with:
|
|
||||||
kv-version: 1
|
|
||||||
```
|
|
||||||
|
|
||||||
### Custom K/V Engine Path
|
|
||||||
|
|
||||||
When you enable the K/V Engine, by default it's placed at the path `secret`, so a secret named `ci` will be accessed from `secret/ci`. However, [if you enabled the secrets engine using a custom `path`](https://www.vaultproject.io/docs/commands/secrets/enable/#inlinecode--path-4), you
|
|
||||||
can pass it as follows:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
with:
|
|
||||||
path: my-secrets
|
|
||||||
secrets: ci npmToken
|
|
||||||
```
|
|
||||||
|
|
||||||
This way, the `ci` secret in the example above will be retrieved from `my-secrets/ci`.
|
|
||||||
|
|
||||||
### Other Secret Engines
|
|
||||||
|
|
||||||
While this action primarily supports the K/V engine, it is possible to request secrets from other engines in Vault.
|
|
||||||
|
|
||||||
To do so when specifying the `Secret Path`, just append a leading formard slash (`/`) and specify the path as described in the Vault API documentation.
|
|
||||||
|
|
||||||
For example, to retrieve a stored secret from the [`cubbyhole` engine](https://www.vaultproject.io/api-docs/secret/cubbyhole/), assuming you have a stored secret at the path `foo` with the contents:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"foo": "bar",
|
|
||||||
"zip": "zap"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
You could request the contents like so:
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
with:
|
with:
|
||||||
@@ -187,43 +194,72 @@ steps:
|
|||||||
run: "my-cli --token '${{ steps.secrets.outputs.MY_KEY }}'"
|
run: "my-cli --token '${{ steps.secrets.outputs.MY_KEY }}'"
|
||||||
```
|
```
|
||||||
|
|
||||||
Secrets pulled from the same `Secret Path` are cached by default. So if you, for example, are using the `aws` engine and retrieve a key, only a single key for a given path is returned.
|
## Adding Extra Headers
|
||||||
|
|
||||||
e.g.:
|
If you ever need to add extra headers to the vault request, say if you need to authenticate with a firewall, all you need to do is set `extraHeaders`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
with:
|
with:
|
||||||
secrets: |
|
secrets: |
|
||||||
/aws/creds/ci access_key | AWS_ACCESS_KEY_ID ;
|
secret/ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
||||||
/aws/creds/ci secret_key | AWS_SECRET_ACCESS_KEY
|
secret/ci/aws secretKey | AWS_SECRET_ACCESS_KEY
|
||||||
|
extraHeaders: |
|
||||||
|
X-Secure-Id: ${{ secrets.SECURE_ID }}
|
||||||
|
X-Secure-Secret: ${{ secrets.SECURE_SECRET }}
|
||||||
```
|
```
|
||||||
|
|
||||||
would work fine.
|
This will automatically add the `x-secure-id` and `x-secure-secret` headers to every request to Vault.
|
||||||
|
|
||||||
NOTE: The `Secret Key` is pulled from the `data` property of the response.
|
|
||||||
|
|
||||||
## Vault Enterprise Features
|
## Vault Enterprise Features
|
||||||
|
|
||||||
### Namespace
|
### Namespace
|
||||||
|
|
||||||
If you need to retrieve secrets from a specific vault namespace, all that's required is an additional parameter specifying the namespace.
|
If you need to retrieve secrets from a specific Vault namespace, all that's required is an additional parameter specifying the namespace.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
# ...
|
# ...
|
||||||
- name: Import Secrets
|
- name: Import Secrets
|
||||||
uses: RichiCoder1/vault-action
|
uses: hashicorp/vault-action
|
||||||
with:
|
with:
|
||||||
url: https://vault-enterprise.mycompany.com:8200
|
url: https://vault-enterprise.mycompany.com:8200
|
||||||
method: token
|
method: token
|
||||||
|
caCertificate: ${{ secrets.VAULTCA }}
|
||||||
token: ${{ secrets.VaultToken }}
|
token: ${{ secrets.VaultToken }}
|
||||||
namespace: ns1
|
namespace: ns1
|
||||||
secrets: |
|
secrets: |
|
||||||
ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
secret/ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
||||||
ci/aws secretKey | AWS_SECRET_ACCESS_KEY ;
|
secret/ci/aws secretKey | AWS_SECRET_ACCESS_KEY ;
|
||||||
ci npm_token
|
secret/ci npm_token
|
||||||
```
|
```
|
||||||
|
|
||||||
## Masking
|
## Reference
|
||||||
|
|
||||||
This action uses Github Action's built in masking, so all variables will automatically be masked if printed to the console or to logs.
|
Here are all the inputs available through `with`:
|
||||||
|
|
||||||
|
| Input | Description | Default | Required |
|
||||||
|
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------- |
|
||||||
|
| `url` | The URL for the vault endpoint | | ✔ |
|
||||||
|
| `secrets` | A semicolon-separated list of secrets to retrieve. These will automatically be converted to environmental variable keys. See README for more details | | ✔ |
|
||||||
|
| `namespace` | The Vault namespace from which to query secrets. Vault Enterprise only, unset by default | | |
|
||||||
|
| `method` | The method to use to authenticate with Vault. | `token` | |
|
||||||
|
| `token` | The Vault Token to be used to authenticate with Vault | | |
|
||||||
|
| `roleId` | The Role Id for App Role authentication | | |
|
||||||
|
| `secretId` | The Secret Id for App Role authentication | | |
|
||||||
|
| `githubToken` | The Github Token to be used to authenticate with Vault | | |
|
||||||
|
| `authPayload` | The JSON payload to be sent to Vault when using a custom authentication method. | | |
|
||||||
|
| `extraHeaders` | A string of newline separated extra headers to include on every request. | | |
|
||||||
|
| `exportEnv` | Whether or not export secrets as environment variables. | `true` | |
|
||||||
|
| `caCertificate` | Base64 encoded CA certificate the server certificate was signed with. | | |
|
||||||
|
| `clientCertificate` | Base64 encoded client certificate the action uses to authenticate with Vault when mTLS is enabled. | | |
|
||||||
|
| `clientKey` | Base64 encoded client key the action uses to authenticate with Vault when mTLS is enabled. | | |
|
||||||
|
| `tlsSkipVerify` | When set to true, disables verification of server certificates when testing the action. | `false` | |
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
**This only obscures secrets from output logs.** If someone has the ability to edit your workflows, then they are able to read and therefore write secrets to somewhere else just like normal GitHub Secrets.
|
||||||
|
|
||||||
|
## Normalization
|
||||||
|
|
||||||
|
To make it simpler to consume certain secrets as env vars, if no Env/Output Var Name is specified `vault-action` will replace and `.` chars with `__`, remove any other non-letter or number characters. If you're concerned about the result, it's recommended to provide an explicit Output Var Key.
|
||||||
|
|||||||
@@ -1,231 +0,0 @@
|
|||||||
// @ts-check
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const core = require('@actions/core');
|
|
||||||
// @ts-ignore
|
|
||||||
const command = require('@actions/core/lib/command');
|
|
||||||
const got = require('got');
|
|
||||||
|
|
||||||
const AUTH_METHODS = ['approle', 'token'];
|
|
||||||
const VALID_KV_VERSION = [-1, 1, 2];
|
|
||||||
|
|
||||||
async function exportSecrets() {
|
|
||||||
const vaultUrl = core.getInput('url', { required: true });
|
|
||||||
const vaultNamespace = core.getInput('namespace', { required: false });
|
|
||||||
|
|
||||||
let enginePath = core.getInput('path', { required: false });
|
|
||||||
let kvVersion = core.getInput('kv-version', { required: false });
|
|
||||||
|
|
||||||
const secretsInput = core.getInput('secrets', { required: true });
|
|
||||||
const secretRequests = parseSecretsInput(secretsInput);
|
|
||||||
|
|
||||||
const vaultMethod = core.getInput('method', { required: false }) || 'token';
|
|
||||||
if (!AUTH_METHODS.includes(vaultMethod)) {
|
|
||||||
throw Error(`Sorry, the authentication method ${vaultMethod} is not currently supported.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
let vaultToken = null;
|
|
||||||
switch (vaultMethod) {
|
|
||||||
case 'approle':
|
|
||||||
const vaultRoleId = core.getInput('roleId', { required: true });
|
|
||||||
const vaultSecretId = core.getInput('secretId', { required: true });
|
|
||||||
core.debug('Try to retrieve Vault Token from approle');
|
|
||||||
var options = {
|
|
||||||
headers: {},
|
|
||||||
json: { role_id: vaultRoleId, secret_id: vaultSecretId },
|
|
||||||
responseType: 'json'
|
|
||||||
};
|
|
||||||
|
|
||||||
if (vaultNamespace != null) {
|
|
||||||
options.headers["X-Vault-Namespace"] = vaultNamespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @type {any} */
|
|
||||||
const result = await got.post(`${vaultUrl}/v1/auth/approle/login`, options);
|
|
||||||
if (result && result.body && result.body.auth && result.body.auth.client_token) {
|
|
||||||
vaultToken = result.body.auth.client_token;
|
|
||||||
core.debug('✔ Vault Token has retrieved from approle');
|
|
||||||
} else {
|
|
||||||
throw Error(`No token was retrieved with the role_id and secret_id provided.`);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
vaultToken = core.getInput('token', { required: true });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!enginePath) {
|
|
||||||
enginePath = 'secret';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!kvVersion) {
|
|
||||||
kvVersion = 2;
|
|
||||||
}
|
|
||||||
kvVersion = +kvVersion;
|
|
||||||
|
|
||||||
if (Number.isNaN(kvVersion) || !VALID_KV_VERSION.includes(kvVersion)) {
|
|
||||||
throw Error(`You must provide a valid K/V version (${VALID_KV_VERSION.slice(1).join(', ')}). Input: "${kvVersion}"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const responseCache = new Map();
|
|
||||||
for (const secretRequest of secretRequests) {
|
|
||||||
const { secretPath, outputVarName, envVarName, secretSelector, isJSONPath } = secretRequest;
|
|
||||||
const requestOptions = {
|
|
||||||
headers: {
|
|
||||||
'X-Vault-Token': vaultToken
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if (vaultNamespace != null) {
|
|
||||||
requestOptions.headers["X-Vault-Namespace"] = vaultNamespace;
|
|
||||||
}
|
|
||||||
|
|
||||||
let requestPath = `${vaultUrl}/v1`;
|
|
||||||
const kvRequest = !secretPath.startsWith('/')
|
|
||||||
if (!kvRequest) {
|
|
||||||
requestPath += secretPath;
|
|
||||||
} else {
|
|
||||||
requestPath += (kvVersion === 2)
|
|
||||||
? `/${enginePath}/data/${secretPath}`
|
|
||||||
: `/${enginePath}/${secretPath}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let body;
|
|
||||||
if (responseCache.has(requestPath)) {
|
|
||||||
body = responseCache.get(requestPath);
|
|
||||||
core.debug('ℹ using cached response');
|
|
||||||
} else {
|
|
||||||
const result = await got(requestPath, requestOptions);
|
|
||||||
body = result.body;
|
|
||||||
responseCache.set(requestPath, body);
|
|
||||||
}
|
|
||||||
|
|
||||||
let dataDepth = isJSONPath === true ? 0 : kvRequest === false ? 1 : kvVersion;
|
|
||||||
|
|
||||||
const secretData = getResponseData(body, dataDepth);
|
|
||||||
const value = selectData(secretData, secretSelector, isJSONPath);
|
|
||||||
command.issue('add-mask', value);
|
|
||||||
core.exportVariable(envVarName, `${value}`);
|
|
||||||
core.setOutput(outputVarName, `${value}`);
|
|
||||||
core.debug(`✔ ${secretPath} => outputs.${outputVarName} | env.${envVarName}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @typedef {Object} SecretRequest
|
|
||||||
* @property {string} secretPath
|
|
||||||
* @property {string} envVarName
|
|
||||||
* @property {string} outputVarName
|
|
||||||
* @property {string} secretSelector
|
|
||||||
* @property {boolean} isJSONPath
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a secrets input string into key paths and their resulting environment variable name.
|
|
||||||
* @param {string} secretsInput
|
|
||||||
*/
|
|
||||||
function parseSecretsInput(secretsInput) {
|
|
||||||
const secrets = secretsInput
|
|
||||||
.split(';')
|
|
||||||
.filter(key => !!key)
|
|
||||||
.map(key => key.trim())
|
|
||||||
.filter(key => key.length !== 0);
|
|
||||||
|
|
||||||
/** @type {SecretRequest[]} */
|
|
||||||
const output = [];
|
|
||||||
for (const secret of secrets) {
|
|
||||||
let path = secret;
|
|
||||||
let outputVarName = null;
|
|
||||||
|
|
||||||
const renameSigilIndex = secret.lastIndexOf('|');
|
|
||||||
if (renameSigilIndex > -1) {
|
|
||||||
path = secret.substring(0, renameSigilIndex).trim();
|
|
||||||
outputVarName = secret.substring(renameSigilIndex + 1).trim();
|
|
||||||
|
|
||||||
if (outputVarName.length < 1) {
|
|
||||||
throw Error(`You must provide a value when mapping a secret to a name. Input: "${secret}"`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const pathParts = path
|
|
||||||
.split(/\s+/)
|
|
||||||
.map(part => part.trim())
|
|
||||||
.filter(part => part.length !== 0);
|
|
||||||
|
|
||||||
if (pathParts.length !== 2) {
|
|
||||||
throw Error(`You must provide a valid path and key. Input: "${secret}"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const [secretPath, secretSelector] = pathParts;
|
|
||||||
|
|
||||||
const isJSONPath = secretSelector.includes('.');
|
|
||||||
|
|
||||||
if (isJSONPath && !outputVarName) {
|
|
||||||
throw Error(`You must provide a name for the output key when using json selectors. Input: "${secret}"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
let envVarName = outputVarName;
|
|
||||||
if (!outputVarName) {
|
|
||||||
outputVarName = secretSelector;
|
|
||||||
envVarName = normalizeOutputKey(outputVarName);
|
|
||||||
}
|
|
||||||
|
|
||||||
output.push({
|
|
||||||
secretPath,
|
|
||||||
envVarName,
|
|
||||||
outputVarName,
|
|
||||||
secretSelector,
|
|
||||||
isJSONPath
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a JSON response and returns the secret data
|
|
||||||
* @param {string} responseBody
|
|
||||||
* @param {number} dataLevel
|
|
||||||
*/
|
|
||||||
function getResponseData(responseBody, dataLevel) {
|
|
||||||
let secretData = JSON.parse(responseBody);
|
|
||||||
|
|
||||||
for (let i = 0; i < dataLevel; i++) {
|
|
||||||
secretData = secretData['data'];
|
|
||||||
}
|
|
||||||
return secretData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses a JSON response and returns the secret data
|
|
||||||
* @param {Object} data
|
|
||||||
* @param {string} selector
|
|
||||||
*/
|
|
||||||
function selectData(data, selector, isJSONPath) {
|
|
||||||
if (!isJSONPath) {
|
|
||||||
return data[selector];
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: JSONPath
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces any forward-slash characters to
|
|
||||||
* @param {string} dataKey
|
|
||||||
*/
|
|
||||||
function normalizeOutputKey(dataKey) {
|
|
||||||
return dataKey.replace('/', '__').replace(/[^\w-]/, '').toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
function parseBoolInput(input) {
|
|
||||||
if (input === null || input === undefined || input.trim() === '') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return Boolean(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
exportSecrets,
|
|
||||||
parseSecretsInput,
|
|
||||||
parseResponse: getResponseData,
|
|
||||||
normalizeOutputKey
|
|
||||||
};
|
|
||||||
+40
-4
@@ -1,18 +1,54 @@
|
|||||||
name: 'Vault Secrets'
|
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 HashiCorp Vault™ secrets as secure environment variables'
|
||||||
inputs:
|
inputs:
|
||||||
url:
|
url:
|
||||||
description: 'The URL for the vault endpoint'
|
description: 'The URL for the vault endpoint'
|
||||||
required: true
|
required: true
|
||||||
token:
|
|
||||||
description: 'The Vault Token to be used to authenticate with Vault'
|
|
||||||
required: true
|
|
||||||
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:
|
namespace:
|
||||||
description: 'The Vault namespace from which to query secrets. Vault Enterprise only, unset by default'
|
description: 'The Vault namespace from which to query secrets. Vault Enterprise only, unset by default'
|
||||||
required: false
|
required: false
|
||||||
|
method:
|
||||||
|
description: 'The method to use to authenticate with Vault.'
|
||||||
|
default: 'token'
|
||||||
|
required: false
|
||||||
|
token:
|
||||||
|
description: 'The Vault Token to be used to authenticate with Vault'
|
||||||
|
required: false
|
||||||
|
roleId:
|
||||||
|
description: 'The Role Id for App Role authentication'
|
||||||
|
required: false
|
||||||
|
secretId:
|
||||||
|
description: 'The Secret Id for App Role authentication'
|
||||||
|
required: false
|
||||||
|
githubToken:
|
||||||
|
description: 'The Github Token to be used to authenticate with Vault'
|
||||||
|
required: false
|
||||||
|
authPayload:
|
||||||
|
description: 'The JSON payload to be sent to Vault when using a custom authentication method.'
|
||||||
|
required: false
|
||||||
|
extraHeaders:
|
||||||
|
description: 'A string of newline separated extra headers to include on every request.'
|
||||||
|
required: false
|
||||||
|
exportEnv:
|
||||||
|
description: 'Whether or not export secrets as environment variables.'
|
||||||
|
default: 'true'
|
||||||
|
required: false
|
||||||
|
caCertificate:
|
||||||
|
description: 'Base64 encoded CA certificate to verify the Vault server certificate.'
|
||||||
|
required: false
|
||||||
|
clientCertificate:
|
||||||
|
description: 'Base64 encoded client certificate for mTLS communication with the Vault server.'
|
||||||
|
required: false
|
||||||
|
clientKey:
|
||||||
|
description: 'Base64 encoded client key for mTLS communication with the Vault server.'
|
||||||
|
required: false
|
||||||
|
tlsSkipVerify:
|
||||||
|
description: 'When set to true, disables verification of the Vault server certificate. Setting this to true in production is not recommended.'
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|||||||
Vendored
+13831
-4169
File diff suppressed because it is too large
Load Diff
+19
-4
@@ -2,16 +2,31 @@
|
|||||||
version: "3.0"
|
version: "3.0"
|
||||||
services:
|
services:
|
||||||
vault:
|
vault:
|
||||||
image: vault:1.3.0
|
image: vault:latest
|
||||||
environment:
|
environment:
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
ports:
|
ports:
|
||||||
- 8200:8200
|
- 8200:8200
|
||||||
privileged: true
|
privileged: true
|
||||||
vault-enterprise:
|
vault-enterprise:
|
||||||
image: hashicorp/vault-enterprise:1.3.0_ent
|
image: hashicorp/vault-enterprise:latest
|
||||||
environment:
|
environment:
|
||||||
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
VAULT_DEV_ROOT_TOKEN_ID: testtoken
|
||||||
ports:
|
ports:
|
||||||
- 8201:8200
|
- 8200:8200
|
||||||
privileged: true
|
privileged: true
|
||||||
|
vault-tls:
|
||||||
|
image: vault:latest
|
||||||
|
hostname: vault-tls
|
||||||
|
environment:
|
||||||
|
VAULT_CAPATH: /etc/vault/ca.crt
|
||||||
|
ports:
|
||||||
|
- 8200:8200
|
||||||
|
privileged: true
|
||||||
|
volumes:
|
||||||
|
- ${PWD}/integrationTests/e2e-tls/configs:/etc/vault
|
||||||
|
- vault-data:/var/lib/vault:rw
|
||||||
|
entrypoint: vault server -config=/etc/vault/config.hcl
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
vault-data:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ 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('../../src/action');
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
|
|
||||||
@@ -42,9 +42,21 @@ describe('integration', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await got(`${vaultUrl}/v1/secret/data/foobar`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': 'testtoken',
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
data: {
|
||||||
|
fookv2: 'bar',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Enable custom secret engine
|
// Enable custom secret engine
|
||||||
try {
|
try {
|
||||||
await got(`${vaultUrl}/v1/sys/mounts/my-secret`, {
|
await got(`${vaultUrl}/v1/sys/mounts/secret-kv1`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
@@ -62,7 +74,7 @@ describe('integration', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await got(`${vaultUrl}/v1/my-secret/test`, {
|
await got(`${vaultUrl}/v1/secret-kv1/test`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
@@ -72,7 +84,17 @@ describe('integration', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await got(`${vaultUrl}/v1/my-secret/nested/test`, {
|
await got(`${vaultUrl}/v1/secret-kv1/foobar`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': 'testtoken',
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
fookv1: 'bar',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`${vaultUrl}/v1/secret-kv1/nested/test`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-Vault-Token': 'testtoken',
|
'X-Vault-Token': 'testtoken',
|
||||||
@@ -101,20 +123,8 @@ describe('integration', () => {
|
|||||||
.mockReturnValueOnce(secrets);
|
.mockReturnValueOnce(secrets);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mockEngineName(name) {
|
|
||||||
when(core.getInput)
|
|
||||||
.calledWith('path')
|
|
||||||
.mockReturnValueOnce(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function mockVersion(version) {
|
|
||||||
when(core.getInput)
|
|
||||||
.calledWith('kv-version')
|
|
||||||
.mockReturnValueOnce(version);
|
|
||||||
}
|
|
||||||
|
|
||||||
it('get simple secret', async () => {
|
it('get simple secret', async () => {
|
||||||
mockInput('test secret');
|
mockInput('secret/data/test secret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -122,7 +132,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('re-map secret', async () => {
|
it('re-map secret', async () => {
|
||||||
mockInput('test secret | TEST_KEY');
|
mockInput('secret/data/test secret | TEST_KEY');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -130,7 +140,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('get nested secret', async () => {
|
it('get nested secret', async () => {
|
||||||
mockInput('nested/test otherSecret');
|
mockInput('secret/data/nested/test otherSecret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -139,9 +149,9 @@ describe('integration', () => {
|
|||||||
|
|
||||||
it('get multiple secrets', async () => {
|
it('get multiple secrets', async () => {
|
||||||
mockInput(`
|
mockInput(`
|
||||||
test secret ;
|
secret/data/test secret ;
|
||||||
test secret | NAMED_SECRET ;
|
secret/data/test secret | NAMED_SECRET ;
|
||||||
nested/test otherSecret ;`);
|
secret/data/nested/test otherSecret ;`);
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -152,10 +162,16 @@ describe('integration', () => {
|
|||||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET');
|
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('leading slash kvv2', async () => {
|
||||||
|
mockInput('/secret/data/foobar fookv2');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('FOOKV2', 'bar');
|
||||||
|
});
|
||||||
|
|
||||||
it('get secret from K/V v1', async () => {
|
it('get secret from K/V v1', async () => {
|
||||||
mockInput('test secret');
|
mockInput('secret-kv1/test secret');
|
||||||
mockEngineName('my-secret');
|
|
||||||
mockVersion('1');
|
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -163,15 +179,21 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('get nested secret from K/V v1', async () => {
|
it('get nested secret from K/V v1', async () => {
|
||||||
mockInput('nested/test otherSecret');
|
mockInput('secret-kv1/nested/test otherSecret');
|
||||||
mockEngineName('my-secret');
|
|
||||||
mockVersion('1');
|
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERCUSTOMSECRET');
|
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERCUSTOMSECRET');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('leading slash kvv1', async () => {
|
||||||
|
mockInput('/secret-kv1/foobar fookv1');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('FOOKV1', 'bar');
|
||||||
|
});
|
||||||
|
|
||||||
describe('generic engines', () => {
|
describe('generic engines', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await got(`${vaultUrl}/v1/cubbyhole/test`, {
|
await got(`${vaultUrl}/v1/cubbyhole/test`, {
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIEFjCCAv6gAwIBAgIUe0i7/HGZKvbDb30L9mC99KXFwj8wDQYJKoZIhvcNAQEL
|
||||||
|
BQAwgaIxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH
|
||||||
|
Ew1TYW4gRnJhbmNpc2NvMRIwEAYDVQQKEwlIYXNoaUNvcnAxIzAhBgNVBAsTGlRl
|
||||||
|
c3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MS0wKwYDVQQDEyRQcm90b3R5cGUgVGVz
|
||||||
|
dCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMjAwODA1MTg1MjAwWhcNMjUwODA0
|
||||||
|
MTg1MjAwWjCBojELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAU
|
||||||
|
BgNVBAcTDVNhbiBGcmFuY2lzY28xEjAQBgNVBAoTCUhhc2hpQ29ycDEjMCEGA1UE
|
||||||
|
CxMaVGVzdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxLTArBgNVBAMTJFByb3RvdHlw
|
||||||
|
ZSBUZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQAD
|
||||||
|
ggEPADCCAQoCggEBAMrRXuu2+zhBs0pLYEdXIaPc4KoWO3xm2RJdbzy3hfjFybQ8
|
||||||
|
H/Y6Hi7txjGGSb45xSfXT/RF2srNfs235I+sfB8rrEizNpzkXqOgGa8LKvh2tgBT
|
||||||
|
BK/jDWsEdDhxmkpFhE69wEW+D5ub7QGnx9jrqLKfwCmUA0utlzcFBk2nRNhRtsrp
|
||||||
|
CI5YL1VN4coLpgXdvbodzbynPzGHe9R/o9K0Uiz2hgHooyKwhkVYwo0BIAQamLFz
|
||||||
|
TS7lyeLf0thDOxV31NX8SpSucqRf50WHNk8T/YtKZ9EhlBDT4ybZwwvcC/ocxxcg
|
||||||
|
1LvB0YweZNjSeO78S4CMh1TFGXnF/xOtGABlIbcCAwEAAaNCMEAwDgYDVR0PAQH/
|
||||||
|
BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFABD/NxvYLpo5zVNeD01
|
||||||
|
r8IIFYlBMA0GCSqGSIb3DQEBCwUAA4IBAQB7TfpIx53gf/oI3mgR6Ciz287WBzFR
|
||||||
|
OzhJXwHk5J3mx8VC1W8tDRXih2lCLd/f9qDy6LyL/hZcoonev6w9oReuOMBiH6l4
|
||||||
|
Pf3yq2aDXX0AoGgm75c1m34kY669JLMsHq5+xuUDeeFUMd60w9zVtZfBSumy/sgN
|
||||||
|
PdjtvThh8sSByocYULs3tuxZDGyQ6GyQcn/xlMrGtmcD5IuX5IXqcKRVlZttykNx
|
||||||
|
S2ltcR00fekw8WZyPSzMJaP+/Kcq3T2viN02MS6qEycQZoYfEAMdj+A0kjbsZG9D
|
||||||
|
6J92z78b2DuLAUvZVpynNk/UbpDeqIDy40V3JDmtvrfGUMkMhMqgK/+J
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIENTCCAx2gAwIBAgIUMu5h1ysA5DlM6lzZFliT2C2n4lEwDQYJKoZIhvcNAQEL
|
||||||
|
BQAwgaIxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH
|
||||||
|
Ew1TYW4gRnJhbmNpc2NvMRIwEAYDVQQKEwlIYXNoaUNvcnAxIzAhBgNVBAsTGlRl
|
||||||
|
c3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MS0wKwYDVQQDEyRQcm90b3R5cGUgVGVz
|
||||||
|
dCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwIBcNMjAwODA1MTg1MjAwWhgPMjEyMDA3
|
||||||
|
MTIxODUyMDBaMIGMMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEW
|
||||||
|
MBQGA1UEBxMNU2FuIEZyYW5jaXNjbzESMBAGA1UEChMJSGFzaGlDb3JwMSMwIQYD
|
||||||
|
VQQLExpUZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTEXMBUGA1UEAxMOaGFzaGlj
|
||||||
|
b3JwLnRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC/zYDKdDGo
|
||||||
|
+Qy7eJUNjOe6jpeGvK1lMu5T1Xka+h2ay6WH5gLyrPw5pi582iYpJdHVbplKMywx
|
||||||
|
LxZv7mAbKNxqdp8UZKy0A3bCuHQqRF8ssXXHufQ8EGxNkLMLJP0e2q39OnrxXekS
|
||||||
|
8Ct3aJm3V8qkcV3CpVdPNgJh4TSuneCXIxVWjFYSiyHi0/5TRd2D+aQPz12szg5F
|
||||||
|
mBW4dLzYKHEMlWcjWG8mxtbLyt+jSR1+tSehQx7KndufdfniOWEDBdbeR3yDnZdn
|
||||||
|
p8DnRWK4oaEI3Sl8tKlDd1Yp+R96aqOEn1tPW6Jy6Vdvk3fCefclbWZ6B9kiJ/1r
|
||||||
|
gxq7AN7iKmHNAgMBAAGjdTBzMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUEDDAKBggr
|
||||||
|
BgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBRn2mwyk+MPChnLg0iWy1r9
|
||||||
|
b3JvwTAfBgNVHSMEGDAWgBQAQ/zcb2C6aOc1TXg9Na/CCBWJQTANBgkqhkiG9w0B
|
||||||
|
AQsFAAOCAQEAOpCy0vHp1Kxgv0VBRrbrwSQLBGP8a1ubVWoeoZQ+EvX9ozqDrHxm
|
||||||
|
gM4XPYUJlUOOEu0ZRgCW60YK33E1zNKnA1F0/3/rmqMkKnm0BBs/5WzMWtsIBPcU
|
||||||
|
e0CeJmaRIXnERQMH/svD+RrFo1dcF8rUDIlWez7+xGqoIGBg7v4jEmkZ3HdckcE+
|
||||||
|
/xvC61YSG8NsJwR/CEcQ8YCyVfgvuS0ukWs4dN15aVDL3Oe61h3bRcGAywOJBrdq
|
||||||
|
9xaq7ezZp/+lUSkYnatWJBuC/aviH9g9s+gMT0I3fWHh8BB0Ne2txwJ15K/qz5he
|
||||||
|
TjxFsumrh50aFqjSiEHndtY5UWuGAFLiSw==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEpAIBAAKCAQEAv82AynQxqPkMu3iVDYznuo6XhrytZTLuU9V5Gvodmsulh+YC
|
||||||
|
8qz8OaYufNomKSXR1W6ZSjMsMS8Wb+5gGyjcanafFGSstAN2wrh0KkRfLLF1x7n0
|
||||||
|
PBBsTZCzCyT9Htqt/Tp68V3pEvArd2iZt1fKpHFdwqVXTzYCYeE0rp3glyMVVoxW
|
||||||
|
Eosh4tP+U0Xdg/mkD89drM4ORZgVuHS82ChxDJVnI1hvJsbWy8rfo0kdfrUnoUMe
|
||||||
|
yp3bn3X54jlhAwXW3kd8g52XZ6fA50ViuKGhCN0pfLSpQ3dWKfkfemqjhJ9bT1ui
|
||||||
|
culXb5N3wnn3JW1megfZIif9a4MauwDe4iphzQIDAQABAoIBAQCYHJuidAoaTwGZ
|
||||||
|
ACV9rJzuqD1lvubpFj5KwEcebPPjmtQ5deIqoaQa+D9wBvYyteq3ENKDNRg8HXL2
|
||||||
|
7B7OC1bbHB5HZxxMW17pSK3gA39Ti52z+zbGF+Q8k6BbG0efG6DW7nUoTOkWeuCN
|
||||||
|
/6fA7uAoEDxirQwUJuo2xAsq3MyMLwcs95rke9Bly8ABFNaV1oMZq8YT/w8oSc2b
|
||||||
|
/7WtxXmChHlVYXTcMqzVPqNFqPRixZRWQ+BSHoXmEDviuGd51L4s9D7iXp32TvUx
|
||||||
|
DMHeS1DFA2en7ZF1uc9VXZeplkkDtVhUe4d6qOqCcUwDFEvMonnyVSa6/FkR5jYZ
|
||||||
|
2yujTdfhAoGBAM0hGOnmnDnCjADUt4mZlr+Mf0XmdKzEV+hid4CQUvBoTXgjYMvv
|
||||||
|
c397eNePce7SwSUE1/APERInGUPhRLVFW5q6/34WRtGBbQkT8ByeJANXes4UFZe3
|
||||||
|
wdNLczWUlSl0G3jTf+Kh3+K5/PtmyxSrAS/9GIk+ibs1mlJOPyVnWqUJAoGBAO9e
|
||||||
|
WlP9/ruXluvkQyM5ZlnAnZYMsFGzzPx4tkazUjurtqxQoyZ0z+pPItGQ7lOl+pDA
|
||||||
|
EWiTun66g+Da9uBiBCJUeXiC1ge2p6bT6N194BrYyrWML9hcIL4mqVojUEUmhnSh
|
||||||
|
6b9h1pC7vFmw5ZFMIIkS60cfBMgQMZxMJN8NuaulAoGBAJM5hwURg90c2ZkbEyPK
|
||||||
|
PVz7fLlxnxoEzcc3LOf0LeLoKXnpgma8VJwRxXiJNs+fKgrkwAtG9QyfTU3f1412
|
||||||
|
2zlhr1ASsv9ZMiXKzpHrmpNfbP+NgLXkqFN7mpPBMZGQCMuemPHTFrpGnODfNTB/
|
||||||
|
T5newIZ4gSgBX+Jk0IOK+47pAoGAeKo6pK6ck9pV5TIbOg18b/AuQG7DD1yxD/CW
|
||||||
|
CkvpP1VPb8vygrdN/FLKPZRu39IC3qdD31DhKXNCeb5Hx1MBvICS/1INLLRCDVIz
|
||||||
|
yDvlFgOFJEG3+LxwcQqyQlMc6s8B5pecarKaZDmPODN5dmZG3HKiEicr1OJ878pe
|
||||||
|
p+aWW1UCgYBmGFbCc1qqlqp+srYGsv3rIgNs5HSfrAjbgY8xh9foMgrYCRAm57gv
|
||||||
|
01yVxMXWmKA6ReVEu8OTVy9fkuOL/vw2o+C6W4IPZYdvSQoPwd5Lf+AqxEQvFF1m
|
||||||
|
tT3SZAM3EhQ7tIXdIQHY27SJ1KlUJMrvUq1CiRWiG/MOKf/87JXPog==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
ui = false
|
||||||
|
disable_mlock = true
|
||||||
|
|
||||||
|
listener "tcp" {
|
||||||
|
address = "[::]:8200"
|
||||||
|
cluster_address = "[::]:8201"
|
||||||
|
tls_cert_file = "/etc/vault/server.crt"
|
||||||
|
tls_key_file = "/etc/vault/server.key"
|
||||||
|
tls_client_ca_file = "/etc/vault/ca.crt"
|
||||||
|
tls_require_and_verify_client_cert = "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
storage "file" {
|
||||||
|
path = "/var/lib/vault"
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIEXjCCA0agAwIBAgIUAswquazrfsyDRvXZwn5718DUhU4wDQYJKoZIhvcNAQEL
|
||||||
|
BQAwgaIxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH
|
||||||
|
Ew1TYW4gRnJhbmNpc2NvMRIwEAYDVQQKEwlIYXNoaUNvcnAxIzAhBgNVBAsTGlRl
|
||||||
|
c3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MS0wKwYDVQQDEyRQcm90b3R5cGUgVGVz
|
||||||
|
dCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwIBcNMjAwODA1MTg1MjAwWhgPMjEyMDA3
|
||||||
|
MTIxODUyMDBaMIGMMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEW
|
||||||
|
MBQGA1UEBxMNU2FuIEZyYW5jaXNjbzESMBAGA1UEChMJSGFzaGlDb3JwMSMwIQYD
|
||||||
|
VQQLExpUZXN0IENlcnRpZmljYXRlIEF1dGhvcml0eTEXMBUGA1UEAxMOaGFzaGlj
|
||||||
|
b3JwLnRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC0azdZsrPC
|
||||||
|
5Rv8nRxVJnLi+oZgCJYgzhCDiEbYqt1QK1gqNXp0ml5ck6ycj0drwzHzrrX+xcPV
|
||||||
|
5FcNKH3RFyon9XkzjwaXkMv6IkgvH6/jQ1dDW9kWBf3Io3Y59wnD/YaIzNK0CYJS
|
||||||
|
fRNdsZb4InH8gh+RL33+FeysgJwXG1TVA4tTUj7DQxDE0cDd9UD+C9Yx7OWiUjC1
|
||||||
|
IjqdFPusX1nziKYjeI5/UiCmOUGqJJRoMPonuzuGIj9GdmBKmga64OfeZFqn4f6a
|
||||||
|
ay61VnGCwZ24VniUwYElsFbcF2Nv9WqnrOeQlHOsYN68VMqHzaYPqE6SPa6mO5mI
|
||||||
|
/tmpXrDG3Y+RAgMBAAGjgZ0wgZowDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoG
|
||||||
|
CCsGAQUFBwMBMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFE03/UTs2ZmJpWHSmstt
|
||||||
|
hDngW6F3MB8GA1UdIwQYMBaAFABD/NxvYLpo5zVNeD01r8IIFYlBMCUGA1UdEQQe
|
||||||
|
MByCCWxvY2FsaG9zdIIJdmF1bHQtdGxzhwR/AAABMA0GCSqGSIb3DQEBCwUAA4IB
|
||||||
|
AQCzarBGJium5oZDSSP5GqxpS13QP2onEen6I1k2eRdcOqtbfNdQ20RJrb4dfNkE
|
||||||
|
Dc09KWVlZAn+hYge2KKTXJ+4ltIC9V1LvquyWipNczOT1ve0H9gt3Wm88LdESqI5
|
||||||
|
HOx43pIaa3cWXBlbzrFmT1SASYm1V5Oo1mXzpUukGokHLLmAz36VVuJGbD0BxYke
|
||||||
|
5MefG4tNT1SsMsIqVvGxI9NiVs7YTdJu81MctSYK5snsEKnYdi9N7CHOk3bdDpeC
|
||||||
|
v2Vo7XBk3s4sBMGmnJO+1JOcRFJioooEFkqNyQmg3atfInysVbreKS5KtWNTaCPm
|
||||||
|
yI55plW8ga5ucja2VX3WbwAO
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEpAIBAAKCAQEAtGs3WbKzwuUb/J0cVSZy4vqGYAiWIM4Qg4hG2KrdUCtYKjV6
|
||||||
|
dJpeXJOsnI9Ha8Mx8661/sXD1eRXDSh90RcqJ/V5M48Gl5DL+iJILx+v40NXQ1vZ
|
||||||
|
FgX9yKN2OfcJw/2GiMzStAmCUn0TXbGW+CJx/IIfkS99/hXsrICcFxtU1QOLU1I+
|
||||||
|
w0MQxNHA3fVA/gvWMezlolIwtSI6nRT7rF9Z84imI3iOf1IgpjlBqiSUaDD6J7s7
|
||||||
|
hiI/RnZgSpoGuuDn3mRap+H+mmsutVZxgsGduFZ4lMGBJbBW3Bdjb/Vqp6znkJRz
|
||||||
|
rGDevFTKh82mD6hOkj2upjuZiP7ZqV6wxt2PkQIDAQABAoIBAQCvK0HsVvLtkSCh
|
||||||
|
HbF6gwAcnHyHFQ8d/rRN4KxYhVynD85j/NRODer8G20F/J6tZDFFlSWinUTMkQxr
|
||||||
|
/BpcPg9yCIWKp50Q30cMLujCyBMvphw9jBmzplGG0h5hnRbgMXDDtYoFvw3HJST+
|
||||||
|
XQRlGpxtO7GGdwPvBD5sJdpnHOQ6g7qIYKmlHM99kHU8vr0VghqZAYxEh8RpnYez
|
||||||
|
NLra+7ep+Zp1pFIniU6B8ohyL3OArbQ65qYrZYriAEI5HeEk0RhjewcPsV56LwbS
|
||||||
|
CncTVS/dNYgk1zRIvytmbDVD3v/4lLvnpIWeKVdk7p1aGJeCdpLeWNvDLX0Ws67r
|
||||||
|
QeZQizwhAoGBAMwAIA6+HPsx+8dhNbN3ydX8YU6uUfSeshhshIFZPIYL2vrKyAHU
|
||||||
|
/GAYVzYJH/cU0IvlLJlLdQuiZkOXEX87tgdfmM/o4Qdl12RR0BvU0Cae0txtzNrP
|
||||||
|
yTdfZqDhTz/V8jOAXUNA5oQA45Y3rI7JES8hBd1F9WFOH2WINp344GzlAoGBAOJo
|
||||||
|
SgmRE24VcnfUMqrBpwZBdBrTxDQyTagvd+MuGomIQfcE2Y4rr1eIuJJ0HF5/eYxc
|
||||||
|
DZRO/LVP9tQ8ozXi2tdmgUdKC79O2edmdOCWW5of464R/TLcM5B4SmS36RtdE3qJ
|
||||||
|
ig4fcUmsJ15MAGpkXLMh5YSD/N3TmcnURtx06Fk9AoGATi+mGcBnnybzFuF9EYHR
|
||||||
|
y7/lE6DgLF8+ZvoAdwralY2pqgFaUslsyO/LTRyGMc66d0OoqkAvZfwiMbmOrTMX
|
||||||
|
ew/6o4Tf6lPwD7UDjAcul/67VlyG7T5CIoTf8r0oAJFhOLf0BrizINiuYX6JFlid
|
||||||
|
y3BerQYJG/gzNFjWhglDCrkCgYA+3wUISRAjNrN10ShMwL/3/b8XIA1RDVMBTEU3
|
||||||
|
gfr+jCb9SIx9bWYgoafXi4TBPRbswjdHIvQMCWuankgYU6m/vQhTWp2Of4AFQS9d
|
||||||
|
moNPdmGMWhR8xidPjAfklimWXq9lDMKYj2SvN64rAmHvKXWQjO4mcVyL4RHIuTkA
|
||||||
|
STqoZQKBgQDKHd8F6tjZHEFolmjS5l682g7zVTpBhozezJ/RqYvhJh5ew1pXoD/O
|
||||||
|
Zu9iMfHoDjR4ZUXq6aeLUj/oIt1AsjwaGChOLLAvFbvePgS9XkYkwIlaxS4efAya
|
||||||
|
+CQE/JmY/a1/c2MDLNMCEXvUqX68pv6iDF8pfn+i4tn0omYqgfUlCA==
|
||||||
|
-----END RSA PRIVATE KEY-----
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
describe('e2e-tls', () => {
|
||||||
|
it('verify', () => {
|
||||||
|
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||||
|
expect(process.env.NAMED_SECRET).toBe("SUPERSECRET");
|
||||||
|
expect(process.env.OTHERSECRET).toBe("OTHERSUPERSECRET");
|
||||||
|
expect(process.env.OTHER_SECRET_OUTPUT).toBe("OTHERSUPERSECRET");
|
||||||
|
expect(process.env.ALTSECRET).toBe("CUSTOMSECRET");
|
||||||
|
expect(process.env.NAMED_ALTSECRET).toBe("CUSTOMSECRET");
|
||||||
|
expect(process.env.OTHERALTSECRET).toBe("OTHERCUSTOMSECRET");
|
||||||
|
expect(process.env.FOO).toBe("bar");
|
||||||
|
expect(process.env.NAMED_CUBBYSECRET).toBe("zap");
|
||||||
|
expect(process.env.SKIP).toBe("true");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
verbose: true
|
||||||
|
};
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
const got = require('got');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
||||||
|
const caCertificateRaw = `${process.env.VAULTCA}`;
|
||||||
|
const clientCertificateRaw = `${process.env.VAULT_CLIENT_CERT}`;
|
||||||
|
const clientKeyRaw = `${process.env.VAULT_CLIENT_KEY}`;
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
var caCertificate = Buffer.from(caCertificateRaw, 'base64').toString();
|
||||||
|
if (caCertificate == null) {
|
||||||
|
throw Error("VAULTCA env not set.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var clientCertificate = Buffer.from(clientCertificateRaw, 'base64').toString();
|
||||||
|
if (clientCertificate == null) {
|
||||||
|
throw Error("VAULT_CLIENT_CERT env not set.")
|
||||||
|
}
|
||||||
|
|
||||||
|
var clientKey = Buffer.from(clientKeyRaw, 'base64').toString();
|
||||||
|
if (clientKey == null) {
|
||||||
|
throw Error("VAULT_CLIENT_KEY env not set.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init
|
||||||
|
const {body} = await got(`https://${vaultUrl}/v1/sys/init`, {
|
||||||
|
method: 'POST',
|
||||||
|
json: {
|
||||||
|
secret_shares: 1,
|
||||||
|
secret_threshold: 1,
|
||||||
|
},
|
||||||
|
responseType: 'json',
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (body.keys_base64.length != 1) {
|
||||||
|
throw Error("No unseal key found after init.")
|
||||||
|
}
|
||||||
|
var unseal = body.keys_base64[0];
|
||||||
|
|
||||||
|
if (body.root_token == "") {
|
||||||
|
throw Error("No root token found after init.")
|
||||||
|
}
|
||||||
|
var rootToken = body.root_token;
|
||||||
|
|
||||||
|
core.exportVariable('VAULT_TOKEN', rootToken);
|
||||||
|
core.setSecret(rootToken)
|
||||||
|
|
||||||
|
// Unseal
|
||||||
|
await got(`https://${vaultUrl}/v1/sys/unseal`, {
|
||||||
|
method: 'POST',
|
||||||
|
json: {
|
||||||
|
key: unseal,
|
||||||
|
},
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`https://${vaultUrl}/v1/sys/mounts/secret`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': rootToken,
|
||||||
|
},
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
type: 'kv-v2'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`https://${vaultUrl}/v1/secret/data/test`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': rootToken,
|
||||||
|
},
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
data: {
|
||||||
|
secret: 'SUPERSECRET',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`https://${vaultUrl}/v1/secret/data/nested/test`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': rootToken,
|
||||||
|
},
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
data: {
|
||||||
|
otherSecret: 'OTHERSUPERSECRET',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`https://${vaultUrl}/v1/secret/data/tlsSkipVerify`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': rootToken,
|
||||||
|
},
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
data: {
|
||||||
|
skip: 'true',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`https://${vaultUrl}/v1/sys/mounts/my-secret`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': rootToken,
|
||||||
|
},
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
type: 'kv'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`https://${vaultUrl}/v1/my-secret/test`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': rootToken,
|
||||||
|
},
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
altSecret: 'CUSTOMSECRET',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`https://${vaultUrl}/v1/my-secret/nested/test`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': rootToken,
|
||||||
|
},
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
otherAltSecret: 'OTHERCUSTOMSECRET',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await got(`https://${vaultUrl}/v1/cubbyhole/test`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-Vault-Token': rootToken,
|
||||||
|
},
|
||||||
|
https: {
|
||||||
|
certificateAuthority: caCertificate,
|
||||||
|
certificate: clientCertificate,
|
||||||
|
key: clientKey,
|
||||||
|
},
|
||||||
|
json: {
|
||||||
|
foo: 'bar',
|
||||||
|
zip: 'zap',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -5,7 +5,7 @@ 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('../../src/action');
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`;
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('get simple secret', async () => {
|
it('get simple secret', async () => {
|
||||||
mockInput('test secret');
|
mockInput('secret/data/test secret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('re-map secret', async () => {
|
it('re-map secret', async () => {
|
||||||
mockInput('test secret | TEST_KEY');
|
mockInput('secret/data/test secret | TEST_KEY');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('get nested secret', async () => {
|
it('get nested secret', async () => {
|
||||||
mockInput('nested/test otherSecret');
|
mockInput('secret/data/nested/test otherSecret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -81,9 +81,9 @@ describe('integration', () => {
|
|||||||
|
|
||||||
it('get multiple secrets', async () => {
|
it('get multiple secrets', async () => {
|
||||||
mockInput(`
|
mockInput(`
|
||||||
test secret ;
|
secret/data/test secret ;
|
||||||
test secret | NAMED_SECRET ;
|
secret/data/test secret | NAMED_SECRET ;
|
||||||
nested/test otherSecret ;`);
|
secret/data/nested/test otherSecret ;`);
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -95,9 +95,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('get secret from K/V v1', async () => {
|
it('get secret from K/V v1', async () => {
|
||||||
mockInput('test secret');
|
mockInput('my-secret/test secret');
|
||||||
mockEngineName('my-secret');
|
|
||||||
mockVersion('1');
|
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -105,9 +103,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('get nested secret from K/V v1', async () => {
|
it('get nested secret from K/V v1', async () => {
|
||||||
mockInput('nested/test otherSecret');
|
mockInput('my-secret/nested/test otherSecret');
|
||||||
mockEngineName('my-secret');
|
|
||||||
mockVersion('1');
|
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
@@ -212,7 +208,7 @@ describe('authenticate with approle', () => {
|
|||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method')
|
.calledWith('method', expect.anything())
|
||||||
.mockReturnValueOnce('approle');
|
.mockReturnValueOnce('approle');
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('roleId')
|
.calledWith('roleId')
|
||||||
@@ -228,8 +224,8 @@ describe('authenticate with approle', () => {
|
|||||||
.mockReturnValueOnce('ns2');
|
.mockReturnValueOnce('ns2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('authenticate with approle', async()=> {
|
it('authenticate with approle', async() => {
|
||||||
mockInput('test secret');
|
mockInput('secret/data/test secret');
|
||||||
|
|
||||||
await exportSecrets();
|
await exportSecrets();
|
||||||
|
|
||||||
|
|||||||
Generated
+2184
-2015
File diff suppressed because it is too large
Load Diff
+22
-11
@@ -4,24 +4,30 @@
|
|||||||
"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": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build index.js -o dist",
|
"build": "ncc build src/entry.js -o dist",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:integration:basic": "jest -c integrationTests/basic/jest.config.js",
|
"test:integration:basic": "jest -c integrationTests/basic/jest.config.js",
|
||||||
"test:integration:enterprise": "jest -c integrationTests/enterprise/jest.config.js",
|
"test:integration:enterprise": "jest -c integrationTests/enterprise/jest.config.js",
|
||||||
"test:e2e": "jest -c integrationTests/e2e/jest.config.js"
|
"test:e2e": "jest -c integrationTests/e2e/jest.config.js",
|
||||||
|
"test:e2e-tls": "jest -c integrationTests/e2e-tls/jest.config.js"
|
||||||
},
|
},
|
||||||
|
"files": [
|
||||||
|
"src/**/*",
|
||||||
|
"dist/**/*"
|
||||||
|
],
|
||||||
"release": {
|
"release": {
|
||||||
"branch": "master",
|
"branch": "master",
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"@semantic-release/commit-analyzer",
|
"@semantic-release/commit-analyzer",
|
||||||
"@semantic-release/release-notes-generator",
|
"@semantic-release/release-notes-generator",
|
||||||
"@semantic-release/github"
|
"@semantic-release/github",
|
||||||
|
"@semantic-release/npm"
|
||||||
],
|
],
|
||||||
"ci": false
|
"ci": false
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/RichiCoder1/vault-action.git"
|
"url": "git+https://github.com/hashicorp/vault-action.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"hashicorp",
|
"hashicorp",
|
||||||
@@ -31,21 +37,26 @@
|
|||||||
"github-actions",
|
"github-actions",
|
||||||
"javascript"
|
"javascript"
|
||||||
],
|
],
|
||||||
"author": "Richard Simpson <richardsimpson@outlook.com>",
|
"author": "HashiCorp",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/RichiCoder1/vault-action/issues"
|
"url": "https://github.com/hashicorp/vault-action/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/RichiCoder1/vault-action#readme",
|
"homepage": "https://github.com/hashicorp/vault-action#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.2",
|
"got": "^11.5.1",
|
||||||
"got": "^10.2.2"
|
"jsonata": "^1.8.2"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@actions/core": ">=1 <2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@actions/core": "^1.2.3",
|
||||||
|
"@types/got": "^9.6.9",
|
||||||
"@types/jest": "^25.1.3",
|
"@types/jest": "^25.1.3",
|
||||||
"@zeit/ncc": "^0.21.1",
|
"@zeit/ncc": "^0.22.0",
|
||||||
"jest": "^25.1.0",
|
"jest": "^25.1.0",
|
||||||
"jest-when": "^2.7.0",
|
"jest-when": "^2.7.0",
|
||||||
"semantic-release": "^15.13.24"
|
"semantic-release": "^17.0.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+196
@@ -0,0 +1,196 @@
|
|||||||
|
// @ts-check
|
||||||
|
const core = require('@actions/core');
|
||||||
|
const command = require('@actions/core/lib/command');
|
||||||
|
const got = require('got').default;
|
||||||
|
const jsonata = require('jsonata');
|
||||||
|
const { auth: { retrieveToken }, secrets: { getSecrets } } = require('./index');
|
||||||
|
|
||||||
|
const AUTH_METHODS = ['approle', 'token', 'github'];
|
||||||
|
|
||||||
|
async function exportSecrets() {
|
||||||
|
const vaultUrl = core.getInput('url', { required: true });
|
||||||
|
const vaultNamespace = core.getInput('namespace', { required: false });
|
||||||
|
const extraHeaders = parseHeadersInput('extraHeaders', { required: false });
|
||||||
|
const exportEnv = core.getInput('exportEnv', { required: false }) != 'false';
|
||||||
|
|
||||||
|
const secretsInput = core.getInput('secrets', { required: true });
|
||||||
|
const secretRequests = parseSecretsInput(secretsInput);
|
||||||
|
|
||||||
|
const vaultMethod = (core.getInput('method', { required: false }) || 'token').toLowerCase();
|
||||||
|
const authPayload = core.getInput('authPayload', { required: false });
|
||||||
|
if (!AUTH_METHODS.includes(vaultMethod) && !authPayload) {
|
||||||
|
throw Error(`Sorry, the provided authentication method ${vaultMethod} is not currently supported and no custom authPayload was provided.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultOptions = {
|
||||||
|
prefixUrl: vaultUrl,
|
||||||
|
headers: {},
|
||||||
|
https: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tlsSkipVerify = (core.getInput('tlsSkipVerify', { required: false }) || 'false').toLowerCase() != 'false';
|
||||||
|
if (tlsSkipVerify === true) {
|
||||||
|
defaultOptions.https.rejectUnauthorized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const caCertificateRaw = core.getInput('caCertificate', { required: false });
|
||||||
|
if (caCertificateRaw != null) {
|
||||||
|
defaultOptions.https.certificateAuthority = Buffer.from(caCertificateRaw, 'base64').toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientCertificateRaw = core.getInput('clientCertificate', { required: false });
|
||||||
|
if (clientCertificateRaw != null) {
|
||||||
|
defaultOptions.https.certificate = Buffer.from(clientCertificateRaw, 'base64').toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const clientKeyRaw = core.getInput('clientKey', { required: false });
|
||||||
|
if (clientKeyRaw != null) {
|
||||||
|
defaultOptions.https.key = Buffer.from(clientKeyRaw, 'base64').toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [headerName, headerValue] of extraHeaders) {
|
||||||
|
defaultOptions.headers[headerName] = headerValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vaultNamespace != null) {
|
||||||
|
defaultOptions.headers["X-Vault-Namespace"] = vaultNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
const vaultToken = await retrieveToken(vaultMethod, got.extend(defaultOptions));
|
||||||
|
defaultOptions.headers['X-Vault-Token'] = vaultToken;
|
||||||
|
const client = got.extend(defaultOptions);
|
||||||
|
|
||||||
|
const requests = secretRequests.map(request => {
|
||||||
|
const { path, selector } = request;
|
||||||
|
return request;
|
||||||
|
});
|
||||||
|
|
||||||
|
const results = await getSecrets(requests, client);
|
||||||
|
|
||||||
|
for (const result of results) {
|
||||||
|
const { value, request, cachedResponse } = result;
|
||||||
|
if (cachedResponse) {
|
||||||
|
core.debug('ℹ using cached response');
|
||||||
|
}
|
||||||
|
command.issue('add-mask', value);
|
||||||
|
if (exportEnv) {
|
||||||
|
core.exportVariable(request.envVarName, `${value}`);
|
||||||
|
}
|
||||||
|
core.setOutput(request.outputVarName, `${value}`);
|
||||||
|
core.debug(`✔ ${request.path} => outputs.${request.outputVarName}${exportEnv ? ` | env.${request.envVarName}` : ''}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @typedef {Object} SecretRequest
|
||||||
|
* @property {string} path
|
||||||
|
* @property {string} envVarName
|
||||||
|
* @property {string} outputVarName
|
||||||
|
* @property {string} selector
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a secrets input string into key paths and their resulting environment variable name.
|
||||||
|
* @param {string} secretsInput
|
||||||
|
*/
|
||||||
|
function parseSecretsInput(secretsInput) {
|
||||||
|
const secrets = secretsInput
|
||||||
|
.split(';')
|
||||||
|
.filter(key => !!key)
|
||||||
|
.map(key => key.trim())
|
||||||
|
.filter(key => key.length !== 0);
|
||||||
|
|
||||||
|
/** @type {SecretRequest[]} */
|
||||||
|
const output = [];
|
||||||
|
for (const secret of secrets) {
|
||||||
|
let pathSpec = secret;
|
||||||
|
let outputVarName = null;
|
||||||
|
|
||||||
|
const renameSigilIndex = secret.lastIndexOf('|');
|
||||||
|
if (renameSigilIndex > -1) {
|
||||||
|
pathSpec = secret.substring(0, renameSigilIndex).trim();
|
||||||
|
outputVarName = secret.substring(renameSigilIndex + 1).trim();
|
||||||
|
|
||||||
|
if (outputVarName.length < 1) {
|
||||||
|
throw Error(`You must provide a value when mapping a secret to a name. Input: "${secret}"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const pathParts = pathSpec
|
||||||
|
.split(/\s+/)
|
||||||
|
.map(part => part.trim())
|
||||||
|
.filter(part => part.length !== 0);
|
||||||
|
|
||||||
|
if (pathParts.length !== 2) {
|
||||||
|
throw Error(`You must provide a valid path and key. Input: "${secret}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [path, selector] = pathParts;
|
||||||
|
|
||||||
|
/** @type {any} */
|
||||||
|
const selectorAst = jsonata(selector).ast();
|
||||||
|
|
||||||
|
if ((selectorAst.type !== "path" || selectorAst.steps[0].stages) && !outputVarName) {
|
||||||
|
throw Error(`You must provide a name for the output key when using json selectors. Input: "${secret}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let envVarName = outputVarName;
|
||||||
|
if (!outputVarName) {
|
||||||
|
outputVarName = normalizeOutputKey(selector);
|
||||||
|
envVarName = normalizeOutputKey(selector, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
output.push({
|
||||||
|
path,
|
||||||
|
envVarName,
|
||||||
|
outputVarName,
|
||||||
|
selector
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces any dot chars to __ and removes non-ascii charts
|
||||||
|
* @param {string} dataKey
|
||||||
|
* @param {boolean=} isEnvVar
|
||||||
|
*/
|
||||||
|
function normalizeOutputKey(dataKey, isEnvVar = false) {
|
||||||
|
let outputKey = dataKey
|
||||||
|
.replace('.', '__').replace(/[^\p{L}\p{N}_-]/gu, '');
|
||||||
|
if (isEnvVar) {
|
||||||
|
outputKey = outputKey.toUpperCase();
|
||||||
|
}
|
||||||
|
return outputKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} inputKey
|
||||||
|
* @param {any} inputOptions
|
||||||
|
*/
|
||||||
|
function parseHeadersInput(inputKey, inputOptions) {
|
||||||
|
/** @type {string}*/
|
||||||
|
const rawHeadersString = core.getInput(inputKey, inputOptions) || '';
|
||||||
|
const headerStrings = rawHeadersString
|
||||||
|
.split('\n')
|
||||||
|
.map(line => line.trim())
|
||||||
|
.filter(line => line !== '');
|
||||||
|
return headerStrings
|
||||||
|
.reduce((map, line) => {
|
||||||
|
const seperator = line.indexOf(':');
|
||||||
|
const key = line.substring(0, seperator).trim().toLowerCase();
|
||||||
|
const value = line.substring(seperator + 1).trim();
|
||||||
|
if (map.has(key)) {
|
||||||
|
map.set(key, [map.get(key), value].join(', '));
|
||||||
|
} else {
|
||||||
|
map.set(key, value);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, new Map());
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
exportSecrets,
|
||||||
|
parseSecretsInput,
|
||||||
|
normalizeOutputKey,
|
||||||
|
parseHeadersInput
|
||||||
|
};
|
||||||
@@ -7,7 +7,8 @@ const got = require('got');
|
|||||||
const {
|
const {
|
||||||
exportSecrets,
|
exportSecrets,
|
||||||
parseSecretsInput,
|
parseSecretsInput,
|
||||||
parseResponse
|
parseResponse,
|
||||||
|
parseHeadersInput
|
||||||
} = require('./action');
|
} = require('./action');
|
||||||
|
|
||||||
const { when } = require('jest-when');
|
const { when } = require('jest-when');
|
||||||
@@ -16,11 +17,10 @@ describe('parseSecretsInput', () => {
|
|||||||
it('parses simple secret', () => {
|
it('parses simple secret', () => {
|
||||||
const output = parseSecretsInput('test key');
|
const output = parseSecretsInput('test key');
|
||||||
expect(output).toContainEqual({
|
expect(output).toContainEqual({
|
||||||
secretPath: 'test',
|
path: 'test',
|
||||||
secretSelector: 'key',
|
selector: 'key',
|
||||||
outputVarName: 'key',
|
outputVarName: 'key',
|
||||||
envVarName: 'KEY',
|
envVarName: 'KEY'
|
||||||
isJSONPath: false
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -48,10 +48,10 @@ describe('parseSecretsInput', () => {
|
|||||||
|
|
||||||
expect(output).toHaveLength(2);
|
expect(output).toHaveLength(2);
|
||||||
expect(output[0]).toMatchObject({
|
expect(output[0]).toMatchObject({
|
||||||
secretPath: 'first',
|
path: 'first',
|
||||||
});
|
});
|
||||||
expect(output[1]).toMatchObject({
|
expect(output[1]).toMatchObject({
|
||||||
secretPath: 'second',
|
path: 'second',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ describe('parseSecretsInput', () => {
|
|||||||
|
|
||||||
expect(output).toHaveLength(3);
|
expect(output).toHaveLength(3);
|
||||||
expect(output[0]).toMatchObject({
|
expect(output[0]).toMatchObject({
|
||||||
secretPath: 'first',
|
path: 'first',
|
||||||
});
|
});
|
||||||
expect(output[1]).toMatchObject({
|
expect(output[1]).toMatchObject({
|
||||||
outputVarName: 'b',
|
outputVarName: 'b',
|
||||||
@@ -87,41 +87,48 @@ describe('parseSecretsInput', () => {
|
|||||||
outputVarName: 'SOME_C',
|
outputVarName: 'SOME_C',
|
||||||
envVarName: 'SOME_C',
|
envVarName: 'SOME_C',
|
||||||
});
|
});
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('parseResponse', () => {
|
|
||||||
// https://www.vaultproject.io/api/secret/kv/kv-v1.html#sample-response
|
|
||||||
it('parses K/V version 1 response', () => {
|
|
||||||
const response = JSON.stringify({
|
|
||||||
data: {
|
|
||||||
foo: 'bar'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const output = parseResponse(response, 1);
|
|
||||||
|
|
||||||
expect(output).toEqual({
|
|
||||||
foo: 'bar'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// https://www.vaultproject.io/api/secret/kv/kv-v2.html#read-secret-version
|
|
||||||
it('parses K/V version 2 response', () => {
|
|
||||||
const response = JSON.stringify({
|
|
||||||
data: {
|
|
||||||
data: {
|
|
||||||
foo: 'bar'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const output = parseResponse(response, 2);
|
|
||||||
|
|
||||||
expect(output).toEqual({
|
|
||||||
foo: 'bar'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('parseHeaders', () => {
|
||||||
|
it('parses simple header', () => {
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('extraHeaders')
|
||||||
|
.mockReturnValueOnce('TEST: 1');
|
||||||
|
const result = parseHeadersInput('extraHeaders');
|
||||||
|
expect(Array.from(result)).toContainEqual(['test', '1']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses simple header with whitespace', () => {
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('extraHeaders')
|
||||||
|
.mockReturnValueOnce(`
|
||||||
|
TEST: 1
|
||||||
|
`);
|
||||||
|
const result = parseHeadersInput('extraHeaders');
|
||||||
|
expect(Array.from(result)).toContainEqual(['test', '1']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses multiple headers', () => {
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('extraHeaders')
|
||||||
|
.mockReturnValueOnce(`
|
||||||
|
TEST: 1
|
||||||
|
FOO: bAr
|
||||||
|
`);
|
||||||
|
const result = parseHeadersInput('extraHeaders');
|
||||||
|
expect(Array.from(result)).toContainEqual(['test', '1']);
|
||||||
|
expect(Array.from(result)).toContainEqual(['foo', 'bAr']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses null response', () => {
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('extraHeaders')
|
||||||
|
.mockReturnValueOnce(null);
|
||||||
|
const result = parseHeadersInput('extraHeaders');
|
||||||
|
expect(Array.from(result)).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('exportSecrets', () => {
|
describe('exportSecrets', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -148,22 +155,24 @@ describe('exportSecrets', () => {
|
|||||||
.mockReturnValueOnce(version);
|
.mockReturnValueOnce(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mockExtraHeaders(headerString) {
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('extraHeaders')
|
||||||
|
.mockReturnValueOnce(headerString);
|
||||||
|
}
|
||||||
|
|
||||||
function mockVaultData(data, version='2') {
|
function mockVaultData(data, version='2') {
|
||||||
switch(version) {
|
switch(version) {
|
||||||
case '1':
|
case '1':
|
||||||
got.mockResolvedValue({
|
got.extend.mockReturnValue({
|
||||||
body: JSON.stringify({
|
get: async () => ({ body: JSON.stringify({ data }) })
|
||||||
data
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case '2':
|
case '2':
|
||||||
got.mockResolvedValue({
|
got.extend.mockReturnValue({
|
||||||
body: JSON.stringify({
|
get: async () => ({ body: JSON.stringify({ data: {
|
||||||
data: {
|
data
|
||||||
data
|
} }) })
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -181,6 +190,18 @@ describe('exportSecrets', () => {
|
|||||||
expect(core.setOutput).toBeCalledWith('key', '1');
|
expect(core.setOutput).toBeCalledWith('key', '1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('intl secret retrieval', async () => {
|
||||||
|
mockInput('测试 测试');
|
||||||
|
mockVaultData({
|
||||||
|
测试: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('测试', '1');
|
||||||
|
expect(core.setOutput).toBeCalledWith('测试', '1');
|
||||||
|
});
|
||||||
|
|
||||||
it('mapped secret retrieval', async () => {
|
it('mapped secret retrieval', async () => {
|
||||||
mockInput('test key|TEST_NAME');
|
mockInput('test key|TEST_NAME');
|
||||||
mockVaultData({
|
mockVaultData({
|
||||||
@@ -196,6 +217,23 @@ describe('exportSecrets', () => {
|
|||||||
it('simple secret retrieval from K/V v1', async () => {
|
it('simple secret retrieval from K/V v1', async () => {
|
||||||
const version = '1';
|
const version = '1';
|
||||||
|
|
||||||
|
mockInput('test key');
|
||||||
|
mockExtraHeaders(`
|
||||||
|
TEST: 1
|
||||||
|
`);
|
||||||
|
mockVaultData({
|
||||||
|
key: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('KEY', '1');
|
||||||
|
expect(core.setOutput).toBeCalledWith('key', '1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('simple secret retrieval with extra headers', async () => {
|
||||||
|
const version = '1';
|
||||||
|
|
||||||
mockInput('test key');
|
mockInput('test key');
|
||||||
mockVersion(version);
|
mockVersion(version);
|
||||||
mockVaultData({
|
mockVaultData({
|
||||||
@@ -207,4 +245,16 @@ describe('exportSecrets', () => {
|
|||||||
expect(core.exportVariable).toBeCalledWith('KEY', '1');
|
expect(core.exportVariable).toBeCalledWith('KEY', '1');
|
||||||
expect(core.setOutput).toBeCalledWith('key', '1');
|
expect(core.setOutput).toBeCalledWith('key', '1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('nested secret retrieval', async () => {
|
||||||
|
mockInput('test key.value');
|
||||||
|
mockVaultData({
|
||||||
|
key: { value: 1 }
|
||||||
|
});
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('KEY__VALUE', '1');
|
||||||
|
expect(core.setOutput).toBeCalledWith('key__value', '1');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
// @ts-check
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Authenticate with Vault and retrieve a Vault token that can be used for requests.
|
||||||
|
* @param {string} method
|
||||||
|
* @param {import('got').Got} client
|
||||||
|
*/
|
||||||
|
async function retrieveToken(method, client) {
|
||||||
|
switch (method) {
|
||||||
|
case 'approle': {
|
||||||
|
const vaultRoleId = core.getInput('roleId', { required: true });
|
||||||
|
const vaultSecretId = core.getInput('secretId', { required: true });
|
||||||
|
return await getClientToken(client, method, { role_id: vaultRoleId, secret_id: vaultSecretId });
|
||||||
|
}
|
||||||
|
case 'github': {
|
||||||
|
const githubToken = core.getInput('githubToken', { required: true });
|
||||||
|
return await getClientToken(client, method, { token: githubToken });
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
if (!method || method === 'token') {
|
||||||
|
return core.getInput('token', { required: true });
|
||||||
|
} else {
|
||||||
|
/** @type {string} */
|
||||||
|
const payload = core.getInput('authPayload', { required: true });
|
||||||
|
if (!payload) {
|
||||||
|
throw Error('When using a custom authentication method, you must provide the payload');
|
||||||
|
}
|
||||||
|
return await getClientToken(client, method, JSON.parse(payload.trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Call the appropriate login endpoint and parse out the token in the response.
|
||||||
|
* @param {import('got').Got} client
|
||||||
|
* @param {string} method
|
||||||
|
* @param {any} payload
|
||||||
|
*/
|
||||||
|
async function getClientToken(client, method, payload) {
|
||||||
|
/** @type {'json'} */
|
||||||
|
const responseType = 'json';
|
||||||
|
var options = {
|
||||||
|
json: payload,
|
||||||
|
responseType,
|
||||||
|
};
|
||||||
|
|
||||||
|
core.debug(`Retrieving Vault Token from v1/auth/${method}/login endpoint`);
|
||||||
|
|
||||||
|
/** @type {import('got').Response<VaultLoginResponse>} */
|
||||||
|
const response = await client.post(`v1/auth/${method}/login`, options);
|
||||||
|
if (response && response.body && response.body.auth && response.body.auth.client_token) {
|
||||||
|
core.debug('✔ Vault Token successfully retrieved');
|
||||||
|
|
||||||
|
core.startGroup('Token Info');
|
||||||
|
core.debug(`Operating under policies: ${JSON.stringify(response.body.auth.policies)}`);
|
||||||
|
core.debug(`Token Metadata: ${JSON.stringify(response.body.auth.metadata)}`);
|
||||||
|
core.endGroup();
|
||||||
|
|
||||||
|
return response.body.auth.client_token;
|
||||||
|
} else {
|
||||||
|
throw Error(`Unable to retrieve token from ${method}'s login endpoint.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* @typedef {Object} VaultLoginResponse
|
||||||
|
* @property {{
|
||||||
|
* client_token: string;
|
||||||
|
* accessor: string;
|
||||||
|
* policies: string[];
|
||||||
|
* metadata: unknown;
|
||||||
|
* lease_duration: number;
|
||||||
|
* renewable: boolean;
|
||||||
|
* }} auth
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
retrieveToken,
|
||||||
|
};
|
||||||
@@ -7,4 +7,4 @@ const { exportSecrets } = require('./action');
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
const auth = require('./auth');
|
||||||
|
const secrets = require('./secrets');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
auth,
|
||||||
|
secrets
|
||||||
|
};
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
const jsonata = require("jsonata");
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {Object} SecretRequest
|
||||||
|
* @property {string} path
|
||||||
|
* @property {string} selector
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template {SecretRequest} TRequest
|
||||||
|
* @typedef {Object} SecretResponse
|
||||||
|
* @property {TRequest} request
|
||||||
|
* @property {string} value
|
||||||
|
* @property {boolean} cachedResponse
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template TRequest
|
||||||
|
* @param {Array<TRequest>} secretRequests
|
||||||
|
* @param {import('got').Got} client
|
||||||
|
* @return {Promise<SecretResponse<TRequest>[]>}
|
||||||
|
*/
|
||||||
|
async function getSecrets(secretRequests, client) {
|
||||||
|
const responseCache = new Map();
|
||||||
|
const results = [];
|
||||||
|
for (const secretRequest of secretRequests) {
|
||||||
|
let { path, selector } = secretRequest;
|
||||||
|
|
||||||
|
const requestPath = `v1/${path}`;
|
||||||
|
let body;
|
||||||
|
let cachedResponse = false;
|
||||||
|
if (responseCache.has(requestPath)) {
|
||||||
|
body = responseCache.get(requestPath);
|
||||||
|
cachedResponse = true;
|
||||||
|
} else {
|
||||||
|
const result = await client.get(requestPath);
|
||||||
|
body = result.body;
|
||||||
|
responseCache.set(requestPath, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
selector = "data." + selector
|
||||||
|
body = JSON.parse(body)
|
||||||
|
if (body.data["data"] != undefined) {
|
||||||
|
selector = "data." + selector
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = selectData(body, selector);
|
||||||
|
results.push({
|
||||||
|
request: secretRequest,
|
||||||
|
value,
|
||||||
|
cachedResponse
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses a Jsonata selector retrieve a bit of data from the result
|
||||||
|
* @param {object} data
|
||||||
|
* @param {string} selector
|
||||||
|
*/
|
||||||
|
function selectData(data, selector) {
|
||||||
|
const ata = jsonata(selector);
|
||||||
|
let result = JSON.stringify(ata.evaluate(data));
|
||||||
|
// Compat for custom engines
|
||||||
|
if (!result && ata.ast().type === "path" && ata.ast()['steps'].length === 1 && selector !== 'data' && 'data' in data) {
|
||||||
|
result = JSON.stringify(jsonata(`data.${selector}`).evaluate(data));
|
||||||
|
} else if (!result) {
|
||||||
|
throw Error(`Unable to retrieve result for ${selector}. No match data was found. Double check your Key or Selector.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.startsWith(`"`)) {
|
||||||
|
result = result.substring(1, result.length - 1);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getSecrets,
|
||||||
|
selectData
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es2019",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"allowJs": true,
|
||||||
|
"noEmit": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user