2018-04-03 14:16:57 +00:00
|
|
|
// This model represents the capabilities on a given `path`
|
|
|
|
// `path` is also the primaryId
|
|
|
|
// https://www.vaultproject.io/docs/concepts/policies.html#capabilities
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
import { computed } from '@ember/object';
|
2018-04-03 14:16:57 +00:00
|
|
|
import DS from 'ember-data';
|
|
|
|
|
|
|
|
const { attr } = DS;
|
|
|
|
|
|
|
|
const SUDO_PATHS = [
|
|
|
|
'sys/seal',
|
|
|
|
'sys/replication/performance/primary/secondary-token',
|
|
|
|
'sys/replication/dr/primary/secondary-token',
|
|
|
|
'sys/replication/reindex',
|
|
|
|
'sys/leases/lookup/',
|
|
|
|
];
|
|
|
|
|
|
|
|
const SUDO_PATH_PREFIXES = ['sys/leases/revoke-prefix', 'sys/leases/revoke-force'];
|
|
|
|
|
|
|
|
export { SUDO_PATHS, SUDO_PATH_PREFIXES };
|
|
|
|
|
|
|
|
const computedCapability = function(capability) {
|
2018-09-25 16:28:26 +00:00
|
|
|
return computed('path', 'capabilities', 'capabilities.[]', function() {
|
2018-04-03 14:16:57 +00:00
|
|
|
const capabilities = this.get('capabilities');
|
|
|
|
const path = this.get('path');
|
|
|
|
if (!capabilities) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (capabilities.includes('root')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (capabilities.includes('deny')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// if the path is sudo protected, they'll need sudo + the appropriate capability
|
2018-10-31 15:24:36 +00:00
|
|
|
if (SUDO_PATHS.includes(path) || SUDO_PATH_PREFIXES.find(item => path.startsWith(item))) {
|
2018-04-03 14:16:57 +00:00
|
|
|
return capabilities.includes('sudo') && capabilities.includes(capability);
|
|
|
|
}
|
|
|
|
return capabilities.includes(capability);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DS.Model.extend({
|
|
|
|
path: attr('string'),
|
|
|
|
capabilities: attr('array'),
|
|
|
|
canSudo: computedCapability('sudo'),
|
|
|
|
canRead: computedCapability('read'),
|
|
|
|
canCreate: computedCapability('create'),
|
|
|
|
canUpdate: computedCapability('update'),
|
|
|
|
canDelete: computedCapability('delete'),
|
|
|
|
canList: computedCapability('list'),
|
|
|
|
allowedParameters: attr(),
|
|
|
|
deniedParameters: attr(),
|
|
|
|
});
|