mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-07 15:16:56 +00:00
Update to v2.3.0 (#231)
This commit is contained in:
parent
b6210c5a51
commit
0451f06f9f
3 changed files with 26 additions and 9 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## 2.3.0 (June 23rd, 2021)
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
* K8s auth method is now supported [GH-218](https://github.com/hashicorp/vault-action/pull/218)
|
* K8s auth method is now supported [GH-218](https://github.com/hashicorp/vault-action/pull/218)
|
||||||
* Custom auth method mount points is configurable [GH-218](https://github.com/hashicorp/vault-action/pull/218)
|
* Custom auth method mount points is configurable [GH-218](https://github.com/hashicorp/vault-action/pull/218)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
# ...
|
# ...
|
||||||
- name: Import Secrets
|
- name: Import Secrets
|
||||||
uses: hashicorp/vault-action@v2.2.0
|
uses: hashicorp/vault-action@v2.3.0
|
||||||
with:
|
with:
|
||||||
url: https://vault.mycompany.com:8200
|
url: https://vault.mycompany.com:8200
|
||||||
token: ${{ secrets.VaultToken }}
|
token: ${{ secrets.VaultToken }}
|
||||||
|
|
|
||||||
31
dist/index.js
vendored
31
dist/index.js
vendored
|
|
@ -976,22 +976,26 @@ exports.default = parseBody;
|
||||||
// @ts-check
|
// @ts-check
|
||||||
const core = __webpack_require__(470);
|
const core = __webpack_require__(470);
|
||||||
const rsasign = __webpack_require__(758);
|
const rsasign = __webpack_require__(758);
|
||||||
|
const fs = __webpack_require__(747);
|
||||||
|
|
||||||
|
const defaultKubernetesTokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token'
|
||||||
/***
|
/***
|
||||||
* Authenticate with Vault and retrieve a Vault token that can be used for requests.
|
* Authenticate with Vault and retrieve a Vault token that can be used for requests.
|
||||||
* @param {string} method
|
* @param {string} method
|
||||||
* @param {import('got').Got} client
|
* @param {import('got').Got} client
|
||||||
*/
|
*/
|
||||||
async function retrieveToken(method, client) {
|
async function retrieveToken(method, client) {
|
||||||
|
const path = core.getInput('path', { required: false }) || method;
|
||||||
|
|
||||||
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: true });
|
||||||
return await getClientToken(client, method, { role_id: vaultRoleId, secret_id: vaultSecretId });
|
return await getClientToken(client, method, path, { role_id: vaultRoleId, secret_id: vaultSecretId });
|
||||||
}
|
}
|
||||||
case 'github': {
|
case 'github': {
|
||||||
const githubToken = core.getInput('githubToken', { required: true });
|
const githubToken = core.getInput('githubToken', { required: true });
|
||||||
return await getClientToken(client, method, { token: githubToken });
|
return await getClientToken(client, method, path, { token: githubToken });
|
||||||
}
|
}
|
||||||
case 'jwt': {
|
case 'jwt': {
|
||||||
const role = core.getInput('role', { required: true });
|
const role = core.getInput('role', { required: true });
|
||||||
|
|
@ -1000,8 +1004,18 @@ async function retrieveToken(method, client) {
|
||||||
const keyPassword = core.getInput('jwtKeyPassword', { required: false });
|
const keyPassword = core.getInput('jwtKeyPassword', { required: false });
|
||||||
const tokenTtl = core.getInput('jwtTtl', { required: false }) || '3600'; // 1 hour
|
const tokenTtl = core.getInput('jwtTtl', { required: false }) || '3600'; // 1 hour
|
||||||
const jwt = generateJwt(privateKey, keyPassword, Number(tokenTtl));
|
const jwt = generateJwt(privateKey, keyPassword, Number(tokenTtl));
|
||||||
return await getClientToken(client, method, { jwt: jwt, role: role });
|
return await getClientToken(client, method, path, { jwt: jwt, role: role });
|
||||||
}
|
}
|
||||||
|
case 'kubernetes': {
|
||||||
|
const role = core.getInput('role', { required: true })
|
||||||
|
const tokenPath = core.getInput('kubernetesTokenPath', { required: false }) || defaultKubernetesTokenPath
|
||||||
|
const data = fs.readFileSync(tokenPath, 'utf8')
|
||||||
|
if (!(role && data) && data != "") {
|
||||||
|
throw new Error("Role Name must be set and a kubernetes token must set")
|
||||||
|
}
|
||||||
|
return await getClientToken(client, method, path, { jwt: data, role: role })
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
if (!method || method === 'token') {
|
if (!method || method === 'token') {
|
||||||
return core.getInput('token', { required: true });
|
return core.getInput('token', { required: true });
|
||||||
|
|
@ -1011,7 +1025,7 @@ async function retrieveToken(method, client) {
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
throw Error('When using a custom authentication method, you must provide the payload');
|
throw Error('When using a custom authentication method, you must provide the payload');
|
||||||
}
|
}
|
||||||
return await getClientToken(client, method, JSON.parse(payload.trim()));
|
return await getClientToken(client, method, path, JSON.parse(payload.trim()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1047,9 +1061,10 @@ function generateJwt(privateKey, keyPassword, ttl) {
|
||||||
* Call the appropriate login endpoint and parse out the token in the response.
|
* Call the appropriate login endpoint and parse out the token in the response.
|
||||||
* @param {import('got').Got} client
|
* @param {import('got').Got} client
|
||||||
* @param {string} method
|
* @param {string} method
|
||||||
|
* @param {string} path
|
||||||
* @param {any} payload
|
* @param {any} payload
|
||||||
*/
|
*/
|
||||||
async function getClientToken(client, method, payload) {
|
async function getClientToken(client, method, path, payload) {
|
||||||
/** @type {'json'} */
|
/** @type {'json'} */
|
||||||
const responseType = 'json';
|
const responseType = 'json';
|
||||||
var options = {
|
var options = {
|
||||||
|
|
@ -1057,10 +1072,10 @@ async function getClientToken(client, method, payload) {
|
||||||
responseType,
|
responseType,
|
||||||
};
|
};
|
||||||
|
|
||||||
core.debug(`Retrieving Vault Token from v1/auth/${method}/login endpoint`);
|
core.debug(`Retrieving Vault Token from v1/auth/${path}/login endpoint`);
|
||||||
|
|
||||||
/** @type {import('got').Response<VaultLoginResponse>} */
|
/** @type {import('got').Response<VaultLoginResponse>} */
|
||||||
const response = await client.post(`v1/auth/${method}/login`, options);
|
const response = await client.post(`v1/auth/${path}/login`, options);
|
||||||
if (response && response.body && response.body.auth && response.body.auth.client_token) {
|
if (response && response.body && response.body.auth && response.body.auth.client_token) {
|
||||||
core.debug('✔ Vault Token successfully retrieved');
|
core.debug('✔ Vault Token successfully retrieved');
|
||||||
|
|
||||||
|
|
@ -14577,7 +14592,7 @@ const got = __webpack_require__(77).default;
|
||||||
const jsonata = __webpack_require__(350);
|
const jsonata = __webpack_require__(350);
|
||||||
const { auth: { retrieveToken }, secrets: { getSecrets } } = __webpack_require__(676);
|
const { auth: { retrieveToken }, secrets: { getSecrets } } = __webpack_require__(676);
|
||||||
|
|
||||||
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt'];
|
const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes'];
|
||||||
|
|
||||||
async function exportSecrets() {
|
async function exportSecrets() {
|
||||||
const vaultUrl = core.getInput('url', { required: true });
|
const vaultUrl = core.getInput('url', { required: true });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue