@@ -976,22 +976,26 @@ exports.default = parseBody;
976976// @ts-check
977977const core = __webpack_require__(470);
978978const rsasign = __webpack_require__(758);
979+ const fs = __webpack_require__(747);
979980
981+ const defaultKubernetesTokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token'
980982/***
981983 * Authenticate with Vault and retrieve a Vault token that can be used for requests.
982984 * @param {string} method
983985 * @param {import('got').Got} client
984986 */
985987async function retrieveToken(method, client) {
988+ const path = core.getInput('path', { required: false }) || method;
989+
986990 switch (method) {
987991 case 'approle': {
988992 const vaultRoleId = core.getInput('roleId', { required: true });
989993 const vaultSecretId = core.getInput('secretId', { required: true });
990- return await getClientToken(client, method, { role_id: vaultRoleId, secret_id: vaultSecretId });
994+ return await getClientToken(client, method, path, { role_id: vaultRoleId, secret_id: vaultSecretId });
991995 }
992996 case 'github': {
993997 const githubToken = core.getInput('githubToken', { required: true });
994- return await getClientToken(client, method, { token: githubToken });
998+ return await getClientToken(client, method, path, { token: githubToken });
995999 }
9961000 case 'jwt': {
9971001 const role = core.getInput('role', { required: true });
@@ -1000,8 +1004,18 @@ async function retrieveToken(method, client) {
10001004 const keyPassword = core.getInput('jwtKeyPassword', { required: false });
10011005 const tokenTtl = core.getInput('jwtTtl', { required: false }) || '3600'; // 1 hour
10021006 const jwt = generateJwt(privateKey, keyPassword, Number(tokenTtl));
1003- return await getClientToken(client, method, { jwt: jwt, role: role });
1007+ return await getClientToken(client, method, path, { jwt: jwt, role: role });
1008+ }
1009+ case 'kubernetes': {
1010+ const role = core.getInput('role', { required: true })
1011+ const tokenPath = core.getInput('kubernetesTokenPath', { required: false }) || defaultKubernetesTokenPath
1012+ const data = fs.readFileSync(tokenPath, 'utf8')
1013+ if (!(role && data) && data != "") {
1014+ throw new Error("Role Name must be set and a kubernetes token must set")
1015+ }
1016+ return await getClientToken(client, method, path, { jwt: data, role: role })
10041017 }
1018+
10051019 default: {
10061020 if (!method || method === 'token') {
10071021 return core.getInput('token', { required: true });
@@ -1011,7 +1025,7 @@ async function retrieveToken(method, client) {
10111025 if (!payload) {
10121026 throw Error('When using a custom authentication method, you must provide the payload');
10131027 }
1014- return await getClientToken(client, method, JSON.parse(payload.trim()));
1028+ return await getClientToken(client, method, path, JSON.parse(payload.trim()));
10151029 }
10161030 }
10171031 }
@@ -1047,20 +1061,21 @@ function generateJwt(privateKey, keyPassword, ttl) {
10471061 * Call the appropriate login endpoint and parse out the token in the response.
10481062 * @param {import('got').Got} client
10491063 * @param {string} method
1064+ * @param {string} path
10501065 * @param {any} payload
10511066 */
1052- async function getClientToken(client, method, payload) {
1067+ async function getClientToken(client, method, path, payload) {
10531068 /** @type {'json'} */
10541069 const responseType = 'json';
10551070 var options = {
10561071 json: payload,
10571072 responseType,
10581073 };
10591074
1060- core.debug(`Retrieving Vault Token from v1/auth/${method }/login endpoint`);
1075+ core.debug(`Retrieving Vault Token from v1/auth/${path }/login endpoint`);
10611076
10621077 /** @type {import('got').Response<VaultLoginResponse>} */
1063- const response = await client.post(`v1/auth/${method }/login`, options);
1078+ const response = await client.post(`v1/auth/${path }/login`, options);
10641079 if (response && response.body && response.body.auth && response.body.auth.client_token) {
10651080 core.debug('✔ Vault Token successfully retrieved');
10661081
@@ -14577,7 +14592,7 @@ const got = __webpack_require__(77).default;
1457714592const jsonata = __webpack_require__(350);
1457814593const { auth: { retrieveToken }, secrets: { getSecrets } } = __webpack_require__(676);
1457914594
14580- const AUTH_METHODS = ['approle', 'token', 'github', 'jwt'];
14595+ const AUTH_METHODS = ['approle', 'token', 'github', 'jwt', 'kubernetes' ];
1458114596
1458214597async function exportSecrets() {
1458314598 const vaultUrl = core.getInput('url', { required: true });
0 commit comments