Closed jmls closed 8 years ago
Here is an example I just used against an already initialized and unsealed Vault:
var vault = new Vault({
vault_host: '127.0.0.1',
vault_port: 8200,
vault_ssl: 0
});
return vault.prepare().then(function () {
return vault.createToken({id: 'trial'}).then(function (token) {
console.log('token:', token);
});
});
token: { lease_id: '',
renewable: false,
lease_duration: 0,
data: null,
warnings: null,
auth:
{ client_token: 'be8d8f1b-e78e-c6da-01d6-7a0a0c85131f',
policies: [ 'root' ],
metadata: null,
lease_duration: 0,
renewable: false } }
If you are not leaving the backup_dir
option because it is a pre-existing Vault, then after setting your token from before, the prepare
method will initialize the internal state of Vaulted
with the Vault by doing the lookup of the initialization, seal-status, etc.
Otherwise you would need to orchestrate the calls to configure the actual state of the Vault within Vaulted manually.
I'm trying to use your sample above, but get the message
unhandled rejection Error: Vault has not been initialized.
the vault is unsealed
jmls@40e1f73476ad:/tmp>curl http://localhost:8200/v1/sys/seal-status
{"sealed":false,"t":3,"n":5,"progress":0}
pretty sure I've got v2
{
"name": "vaulted",
"version": "2.0.0",
"description": "A nodejs wrapper library for using HashiCorp's Vault",
"main": "index.js",
so I don't know what's happening :(
looking through lib/vaulted.js it seems to me that Vaulted.prototype.validateEndpoint checks the this.initialized flag to make sure everything is ready.
However, the only time this flag is set is during the Vaulted.prototype.setKeys function, so if I don't call it, initialized is always false
For security reasons, I don't know the keys ... so how can I set them ?
update
ok, so if I also add
vault.setToken("myToken");
vault.setKeys(["fake"]);
then everything works as expected
For existing Vaults, you would need to either set the Tokens and key(s) manually, such that calling prepare can properly set the Vault state into Vaulted, or if those values were backed up at the BACKUP_DIR
location then when calling prepare it will recover those values from the backup and set it for you automatically.
That flow needs better documentation.
Glad it is working for you now!
right - but obviously you don't need valid keys - so why not dispense with the requirement to call setKeys() just in order to mark vault as initialized. The keys are only needed for certain operations, so it is just a step to have to go through for no reason.
Just saying ;)
done via commit 22245793654245887f33eec021e37ed7b9a08788
cool. thanks
Using the v2.0.0 tag code, when I try to call the createToken(options) method of vaulted, I get the following error:
however, if I call the sealStatus() method, I get
which would imply that the vault is in fact initialised