mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-07-26 00:13:16 +03:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 867290158a | |||
| 790b5eac34 | |||
| 074f580c7d | |||
| 14c5ac9697 | |||
| ee41aa2fcf | |||
| 77efb36ae3 | |||
| a727ce205a | |||
| d1720f055e | |||
| 92626383ce | |||
| 9c2d817b85 | |||
| b477844b5f | |||
| 9f522b8598 | |||
| efab57ede0 | |||
| d523bb05b2 | |||
| 11845b19f6 | |||
| 7a6258bb0b | |||
| a0b66b1cc3 | |||
| c616aba63e | |||
| e3d5714d59 | |||
| 00bce0da9c | |||
| 6853090cd9 | |||
| 45dc5344f1 | |||
| 2fb925f14c | |||
| caba6efd0e | |||
| affa6f04da | |||
| 4727f0b168 | |||
| 86c7f837eb | |||
| 375956aa33 | |||
| 1328cd9fa9 | |||
| d4437ee96c | |||
| a5f6c67fe1 | |||
| d9197ec2d2 | |||
| cb841f2c86 | |||
| 0010502df7 | |||
| 65d7a12a80 | |||
| b138504969 |
@@ -3,21 +3,29 @@ name: Bug report
|
|||||||
about: Create a report to help us improve
|
about: Create a report to help us improve
|
||||||
title: "[BUG] "
|
title: "[BUG] "
|
||||||
labels: bug
|
labels: bug
|
||||||
assignees: RichiCoder1
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Describe the bug**
|
## Vault server version
|
||||||
|
v0.0.0
|
||||||
|
|
||||||
|
## vault-action version
|
||||||
|
v0.0.0
|
||||||
|
|
||||||
|
## Describe the bug
|
||||||
A clear and concise description of what the bug is.
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
**To Reproduce**
|
## To Reproduce
|
||||||
The yaml of the `vault-action` step, with any sensitive information masked or removed.
|
The yaml of the `vault-action` step, with any sensitive information masked or removed.
|
||||||
|
|
||||||
**Expected behavior**
|
## Expected behavior
|
||||||
A clear and concise description of what you expected to happen.
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
**Log Output**
|
## Log Output
|
||||||
For the most verbose logs, [add a secret called `ACTIONS_STEP_DEBUG` with the value `true`](https://github.com/actions/toolkit/blob/main/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.
|
For the most verbose logs, add a secret called
|
||||||
|
[`ACTIONS_STEP_DEBUG`](https://github.com/actions/toolkit/blob/main/docs/action-debugging.md)
|
||||||
|
with the value `true`. 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**
|
## Additional context
|
||||||
Add any other context about the problem here.
|
Add any other context about the problem here.
|
||||||
|
|||||||
@@ -3,18 +3,17 @@ name: Feature request
|
|||||||
about: Suggest an idea for this project
|
about: Suggest an idea for this project
|
||||||
title: "[FEAT] "
|
title: "[FEAT] "
|
||||||
labels: enhancement
|
labels: enhancement
|
||||||
assignees: RichiCoder1
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
## 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 [...]
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
## Describe the solution you'd like
|
||||||
A clear and concise description of what you want to happen.
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
## Describe alternatives you've considered
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
**Additional context**
|
## Additional context
|
||||||
Add any other context or screenshots about the feature request here.
|
Add any other context or screenshots about the feature request here.
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
### Description
|
||||||
|
<!--- Description of the change. For example: This PR updates ABC resource so that we can XYZ --->
|
||||||
|
|
||||||
|
|
||||||
|
<!--- If your PR fully resolves and should automatically close the linked issue, use Closes. Otherwise, use Relates --->
|
||||||
|
Relates OR Closes #0000
|
||||||
|
|
||||||
|
|
||||||
|
### Checklist
|
||||||
|
- [ ] Added [CHANGELOG](https://github.com/hashicorp/vault-action/blob/master/CHANGELOG.md) entry (only for user-facing changes)
|
||||||
|
|
||||||
|
|
||||||
|
### Community Note
|
||||||
|
|
||||||
|
* Please vote on this pull request by adding a 👍
|
||||||
|
[reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/)
|
||||||
|
to the original pull request comment to help the community and maintainers
|
||||||
|
prioritize this request
|
||||||
|
* Please do not leave "+1" comments, they generate extra noise for pull request
|
||||||
|
followers and do not help prioritize the request
|
||||||
+15
-15
@@ -10,7 +10,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||||
with:
|
with:
|
||||||
node-version: '16.14.0'
|
node-version: '20.12.2'
|
||||||
|
|
||||||
- name: Setup NPM Cache
|
- name: Setup NPM Cache
|
||||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||||
@@ -40,7 +40,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||||
with:
|
with:
|
||||||
node-version: '16.14.0'
|
node-version: '20.12.2'
|
||||||
|
|
||||||
- name: Setup NPM Cache
|
- name: Setup NPM Cache
|
||||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||||
@@ -76,7 +76,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||||
with:
|
with:
|
||||||
node-version: '16.14.0'
|
node-version: '20.12.2'
|
||||||
|
|
||||||
- name: Setup NPM Cache
|
- name: Setup NPM Cache
|
||||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||||
@@ -110,7 +110,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||||
with:
|
with:
|
||||||
node-version: '16.14.0'
|
node-version: '20.12.2'
|
||||||
|
|
||||||
- name: Setup NPM Cache
|
- name: Setup NPM Cache
|
||||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||||
@@ -133,7 +133,7 @@ jobs:
|
|||||||
VAULT_PORT: 8200
|
VAULT_PORT: 8200
|
||||||
|
|
||||||
- name: Test Vault Action (default KV V2)
|
- name: Test Vault Action (default KV V2)
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
id: kv-secrets
|
id: kv-secrets
|
||||||
with:
|
with:
|
||||||
url: http://localhost:8200
|
url: http://localhost:8200
|
||||||
@@ -144,7 +144,7 @@ jobs:
|
|||||||
secret/data/nested/test otherSecret ;
|
secret/data/nested/test otherSecret ;
|
||||||
|
|
||||||
- name: Test Vault Action (default KV V1)
|
- name: Test Vault Action (default KV V1)
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
with:
|
with:
|
||||||
url: http://localhost:8200
|
url: http://localhost:8200
|
||||||
token: testtoken
|
token: testtoken
|
||||||
@@ -154,7 +154,7 @@ jobs:
|
|||||||
my-secret/nested/test otherAltSecret ;
|
my-secret/nested/test otherAltSecret ;
|
||||||
|
|
||||||
- name: Test Vault Action (cubbyhole)
|
- name: Test Vault Action (cubbyhole)
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
with:
|
with:
|
||||||
url: http://localhost:8200
|
url: http://localhost:8200
|
||||||
token: testtoken
|
token: testtoken
|
||||||
@@ -165,7 +165,7 @@ jobs:
|
|||||||
# The ordering of these two Test Vault Action Overwrites Env Vars In Subsequent Action steps matters
|
# The ordering of these two Test Vault Action Overwrites Env Vars In Subsequent Action steps matters
|
||||||
# They should come before the Verify Vault Action Outputs step
|
# They should come before the Verify Vault Action Outputs step
|
||||||
- name: Test Vault Action Overwrites Env Vars In Subsequent Action (part 1/2)
|
- name: Test Vault Action Overwrites Env Vars In Subsequent Action (part 1/2)
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
with:
|
with:
|
||||||
url: http://localhost:8200/
|
url: http://localhost:8200/
|
||||||
token: testtoken
|
token: testtoken
|
||||||
@@ -173,7 +173,7 @@ jobs:
|
|||||||
secret/data/test secret | SUBSEQUENT_TEST_SECRET;
|
secret/data/test secret | SUBSEQUENT_TEST_SECRET;
|
||||||
|
|
||||||
- name: Test Vault Action Overwrites Env Vars In Subsequent Action (part 2/2)
|
- name: Test Vault Action Overwrites Env Vars In Subsequent Action (part 2/2)
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
with:
|
with:
|
||||||
url: http://localhost:8200/
|
url: http://localhost:8200/
|
||||||
token: testtoken
|
token: testtoken
|
||||||
@@ -181,7 +181,7 @@ jobs:
|
|||||||
secret/data/subsequent-test secret | SUBSEQUENT_TEST_SECRET;
|
secret/data/subsequent-test secret | SUBSEQUENT_TEST_SECRET;
|
||||||
|
|
||||||
- name: Test JSON Secrets
|
- name: Test JSON Secrets
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
with:
|
with:
|
||||||
url: http://localhost:8200
|
url: http://localhost:8200
|
||||||
token: testtoken
|
token: testtoken
|
||||||
@@ -207,7 +207,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||||
with:
|
with:
|
||||||
node-version: '16.14.0'
|
node-version: '20.12.2'
|
||||||
|
|
||||||
- name: Setup NPM Cache
|
- name: Setup NPM Cache
|
||||||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
|
||||||
@@ -233,7 +233,7 @@ jobs:
|
|||||||
VAULT_CLIENT_KEY: ${{ secrets.VAULT_CLIENT_KEY }}
|
VAULT_CLIENT_KEY: ${{ secrets.VAULT_CLIENT_KEY }}
|
||||||
|
|
||||||
- name: Test Vault Action (default KV V2)
|
- name: Test Vault Action (default KV V2)
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
id: kv-secrets-tls
|
id: kv-secrets-tls
|
||||||
with:
|
with:
|
||||||
url: https://localhost:8200
|
url: https://localhost:8200
|
||||||
@@ -247,7 +247,7 @@ jobs:
|
|||||||
secret/data/nested/test otherSecret ;
|
secret/data/nested/test otherSecret ;
|
||||||
|
|
||||||
- name: Test Vault Action (tlsSkipVerify)
|
- name: Test Vault Action (tlsSkipVerify)
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
with:
|
with:
|
||||||
url: https://localhost:8200
|
url: https://localhost:8200
|
||||||
token: ${{ env.VAULT_TOKEN }}
|
token: ${{ env.VAULT_TOKEN }}
|
||||||
@@ -258,7 +258,7 @@ jobs:
|
|||||||
secret/data/tlsSkipVerify skip ;
|
secret/data/tlsSkipVerify skip ;
|
||||||
|
|
||||||
- name: Test Vault Action (default KV V1)
|
- name: Test Vault Action (default KV V1)
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
with:
|
with:
|
||||||
url: https://localhost:8200
|
url: https://localhost:8200
|
||||||
token: ${{ env.VAULT_TOKEN }}
|
token: ${{ env.VAULT_TOKEN }}
|
||||||
@@ -271,7 +271,7 @@ jobs:
|
|||||||
my-secret/nested/test otherAltSecret ;
|
my-secret/nested/test otherAltSecret ;
|
||||||
|
|
||||||
- name: Test Vault Action (cubbyhole)
|
- name: Test Vault Action (cubbyhole)
|
||||||
uses: ./
|
uses: hashicorp/vault-action@main
|
||||||
with:
|
with:
|
||||||
url: https://localhost:8200
|
url: https://localhost:8200
|
||||||
token: ${{ env.VAULT_TOKEN }}
|
token: ${{ env.VAULT_TOKEN }}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
|
||||||
with:
|
with:
|
||||||
node-version: '16.14.0'
|
node-version: '20.9.0'
|
||||||
|
|
||||||
- name: NPM Install
|
- name: NPM Install
|
||||||
run: npm ci
|
run: npm ci
|
||||||
@@ -48,14 +48,26 @@ jobs:
|
|||||||
token: testtoken
|
token: testtoken
|
||||||
secrets: |
|
secrets: |
|
||||||
secret/data/test-json-string jsonString;
|
secret/data/test-json-string jsonString;
|
||||||
|
secret/data/test-json-data jsonData;
|
||||||
|
|
||||||
- name: Check Secrets
|
- uses: actions/github-script@v7
|
||||||
run: |
|
with:
|
||||||
touch secrets.json
|
github-token: "foobar"
|
||||||
echo "${{ steps.import-secrets.outputs.jsonString }}" >> secrets.json
|
script: |
|
||||||
|
const { JSONSTRING, JSONDATA } = process.env
|
||||||
|
|
||||||
- name: Check json file format
|
console.log(`string ${JSONSTRING}`)
|
||||||
run: |
|
console.log(`data ${JSONDATA}`)
|
||||||
echo
|
const str = JSONDATA
|
||||||
cat secrets.json
|
|
||||||
jq -c . < secrets.json
|
let valid = true
|
||||||
|
try {
|
||||||
|
JSON.parse(str)
|
||||||
|
} catch (e) {
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
if (valid) {
|
||||||
|
console.log("valid json")
|
||||||
|
} else {
|
||||||
|
console.log("not valid json")
|
||||||
|
}
|
||||||
|
|||||||
+60
-1
@@ -1,6 +1,65 @@
|
|||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
* Add changes here
|
Improvements:
|
||||||
|
|
||||||
|
* chore(deps): bump jsonata from 2.0.3 to 2.0.4 [GH-531](https://github.com/hashicorp/vault-action/pull/531)
|
||||||
|
* chore(deps): bump got from 11.8.6 to 14.2.1 [GH-533](https://github.com/hashicorp/vault-action/pull/533)
|
||||||
|
* convert project from common js to an esm module [GH-533](https://github.com/hashicorp/vault-action/pull/533)
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
* `secretId` is no longer required for approle to support advanced use cases like machine login when `bind_secret_id` is false. [GH-522](https://github.com/hashicorp/vault-action/pull/522)
|
||||||
|
|
||||||
|
## 3.0.0 (February 15, 2024)
|
||||||
|
|
||||||
|
Improvements:
|
||||||
|
|
||||||
|
* Bump node runtime from node16 to node20 [GH-529](https://github.com/hashicorp/vault-action/pull/529)
|
||||||
|
|
||||||
|
## 2.8.1 (February 15, 2024)
|
||||||
|
|
||||||
|
Bugs:
|
||||||
|
|
||||||
|
* Revert [GH-509](https://github.com/hashicorp/vault-action/pull/509) which made a backwards incompatible bump of the node runtime from node16 to node20 [GH-527](https://github.com/hashicorp/vault-action/pull/527)
|
||||||
|
|
||||||
|
## 2.8.0 (February 1, 2024)
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
* Add `ignoreNotFound` input (default: false) to prevent the action from failing when a secret does not exist [GH-518](https://github.com/hashicorp/vault-action/pull/518)
|
||||||
|
|
||||||
|
Improvements:
|
||||||
|
|
||||||
|
* bump jsrsasign from 10.8.6 to 11.0.0 [GH-513](https://github.com/hashicorp/vault-action/pull/513)
|
||||||
|
* bump @actions/core from 1.10.0 to 1.10.1 [GH-489](https://github.com/hashicorp/vault-action/pull/489)
|
||||||
|
* bump jest-when from 3.5.2 to 3.6.0 [GH-484](https://github.com/hashicorp/vault-action/pull/484)
|
||||||
|
* bump jest from 29.5.0 to 29.7.0 [GH-490](https://github.com/hashicorp/vault-action/pull/490)
|
||||||
|
* bump @vercel/ncc from 0.36.1 to 0.38.1 [GH-503](https://github.com/hashicorp/vault-action/pull/503)
|
||||||
|
|
||||||
|
## 2.7.5 (January 30, 2024)
|
||||||
|
|
||||||
|
Improvements:
|
||||||
|
|
||||||
|
* Bump node runtime from node16 to node20 [GH-509](https://github.com/hashicorp/vault-action/pull/509)
|
||||||
|
* Bump got from 11.8.5 to 11.8.6 [GH-492](https://github.com/hashicorp/vault-action/pull/492)
|
||||||
|
|
||||||
|
## 2.7.4 (October 26, 2023)
|
||||||
|
|
||||||
|
Features:
|
||||||
|
|
||||||
|
* Add ability to specify a wildcard for the key name to get all keys in the path [GH-488](https://github.com/hashicorp/vault-action/pull/488)
|
||||||
|
|
||||||
|
## 2.7.3 (July 13, 2023)
|
||||||
|
|
||||||
|
Bugs:
|
||||||
|
|
||||||
|
* Revert to the handling of secrets in JSON format since v2.1.2 [GH-478](https://github.com/hashicorp/vault-action/pull/478)
|
||||||
|
|
||||||
|
## 2.7.2 (July 6, 2023)
|
||||||
|
|
||||||
|
Bugs:
|
||||||
|
|
||||||
|
* Fix a regression that broke support for secrets in JSON format [GH-473](https://github.com/hashicorp/vault-action/pull/473)
|
||||||
|
|
||||||
## 2.7.1 (July 3, 2023)
|
## 2.7.1 (July 3, 2023)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
A helper action for easily pulling secrets from HashiCorp Vault™.
|
A helper action for easily pulling secrets from HashiCorp Vault™.
|
||||||
|
|
||||||
|
Note: The Vault Github Action is a read-only action, and in general
|
||||||
|
is not meant to modify Vault’s state.
|
||||||
|
|
||||||
<!-- TOC -->
|
<!-- TOC -->
|
||||||
|
|
||||||
- [Vault GitHub Action](#vault-github-action)
|
- [Vault GitHub Action](#vault-github-action)
|
||||||
@@ -22,6 +25,7 @@ A helper action for easily pulling secrets from HashiCorp Vault™.
|
|||||||
- [Userpass](#userpass)
|
- [Userpass](#userpass)
|
||||||
- [Ldap](#ldap)
|
- [Ldap](#ldap)
|
||||||
- [Other Auth Methods](#other-auth-methods)
|
- [Other Auth Methods](#other-auth-methods)
|
||||||
|
- [Custom Path](#custom-path-name)
|
||||||
- [Key Syntax](#key-syntax)
|
- [Key Syntax](#key-syntax)
|
||||||
- [Simple Key](#simple-key)
|
- [Simple Key](#simple-key)
|
||||||
- [Set Output Variable Name](#set-output-variable-name)
|
- [Set Output Variable Name](#set-output-variable-name)
|
||||||
@@ -76,7 +80,7 @@ For example, a common pattern is to save all the secrets in a JSON file:
|
|||||||
- name: Step following 'Import Secrets'
|
- name: Step following 'Import Secrets'
|
||||||
run: |
|
run: |
|
||||||
touch secrets.json
|
touch secrets.json
|
||||||
echo "${{ toJson(steps.import-secrets.outputs) }}" >> secrets.json
|
echo '${{ toJson(steps.import-secrets.outputs) }}' >> secrets.json
|
||||||
# ...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -297,6 +301,20 @@ with:
|
|||||||
If any other method is specified and you provide an `authPayload`, the action will
|
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.
|
attempt to `POST` to `auth/${method}/login` with the provided payload and parse out the client token.
|
||||||
|
|
||||||
|
### Custom Path Name
|
||||||
|
|
||||||
|
Auth methods at custom path names can be configured using the [`path`](#path) parameter
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
with:
|
||||||
|
url: https://vault.mycompany.com:8200
|
||||||
|
caCertificate: ${{ secrets.VAULT_CA_CERT }}
|
||||||
|
path: my-custom-path
|
||||||
|
method: userpass
|
||||||
|
username: ${{ secrets.VAULT_USERNAME }}
|
||||||
|
password: ${{ secrets.VAULT_PASSWORD }}
|
||||||
|
```
|
||||||
|
|
||||||
## Key Syntax
|
## 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.
|
||||||
@@ -373,6 +391,13 @@ with:
|
|||||||
secret/data/ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
secret/data/ci/aws accessKey | AWS_ACCESS_KEY_ID ;
|
||||||
secret/data/ci/aws secretKey | AWS_SECRET_ACCESS_KEY
|
secret/data/ci/aws secretKey | AWS_SECRET_ACCESS_KEY
|
||||||
```
|
```
|
||||||
|
You can specify a wildcard * for the key name to get all keys in the path. If you provide an output name with the wildcard, the name will be prepended to the key name:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
with:
|
||||||
|
secrets: |
|
||||||
|
secret/data/ci/aws * | MYAPP_ ;
|
||||||
|
```
|
||||||
|
|
||||||
## Other Secret Engines
|
## Other Secret Engines
|
||||||
|
|
||||||
@@ -457,34 +482,179 @@ steps:
|
|||||||
|
|
||||||
Here are all the inputs available through `with`:
|
Here are all the inputs available through `with`:
|
||||||
|
|
||||||
| Input | Description | Default | Required |
|
### `url`
|
||||||
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------- |
|
|
||||||
| `url` | The URL for the vault endpoint | | ✔ |
|
**Type: `string`**\
|
||||||
| `secrets` | A semicolon-separated list of secrets to retrieve. These will automatically be converted to environmental variable keys. See README for more details | | |
|
**Required**
|
||||||
| `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` | |
|
The URL for the Vault endpoint.
|
||||||
| `role` | Vault role for specified auth method | | |
|
|
||||||
| `path` | Custom vault path, if the auth method was enabled at a different path | | |
|
### `secrets`
|
||||||
| `token` | The Vault Token to be used to authenticate with Vault | | |
|
|
||||||
| `roleId` | The Role Id for App Role authentication | | |
|
**Type: `string`**
|
||||||
| `secretId` | The Secret Id for App Role authentication | | |
|
|
||||||
| `githubToken` | The Github Token to be used to authenticate with Vault | | |
|
A semicolon-separated list of secrets to retrieve. These will automatically be
|
||||||
| `jwtPrivateKey` | Base64 encoded Private key to sign JWT | | |
|
converted to environmental variable keys. See [Key Syntax](#key-syntax) for
|
||||||
| `jwtKeyPassword` | Password for key stored in jwtPrivateKey (if needed) | | |
|
more details.
|
||||||
| `jwtGithubAudience` | Identifies the recipient ("aud" claim) that the JWT is intended for |`sigstore`| |
|
|
||||||
| `jwtTtl` | Time in seconds, after which token expires | | 3600 |
|
### `namespace`
|
||||||
| `kubernetesTokenPath` | The path to the service-account secret with the jwt token for kubernetes based authentication |`/var/run/secrets/kubernetes.io/serviceaccount/token` | |
|
|
||||||
| `username` | The username of the user to log in to Vault as. Available to both Userpass and LDAP auth methods | | |
|
**Type: `string`**
|
||||||
| `password` | The password of the user to log in to Vault as. Available to both Userpass and LDAP auth methods | | |
|
|
||||||
| `authPayload` | The JSON payload to be sent to Vault when using a custom authentication method. | | |
|
The Vault namespace from which to query secrets. Vault Enterprise only, unset by default.
|
||||||
| `extraHeaders` | A string of newline separated extra headers to include on every request. | | |
|
|
||||||
| `exportEnv` | Whether or not export secrets as environment variables. | `true` | |
|
### `method`
|
||||||
| `exportToken` | Whether or not export Vault token as environment variables (i.e VAULT_TOKEN). | `false` | |
|
|
||||||
| `outputToken` | Whether or not to set the `vault_token` output to contain the Vault token after authentication. | `false` | |
|
**Type: `string`**\
|
||||||
| `caCertificate` | Base64 encoded CA certificate the server certificate was signed with. | | |
|
**Default: `token`**
|
||||||
| `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. | | |
|
The method to use to authenticate with Vault.
|
||||||
| `tlsSkipVerify` | When set to true, disables verification of server certificates when testing the action. | `false` | |
|
|
||||||
|
### `role`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
Vault role for the specified auth method.
|
||||||
|
|
||||||
|
### `path`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
The Vault path for the auth method.
|
||||||
|
|
||||||
|
### `token`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
The Vault token to be used to authenticate with Vault.
|
||||||
|
|
||||||
|
### `roleId`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
The role ID for App Role authentication.
|
||||||
|
|
||||||
|
### `secretId`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
The secret ID for App Role authentication.
|
||||||
|
|
||||||
|
### `githubToken`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
The Github Token to be used to authenticate with Vault.
|
||||||
|
|
||||||
|
### `jwtPrivateKey`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
Base64 encoded private key to sign the JWT.
|
||||||
|
|
||||||
|
### `jwtKeyPassword`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
Password for key stored in `jwtPrivateKey` (if needed).
|
||||||
|
|
||||||
|
### `jwtGithubAudience`
|
||||||
|
|
||||||
|
**Type: `string`**\
|
||||||
|
**Default: `sigstore`**
|
||||||
|
|
||||||
|
Identifies the recipient ("aud" claim) that the JWT is intended for.
|
||||||
|
|
||||||
|
### `jwtTtl`
|
||||||
|
|
||||||
|
**Type: `string`**\
|
||||||
|
**Default: `3600`**
|
||||||
|
|
||||||
|
Time in seconds, after which token expires.
|
||||||
|
|
||||||
|
### `kubernetesTokenPath`
|
||||||
|
|
||||||
|
**Type: `string`**\
|
||||||
|
**Default: `/var/run/secrets/kubernetes.io/serviceaccount/token`**
|
||||||
|
|
||||||
|
The path to the service-account secret with the jwt token for kubernetes based authentication.
|
||||||
|
|
||||||
|
### `username`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
The username of the user to log in to Vault as. Available to both Userpass and LDAP auth methods.
|
||||||
|
|
||||||
|
### `password`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
The password of the user to log in to Vault as. Available to both Userpass and LDAP auth methods.
|
||||||
|
|
||||||
|
### `authPayload`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
The JSON payload to be sent to Vault when using a custom authentication method.
|
||||||
|
|
||||||
|
### `extraHeaders`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
A string of newline separated extra headers to include on every request.
|
||||||
|
|
||||||
|
### `exportEnv`
|
||||||
|
|
||||||
|
**Type: `string`**\
|
||||||
|
**Default: `true`**
|
||||||
|
|
||||||
|
Whether or not to export secrets as environment variables.
|
||||||
|
|
||||||
|
### `exportToken`
|
||||||
|
|
||||||
|
**Type: `string`**\
|
||||||
|
**Default: `false`**
|
||||||
|
|
||||||
|
Whether or not export Vault token as environment variables (i.e VAULT_TOKEN).
|
||||||
|
|
||||||
|
### `outputToken`
|
||||||
|
|
||||||
|
**Type: `string`**\
|
||||||
|
**Default: `false`**
|
||||||
|
|
||||||
|
Whether or not to set the `vault_token` output to contain the Vault token after authentication.
|
||||||
|
|
||||||
|
### `caCertificate`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
Base64 encoded CA certificate the server certificate was signed with. Defaults to CAs provided by Mozilla.
|
||||||
|
|
||||||
|
### `clientCertificate`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
Base64 encoded client certificate the action uses to authenticate with Vault when mTLS is enabled.
|
||||||
|
|
||||||
|
### `clientKey`
|
||||||
|
|
||||||
|
**Type: `string`**
|
||||||
|
|
||||||
|
Base64 encoded client key the action uses to authenticate with Vault when mTLS is enabled.
|
||||||
|
|
||||||
|
### `tlsSkipVerify`
|
||||||
|
|
||||||
|
**Type: `string`**\
|
||||||
|
**Default: `false`**
|
||||||
|
|
||||||
|
When set to true, disables verification of server certificates when testing the action.
|
||||||
|
|
||||||
|
### `ignoreNotFound`
|
||||||
|
|
||||||
|
**Type: `string`**\
|
||||||
|
**Default: `false`**
|
||||||
|
|
||||||
|
When set to true, prevents the action from failing when a secret does not exist.
|
||||||
|
|
||||||
## Masking - Hiding Secrets from Logs
|
## Masking - Hiding Secrets from Logs
|
||||||
|
|
||||||
|
|||||||
+11
-7
@@ -1,4 +1,4 @@
|
|||||||
name: 'Vault Secrets'
|
name: 'HashiCorp Vault'
|
||||||
description: 'A Github Action that allows you to consume HashiCorp Vault™ secrets as secure environment variables'
|
description: 'A Github Action that allows you to consume HashiCorp Vault™ secrets as secure environment variables'
|
||||||
inputs:
|
inputs:
|
||||||
url:
|
url:
|
||||||
@@ -18,16 +18,16 @@ inputs:
|
|||||||
description: 'Vault role for specified auth method'
|
description: 'Vault role for specified auth method'
|
||||||
required: false
|
required: false
|
||||||
path:
|
path:
|
||||||
description: 'Custom Vault path, if the auth method was mounted at a different path'
|
description: 'The Vault path for the auth method.'
|
||||||
required: false
|
required: false
|
||||||
token:
|
token:
|
||||||
description: 'The Vault Token to be used to authenticate with Vault'
|
description: 'The Vault token to be used to authenticate with Vault'
|
||||||
required: false
|
required: false
|
||||||
roleId:
|
roleId:
|
||||||
description: 'The Role Id for App Role authentication'
|
description: 'The role ID for App Role authentication'
|
||||||
required: false
|
required: false
|
||||||
secretId:
|
secretId:
|
||||||
description: 'The Secret Id for App Role authentication'
|
description: 'The secret ID for App Role authentication'
|
||||||
required: false
|
required: false
|
||||||
githubToken:
|
githubToken:
|
||||||
description: 'The Github Token to be used to authenticate with Vault'
|
description: 'The Github Token to be used to authenticate with Vault'
|
||||||
@@ -61,7 +61,7 @@ inputs:
|
|||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
caCertificate:
|
caCertificate:
|
||||||
description: 'Base64 encoded CA certificate to verify the Vault server certificate.'
|
description: 'Base64 encoded CA certificate the server certificate was signed with. Defaults to CAs provided by Mozilla.'
|
||||||
required: false
|
required: false
|
||||||
clientCertificate:
|
clientCertificate:
|
||||||
description: 'Base64 encoded client certificate for mTLS communication with the Vault server.'
|
description: 'Base64 encoded client certificate for mTLS communication with the Vault server.'
|
||||||
@@ -89,8 +89,12 @@ inputs:
|
|||||||
secretEncodingType:
|
secretEncodingType:
|
||||||
description: 'The encoding type of the secret to decode. If not specified, the secret will not be decoded. Supported values: base64, hex, utf8'
|
description: 'The encoding type of the secret to decode. If not specified, the secret will not be decoded. Supported values: base64, hex, utf8'
|
||||||
required: false
|
required: false
|
||||||
|
ignoreNotFound:
|
||||||
|
description: 'Whether or not the action should exit successfully if some requested secrets were not found.'
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node20'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
branding:
|
branding:
|
||||||
icon: 'unlock'
|
icon: 'unlock'
|
||||||
|
|||||||
Vendored
+9204
-13751
File diff suppressed because one or more lines are too long
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
const got = require('got');
|
vi.mock('@actions/core');
|
||||||
const { when } = require('jest-when');
|
import core from '@actions/core';
|
||||||
|
|
||||||
const { exportSecrets } = require('../../src/action');
|
import got from 'got';
|
||||||
|
import { when } from 'jest-when'
|
||||||
|
|
||||||
|
import { exportSecrets } from '../../src/action.js';
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
@@ -102,7 +103,7 @@ describe('authenticate with approle', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method', expect.anything())
|
.calledWith('method', expect.anything())
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
const got = require('got');
|
vi.mock('@actions/core');
|
||||||
const { when } = require('jest-when');
|
import core from '@actions/core';
|
||||||
|
|
||||||
const { exportSecrets } = require('../../src/action');
|
import got from 'got';
|
||||||
|
import { when } from 'jest-when'
|
||||||
|
|
||||||
|
import { exportSecrets } from '../../src/action.js';
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
@@ -107,7 +108,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
@@ -124,12 +125,34 @@ describe('integration', () => {
|
|||||||
.mockReturnValueOnce(secrets);
|
.mockReturnValueOnce(secrets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mockIgnoreNotFound(shouldIgnore) {
|
||||||
|
when(core.getInput)
|
||||||
|
.calledWith('ignoreNotFound', expect.anything())
|
||||||
|
.mockReturnValueOnce(shouldIgnore);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
it('prints a nice error message when secret not found', async () => {
|
it('prints a nice error message when secret not found', async () => {
|
||||||
mockInput(`secret/data/test secret ;
|
mockInput(`secret/data/test secret ;
|
||||||
secret/data/test secret | NAMED_SECRET ;
|
secret/data/test secret | NAMED_SECRET ;
|
||||||
secret/data/notFound kehe | NO_SIR ;`);
|
secret/data/notFound kehe | NO_SIR ;`);
|
||||||
|
|
||||||
expect(exportSecrets()).rejects.toEqual(Error(`Unable to retrieve result for "secret/data/notFound" because it was not found: {"errors":[]}`));
|
await expect(exportSecrets()).rejects.toEqual(Error(`Unable to retrieve result for "secret/data/notFound" because it was not found: {"errors":[]}`));
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does not error when secret not found and ignoreNotFound is true', async () => {
|
||||||
|
mockInput(`secret/data/test secret ;
|
||||||
|
secret/data/test secret | NAMED_SECRET ;
|
||||||
|
secret/data/notFound kehe | NO_SIR ;`);
|
||||||
|
|
||||||
|
mockIgnoreNotFound("true");
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledTimes(2);
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET');
|
||||||
|
expect(core.exportVariable).toBeCalledWith('NAMED_SECRET', 'SUPERSECRET');
|
||||||
})
|
})
|
||||||
|
|
||||||
it('get simple secret', async () => {
|
it('get simple secret', async () => {
|
||||||
@@ -171,6 +194,26 @@ describe('integration', () => {
|
|||||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRETDASH', 'OTHERSUPERSECRET');
|
expect(core.exportVariable).toBeCalledWith('OTHERSECRETDASH', 'OTHERSUPERSECRET');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('get wildcard secrets', async () => {
|
||||||
|
mockInput(`secret/data/test * ;`);
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get wildcard secrets with name prefix', async () => {
|
||||||
|
mockInput(`secret/data/test * | GROUP_ ;`);
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('GROUP_SECRET', 'SUPERSECRET');
|
||||||
|
});
|
||||||
|
|
||||||
it('leading slash kvv2', async () => {
|
it('leading slash kvv2', async () => {
|
||||||
mockInput('/secret/data/foobar fookv2');
|
mockInput('/secret/data/foobar fookv2');
|
||||||
|
|
||||||
@@ -195,6 +238,34 @@ describe('integration', () => {
|
|||||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRETDASH', 'OTHERCUSTOMSECRET');
|
expect(core.exportVariable).toBeCalledWith('OTHERSECRETDASH', 'OTHERCUSTOMSECRET');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('get K/V v1 wildcard secrets', async () => {
|
||||||
|
mockInput(`secret-kv1/test * ;`);
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'CUSTOMSECRET');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get K/V v1 wildcard secrets with name prefix', async () => {
|
||||||
|
mockInput(`secret-kv1/test * | GROUP_ ;`);
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledTimes(1);
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('GROUP_SECRET', 'CUSTOMSECRET');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get wildcard nested secret from K/V v1', async () => {
|
||||||
|
mockInput('secret-kv1/nested/test *');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('OTHERSECRETDASH', 'OTHERCUSTOMSECRET');
|
||||||
|
});
|
||||||
|
|
||||||
it('leading slash kvv1', async () => {
|
it('leading slash kvv1', async () => {
|
||||||
mockInput('/secret-kv1/foobar fookv1');
|
mockInput('/secret-kv1/foobar fookv1');
|
||||||
|
|
||||||
@@ -225,6 +296,17 @@ describe('integration', () => {
|
|||||||
expect(core.exportVariable).toBeCalledWith('FOO', 'bar');
|
expect(core.exportVariable).toBeCalledWith('FOO', 'bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('wildcard supports cubbyhole', async () => {
|
||||||
|
mockInput('/cubbyhole/test *');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledTimes(2);
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('FOO', 'bar');
|
||||||
|
expect(core.exportVariable).toBeCalledWith('ZIP', 'zap');
|
||||||
|
});
|
||||||
|
|
||||||
it('caches responses', async () => {
|
it('caches responses', async () => {
|
||||||
mockInput(`
|
mockInput(`
|
||||||
/cubbyhole/test foo ;
|
/cubbyhole/test foo ;
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
verbose: true
|
|
||||||
};
|
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
const core = require('@actions/core');
|
vi.mock('@actions/core');
|
||||||
const rsasign = require('jsrsasign');
|
import core from '@actions/core';
|
||||||
const {
|
import rsasign from 'jsrsasign';
|
||||||
|
import {
|
||||||
privateRsaKey,
|
privateRsaKey,
|
||||||
privateRsaKeyBase64,
|
privateRsaKeyBase64,
|
||||||
publicRsaKey
|
publicRsaKey
|
||||||
} = require('./rsa_keys');
|
} from './rsa_keys.js';
|
||||||
|
|
||||||
const got = require('got');
|
import got from 'got';
|
||||||
const { when } = require('jest-when');
|
import { when } from 'jest-when'
|
||||||
|
|
||||||
const { exportSecrets } = require('../../src/action');
|
import { exportSecrets } from '../../src/action.js';
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
@@ -139,7 +140,7 @@ describe('jwt auth', () => {
|
|||||||
|
|
||||||
describe('authenticate with private key', () => {
|
describe('authenticate with private key', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
@@ -189,7 +190,7 @@ describe('jwt auth', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ LrJEY9tZaRF8xraMZiOcBcyAt6S/TS29HttJ6+zlhcWx34fItEZ8jA5gzhTmspOY
|
|||||||
-----END PUBLIC KEY-----
|
-----END PUBLIC KEY-----
|
||||||
`;
|
`;
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
privateRsaKey,
|
privateRsaKey,
|
||||||
privateRsaKeyBase64,
|
privateRsaKeyBase64,
|
||||||
publicRsaKey
|
publicRsaKey
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
const got = require('got');
|
vi.mock('@actions/core');
|
||||||
const { when } = require('jest-when');
|
import core from '@actions/core';
|
||||||
|
|
||||||
const { exportSecrets } = require('../../src/action');
|
import got from 'got';
|
||||||
|
import { when } from 'jest-when'
|
||||||
|
|
||||||
|
import { exportSecrets } from '../../src/action.js';
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8200'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
@@ -84,7 +85,7 @@ describe('authenticate with userpass', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method', expect.anything())
|
.calledWith('method', expect.anything())
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { defineConfig, configDefaults } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
// required to make jest-when work with vitest
|
||||||
|
globals: true,
|
||||||
|
include: [
|
||||||
|
'**/integrationTests/basic/**.{test,spec}.?(c|m)[jt]s?(x)',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
describe('e2e-tls', () => {
|
describe('e2e-tls', () => {
|
||||||
it('verify', () => {
|
it('verify', () => {
|
||||||
expect(process.env.SECRET).toBe("SUPERSECRET");
|
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
verbose: true
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
const got = require('got');
|
import got from 'got';
|
||||||
const core = require('@actions/core');
|
import core from '@actions/core';
|
||||||
|
|
||||||
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
||||||
const caCertificateRaw = `${process.env.VAULTCA}`;
|
const caCertificateRaw = `${process.env.VAULTCA}`;
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { defineConfig, configDefaults } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
// required to make jest-when work with vitest
|
||||||
|
globals: true,
|
||||||
|
include: [
|
||||||
|
'**/integrationTests/e2e-tls/**.{test,spec}.?(c|m)[jt]s?(x)',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
describe('e2e', () => {
|
describe('e2e', () => {
|
||||||
it('verify', () => {
|
it('verify', () => {
|
||||||
expect(process.env.SECRET).toBe("SUPERSECRET");
|
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||||
@@ -12,9 +14,6 @@ describe('e2e', () => {
|
|||||||
expect(process.env.SUBSEQUENT_TEST_SECRET).toBe("SUBSEQUENT_TEST_SECRET");
|
expect(process.env.SUBSEQUENT_TEST_SECRET).toBe("SUBSEQUENT_TEST_SECRET");
|
||||||
expect(process.env.JSONSTRING).toBe('{"x":1,"y":"qux"}');
|
expect(process.env.JSONSTRING).toBe('{"x":1,"y":"qux"}');
|
||||||
expect(process.env.JSONSTRINGMULTILINE).toBe('{"x": 1, "y": "q\\nux"}');
|
expect(process.env.JSONSTRINGMULTILINE).toBe('{"x": 1, "y": "q\\nux"}');
|
||||||
|
expect(process.env.JSONDATA).toBe('{"x":1,"y":"qux"}');
|
||||||
let result = JSON.stringify('{"x":1,"y":"qux"}');
|
|
||||||
result = result.substring(1, result.length - 1);
|
|
||||||
expect(process.env.JSONDATA).toBe(result);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
verbose: true
|
|
||||||
};
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const got = require('got');
|
import got from 'got';
|
||||||
|
|
||||||
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
const vaultUrl = `${process.env.VAULT_HOST}:${process.env.VAULT_PORT}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN}` === undefined ? `${process.env.VAULT_TOKEN}` : "testtoken";
|
const vaultToken = `${process.env.VAULT_TOKEN}` === undefined ? `${process.env.VAULT_TOKEN}` : "testtoken";
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { defineConfig, configDefaults } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
// required to make jest-when work with vitest
|
||||||
|
globals: true,
|
||||||
|
include: [
|
||||||
|
'**/integrationTests/e2e/**.{test,spec}.?(c|m)[jt]s?(x)',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
const core = require('@actions/core');
|
|
||||||
|
|
||||||
const got = require('got');
|
vi.mock('@actions/core');
|
||||||
const { when } = require('jest-when');
|
import core from '@actions/core';
|
||||||
|
|
||||||
const { exportSecrets } = require('../../src/action');
|
import got from 'got';
|
||||||
|
import { when } from 'jest-when'
|
||||||
|
|
||||||
|
import { exportSecrets } from '../../src/action.js';
|
||||||
|
|
||||||
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`;
|
const vaultUrl = `http://${process.env.VAULT_HOST || 'localhost'}:${process.env.VAULT_PORT || '8201'}`;
|
||||||
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
const vaultToken = `${process.env.VAULT_TOKEN || 'testtoken'}`
|
||||||
@@ -41,7 +42,7 @@ describe('integration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
@@ -72,6 +73,22 @@ describe('integration', () => {
|
|||||||
expect(core.exportVariable).toBeCalledWith('TEST_KEY', 'SUPERSECRET_IN_NAMESPACE');
|
expect(core.exportVariable).toBeCalledWith('TEST_KEY', 'SUPERSECRET_IN_NAMESPACE');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('get wildcard secrets', async () => {
|
||||||
|
mockInput('secret/data/test *');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET_IN_NAMESPACE');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get wildcard secrets with name prefix', async () => {
|
||||||
|
mockInput('secret/data/test * | GROUP_');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('GROUP_SECRET', 'SUPERSECRET_IN_NAMESPACE');
|
||||||
|
});
|
||||||
|
|
||||||
it('get nested secret', async () => {
|
it('get nested secret', async () => {
|
||||||
mockInput('secret/data/nested/test otherSecret');
|
mockInput('secret/data/nested/test otherSecret');
|
||||||
|
|
||||||
@@ -103,6 +120,22 @@ describe('integration', () => {
|
|||||||
expect(core.exportVariable).toBeCalledWith('SECRET', 'CUSTOMSECRET_IN_NAMESPACE');
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'CUSTOMSECRET_IN_NAMESPACE');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('get wildcard secrets from K/V v1', async () => {
|
||||||
|
mockInput('my-secret/test *');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('SECRET', 'CUSTOMSECRET_IN_NAMESPACE');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get wildcard secrets from K/V v1 with name prefix', async () => {
|
||||||
|
mockInput('my-secret/test * | GROUP_');
|
||||||
|
|
||||||
|
await exportSecrets();
|
||||||
|
|
||||||
|
expect(core.exportVariable).toBeCalledWith('GROUP_SECRET', 'CUSTOMSECRET_IN_NAMESPACE');
|
||||||
|
});
|
||||||
|
|
||||||
it('get nested secret from K/V v1', async () => {
|
it('get nested secret from K/V v1', async () => {
|
||||||
mockInput('my-secret/nested/test otherSecret');
|
mockInput('my-secret/nested/test otherSecret');
|
||||||
|
|
||||||
@@ -206,7 +239,7 @@ describe('authenticate with approle', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method', expect.anything())
|
.calledWith('method', expect.anything())
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
verbose: true
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { defineConfig, configDefaults } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
// required to make jest-when work with vitest
|
||||||
|
globals: true,
|
||||||
|
include: [
|
||||||
|
'**/integrationTests/enterprise/**.{test,spec}.?(c|m)[jt]s?(x)',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integrationTests/'],
|
|
||||||
};
|
|
||||||
+1
-1
@@ -7,4 +7,4 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2018"
|
"target": "es2018"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+4849
-2085
File diff suppressed because it is too large
Load Diff
+14
-16
@@ -2,14 +2,15 @@
|
|||||||
"name": "vault-action",
|
"name": "vault-action",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "A Github Action that allows you to consume vault secrets as secure environment variables.",
|
"description": "A Github Action that allows you to consume vault secrets as secure environment variables.",
|
||||||
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build src/entry.js -o dist",
|
"build": "ncc build src/entry.js -o dist",
|
||||||
"test": "jest",
|
"test": "vitest run",
|
||||||
"test:integration:basic": "jest -c integrationTests/basic/jest.config.js",
|
"test:integration:basic": "vitest run -c integrationTests/basic/vitest.config.js",
|
||||||
"test:integration:enterprise": "jest -c integrationTests/enterprise/jest.config.js",
|
"test:integration:enterprise": "vitest run -c integrationTests/enterprise/vitest.config.js",
|
||||||
"test:integration:e2e": "jest -c integrationTests/e2e/jest.config.js",
|
"test:integration:e2e": "vitest run -c integrationTests/e2e/vitest.config.js",
|
||||||
"test:integration:e2e-tls": "jest -c integrationTests/e2e-tls/jest.config.js"
|
"test:integration:e2e-tls": "vitest run -c integrationTests/e2e-tls/vitest.config.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/**/*",
|
"src/**/*",
|
||||||
@@ -34,18 +35,15 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/hashicorp/vault-action#readme",
|
"homepage": "https://github.com/hashicorp/vault-action#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"got": "^11.8.5",
|
"@actions/core": "^1.10.1",
|
||||||
"jsonata": "^2.0.3",
|
"got": "^14.2.1",
|
||||||
"jsrsasign": "^10.8.6"
|
"jsonata": "^2.0.4",
|
||||||
},
|
"jsrsasign": "^11.0.0"
|
||||||
"peerDependencies": {
|
|
||||||
"@actions/core": ">=1 <2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@vercel/ncc": "^0.38.1",
|
||||||
"@vercel/ncc": "^0.36.1",
|
"jest-when": "^3.6.0",
|
||||||
"jest": "^29.5.0",
|
"mock-http-server": "^1.4.5",
|
||||||
"jest-when": "^3.5.2",
|
"vitest": "^1.3.1"
|
||||||
"mock-http-server": "^1.4.5"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-24
@@ -1,9 +1,14 @@
|
|||||||
// @ts-check
|
import core from '@actions/core';
|
||||||
const core = require('@actions/core');
|
import got from 'got';
|
||||||
const command = require('@actions/core/lib/command');
|
|
||||||
const got = require('got').default;
|
import { normalizeOutputKey } from './utils.js';
|
||||||
|
import { WILDCARD } from './constants.js';
|
||||||
|
import { retrieveToken } from './auth.js';
|
||||||
|
import { getSecrets } from './secrets.js';
|
||||||
|
|
||||||
|
// ncc doesn't compile jsonata imports properly, so we must use our own custom require
|
||||||
|
import require from "./cjs-require.js";
|
||||||
const jsonata = require('jsonata');
|
const jsonata = require('jsonata');
|
||||||
const { auth: { retrieveToken }, secrets: { getSecrets } } = require('./index');
|
|
||||||
|
|
||||||
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes', 'ldap', 'userpass'];
|
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes', 'ldap', 'userpass'];
|
||||||
const ENCODING_TYPES = ['base64', 'hex', 'utf8'];
|
const ENCODING_TYPES = ['base64', 'hex', 'utf8'];
|
||||||
@@ -171,7 +176,7 @@ function parseSecretsInput(secretsInput) {
|
|||||||
const selectorAst = jsonata(selectorQuoted).ast();
|
const selectorAst = jsonata(selectorQuoted).ast();
|
||||||
const selector = selectorQuoted.replace(new RegExp('"', 'g'), '');
|
const selector = selectorQuoted.replace(new RegExp('"', 'g'), '');
|
||||||
|
|
||||||
if ((selectorAst.type !== "path" || selectorAst.steps[0].stages) && selectorAst.type !== "string" && !outputVarName) {
|
if (selector !== WILDCARD && (selectorAst.type !== "path" || selectorAst.steps[0].stages) && selectorAst.type !== "string" && !outputVarName) {
|
||||||
throw Error(`You must provide a name for the output key when using json selectors. Input: "${secret}"`);
|
throw Error(`You must provide a name for the output key when using json selectors. Input: "${secret}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,20 +196,6 @@ function parseSecretsInput(secretsInput) {
|
|||||||
return output;
|
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(new RegExp('-', 'g'), '').replace(/[^\p{L}\p{N}_-]/gu, '');
|
|
||||||
if (isEnvVar) {
|
|
||||||
outputKey = outputKey.toUpperCase();
|
|
||||||
}
|
|
||||||
return outputKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} inputKey
|
* @param {string} inputKey
|
||||||
* @param {any} inputOptions
|
* @param {any} inputOptions
|
||||||
@@ -230,9 +221,8 @@ function parseHeadersInput(inputKey, inputOptions) {
|
|||||||
}, new Map());
|
}, new Map());
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
exportSecrets,
|
exportSecrets,
|
||||||
parseSecretsInput,
|
parseSecretsInput,
|
||||||
normalizeOutputKey,
|
parseHeadersInput,
|
||||||
parseHeadersInput
|
}
|
||||||
};
|
|
||||||
|
|||||||
+11
-14
@@ -1,17 +1,17 @@
|
|||||||
jest.mock('got');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core');
|
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
|
|
||||||
const command = require('@actions/core/lib/command');
|
vi.mock('got');
|
||||||
const core = require('@actions/core');
|
vi.mock('@actions/core');
|
||||||
const got = require('got');
|
|
||||||
const {
|
import core from '@actions/core';
|
||||||
|
import got from 'got';
|
||||||
|
import {
|
||||||
exportSecrets,
|
exportSecrets,
|
||||||
parseSecretsInput,
|
parseSecretsInput,
|
||||||
parseHeadersInput
|
parseHeadersInput
|
||||||
} = require('./action');
|
} from './action.js';
|
||||||
|
|
||||||
const { when } = require('jest-when');
|
import { when } from 'jest-when'
|
||||||
|
|
||||||
describe('parseSecretsInput', () => {
|
describe('parseSecretsInput', () => {
|
||||||
it('parses simple secret', () => {
|
it('parses simple secret', () => {
|
||||||
@@ -132,7 +132,7 @@ describe('parseHeaders', () => {
|
|||||||
|
|
||||||
describe('exportSecrets', () => {
|
describe('exportSecrets', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
@@ -223,10 +223,7 @@ describe('exportSecrets', () => {
|
|||||||
it('JSON data secret retrieval', async () => {
|
it('JSON data secret retrieval', async () => {
|
||||||
const jsonData = {"x":1,"y":2};
|
const jsonData = {"x":1,"y":2};
|
||||||
|
|
||||||
// for secrets stored in Vault as pure JSON, we call stringify twice
|
let result = JSON.stringify(jsonData);
|
||||||
// and remove the added surrounding quotes
|
|
||||||
let result = JSON.stringify(JSON.stringify(jsonData));
|
|
||||||
result = result.substring(1, result.length - 1);
|
|
||||||
|
|
||||||
mockInput('test key');
|
mockInput('test key');
|
||||||
mockVaultData({
|
mockVaultData({
|
||||||
|
|||||||
+6
-6
@@ -1,8 +1,8 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
const core = require('@actions/core');
|
import core from '@actions/core';
|
||||||
const rsasign = require('jsrsasign');
|
import * as fs from 'fs';
|
||||||
const fs = require('fs');
|
import got from 'got';
|
||||||
const { default: got } = require('got');
|
import rsasign from 'jsrsasign';
|
||||||
|
|
||||||
const defaultKubernetesTokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token'
|
const defaultKubernetesTokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token'
|
||||||
/***
|
/***
|
||||||
@@ -17,7 +17,7 @@ async function retrieveToken(method, client) {
|
|||||||
switch (method) {
|
switch (method) {
|
||||||
case 'approle': {
|
case 'approle': {
|
||||||
const vaultRoleId = core.getInput('roleId', { required: true });
|
const vaultRoleId = core.getInput('roleId', { required: true });
|
||||||
const vaultSecretId = core.getInput('secretId', { required: true });
|
const vaultSecretId = core.getInput('secretId', { required: false });
|
||||||
return await getClientToken(client, method, path, { role_id: vaultRoleId, secret_id: vaultSecretId });
|
return await getClientToken(client, method, path, { role_id: vaultRoleId, secret_id: vaultSecretId });
|
||||||
}
|
}
|
||||||
case 'github': {
|
case 'github': {
|
||||||
@@ -154,6 +154,6 @@ async function getClientToken(client, method, path, payload) {
|
|||||||
* }} auth
|
* }} auth
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
retrieveToken,
|
retrieveToken,
|
||||||
};
|
};
|
||||||
|
|||||||
+15
-17
@@ -1,22 +1,20 @@
|
|||||||
jest.mock('got');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core');
|
|
||||||
jest.mock('@actions/core/lib/command');
|
vi.mock('got');
|
||||||
jest.mock('fs', () => ({
|
vi.mock('@actions/core');
|
||||||
stat: jest.fn().mockResolvedValue(null),
|
vi.mock('fs', () => ({
|
||||||
|
stat: vi.fn().mockResolvedValue(null),
|
||||||
promises: {
|
promises: {
|
||||||
access: jest.fn().mockResolvedValue(null),
|
access: vi.fn().mockResolvedValue(null),
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const core = require('@actions/core');
|
import core from '@actions/core';
|
||||||
const got = require('got');
|
import got from 'got'
|
||||||
const fs = require("fs")
|
import * as fs from 'fs';
|
||||||
const { when } = require('jest-when');
|
import { when } from 'jest-when'
|
||||||
|
|
||||||
|
import { retrieveToken } from './auth.js';
|
||||||
const {
|
|
||||||
retrieveToken
|
|
||||||
} = require('./auth');
|
|
||||||
|
|
||||||
|
|
||||||
function mockInput(name, key) {
|
function mockInput(name, key) {
|
||||||
@@ -27,7 +25,7 @@ function mockInput(name, key) {
|
|||||||
|
|
||||||
function mockApiResponse() {
|
function mockApiResponse() {
|
||||||
const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } }
|
const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } }
|
||||||
got.post = jest.fn()
|
got.post = vi.fn()
|
||||||
got.post.mockReturnValue(response)
|
got.post.mockReturnValue(response)
|
||||||
}
|
}
|
||||||
const testToken = "testoken";
|
const testToken = "testoken";
|
||||||
@@ -35,7 +33,7 @@ const testToken = "testoken";
|
|||||||
describe("test retrival for token", () => {
|
describe("test retrival for token", () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test retrival with approle", async () => {
|
it("test retrival with approle", async () => {
|
||||||
@@ -76,7 +74,7 @@ describe("test retrival for token", () => {
|
|||||||
mockInput("kubernetesTokenPath", testTokenPath)
|
mockInput("kubernetesTokenPath", testTokenPath)
|
||||||
mockInput("role", testRole)
|
mockInput("role", testRole)
|
||||||
mockInput("path", testPath)
|
mockInput("path", testPath)
|
||||||
fs.readFileSync = jest.fn()
|
fs.readFileSync = vi.fn()
|
||||||
fs.readFileSync.mockReturnValueOnce(jwtToken)
|
fs.readFileSync.mockReturnValueOnce(jwtToken)
|
||||||
const token = await retrieveToken(method, got)
|
const token = await retrieveToken(method, got)
|
||||||
expect(token).toEqual(testToken)
|
expect(token).toEqual(testToken)
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// This allows us to use `require` in our ECMAScript module
|
||||||
|
// See: https://github.com/vercel/ncc/issues/791
|
||||||
|
import { createRequire } from 'node:module';
|
||||||
|
import url from 'node:url';
|
||||||
|
|
||||||
|
const __filename = url.fileURLToPath(import.meta.url);
|
||||||
|
globalThis.require = createRequire(__filename);
|
||||||
|
|
||||||
|
export default require;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
const WILDCARD = '*';
|
||||||
|
|
||||||
|
export {
|
||||||
|
WILDCARD
|
||||||
|
};
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
const core = require('@actions/core');
|
import core from '@actions/core';
|
||||||
const { exportSecrets } = require('./action');
|
import { exportSecrets } from './action.js';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+4
-4
@@ -1,7 +1,7 @@
|
|||||||
const auth = require('./auth');
|
import auth from './auth.js';
|
||||||
const secrets = require('./secrets');
|
import secrets from './secrets.js';
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
auth,
|
auth,
|
||||||
secrets
|
secrets
|
||||||
};
|
};
|
||||||
|
|||||||
+16
-14
@@ -1,17 +1,19 @@
|
|||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
const core = require('@actions/core');
|
vi.mock('@actions/core');
|
||||||
const ServerMock = require("mock-http-server");
|
|
||||||
const { exportSecrets } = require("./action");
|
import core from '@actions/core';
|
||||||
const { when } = require('jest-when');
|
import ServerMock from 'mock-http-server';
|
||||||
|
import { exportSecrets } from './action.js';
|
||||||
|
import { when } from 'jest-when';
|
||||||
|
|
||||||
describe('exportSecrets retries', () => {
|
describe('exportSecrets retries', () => {
|
||||||
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
||||||
var calls = 0;
|
var calls = 0;
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach(() => new Promise(done => {
|
||||||
calls = 0;
|
calls = 0;
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('token', expect.anything())
|
.calledWith('token', expect.anything())
|
||||||
@@ -28,11 +30,11 @@ describe('exportSecrets retries', () => {
|
|||||||
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
afterEach((done) => {
|
afterEach(() => new Promise(done => {
|
||||||
server.stop(done);
|
server.stop(done);
|
||||||
});
|
}));
|
||||||
|
|
||||||
function mockStatusCodes(statusCodes) {
|
function mockStatusCodes(statusCodes) {
|
||||||
server.on({
|
server.on({
|
||||||
@@ -51,19 +53,19 @@ describe('exportSecrets retries', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('retries on 412 status code', (done) => {
|
it('retries on 412 status code', () => new Promise(done => {
|
||||||
mockStatusCodes([412, 200])
|
mockStatusCodes([412, 200])
|
||||||
exportSecrets().then(() => {
|
exportSecrets().then(() => {
|
||||||
expect(calls).toEqual(2);
|
expect(calls).toEqual(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('retries on 500 status code', (done) => {
|
it('retries on 500 status code', () => new Promise(done => {
|
||||||
mockStatusCodes([500, 200])
|
mockStatusCodes([500, 200])
|
||||||
exportSecrets().then(() => {
|
exportSecrets().then(() => {
|
||||||
expect(calls).toEqual(2);
|
expect(calls).toEqual(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
|||||||
+97
-62
@@ -1,4 +1,10 @@
|
|||||||
const jsonata = require("jsonata");
|
import core from '@actions/core';
|
||||||
|
import { WILDCARD } from './constants.js';
|
||||||
|
import { normalizeOutputKey } from './utils.js';
|
||||||
|
|
||||||
|
// ncc doesn't compile jsonata imports properly, so we must use our own custom require
|
||||||
|
import require from "./cjs-require.js";
|
||||||
|
const jsonata = require('jsonata');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,9 +27,10 @@ const jsonata = require("jsonata");
|
|||||||
* @param {import('got').Got} client
|
* @param {import('got').Got} client
|
||||||
* @return {Promise<SecretResponse<TRequest>[]>}
|
* @return {Promise<SecretResponse<TRequest>[]>}
|
||||||
*/
|
*/
|
||||||
async function getSecrets(secretRequests, client) {
|
async function getSecrets(secretRequests, client, ignoreNotFound) {
|
||||||
const responseCache = new Map();
|
const responseCache = new Map();
|
||||||
const results = [];
|
let results = [];
|
||||||
|
|
||||||
for (const secretRequest of secretRequests) {
|
for (const secretRequest of secretRequests) {
|
||||||
let { path, selector } = secretRequest;
|
let { path, selector } = secretRequest;
|
||||||
|
|
||||||
@@ -41,27 +48,65 @@ async function getSecrets(secretRequests, client) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
const {response} = error;
|
const {response} = error;
|
||||||
if (response?.statusCode === 404) {
|
if (response?.statusCode === 404) {
|
||||||
throw Error(`Unable to retrieve result for "${path}" because it was not found: ${response.body.trim()}`)
|
let notFoundMsg = `Unable to retrieve result for "${path}" because it was not found: ${response.body.trim()}`;
|
||||||
|
const ignoreNotFound = (core.getInput('ignoreNotFound', { required: false }) || 'false').toLowerCase() != 'false';
|
||||||
|
if (ignoreNotFound) {
|
||||||
|
core.error(`✘ ${notFoundMsg}`);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
throw Error(notFoundMsg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!selector.match(/.*[\.].*/)) {
|
|
||||||
selector = '"' + selector + '"'
|
|
||||||
}
|
|
||||||
selector = "data." + selector
|
|
||||||
body = JSON.parse(body)
|
|
||||||
if (body.data["data"] != undefined) {
|
|
||||||
selector = "data." + selector
|
|
||||||
}
|
|
||||||
|
|
||||||
const value = await selectData(body, selector);
|
body = JSON.parse(body);
|
||||||
results.push({
|
|
||||||
request: secretRequest,
|
if (selector == WILDCARD) {
|
||||||
value,
|
let keys = body.data;
|
||||||
cachedResponse
|
if (body.data["data"] != undefined) {
|
||||||
});
|
keys = keys.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let key in keys) {
|
||||||
|
let newRequest = Object.assign({},secretRequest);
|
||||||
|
newRequest.selector = key;
|
||||||
|
|
||||||
|
if (secretRequest.selector === secretRequest.outputVarName) {
|
||||||
|
newRequest.outputVarName = key;
|
||||||
|
newRequest.envVarName = key;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newRequest.outputVarName = secretRequest.outputVarName+key;
|
||||||
|
newRequest.envVarName = secretRequest.envVarName+key;
|
||||||
|
}
|
||||||
|
|
||||||
|
newRequest.outputVarName = normalizeOutputKey(newRequest.outputVarName);
|
||||||
|
newRequest.envVarName = normalizeOutputKey(newRequest.envVarName,true);
|
||||||
|
|
||||||
|
selector = key;
|
||||||
|
|
||||||
|
results = await selectAndAppendResults(
|
||||||
|
selector,
|
||||||
|
body,
|
||||||
|
cachedResponse,
|
||||||
|
newRequest,
|
||||||
|
results
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
results = await selectAndAppendResults(
|
||||||
|
selector,
|
||||||
|
body,
|
||||||
|
cachedResponse,
|
||||||
|
secretRequest,
|
||||||
|
results
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,13 +117,7 @@ async function getSecrets(secretRequests, client) {
|
|||||||
*/
|
*/
|
||||||
async function selectData(data, selector) {
|
async function selectData(data, selector) {
|
||||||
const ata = jsonata(selector);
|
const ata = jsonata(selector);
|
||||||
let d = await ata.evaluate(data);
|
let result = JSON.stringify(await ata.evaluate(data));
|
||||||
console.log(selector);
|
|
||||||
|
|
||||||
// If we have a Javascript Object, then this data was stored in Vault as
|
|
||||||
// pure JSON (not a JSON string). We will capture that before we stringify it.
|
|
||||||
const storedAsJSONData = isObject(d);
|
|
||||||
result = JSON.stringify(d);
|
|
||||||
|
|
||||||
// Compat for custom engines
|
// Compat for custom engines
|
||||||
if (!result && ((ata.ast().type === "path" && ata.ast()['steps'].length === 1) || ata.ast().type === "string") && selector !== 'data' && 'data' in data) {
|
if (!result && ((ata.ast().type === "path" && ata.ast()['steps'].length === 1) || ata.ast().type === "string") && selector !== 'data' && 'data' in data) {
|
||||||
@@ -88,53 +127,49 @@ async function selectData(data, selector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result.startsWith(`"`)) {
|
if (result.startsWith(`"`)) {
|
||||||
// we need to strip the beginning and ending quotes otherwise it will
|
|
||||||
// always successfully parse as a JSON string
|
|
||||||
// result = result.substring(1, result.length - 1);
|
|
||||||
// if (!isJSONString(result)) {
|
|
||||||
// // add the quotes back so we can parse it into a Javascript object
|
|
||||||
// // to allow support for multi-line secrets. See https://github.com/hashicorp/vault-action/issues/160
|
|
||||||
// result = `"${result}"`
|
|
||||||
console.log(" =>>> PARSING")
|
|
||||||
result = JSON.parse(result);
|
result = JSON.parse(result);
|
||||||
// }
|
|
||||||
} else {
|
|
||||||
console.log('does not start with quote')
|
|
||||||
// Support secrets stored in Vault as pure JSON.
|
|
||||||
// See https://github.com/hashicorp/vault-action/issues/194 and https://github.com/hashicorp/vault-action/pull/173
|
|
||||||
result = JSON.stringify(result);
|
|
||||||
result = result.substring(1, result.length - 1);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* isOjbect returns true if target is a Javascript object
|
* Uses selectData with the selector to get the value and then appends it to the
|
||||||
* @param {Type} target
|
* results. Returns a new array with all of the results.
|
||||||
|
* @param {string} selector
|
||||||
|
* @param {object} body
|
||||||
|
* @param {object} cachedResponse
|
||||||
|
* @param {TRequest} secretRequest
|
||||||
|
* @param {SecretResponse<TRequest>[]} results
|
||||||
|
* @return {Promise<SecretResponse<TRequest>[]>}
|
||||||
*/
|
*/
|
||||||
function isObject(target) {
|
const selectAndAppendResults = async (
|
||||||
return typeof target === 'object' && target !== null;
|
selector,
|
||||||
}
|
body,
|
||||||
|
cachedResponse,
|
||||||
|
secretRequest,
|
||||||
|
results
|
||||||
|
) => {
|
||||||
|
if (!selector.match(/.*[\.].*/)) {
|
||||||
|
selector = '"' + selector + '"';
|
||||||
|
}
|
||||||
|
selector = "data." + selector;
|
||||||
|
|
||||||
/**
|
if (body.data["data"] != undefined) {
|
||||||
* isJSONString returns true if target parses as a valid JSON string
|
selector = "data." + selector;
|
||||||
* @param {Type} target
|
}
|
||||||
*/
|
|
||||||
function isJSONString(target) {
|
|
||||||
if (typeof target !== "string"){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
const value = await selectData(body, selector);
|
||||||
JSON.parse(target);
|
return [
|
||||||
} catch (e) {
|
...results,
|
||||||
return false;
|
{
|
||||||
}
|
request: secretRequest,
|
||||||
|
value,
|
||||||
|
cachedResponse,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
return true;
|
export {
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getSecrets,
|
getSecrets,
|
||||||
selectData
|
selectData
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* 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(new RegExp("-", "g"), "")
|
||||||
|
.replace(/[^\p{L}\p{N}_-]/gu, "");
|
||||||
|
if (isEnvVar) {
|
||||||
|
outputKey = outputKey.toUpperCase();
|
||||||
|
}
|
||||||
|
return outputKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
normalizeOutputKey
|
||||||
|
};
|
||||||
+1
-1
@@ -9,4 +9,4 @@
|
|||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { defineConfig, configDefaults } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
// required to make jest-when work with vitest
|
||||||
|
globals: true,
|
||||||
|
exclude:[
|
||||||
|
...configDefaults.exclude,
|
||||||
|
'**/integrationTests/**'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user