Skip to content
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

Backport: UI/Wrong sentinel error message for auth methods #14551 #14623

Merged
merged 3 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/14551.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix issue where UI incorrectly handled API errors when mounting backends
```
11 changes: 2 additions & 9 deletions ui/app/adapters/secret-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,8 @@ export default ApplicationAdapter.extend({
data.id = path;
}
// first create the engine
try {
await this.ajax(this.url(path), 'POST', { data });
} catch (e) {
// if error determine if path duplicate or permissions
if (e.httpStatus === 400) {
throw new Error('samePath');
}
throw new Error('mountIssue');
}
await this.ajax(this.url(path), 'POST', { data });

// second post to config
try {
await this.ajax(this.urlForConfig(path), 'POST', { data: configData });
Expand Down
45 changes: 31 additions & 14 deletions ui/app/components/mount-backend-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,49 @@ export default Component.extend({
}
}

if (!capabilities.get('canUpdate')) {
// if there is no sys/mount issue then error is config endpoint.
this.flashMessages.warning(
'You do not have access to the config endpoint. The secret engine was mounted, but the configuration settings were not saved.'
);
// remove the config data from the model otherwise it will save it even if the network request failed.
[this.mountModel.maxVersions, this.mountModel.casRequired, this.mountModel.deleteVersionAfter] = [
0,
false,
0,
];
}
let changedAttrKeys = Object.keys(mountModel.changedAttributes());
const updatesConfig =
mountModel.isV2KV &&
(changedAttrKeys.includes('casRequired') ||
changedAttrKeys.includes('deleteVersionAfter') ||
changedAttrKeys.includes('maxVersions'));

try {
yield mountModel.save();
} catch (err) {
if (err.message === 'mountIssue') {
if (err.httpStatus === 403) {
this.mountIssue = true;
this.set('isFormInvalid', this.mountIssue);
this.flashMessages.danger(
'You do not have access to the sys/mounts endpoint. The secret engine was not mounted.'
);
return;
}
this.set('errorMessage', 'This mount path already exist.');
if (err.errors) {
let errors = err.errors.map((e) => {
if (typeof e === 'object') return e.title || e.message || JSON.stringify(e);
return e;
});
this.set('errors', errors);
} else if (err.message) {
this.set('errorMessage', err.message);
} else {
this.set('errorMessage', 'An error occurred, check the vault logs.');
}
return;
}
if (updatesConfig && !capabilities.get('canUpdate')) {
// config error is not thrown from secret-engine adapter, so handling here
this.flashMessages.warning(
'You do not have access to the config endpoint. The secret engine was mounted, but the configuration settings were not saved.'
);
// remove the config data from the model otherwise it will save it even if the network request failed.
[this.mountModel.maxVersions, this.mountModel.casRequired, this.mountModel.deleteVersionAfter] = [
0,
false,
0,
];
}
let mountType = this.mountType;
mountType = mountType === 'secret' ? `${mountType}s engine` : `${mountType} method`;
this.flashMessages.success(`Successfully mounted the ${type} ${mountType} at ${path}.`);
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/mount-backend-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<form {{action (perform this.mountBackend) on="submit"}}>
<div class="box is-sideless is-fullwidth is-marginless">
<NamespaceReminder @mode="enable" @noun={{if (eq this.mountType "auth") "Auth Method" "Secret Engine"}} />
<MessageError @model={{this.model}} @errorMessage={{this.errorMessage}} />
<MessageError @model={{this.model}} @errorMessage={{this.errorMessage}} @errors={{this.errors}} />
{{#if this.showEnable}}
<FormFieldGroups
@model={{this.mountModel}}
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/settings/mount-secret-backend-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module('Acceptance | settings/mount-secret-backend', function (hooks) {
await page.enableEngine();
await page.selectType('kv');
await page.next().path(path).submit();
assert.dom('.alert-banner-message-body').hasText('This mount path already exist.');
assert.dom('.alert-banner-message-body').containsText(`path is already in use at ${path}`);
assert.equal(currentRouteName(), 'vault.cluster.settings.mount-secret-backend');

await page.secretList();
Expand Down