vault/ui/app/models/secret-engine.js
Vault Automation b593ca128e
Backport [VAULT-40813] ManageDropdown component into ce/main (#12508)
* [VAULT-40813] ManageDropdown component (#12295)

* [VAULT-40813] ManageDropdown component

* address pr comments, add routing test coverage

* fix test: generate policy is an enterprise-only feature

---------

Co-authored-by: Shannon Roberts (Beagin) <beagins@users.noreply.github.com>
Co-authored-by: Shannon Roberts <shannon.roberts@hashicorp.com>
2026-02-25 10:37:43 -08:00

283 lines
9.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Copyright IBM Corp. 2016, 2025
* SPDX-License-Identifier: BUSL-1.1
*/
import Model, { attr, belongsTo } from '@ember-data/model';
import { ALL_ENGINES, isAddonEngine } from 'core/utils/all-engines-metadata';
import { withExpandedAttributes } from 'vault/decorators/model-expanded-attributes';
import { withModelValidations } from 'vault/decorators/model-validations';
import engineDisplayData from 'vault/helpers/engines-display-data';
import { supportedSecretBackends } from 'vault/helpers/supported-secret-backends';
import { INTERNAL_ENGINE_TYPES } from 'vault/utils/all-engines-metadata';
import { getEffectiveEngineType } from 'vault/utils/external-plugin-helpers';
import { WHITESPACE_WARNING } from 'vault/utils/forms/validators';
const LINKED_BACKENDS = supportedSecretBackends();
const validations = {
path: [
{ type: 'presence', message: "Path can't be blank." },
{
type: 'containsWhiteSpace',
message: WHITESPACE_WARNING('path'),
level: 'warn',
},
],
maxVersions: [
{ type: 'number', message: 'Maximum versions must be a number.' },
{ type: 'length', options: { min: 1, max: 16 }, message: 'You cannot go over 16 characters.' },
],
};
@withModelValidations(validations)
@withExpandedAttributes()
export default class SecretEngineModel extends Model {
@attr('string') path;
@attr('string') type;
@attr('string', {
editType: 'textarea',
})
description;
@belongsTo('mount-config', { async: false, inverse: null }) config;
// Enterprise options (still available on OSS)
@attr('boolean', {
helpText:
'When Replication is enabled, a local mount will not be replicated across clusters. This can only be specified at mount time.',
})
local;
@attr('boolean', {
helpText:
'When enabled - if a seal supporting seal wrapping is specified in the configuration, all critical security parameters (CSPs) in this backend will be seal wrapped. (For KV mounts, all values will be seal wrapped.) This can only be specified at mount time.',
})
sealWrap;
@attr('boolean') externalEntropyAccess;
// options.version
@attr('number', {
label: 'Version',
helpText:
'The KV Secrets Engine can operate in different modes. Version 1 is the original generic Secrets Engine the allows for storing of static key/value pairs. Version 2 added more features including data versioning, TTLs, and check and set.',
possibleValues: [2, 1],
// This shouldn't be defaultValue because if no version comes back from API we should assume it's v1
defaultFormValue: 2, // Set the form to 2 by default
})
version;
// AWS specific attributes
@attr('string') lease;
@attr('string') leaseMax;
// Returned from API response
@attr('string') accessor;
// KV 2 additional config default options
@attr('number', {
defaultValue: 0,
label: 'Maximum number of versions',
subText:
'The number of versions to keep per key. Once the number of keys exceeds the maximum number set here, the oldest version will be permanently deleted. This value applies to all keys, but a keys metadata settings can overwrite this value. When 0 is used or the value is unset, Vault will keep 10 versions.',
})
maxVersions;
@attr('boolean', {
defaultValue: false,
label: 'Require Check and Set',
subText:
'If checked, all keys will require the cas parameter to be set on all write requests. A keys metadata settings can overwrite this value.',
})
casRequired;
@attr({
defaultValue: 0,
editType: 'ttl',
label: 'Automate secret deletion',
helperTextDisabled: 'A secrets version must be manually deleted.',
helperTextEnabled: 'Delete all new versions of this secret after',
})
deleteVersionAfter;
// `plugin_version` represents the version specified at mount time (if any), and is only used for external plugins.
// For built-in plugins, this field is intentionally left empty to simplify upgrades.
//
// `running_plugin_version` reflects the actual version of the plugin currently running,
// regardless of whether it is built-in or external. This provides a reliable source of truth
// and is why we are surfacing it over plugin_version.
@attr('string') runningPluginVersion;
/* GETTERS */
get isV2KV() {
const effectiveType = getEffectiveEngineType(this.engineType);
return this.version === 2 && ['kv', 'generic'].includes(effectiveType);
}
get attrs() {
return this.formFields.map((fieldName) => {
return this.allByKey[fieldName];
});
}
get fieldGroups() {
return this._expandGroups(this.formFieldGroups);
}
get icon() {
const engineData = engineDisplayData(this.engineType);
return engineData?.glyph || 'lock';
}
get engineType() {
return (this.type || '').replace(/^ns_/, '');
}
get shouldIncludeInList() {
return !INTERNAL_ENGINE_TYPES.includes(this.engineType);
}
get isSupportedBackend() {
return LINKED_BACKENDS.includes(this.engineType);
}
get backendLink() {
const effectiveType = getEffectiveEngineType(this.engineType);
if (effectiveType === 'database') {
return 'vault.cluster.secrets.backend.overview';
}
if (isAddonEngine(effectiveType, this.version)) {
return `vault.cluster.secrets.backend.${engineDisplayData(effectiveType).engineRoute}`;
}
if (this.isV2KV) {
// if it's KV v2 but not registered as an addon, it's type generic
return 'vault.cluster.secrets.backend.kv.list';
}
return `vault.cluster.secrets.backend.list-root`;
}
get backendConfigurationLink() {
const effectiveType = getEffectiveEngineType(this.engineType);
if (isAddonEngine(effectiveType, this.version)) {
return `vault.cluster.secrets.backend.${effectiveType}.configuration`;
}
return `vault.cluster.secrets.backend.configuration.general-settings`;
}
get localDisplay() {
return this.local ? 'local' : 'replicated';
}
get formFields() {
const type = this.engineType;
const fields = ['type', 'path', 'description', 'accessor', 'runningPluginVersion', 'local', 'sealWrap'];
// no ttl options for keymgmt
if (type !== 'keymgmt') {
fields.push('config.defaultLeaseTtl', 'config.maxLeaseTtl');
}
fields.push(
'config.allowedManagedKeys',
'config.auditNonHmacRequestKeys',
'config.auditNonHmacResponseKeys',
'config.passthroughRequestHeaders',
'config.allowedResponseHeaders'
);
if (type === 'kv' || type === 'generic') {
fields.push('version');
}
// version comes in as number not string
if (type === 'kv' && parseInt(this.version, 10) === 2) {
fields.push('casRequired', 'deleteVersionAfter', 'maxVersions');
}
// For WIF Secret engines, allow users to set the identity token key when mounting the engine.
if (engineDisplayData(type)?.isWIF) {
fields.push('config.identityTokenKey');
}
return fields;
}
get formFieldGroups() {
let defaultFields = ['path'];
let optionFields;
const CORE_OPTIONS = ['description', 'config.listingVisibility', 'local', 'sealWrap'];
const STANDARD_CONFIG = [
'config.auditNonHmacRequestKeys',
'config.auditNonHmacResponseKeys',
'config.passthroughRequestHeaders',
'config.allowedResponseHeaders',
'config.plugin_version',
];
switch (this.engineType) {
case 'kv':
defaultFields = ['path', 'maxVersions', 'casRequired', 'deleteVersionAfter'];
optionFields = [
'version',
...CORE_OPTIONS,
'config.defaultLeaseTtl',
'config.maxLeaseTtl',
'config.allowedManagedKeys',
...STANDARD_CONFIG,
];
break;
case 'generic':
optionFields = [
'version',
...CORE_OPTIONS,
'config.defaultLeaseTtl',
'config.maxLeaseTtl',
'config.allowedManagedKeys',
...STANDARD_CONFIG,
];
break;
case 'database':
// Highlight TTLs in default
defaultFields = ['path', 'config.defaultLeaseTtl', 'config.maxLeaseTtl'];
optionFields = [...CORE_OPTIONS, 'config.allowedManagedKeys', ...STANDARD_CONFIG];
break;
case 'pki':
defaultFields = ['path', 'config.defaultLeaseTtl', 'config.maxLeaseTtl', 'config.allowedManagedKeys'];
optionFields = [...CORE_OPTIONS, ...STANDARD_CONFIG];
break;
case 'keymgmt':
// no ttl options for keymgmt
optionFields = [...CORE_OPTIONS, 'config.allowedManagedKeys', ...STANDARD_CONFIG];
break;
case ALL_ENGINES.find((engine) => engine.type === this.engineType && engine.isWIF)?.type:
defaultFields = ['path'];
optionFields = [
...CORE_OPTIONS,
'config.defaultLeaseTtl',
'config.maxLeaseTtl',
'config.identityTokenKey',
'config.allowedManagedKeys',
...STANDARD_CONFIG,
];
break;
default:
defaultFields = ['path'];
optionFields = [
...CORE_OPTIONS,
'config.defaultLeaseTtl',
'config.maxLeaseTtl',
'config.allowedManagedKeys',
...STANDARD_CONFIG,
];
break;
}
return [
{ default: defaultFields },
{
'Method Options': optionFields,
},
];
}
/* ACTIONS */
saveZeroAddressConfig() {
return this.save({
adapterOptions: {
adapterMethod: 'saveZeroAddressConfig',
},
});
}
}