Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
feat: Vault namespace support (#403)
Browse files Browse the repository at this point in the history
* Grab the vault namespace from the environment

* Apply the Vault Namespace header

* fix: Missing space on if statement

* Doc: Adding documentation referencing how to use `VAULT_NAMESPACE`
  • Loading branch information
rimitchell authored Jun 18, 2020
1 parent 7190120 commit 6bd9570
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ spec:
property: api-key
```
If you use Vault Namespaces (a Vault Enterprise feature) you can set the namespace to interact with via the `VAULT_NAMESPACE` environment variable.

If Vault uses a certificate issued by a self-signed CA you will need to provide that certificate:

```sh
Expand Down
4 changes: 4 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ if (environment === 'development') {
}

const vaultEndpoint = process.env.VAULT_ADDR || 'http://127.0.0.1:8200'
// Grab the vault namespace from the environment
const vaultNamespace = process.env.VAULT_NAMESPACE || null

const pollerIntervalMilliseconds = process.env.POLLER_INTERVAL_MILLISECONDS
? Number(process.env.POLLER_INTERVAL_MILLISECONDS) : 10000

Expand All @@ -32,6 +35,7 @@ const customResourceManagerDisabled = 'DISABLE_CUSTOM_RESOURCE_MANAGER' in proce

module.exports = {
vaultEndpoint,
vaultNamespace,
environment,
pollerIntervalMilliseconds,
metricsPort,
Expand Down
12 changes: 10 additions & 2 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,23 @@ const systemManagerBackend = new SystemManagerBackend({
assumeRole: awsConfig.assumeRole,
logger
})
const vaultClient = vault({
const vaultOptions = {
apiVersion: 'v1',
endpoint: envConfig.vaultEndpoint,
requestOptions: {
// When running vault in HA mode, you must follow redirects on PUT/POST/DELETE
// See: https://github.com/kr1sp1n/node-vault/issues/23
followAllRedirects: true
}
})
}
// Include the Vault Namespace header if we have provided it as an env var.
// See: https://github.com/kr1sp1n/node-vault/pull/137#issuecomment-585309687
if (envConfig.vaultNamespace) {
vaultOptions.headers = {
'X-VAULT-NAMESPACE': envConfig.vaultNamespace
}
}
const vaultClient = vault(vaultOptions)
const vaultBackend = new VaultBackend({ client: vaultClient, logger })
const azureKeyVaultBackend = new AzureKeyVaultBackend({
credential: azureConfig.azureKeyVault(),
Expand Down

0 comments on commit 6bd9570

Please sign in to comment.