Compare commits

..

3 Commits

Author SHA1 Message Date
Richard Simpson 9878eba70a chore: rebuild action 2020-04-07 12:16:27 -05:00
Richard Simpson 83d944ba1a fix: actually allow custom methods 2020-04-07 12:14:02 -05:00
Richard Simpson 567ec72c33 fix: document custom authentication method 2020-04-07 12:09:06 -05:00
3 changed files with 44 additions and 29 deletions
+5 -2
View File
@@ -45,7 +45,7 @@ jobs:
## Authentication method
While most workflows will likely use a vault token, you can also use an `approle` to authenticate with vaule. You can configure which by using the `method` parameter:
While most workflows will likely use a vault token, you can also use an `approle` to authenticate with Vault. You can configure which by using the `method` parameter:
- **token**: (by default) you must provide a `token` parameter
```yaml
@@ -72,6 +72,8 @@ with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
```
If any other method is specified and you provide an `authPayload`, the action will attempt to `POST` to `auth/${method}/login` with the provided payload and parse out the client token.
## Key Syntax
The `secrets` parameter is a set of multiple secret requests separated by the `;` character.
@@ -97,7 +99,7 @@ with:
NPMTOKEN=somelongtoken
```
You can also access the secret via ouputs:
You can also access the secret via outputs:
```yaml
steps:
@@ -285,6 +287,7 @@ Here is all the inputs available through `with`:
| `roleId` | The Role Id for App Role authentication | | |
| `secretId` | The Secret Id for App Role authentication | | |
| `githubToken` | The Github Token to be used to authenticate with Vault | | |
| `authPayload` | The JSON payload to be sent to Vault when using a custom authentication method. | | |
| `extraHeaders` | A string of newline separated extra headers to include on every request. | | |
| `exportEnv` | Whether or not export secrets as environment variables. | `true` | |
+36 -25
View File
@@ -1557,12 +1557,13 @@ module.exports.iterator = (emitter, event, options) => {
/***/ 151:
/***/ (function(module, __unusedexports, __webpack_require__) {
// @ts-check
const core = __webpack_require__(470);
/***
* Authentication with Vault and retrieve a vault token
* Authenticate with Vault and retrieve a Vault token that can be used for requests.
* @param {string} method
* @param {import('got')} client
* @param {import('got').Got} client
*/
async function retrieveToken(method, client) {
switch (method) {
@@ -1591,31 +1592,52 @@ async function retrieveToken(method, client) {
}
/***
* Authentication with Vault and retrieve a vault token
* @param {import('got')} client
* Call the appropriate login endpoint and parse out the token in the response.
* @param {import('got').Got} client
* @param {string} method
* @param {any} payload
*/
async function getClientToken(client, method, payload) {
/** @type {any} */
/** @type {'json'} */
const responseType = 'json';
var options = {
json: payload,
responseType: 'json'
responseType,
};
core.debug(`Retrieving Vault Token from v1/auth/${method}/login endpoint`);
/** @type {import('got').Response<VaultLoginResponse>} */
const response = await client.post(`v1/auth/${method}/login`, options);
if (response && response.body && response.body.auth && response.body.auth.client_token) {
core.debug('✔ Vault Token successfully retrieved');
core.startGroup('Token Info');
core.debug(`Operating under policies: ${JSON.stringify(response.body.auth.policies)}`);
core.debug(`Token Metadata: ${JSON.stringify(response.body.auth.metadata)}`);
core.endGroup();
return response.body.auth.client_token;
} else {
throw Error(`Unable to retrieve token from ${method}'s login endpoint.`);
}
}
/***
* @typedef {Object} VaultLoginResponse
* @property {{
* client_token: string;
* accessor: string;
* policies: string[];
* metadata: unknown;
* lease_duration: number;
* renewable: boolean;
* }} auth
*/
module.exports = {
retrieveToken
}
retrieveToken,
};
/***/ }),
@@ -5711,11 +5733,9 @@ module.exports = require("dns");
/***/ (function(module, __unusedexports, __webpack_require__) {
// @ts-check
// @ts-ignore
const core = __webpack_require__(470);
// @ts-ignore
const command = __webpack_require__(431);
const got = __webpack_require__(77);
const got = __webpack_require__(77).default;
const { retrieveToken } = __webpack_require__(151);
const AUTH_METHODS = ['approle', 'token', 'github'];
@@ -5728,14 +5748,16 @@ async function exportSecrets() {
const exportEnv = core.getInput('exportEnv', { required: false }) != 'false';
let enginePath = core.getInput('path', { required: false });
/** @type {number | string} */
let kvVersion = core.getInput('kv-version', { required: false });
const secretsInput = core.getInput('secrets', { required: true });
const secretRequests = parseSecretsInput(secretsInput);
const vaultMethod = (core.getInput('method', { required: false }) || 'token').toLowerCase();
if (!AUTH_METHODS.includes(vaultMethod)) {
throw Error(`Sorry, the authentication method ${vaultMethod} is not currently supported.`);
const authPayload = core.getInput('authPayload', { required: false });
if (!AUTH_METHODS.includes(vaultMethod) && !authPayload) {
throw Error(`Sorry, the provided authentication method ${vaultMethod} is not currently supported and no custom authPayload was provided.`);
}
const defaultOptions = {
@@ -5752,7 +5774,7 @@ async function exportSecrets() {
}
const client = got.extend(defaultOptions);
const vaultToken = await retrieveToken(vaultMethod, /** @type {any} */ (client));
const vaultToken = await retrieveToken(vaultMethod, client);
if (!enginePath) {
enginePath = 'secret';
@@ -5921,17 +5943,6 @@ function normalizeOutputKey(dataKey) {
return dataKey.replace('/', '__').replace(/[^\w-]/, '').toUpperCase();
}
// @ts-ignore
/**
* @param {string} input
*/
function parseBoolInput(input) {
if (input === null || input === undefined || input.trim() === '') {
return null;
}
return Boolean(input);
}
/**
* @param {string} inputKey
* @param {any} inputOptions
+3 -2
View File
@@ -21,8 +21,9 @@ async function exportSecrets() {
const secretRequests = parseSecretsInput(secretsInput);
const vaultMethod = (core.getInput('method', { required: false }) || 'token').toLowerCase();
if (!AUTH_METHODS.includes(vaultMethod)) {
throw Error(`Sorry, the authentication method ${vaultMethod} is not currently supported.`);
const authPayload = core.getInput('authPayload', { required: false });
if (!AUTH_METHODS.includes(vaultMethod) && !authPayload) {
throw Error(`Sorry, the provided authentication method ${vaultMethod} is not currently supported and no custom authPayload was provided.`);
}
const defaultOptions = {