From 27029021203664da39c6c19d68bf2451224d4cc3 Mon Sep 17 00:00:00 2001 From: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> Date: Mon, 23 Jan 2023 13:36:34 -0600 Subject: [PATCH] UI: PKI URLs section on generate-root form (#18781) --- ui/app/adapters/pki/urls.js | 20 +++ ui/app/models/pki/action.js | 2 + ui/app/models/pki/urls.js | 42 +++++ ui/app/serializers/pki/action.js | 15 +- .../addon/components/pki-configure-form.hbs | 10 +- .../addon/components/pki-generate-root.hbs | 35 +++- .../pki/addon/components/pki-generate-root.js | 31 ++-- .../pki/addon/routes/configuration/create.js | 20 ++- .../addon/templates/configuration/create.hbs | 4 +- .../addon/templates/issuers/generate-root.hbs | 1 - ui/lib/pki/addon/utils/action-params.js | 14 ++ ui/lib/pki/app/utils/action-params.js | 2 + .../pki/pki-engine-workflow-test.js | 52 ++++++ .../secrets/backend/pki/cert-test.js | 18 +- ui/tests/helpers/pki/pki-configure-form.js | 13 ++ ui/tests/helpers/pki/pki-generate-root.js | 17 ++ ui/tests/helpers/pki/pki-issuer-details.js | 1 + ui/tests/helpers/pki/values.js | 126 ++++++++++++++ ui/tests/helpers/pki/workflow.js | 7 + .../components/pki-configure-form-test.js | 7 +- .../components/pki-generate-root-test.js | 54 +++--- .../components/pki/pki-issuer-import-test.js | 51 +----- .../integration/components/text-file-test.js | 21 +-- ui/tests/unit/adapters/pki/action-test.js | 18 +- .../adapters/pki/certificate/sign-test.js | 18 +- ui/tests/unit/adapters/pki/urls-test.js | 48 ++++++ ui/tests/unit/serializers/pki/action-test.js | 162 +++++++++++++++++- 27 files changed, 626 insertions(+), 183 deletions(-) create mode 100644 ui/app/adapters/pki/urls.js create mode 100644 ui/app/models/pki/urls.js create mode 100644 ui/lib/pki/addon/utils/action-params.js create mode 100644 ui/lib/pki/app/utils/action-params.js create mode 100644 ui/tests/helpers/pki/pki-configure-form.js create mode 100644 ui/tests/helpers/pki/pki-generate-root.js create mode 100644 ui/tests/helpers/pki/values.js create mode 100644 ui/tests/unit/adapters/pki/urls-test.js diff --git a/ui/app/adapters/pki/urls.js b/ui/app/adapters/pki/urls.js new file mode 100644 index 000000000..c75f3212c --- /dev/null +++ b/ui/app/adapters/pki/urls.js @@ -0,0 +1,20 @@ +import { encodePath } from 'vault/utils/path-encoding-helpers'; +import ApplicationAdapter from '../application'; + +export default class PkiUrlsAdapter extends ApplicationAdapter { + namespace = 'v1'; + + _url(backend) { + return `${this.buildURL()}/${encodePath(backend)}/config/urls`; + } + + urlForCreateRecord(modelName, snapshot) { + return this._url(snapshot.record.id); + } + urlForFindRecord(id) { + return this._url(id); + } + urlForUpdateRecord(store, type, snapshot) { + return this._url(snapshot.record.id); + } +} diff --git a/ui/app/models/pki/action.js b/ui/app/models/pki/action.js index 499db2f76..07160545e 100644 --- a/ui/app/models/pki/action.js +++ b/ui/app/models/pki/action.js @@ -151,6 +151,8 @@ export default class PkiActionModel extends Model { @attr('string') ttl; @attr('date') notAfter; + @attr('string', { readOnly: true }) issuerId; // returned from generate-root action + get backend() { return this.secretMountPath.currentPath; } diff --git a/ui/app/models/pki/urls.js b/ui/app/models/pki/urls.js new file mode 100644 index 000000000..61c25bf9c --- /dev/null +++ b/ui/app/models/pki/urls.js @@ -0,0 +1,42 @@ +import Model, { attr } from '@ember-data/model'; +import { withFormFields } from 'vault/decorators/model-form-fields'; +import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities'; + +@withFormFields() +export default class PkiUrlsModel extends Model { + // This model uses the backend value as the model ID + get useOpenAPI() { + return true; + } + getHelpUrl(backendPath) { + return `/v1/${backendPath}/config/urls?help=1`; + } + + @attr({ + label: 'Issuing certificates', + subText: + 'The URL values for the Issuing Certificate field. These are different URLs for the same resource, and should be added individually, not in a comma-separated list.', + showHelpText: false, + }) + issuingCertificates; + + @attr({ + label: 'CRL distribution points', + subText: 'Specifies the URL values for the CRL Distribution Points field.', + showHelpText: false, + }) + crlDistributionPoints; + + @attr({ + label: 'OSCP Servers', + subText: 'Specifies the URL values for the OCSP Servers field.', + showHelpText: false, + }) + ocspServers; + + @lazyCapabilities(apiPath`${'id'}/config/urls`, 'id') urlsPath; + + get canSet() { + return this.urlsPath.get('canCreate') !== false; + } +} diff --git a/ui/app/serializers/pki/action.js b/ui/app/serializers/pki/action.js index 1575a3ce1..b4852fe9b 100644 --- a/ui/app/serializers/pki/action.js +++ b/ui/app/serializers/pki/action.js @@ -1,3 +1,5 @@ +import { underscore } from '@ember/string'; +import { keyParamsByType } from 'pki/utils/action-params'; import ApplicationSerializer from '../application'; export default class PkiActionSerializer extends ApplicationSerializer { @@ -9,7 +11,7 @@ export default class PkiActionSerializer extends ApplicationSerializer { serialize(snapshot, requestType) { const data = super.serialize(snapshot); // requestType is a custom value specified from the pki/action adapter - const allowedPayloadAttributes = this._allowedParamsByType(requestType); + const allowedPayloadAttributes = this._allowedParamsByType(requestType, snapshot.record.type); if (!allowedPayloadAttributes) return data; const payload = {}; @@ -21,7 +23,8 @@ export default class PkiActionSerializer extends ApplicationSerializer { return payload; } - _allowedParamsByType(actionType) { + _allowedParamsByType(actionType, type) { + const keyFields = keyParamsByType(type).map((attrName) => underscore(attrName).toLowerCase()); switch (actionType) { case 'import': return ['pem_bundle']; @@ -34,13 +37,7 @@ export default class PkiActionSerializer extends ApplicationSerializer { 'format', 'ip_sans', 'issuer_name', - 'key_bits', - 'key_name', - 'key_ref', - 'key_type', 'locality', - 'managed_key_id', - 'managed_key_name', 'max_path_length', 'not_after', 'not_before_duration', @@ -53,7 +50,9 @@ export default class PkiActionSerializer extends ApplicationSerializer { 'province', 'serial_number', 'street_address', + 'ttl', 'type', + ...keyFields, ]; default: // if type doesn't match, serialize all diff --git a/ui/lib/pki/addon/components/pki-configure-form.hbs b/ui/lib/pki/addon/components/pki-configure-form.hbs index bbe7ae043..2ddfc8360 100644 --- a/ui/lib/pki/addon/components/pki-configure-form.hbs +++ b/ui/lib/pki/addon/components/pki-configure-form.hbs @@ -31,20 +31,24 @@ {{else if (eq this.actionType "generate-root")}} {{else if (eq this.actionType "generate-csr")}} POST /intermediate/generate/:type ~or~ /issuers/generate/intermediate/:type {{else}} - +