-
Notifications
You must be signed in to change notification settings - Fork 4.6k
UI: Add password field to static role creation page #30275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
8972d77
68d2d07
f26fab5
4de0211
db752b8
0657a9a
b50c6e0
a5ed769
cc45fb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ```release-note:improvement | ||
| ui/database: Adding password input field for creating a static role | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,8 @@ export default class RoleModel extends Model { | |
| }) | ||
| revocation_statement; | ||
|
|
||
| @attr('string', { readOnly: true }) last_vault_rotation; | ||
|
|
||
| // ENTERPRISE ONLY | ||
| @attr({ | ||
| label: 'Rotate immediately', | ||
|
|
@@ -135,6 +137,12 @@ export default class RoleModel extends Model { | |
| }) | ||
| skip_import_rotation; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would imagine that this field is actually not editType password. Instead, it should be sensitive—see example here. The difference is that password fields (only used once that I can see) is old and not really something we should support in form-fields. Imagine a password field as something you login with. Sensitive fields by contrast are masked as you input them but allow you to toggle the view which is helpful when trying to set something. |
||
| @attr('string', { | ||
| editType: 'password', | ||
| subText: 'The database password that this Vault role corresponds to.', | ||
| }) | ||
| password; | ||
|
|
||
| /* FIELD ATTRIBUTES */ | ||
| get fieldAttrs() { | ||
| // Main fields on edit/create form | ||
|
|
@@ -156,6 +164,7 @@ export default class RoleModel extends Model { | |
| 'default_ttl', | ||
| 'max_ttl', | ||
| 'username', | ||
| 'password', | ||
| 'rotation_period', | ||
| 'skip_import_rotation', | ||
| 'creation_statements', | ||
|
|
@@ -169,7 +178,9 @@ export default class RoleModel extends Model { | |
|
|
||
| // remove enterprise-only attrs if on community | ||
| if (!this.version.isEnterprise) { | ||
| allRoleSettingFields = allRoleSettingFields.filter((role) => role !== 'skip_import_rotation'); | ||
| allRoleSettingFields = allRoleSettingFields.filter( | ||
| (role) => !['skip_import_rotation', 'password'].includes(role) | ||
| ); | ||
| } | ||
|
|
||
| return expandAttributeMeta(this, allRoleSettingFields); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,16 @@ | |
| {{else}} | ||
| <ReadonlyFormField @attr={{attr}} @value={{get @model attr.name}} /> | ||
| {{/if}} | ||
| {{else if (and (eq @mode "edit") (eq attr.name "password"))}} | ||
| {{! password field is disabled on edit once password has been rotated }} | ||
|
||
| <EnableInput | ||
| data-test-enable-field={{attr.name}} | ||
| class="field" | ||
| @attr={{attr}} | ||
| @disabled={{(not (eq (get @model "last_vault_rotation") undefined))}} | ||
| > | ||
| <FormField @attr={{attr}} @model={{@model}} /> | ||
| </EnableInput> | ||
| {{else}} | ||
| <FormField data-test-field={{true}} @attr={{attr}} @model={{@model}} @modelValidations={{@modelValidations}} /> | ||
| {{#if (and (eq attr.name "skip_import_rotation") this.isOverridden)}} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ import { tracked } from '@glimmer/tracking'; | |||||
| interface Args { | ||||||
| attr?: AttrData; | ||||||
| label?: string; | ||||||
| disabled?: boolean; // specifically used for disabling on edit | ||||||
| } | ||||||
| interface AttrData { | ||||||
| name: string; // required if @attr is passed | ||||||
|
|
@@ -38,6 +39,7 @@ interface AttrData { | |||||
|
|
||||||
| * @param {object} [attr] - used to generate label for `ReadonlyFormField`, `name` key is required. Can be an attribute from a model exported with expandAttributeMeta. | ||||||
| * @param {string} [label] - required if no attr passed. Used to ensure a11y conformance for the readonly input. | ||||||
| * @param {boolean} [disabled] - to be used in specific scenarios where a user can visually see but not interact with the input field. ie. disabling a field on edit | ||||||
|
||||||
| * @param {boolean} [disabled] - to be used in specific scenarios where a user can visually see but not interact with the input field. ie. disabling a field on edit | |
| * @param {boolean} [disabled=false] - to be used in specific scenarios where a user can visually see but not interact with the input field. ie. disabling a field on edit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,7 @@ module('Integration | Component | database-role-edit', function (hooks) { | |
| { | ||
| path: 'static-roles', | ||
| username: 'staticTestUser', | ||
| password: 'testPassword', | ||
| rotation_period: '172800s', // 2 days in seconds | ||
| skip_import_rotation: true, | ||
| }, | ||
|
|
@@ -97,11 +98,16 @@ module('Integration | Component | database-role-edit', function (hooks) { | |
| await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="create"/>`); | ||
| await fillIn('[data-test-ttl-value="Rotation period"]', '2'); | ||
| await click('[data-test-toggle-input="toggle-skip_import_rotation"]'); | ||
| await fillIn('[data-test-input="password"]', 'testPassword'); // fill in password field | ||
|
||
|
|
||
| await click('[data-test-secret-save]'); | ||
|
|
||
| await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`); | ||
| assert.dom('[data-test-value-div="Rotate immediately"]').containsText('No'); | ||
| assert.dom('[data-test-value="Password"]').doesNotExist(); // verify password field doesn't show on details view | ||
|
||
|
|
||
| await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="edit"/>`); | ||
| assert.dom('[data-test-icon="edit"]').exists(); // verify password field is enabled for edit & enable button is rendered bc role hasn't been rotated | ||
| }); | ||
|
|
||
| test('enterprise: it should successfully create user that does rotate immediately & verify warning modal pops up', async function (assert) { | ||
|
|
@@ -116,6 +122,9 @@ module('Integration | Component | database-role-edit', function (hooks) { | |
|
|
||
| await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="show"/>`); | ||
| assert.dom('[data-test-value-div="Rotate immediately"]').containsText('Yes'); | ||
|
|
||
| await render(hbs`<DatabaseRoleEdit @model={{this.modelStatic}} @mode="edit"/>`); | ||
| assert.dom('[data-test-icon="edit"]').doesNotExist(); // verify password field is disabled for edit & enable button isn't rendered bc role has already been rotated | ||
| }); | ||
|
|
||
| test('it should show Get credentials button when a user has the correct policy', async function (assert) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for conditionally hiding the password field on the details view, without removing it from the attrs
Not sure if there's a better way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't really need to do this. If it's not returned from the API then it shouldn't show. I suspect we're solving the issue of state problems here, is that correct (e.g. this field is removed on refresh of the details view)? If that's the case, let's do a follow up PR to address this issue.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still shows because its part of the attrs array of a role,
but because the API doesn't return a value, it'll just be blank so it looks like this (even on refresh):
i can remove this if we're okay with showing the password like that^