vvauth 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +16 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -56,17 +56,17 @@ class vvauth {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
this.
|
|
59
|
+
this.VAULT_ADDR = this.rc.vault_addr;
|
|
60
60
|
|
|
61
|
-
if(!this.
|
|
61
|
+
if(!this.VAULT_ADDR)
|
|
62
62
|
throw `Invalid vault remote`;
|
|
63
63
|
|
|
64
64
|
this.VAULT_TOKEN = process.env.VAULT_TOKEN;
|
|
65
|
-
console.error("vauth bound to '%s'", this.
|
|
65
|
+
console.error("vauth bound to '%s'", this.VAULT_ADDR);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
async connect() {
|
|
69
|
-
let
|
|
69
|
+
let VAULT_TOKEN, {rc : {ssh_auth, jwt_auth}} = this;
|
|
70
70
|
|
|
71
71
|
if(!VAULT_TOKEN && ssh_auth && process.env.SSH_AUTH_SOCK)
|
|
72
72
|
VAULT_TOKEN = await this._login_vault_ssh({...ssh_auth});
|
|
@@ -90,7 +90,7 @@ class vvauth {
|
|
|
90
90
|
_publish_env(env) {
|
|
91
91
|
let cmds = [];
|
|
92
92
|
for(let [k, v] of Object.entries(env)) {
|
|
93
|
-
cmds.push(`export ${k}
|
|
93
|
+
cmds.push(`export ${k}=${shellEscape(v)}`);
|
|
94
94
|
cmds.push(`echo export ${k}=[redacted] >&2`);
|
|
95
95
|
}
|
|
96
96
|
process.stdout.write(cmds.join("\n") + "\n");
|
|
@@ -136,7 +136,7 @@ class vvauth {
|
|
|
136
136
|
async env(source = false) {
|
|
137
137
|
let {profile} = await this._get_profile();
|
|
138
138
|
|
|
139
|
-
let env = {VAULT_TOKEN : this.VAULT_TOKEN}, secrets = {},
|
|
139
|
+
let env = {VAULT_TOKEN : this.VAULT_TOKEN, VAULT_ADDR : this.VAULT_ADDR}, secrets = {},
|
|
140
140
|
{git, map = {}, paths, path : mount = "secrets"} = this.rc.env || {};
|
|
141
141
|
|
|
142
142
|
if(git) {
|
|
@@ -166,7 +166,7 @@ class vvauth {
|
|
|
166
166
|
|
|
167
167
|
|
|
168
168
|
async _read(mount, secret_path) {
|
|
169
|
-
let remote_url = `${trim(this.
|
|
169
|
+
let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/${mount}/data/${trim(secret_path, '/')}`;
|
|
170
170
|
let query = {...url.parse(remote_url), headers : {'x-vault-token' : this.VAULT_TOKEN}, expect : 200};
|
|
171
171
|
let res = await request(query);
|
|
172
172
|
return get(JSON.parse(String(await drain(res))), 'data.data');
|
|
@@ -184,7 +184,7 @@ class vvauth {
|
|
|
184
184
|
if(token)
|
|
185
185
|
return;
|
|
186
186
|
|
|
187
|
-
let remote_url = `${trim(this.
|
|
187
|
+
let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/auth/${path}/nonce`;
|
|
188
188
|
let query = {...url.parse(remote_url), json : true};
|
|
189
189
|
let res = await request(query);
|
|
190
190
|
let {data : {nonce}} = JSON.parse(String(await drain(res)));
|
|
@@ -227,7 +227,7 @@ class vvauth {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
async _lookup_token(token) {
|
|
230
|
-
let remote_url = `${trim(this.
|
|
230
|
+
let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/auth/token/lookup-self`;
|
|
231
231
|
let query = {...url.parse(remote_url), headers : {'x-vault-token' : token}, expect : 200};
|
|
232
232
|
let res = await request(query);
|
|
233
233
|
let response = JSON.parse(await drain(res)).data;
|
|
@@ -235,14 +235,14 @@ class vvauth {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
async _lookup_identity(token, id) {
|
|
238
|
-
let remote_url = `${trim(this.
|
|
238
|
+
let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/identity/entity/id/${id}`;
|
|
239
239
|
let query = {...url.parse(remote_url), headers : {'x-vault-token' : token}, expect : 200};
|
|
240
240
|
let res = await request(query);
|
|
241
241
|
return JSON.parse(String(await drain(res))).data;
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
async _update_identity(token, id, payload) {
|
|
245
|
-
let remote_url = `${trim(this.
|
|
245
|
+
let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/identity/entity/id/${id}`;
|
|
246
246
|
let query = {...url.parse(remote_url), headers : {'x-vault-token' : token}, expect : 204, json : true};
|
|
247
247
|
await request(query, payload);
|
|
248
248
|
return payload;
|
|
@@ -251,7 +251,7 @@ class vvauth {
|
|
|
251
251
|
|
|
252
252
|
|
|
253
253
|
async _login_vault(path, payload) {
|
|
254
|
-
let remote_url = `${trim(this.
|
|
254
|
+
let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/auth/${path}/login`;
|
|
255
255
|
let query = {...url.parse(remote_url), json : true};
|
|
256
256
|
let res = await request(query, payload);
|
|
257
257
|
let response = String(await drain(res));
|
|
@@ -266,6 +266,10 @@ class vvauth {
|
|
|
266
266
|
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
const shellEscape = (arg) => {
|
|
270
|
+
return arg.replace(/([$!'"();`*?{}[\]<>&%#~@\\ ])/g, '\\$1');
|
|
271
|
+
};
|
|
272
|
+
|
|
269
273
|
//ensure module is called directly, i.e. not required
|
|
270
274
|
if(module.parent === null)
|
|
271
275
|
require('cnyks/lib/bundle')(vvauth);
|