From 67ba021e36361d714c90783eaa4ec21f4213875e Mon Sep 17 00:00:00 2001 From: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> Date: Fri, 25 Feb 2022 12:16:54 -0600 Subject: [PATCH] UI: add Database static role password rotation (#14268) * Add UI feature allowing database role credential rotation * Only show the 'rotate credentials' option for static roles * rotate role path uses id for permissions * Add rotate credentials button to show page on static role * Mirage handlers for role for simple testing * Add changelog * lint rules * fix lint Co-authored-by: Bartek Marczak --- changelog/14268.txt | 3 +++ ui/app/adapters/database/credential.js | 7 +++++ ui/app/components/database-role-edit.js | 13 +++++++++ .../secret-list/database-list-item.js | 13 +++++++++ ui/app/models/database/role.js | 2 ++ .../components/database-role-edit.hbs | 5 ++++ .../secret-list/database-list-item.hbs | 7 +++++ ui/mirage/handlers/db.js | 27 +++++++++++++++++++ ui/mirage/handlers/index.js | 3 ++- 9 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 changelog/14268.txt create mode 100644 ui/mirage/handlers/db.js diff --git a/changelog/14268.txt b/changelog/14268.txt new file mode 100644 index 000000000..85de0a898 --- /dev/null +++ b/changelog/14268.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: Allow static role credential rotation in Database secrets engines +``` diff --git a/ui/app/adapters/database/credential.js b/ui/app/adapters/database/credential.js index 6f7763e2e..b3652c2ff 100644 --- a/ui/app/adapters/database/credential.js +++ b/ui/app/adapters/database/credential.js @@ -47,4 +47,11 @@ export default ApplicationAdapter.extend({ queryRecord(store, type, query) { return this.fetchByQuery(store, query); }, + + rotateRoleCredentials(backend, id) { + return this.ajax( + `${this.buildURL()}/${encodeURIComponent(backend)}/rotate-role/${encodeURIComponent(id)}`, + 'POST' + ); + }, }); diff --git a/ui/app/components/database-role-edit.js b/ui/app/components/database-role-edit.js index 988396b52..ff8d8b60a 100644 --- a/ui/app/components/database-role-edit.js +++ b/ui/app/components/database-role-edit.js @@ -108,4 +108,17 @@ export default class DatabaseRoleEdit extends Component { this.loading = false; }); } + @action + rotateRoleCred(id) { + const backend = this.args.model?.backend; + let adapter = this.store.adapterFor('database/credential'); + adapter + .rotateRoleCredentials(backend, id) + .then(() => { + this.flashMessages.success(`Success: Credentials for ${id} role were rotated`); + }) + .catch((e) => { + this.flashMessages.danger(e.errors); + }); + } } diff --git a/ui/app/components/secret-list/database-list-item.js b/ui/app/components/secret-list/database-list-item.js index 76663617c..32b057248 100644 --- a/ui/app/components/secret-list/database-list-item.js +++ b/ui/app/components/secret-list/database-list-item.js @@ -58,4 +58,17 @@ export default class DatabaseListItem extends Component { this.flashMessages.danger(e.errors); }); } + @action + rotateRoleCred(id) { + const { backend } = this.args.item; + let adapter = this.store.adapterFor('database/credential'); + adapter + .rotateRoleCredentials(backend, id) + .then(() => { + this.flashMessages.success(`Success: Credentials for ${id} role were rotated`); + }) + .catch((e) => { + this.flashMessages.danger(e.errors); + }); + } } diff --git a/ui/app/models/database/role.js b/ui/app/models/database/role.js index fb3d71670..e8fc3a67a 100644 --- a/ui/app/models/database/role.js +++ b/ui/app/models/database/role.js @@ -130,4 +130,6 @@ export default Model.extend({ canGetCredentials: alias('staticCredentialPath.canRead'), databasePath: lazyCapabilities(apiPath`${'backend'}/config/${'database[0]'}`, 'backend', 'database'), canUpdateDb: alias('databasePath.canUpdate'), + rotateRolePath: lazyCapabilities(apiPath`${'backend'}/rotate-role/${'id'}`, 'backend', 'id'), + canRotateRoleCredentials: alias('rotateRolePath.canUpdate'), }); diff --git a/ui/app/templates/components/database-role-edit.hbs b/ui/app/templates/components/database-role-edit.hbs index 5e8a8e854..9293e23e2 100644 --- a/ui/app/templates/components/database-role-edit.hbs +++ b/ui/app/templates/components/database-role-edit.hbs @@ -31,6 +31,11 @@
{{/if}} + {{#if (and @model.canRotateRoleCredentials (eq @model.type "static"))}} + + {{/if}} {{#if @model.canGenerateCredentials}} + + {{/if}} {{#if @item.canRotateRoot}}