node-vault-client 0.5.0 → 0.5.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-vault-client",
3
- "version": "0.5.0",
3
+ "version": "0.5.6",
4
4
  "description": "A Vault Client implemented in pure javascript for HashiCorp Vault. It supports variety of Auth Backends and performs lease renewal for issued auth token.",
5
5
  "repository": "github:namecheap/node-vault-client",
6
6
  "engines": {
@@ -147,7 +147,7 @@ class VaultClient {
147
147
  api,
148
148
  this.__log,
149
149
  authConfig.config,
150
- authConfig.mount,
150
+ authConfig.mount
151
151
  );
152
152
  }
153
153
 
@@ -1,41 +1,47 @@
1
+ const fs = require('fs');
1
2
  const VaultBaseAuth = require('./VaultBaseAuth');
2
- const readFile = require('../utils/readFile');
3
3
 
4
4
  class VaultKubernetesAuth extends VaultBaseAuth {
5
5
  /**
6
6
  * @param {VaultApiClient} apiClient - see {@link VaultBaseAuth#constructor}
7
7
  * @param {Object} config
8
- * @param {String} config.role - Role of the Kubernetes.
9
- * @param {String} [config.jwt] - Your service jwt token.
8
+ * @param {String} config.role - Role configured in Vault Kubernetes Auth backend under which we want to issue Vault token.
9
+ * @param {String} [config.tokenPath] - Path to the Kube JWT token. If omitted - default will be used.
10
10
  * @param {String} mount - Vault's mount point ("kubernetes" by default)
11
11
  */
12
12
  constructor(apiClient, logger, config, mount) {
13
13
  super(apiClient, logger, mount || 'kubernetes');
14
14
 
15
15
  this.__role = config.role;
16
- this.__filePath = '/var/run/secrets/kubernetes.io/serviceaccount/token';
16
+ this.__tokenPath = '/var/run/secrets/kubernetes.io/serviceaccount/token';
17
+ if (config.tokenPath !== undefined) {
18
+ this.__tokenPath = config.tokenPath;
19
+ }
17
20
  }
18
21
 
19
22
  _authenticate() {
20
23
  this._log.info(
21
- 'making authentication request: role_id=%s',
22
- this.__roleId,
24
+ 'making authentication request: Vault role: "%s"; K8s token path: "%s"',
25
+ this.__role, this.__tokenPath
23
26
  );
24
27
 
25
- return readFile(this.__filePath)
26
- .then((jwt) => {
27
- this.__apiClient.makeRequest('POST', `/auth/${this._mount}/login`, {
28
- role: this.__role,
29
- jwt,
30
- });
31
- })
32
- .then((res) => {
33
- this._log.debug(
34
- 'receive token: %s',
35
- res.auth.client_token,
36
- );
37
- return this._getTokenEntity(res.auth.client_token);
38
- });
28
+ const k8sJwtToken = fs.readFileSync(this.__tokenPath).toString();
29
+ this._log.debug(
30
+ 'receive K8s token: %s',
31
+ k8sJwtToken
32
+ );
33
+
34
+ return this.__apiClient.makeRequest('POST', `/auth/${this._mount}/login`, {
35
+ role: this.__role,
36
+ jwt: k8sJwtToken,
37
+ }).then((res) => {
38
+ this._log.debug(
39
+ 'receive token: %s',
40
+ res.auth.client_token
41
+ );
42
+
43
+ return this._getTokenEntity(res.auth.client_token);
44
+ });
39
45
  }
40
46
  }
41
47
 
@@ -1,7 +0,0 @@
1
- const { readFile } = require('fs');
2
-
3
- module.exports = function (filePath) {
4
- return new Promise((resolve, reject) => {
5
- readFile(filePath, (err, data) => (err ? reject(err) : resolve(data)));
6
- });
7
- };