mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-07-26 00:13:16 +03:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b8899915e | |||
| a5f6c67fe1 | |||
| d9197ec2d2 | |||
| cb841f2c86 | |||
| 0010502df7 |
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
* Add changes here
|
* Add changes here
|
||||||
|
|
||||||
|
## 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)
|
## 2.7.2 (July 6, 2023)
|
||||||
|
|
||||||
Bugs:
|
Bugs:
|
||||||
|
|||||||
@@ -76,7 +76,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
|
||||||
# ...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -373,6 +373,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
|
||||||
|
|
||||||
|
|||||||
Vendored
+128
-43
@@ -3702,6 +3702,7 @@ function asPromise(normalizedOptions) {
|
|||||||
request._beforeError(new types_1.HTTPError(response));
|
request._beforeError(new types_1.HTTPError(response));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
request.destroy();
|
||||||
resolve(request.options.resolveBodyOnly ? response.body : response);
|
resolve(request.options.resolveBodyOnly ? response.body : response);
|
||||||
});
|
});
|
||||||
const onError = (error) => {
|
const onError = (error) => {
|
||||||
@@ -18516,6 +18517,9 @@ const core = __nccwpck_require__(2186);
|
|||||||
const command = __nccwpck_require__(7351);
|
const command = __nccwpck_require__(7351);
|
||||||
const got = (__nccwpck_require__(3061)["default"]);
|
const got = (__nccwpck_require__(3061)["default"]);
|
||||||
const jsonata = __nccwpck_require__(4245);
|
const jsonata = __nccwpck_require__(4245);
|
||||||
|
const { normalizeOutputKey } = __nccwpck_require__(1608);
|
||||||
|
const { WILDCARD } = __nccwpck_require__(4438);
|
||||||
|
|
||||||
const { auth: { retrieveToken }, secrets: { getSecrets } } = __nccwpck_require__(4351);
|
const { auth: { retrieveToken }, secrets: { getSecrets } } = __nccwpck_require__(4351);
|
||||||
|
|
||||||
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes', 'ldap', 'userpass'];
|
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes', 'ldap', 'userpass'];
|
||||||
@@ -18684,7 +18688,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}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18704,20 +18708,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
|
||||||
@@ -18746,11 +18736,11 @@ function parseHeadersInput(inputKey, inputOptions) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
exportSecrets,
|
exportSecrets,
|
||||||
parseSecretsInput,
|
parseSecretsInput,
|
||||||
normalizeOutputKey,
|
parseHeadersInput,
|
||||||
parseHeadersInput
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 4915:
|
/***/ 4915:
|
||||||
@@ -18917,6 +18907,17 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 4438:
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
const WILDCARD = '*';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
WILDCARD
|
||||||
|
};
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 4351:
|
/***/ 4351:
|
||||||
@@ -18936,8 +18937,8 @@ module.exports = {
|
|||||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||||
|
|
||||||
const jsonata = __nccwpck_require__(4245);
|
const jsonata = __nccwpck_require__(4245);
|
||||||
|
const { WILDCARD } = __nccwpck_require__(4438);
|
||||||
|
const { normalizeOutputKey } = __nccwpck_require__(1608);
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} SecretRequest
|
* @typedef {Object} SecretRequest
|
||||||
* @property {string} path
|
* @property {string} path
|
||||||
@@ -18960,7 +18961,8 @@ const jsonata = __nccwpck_require__(4245);
|
|||||||
*/
|
*/
|
||||||
async function getSecrets(secretRequests, client) {
|
async function getSecrets(secretRequests, client) {
|
||||||
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;
|
||||||
|
|
||||||
@@ -18983,22 +18985,53 @@ async function getSecrets(secretRequests, client) {
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!selector.match(/.*[\.].*/)) {
|
|
||||||
selector = '"' + selector + '"'
|
body = JSON.parse(body);
|
||||||
}
|
|
||||||
selector = "data." + selector
|
if (selector == WILDCARD) {
|
||||||
body = JSON.parse(body)
|
let keys = body.data;
|
||||||
if (body.data["data"] != undefined) {
|
if (body.data["data"] != undefined) {
|
||||||
selector = "data." + selector
|
keys = keys.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = await selectData(body, selector);
|
for (let key in keys) {
|
||||||
results.push({
|
let newRequest = Object.assign({},secretRequest);
|
||||||
request: secretRequest,
|
newRequest.selector = key;
|
||||||
value,
|
|
||||||
cachedResponse
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19019,28 +19052,80 @@ async function selectData(data, selector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result.startsWith(`"`)) {
|
if (result.startsWith(`"`)) {
|
||||||
// Support multi-line secrets like JSON strings and ssh keys, see https://github.com/hashicorp/vault-action/pull/173
|
|
||||||
// Deserialize the value so that newlines and special characters are
|
|
||||||
// not escaped in our return value.
|
|
||||||
result = JSON.parse(result);
|
result = JSON.parse(result);
|
||||||
} else {
|
|
||||||
// Support secrets stored in Vault as pure JSON, see https://github.com/hashicorp/vault-action/issues/194
|
|
||||||
// Serialize the value so that any special characters in the data are
|
|
||||||
// properly escaped.
|
|
||||||
result = JSON.stringify(result);
|
|
||||||
// strip the surrounding quotes added by stringify because the data did
|
|
||||||
// not have them in the first place
|
|
||||||
result = result.substring(1, result.length - 1);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses selectData with the selector to get the value and then appends it to the
|
||||||
|
* 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>[]>}
|
||||||
|
*/
|
||||||
|
const selectAndAppendResults = async (
|
||||||
|
selector,
|
||||||
|
body,
|
||||||
|
cachedResponse,
|
||||||
|
secretRequest,
|
||||||
|
results
|
||||||
|
) => {
|
||||||
|
if (!selector.match(/.*[\.].*/)) {
|
||||||
|
selector = '"' + selector + '"';
|
||||||
|
}
|
||||||
|
selector = "data." + selector;
|
||||||
|
|
||||||
|
if (body.data["data"] != undefined) {
|
||||||
|
selector = "data." + selector;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = await selectData(body, selector);
|
||||||
|
return [
|
||||||
|
...results,
|
||||||
|
{
|
||||||
|
request: secretRequest,
|
||||||
|
value,
|
||||||
|
cachedResponse,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getSecrets,
|
getSecrets,
|
||||||
selectData
|
selectData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 1608:
|
||||||
|
/***/ ((module) => {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
normalizeOutputKey
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 9491:
|
/***/ 9491:
|
||||||
|
|||||||
@@ -171,6 +171,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 +215,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 +273,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 ;
|
||||||
|
|||||||
@@ -12,9 +12,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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -72,6 +72,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 +119,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');
|
||||||
|
|
||||||
|
|||||||
Generated
+7
-7
@@ -9,7 +9,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"got": "^11.8.5",
|
"got": "^11.8.6",
|
||||||
"jsonata": "^2.0.3",
|
"jsonata": "^2.0.3",
|
||||||
"jsrsasign": "^10.8.6"
|
"jsrsasign": "^10.8.6"
|
||||||
},
|
},
|
||||||
@@ -2150,9 +2150,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/got": {
|
"node_modules/got": {
|
||||||
"version": "11.8.5",
|
"version": "11.8.6",
|
||||||
"resolved": "https://registry.npmjs.org/got/-/got-11.8.5.tgz",
|
"resolved": "https://registry.npmjs.org/got/-/got-11.8.6.tgz",
|
||||||
"integrity": "sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ==",
|
"integrity": "sha512-6tfZ91bOr7bOXnK7PRDCGBLa1H4U080YHNaAQ2KsMGlLEzRbk44nsZF2E1IeRc3vtJHPVbKCYgdFbaGO2ljd8g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sindresorhus/is": "^4.0.0",
|
"@sindresorhus/is": "^4.0.0",
|
||||||
"@szmarczak/http-timer": "^4.0.5",
|
"@szmarczak/http-timer": "^4.0.5",
|
||||||
@@ -5975,9 +5975,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"got": {
|
"got": {
|
||||||
"version": "11.8.5",
|
"version": "11.8.6",
|
||||||
"resolved": "https://registry.npmjs.org/got/-/got-11.8.5.tgz",
|
"resolved": "https://registry.npmjs.org/got/-/got-11.8.6.tgz",
|
||||||
"integrity": "sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ==",
|
"integrity": "sha512-6tfZ91bOr7bOXnK7PRDCGBLa1H4U080YHNaAQ2KsMGlLEzRbk44nsZF2E1IeRc3vtJHPVbKCYgdFbaGO2ljd8g==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@sindresorhus/is": "^4.0.0",
|
"@sindresorhus/is": "^4.0.0",
|
||||||
"@szmarczak/http-timer": "^4.0.5",
|
"@szmarczak/http-timer": "^4.0.5",
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/hashicorp/vault-action#readme",
|
"homepage": "https://github.com/hashicorp/vault-action#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"got": "^11.8.5",
|
"got": "^11.8.6",
|
||||||
"jsonata": "^2.0.3",
|
"jsonata": "^2.0.3",
|
||||||
"jsrsasign": "^10.8.6"
|
"jsrsasign": "^10.8.6"
|
||||||
},
|
},
|
||||||
|
|||||||
+6
-17
@@ -3,6 +3,9 @@ const core = require('@actions/core');
|
|||||||
const command = require('@actions/core/lib/command');
|
const command = require('@actions/core/lib/command');
|
||||||
const got = require('got').default;
|
const got = require('got').default;
|
||||||
const jsonata = require('jsonata');
|
const jsonata = require('jsonata');
|
||||||
|
const { normalizeOutputKey } = require('./utils');
|
||||||
|
const { WILDCARD } = require('./constants');
|
||||||
|
|
||||||
const { auth: { retrieveToken }, secrets: { getSecrets } } = require('./index');
|
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'];
|
||||||
@@ -171,7 +174,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 +194,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
|
||||||
@@ -233,6 +222,6 @@ function parseHeadersInput(inputKey, inputOptions) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
exportSecrets,
|
exportSecrets,
|
||||||
parseSecretsInput,
|
parseSecretsInput,
|
||||||
normalizeOutputKey,
|
parseHeadersInput,
|
||||||
parseHeadersInput
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -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 surrounding quotes
|
|
||||||
let result = JSON.stringify(JSON.stringify(jsonData));
|
|
||||||
result = result.substring(1, result.length - 1);
|
|
||||||
|
|
||||||
mockInput('test key');
|
mockInput('test key');
|
||||||
mockVaultData({
|
mockVaultData({
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
const WILDCARD = '*';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
WILDCARD
|
||||||
|
};
|
||||||
+84
-26
@@ -1,6 +1,6 @@
|
|||||||
const jsonata = require("jsonata");
|
const jsonata = require("jsonata");
|
||||||
|
const { WILDCARD } = require("./constants");
|
||||||
|
const { normalizeOutputKey } = require("./utils");
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} SecretRequest
|
* @typedef {Object} SecretRequest
|
||||||
* @property {string} path
|
* @property {string} path
|
||||||
@@ -23,7 +23,8 @@ const jsonata = require("jsonata");
|
|||||||
*/
|
*/
|
||||||
async function getSecrets(secretRequests, client) {
|
async function getSecrets(secretRequests, client) {
|
||||||
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;
|
||||||
|
|
||||||
@@ -46,22 +47,53 @@ async function getSecrets(secretRequests, client) {
|
|||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!selector.match(/.*[\.].*/)) {
|
|
||||||
selector = '"' + selector + '"'
|
body = JSON.parse(body);
|
||||||
}
|
|
||||||
selector = "data." + selector
|
if (selector == WILDCARD) {
|
||||||
body = JSON.parse(body)
|
let keys = body.data;
|
||||||
if (body.data["data"] != undefined) {
|
if (body.data["data"] != undefined) {
|
||||||
selector = "data." + selector
|
keys = keys.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = await selectData(body, selector);
|
for (let key in keys) {
|
||||||
results.push({
|
let newRequest = Object.assign({},secretRequest);
|
||||||
request: secretRequest,
|
newRequest.selector = key;
|
||||||
value,
|
|
||||||
cachedResponse
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,22 +114,48 @@ async function selectData(data, selector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result.startsWith(`"`)) {
|
if (result.startsWith(`"`)) {
|
||||||
// Support multi-line secrets like JSON strings and ssh keys, see https://github.com/hashicorp/vault-action/pull/173
|
|
||||||
// Deserialize the value so that newlines and special characters are
|
|
||||||
// not escaped in our return value.
|
|
||||||
result = JSON.parse(result);
|
result = JSON.parse(result);
|
||||||
} else {
|
|
||||||
// Support secrets stored in Vault as pure JSON, see https://github.com/hashicorp/vault-action/issues/194
|
|
||||||
// Serialize the value so that any special characters in the data are
|
|
||||||
// properly escaped.
|
|
||||||
result = JSON.stringify(result);
|
|
||||||
// strip the surrounding quotes added by stringify because the data did
|
|
||||||
// not have them in the first place
|
|
||||||
result = result.substring(1, result.length - 1);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses selectData with the selector to get the value and then appends it to the
|
||||||
|
* 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>[]>}
|
||||||
|
*/
|
||||||
|
const selectAndAppendResults = async (
|
||||||
|
selector,
|
||||||
|
body,
|
||||||
|
cachedResponse,
|
||||||
|
secretRequest,
|
||||||
|
results
|
||||||
|
) => {
|
||||||
|
if (!selector.match(/.*[\.].*/)) {
|
||||||
|
selector = '"' + selector + '"';
|
||||||
|
}
|
||||||
|
selector = "data." + selector;
|
||||||
|
|
||||||
|
if (body.data["data"] != undefined) {
|
||||||
|
selector = "data." + selector;
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = await selectData(body, selector);
|
||||||
|
return [
|
||||||
|
...results,
|
||||||
|
{
|
||||||
|
request: secretRequest,
|
||||||
|
value,
|
||||||
|
cachedResponse,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
normalizeOutputKey
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user