Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions features.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
`POST /auth/{{mount_point}}{{^mount_point}}approle{{/mount_point}}/role/{{role_name}}/secret-id`


## vault.generateRootStatus

`GET /sys/generate-root/attempt`


## vault.generateRootInit

`PUT /sys/generate-root/attempt`
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ declare namespace NodeVault {
init(options?: Option): Promise<any>;
unseal(options?: Option): Promise<any>;
seal(options?: Option): Promise<any>;
generateRootStatus(options?: Option): Promise<any>;
generateRootInit(options?: Option): Promise<any>;
generateRootCancel(options?: Option): Promise<any>;
generateRootUpdate(options?: Option): Promise<any>;
Expand Down
129 changes: 103 additions & 26 deletions src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,32 +208,72 @@ module.exports = {
path: '/auth/{{mount_point}}{{^mount_point}}{{kubernetesPath}}{{/mount_point}}/role/{{ role_name }}',
schema: {
req: {
name: {
type: 'string',
},
bound_cidrs: {
type: 'array',
},
bound_service_account_names: {
type: 'array',
},
bound_service_account_namespaces: {
type: 'array',
},
ttl: {
type: 'integer',
},
max_ttl: {
type: 'integer',
},
policies: {
type: 'array',
},
num_uses: {
type: 'integer',
},
period: {
type: 'integer',
type: 'object',
properties: {
bound_service_account_names: {
type: ['array', 'string'],
},
bound_service_account_namespaces: {
type: ['array', 'string'],
},
bound_service_account_namespace_selector: {
type: 'string',
},
audience: {
type: 'string',
},
alias_name_source: {
type: 'string',
},
alias_metadata: {
type: ['object', 'array'],
},
token_policies: {
type: ['array', 'string'],
},
token_ttl: {
type: ['integer', 'string'],
},
token_max_ttl: {
type: ['integer', 'string'],
},
token_explicit_max_ttl: {
type: ['integer', 'string'],
},
token_period: {
type: ['integer', 'string'],
},
token_bound_cidrs: {
type: ['array', 'string'],
},
token_num_uses: {
type: 'integer',
},
token_no_default_policy: {
type: 'boolean',
},
token_type: {
type: 'string',
},
// Deprecated aliases of the token_* fields; Vault still accepts them.
policies: {
type: ['array', 'string'],
},
ttl: {
type: ['integer', 'string'],
},
max_ttl: {
type: ['integer', 'string'],
},
period: {
type: ['integer', 'string'],
},
bound_cidrs: {
type: ['array', 'string'],
},
num_uses: {
type: 'integer',
},
},
},
},
Expand Down Expand Up @@ -341,6 +381,38 @@ module.exports = {
}
},
},
generateRootStatus: {
method: 'GET',
path: '/sys/generate-root/attempt',
schema: {
res: {
type: 'object',
properties: {
started: {
type: 'boolean',
},
nonce: {
type: 'string',
},
progress: {
type: 'integer',
minimum: 0,
},
required: {
type: 'integer',
minimum: 1,
},
pgp_fingerprint: {
type: 'string',
},
complete: {
type: 'boolean',
},
},
required: ['started', 'nonce', 'progress', 'required', 'pgp_fingerprint', 'complete'],
},
},
},
generateRootInit: {
method: 'PUT',
path: '/sys/generate-root/attempt',
Expand Down Expand Up @@ -759,6 +831,11 @@ module.exports = {
schema: {
req: {
type: 'object',
properties: {
name: {
type: 'string',
},
},
},
res: tokenResponse,
},
Expand Down
100 changes: 100 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,106 @@ describe('node-vault', () => {
});
});

describe('auth and sys commands', () => {
it('should send addKubernetesRole settings as the request body', (done) => {
const settings = {
bound_service_account_names: 'app',
bound_service_account_namespaces: ['default'],
audience: 'vault',
token_policies: ['read-only'],
token_ttl: '1h',
token_bound_cidrs: ['10.0.0.0/8'],
};
vault.addKubernetesRole({ role_name: 'my-role', ...settings })
.then(() => {
request.should.have.calledOnce();
const options = request.firstCall.args[0];
options.method.should.equal('POST');
options.path.should.equal('/auth/kubernetes/role/my-role');
options.json.should.deep.equal(settings);
done();
})
.catch(done);
});

it('should still send the deprecated addKubernetesRole field names', (done) => {
const settings = { policies: 'read-only,audit', ttl: 3600, num_uses: 5 };
vault.addKubernetesRole({ role_name: 'my-role', ...settings })
.then(() => {
request.firstCall.args[0].json.should.deep.equal(settings);
done();
})
.catch(done);
});

it('should reject addKubernetesRole settings of the wrong type without a request', (done) => {
vault.addKubernetesRole({ role_name: 'my-role', token_num_uses: 'many' })
.then(() => done(new Error('expected a validation error')))
.catch((err) => {
err.message.should.contain('Invalid type');
request.should.not.have.been.called();
done();
})
.catch(done);
});

it('should not send per-call requestOptions as the certLogin body', (done) => {
response.body = { auth: { client_token: 'cert-token' } };
vault.certLogin({ requestOptions: { cert: 'client-cert', key: 'client-key' } })
.then(() => {
const options = request.firstCall.args[0];
options.path.should.equal('/auth/cert/login');
expect(options.json).to.be.undefined();
options.cert.should.equal('client-cert');
done();
})
.catch(done);
});

it('should send the certLogin role name as the request body', (done) => {
response.body = { auth: { client_token: 'cert-token' } };
vault.certLogin({ name: 'web' })
.then(() => {
request.should.have.calledOnce();
const options = request.firstCall.args[0];
options.method.should.equal('POST');
options.path.should.equal('/auth/cert/login');
options.json.should.deep.equal({ name: 'web' });
vault.token.should.equal('cert-token');
done();
})
.catch(done);
});

it('should call generateRootStatus with correct path and method', (done) => {
const params = {
method: 'GET',
path: '/sys/generate-root/attempt',
};
vault.generateRootStatus()
.then(assertRequest(request, params, done))
.catch(done);
});
});

describe('command definitions', () => {
// extendOptions only forwards args named in schema.req/query.properties,
// so a schema without them silently breaks its command.
it('should declare an object schema with properties for every req and query', () => {
const malformed = [];
Object.keys(vault.commands).forEach((name) => {
const { schema } = vault.commands[name];
['req', 'query'].forEach((part) => {
const s = schema && schema[part];
if (s && (s.type !== 'object' || !s.properties || typeof s.properties !== 'object')) {
malformed.push(`${name}.schema.${part}`);
}
});
});
malformed.should.deep.equal([]);
});
});

describe('commands export', () => {
it('should expose commands object on client', () => {
vault.commands.should.be.an('object');
Expand Down
Loading