[ML] Update file data visualizer permissions (#101169)

* [ML] Update file data visualizer permissions

* adding home bundle

* fixing translations

* removing home from bundles

* switching to current user for analysis

* adding find structure permission check

* clean up

* updating text

* updating maps

* removing has_find_file_structure_permission endpoint

* removing more code

* adding permission error message

* renaming variable

* adding fileUpload:analyzeFile back into ML

* updating error text

* updating snapshots

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
James Gowdy 2021-06-29 21:07:07 +01:00 committed by GitHub
parent c24318ae40
commit 21dad7edb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 18 deletions

View file

@ -15,7 +15,11 @@ import { isEqual } from 'lodash';
import { AboutPanel, LoadingPanel } from '../about_panel'; import { AboutPanel, LoadingPanel } from '../about_panel';
import { BottomBar } from '../bottom_bar'; import { BottomBar } from '../bottom_bar';
import { ResultsView } from '../results_view'; import { ResultsView } from '../results_view';
import { FileCouldNotBeRead, FileTooLarge } from './file_error_callouts'; import {
FileCouldNotBeRead,
FileTooLarge,
FindFileStructurePermissionDenied,
} from './file_error_callouts';
import { EditFlyout } from '../edit_flyout'; import { EditFlyout } from '../edit_flyout';
import { ExplanationFlyout } from '../explanation_flyout'; import { ExplanationFlyout } from '../explanation_flyout';
import { ImportView } from '../import_view'; import { ImportView } from '../import_view';
@ -50,6 +54,7 @@ export class FileDataVisualizerView extends Component {
isExplanationFlyoutVisible: false, isExplanationFlyoutVisible: false,
bottomBarVisible: false, bottomBarVisible: false,
hasPermissionToImport: false, hasPermissionToImport: false,
fileCouldNotBeReadPermissionError: false,
}; };
this.overrides = {}; this.overrides = {};
@ -87,6 +92,7 @@ export class FileDataVisualizerView extends Component {
fileSize: 0, fileSize: 0,
fileTooLarge: false, fileTooLarge: false,
fileCouldNotBeRead: false, fileCouldNotBeRead: false,
fileCouldNotBeReadPermissionError: false,
serverError: null, serverError: null,
results: undefined, results: undefined,
explanation: undefined, explanation: undefined,
@ -182,17 +188,19 @@ export class FileDataVisualizerView extends Component {
fileCouldNotBeRead: isRetry, fileCouldNotBeRead: isRetry,
}); });
} catch (error) { } catch (error) {
const fileCouldNotBeReadPermissionError = error.body.statusCode === 403;
this.setState({ this.setState({
results: undefined, results: undefined,
explanation: undefined, explanation: undefined,
loaded: false, loaded: false,
loading: false, loading: false,
fileCouldNotBeRead: true, fileCouldNotBeRead: true,
fileCouldNotBeReadPermissionError,
serverError: error, serverError: error,
}); });
// reload the results with the previous overrides // reload the results with the previous overrides
if (isRetry === false) { if (isRetry === false && fileCouldNotBeReadPermissionError === false) {
this.setState({ this.setState({
loading: true, loading: true,
loaded: false, loaded: false,
@ -275,6 +283,7 @@ export class FileDataVisualizerView extends Component {
isExplanationFlyoutVisible, isExplanationFlyoutVisible,
bottomBarVisible, bottomBarVisible,
hasPermissionToImport, hasPermissionToImport,
fileCouldNotBeReadPermissionError,
} = this.state; } = this.state;
const fields = const fields =
@ -286,7 +295,12 @@ export class FileDataVisualizerView extends Component {
<div> <div>
{mode === MODE.READ && ( {mode === MODE.READ && (
<> <>
{!loading && !loaded && <AboutPanel onFilePickerChange={this.onFilePickerChange} />} {!loading && !loaded && (
<AboutPanel
onFilePickerChange={this.onFilePickerChange}
disabled={!fileCouldNotBeReadPermissionError}
/>
)}
{loading && <LoadingPanel />} {loading && <LoadingPanel />}
@ -296,11 +310,15 @@ export class FileDataVisualizerView extends Component {
{fileCouldNotBeRead && loading === false && ( {fileCouldNotBeRead && loading === false && (
<> <>
<FileCouldNotBeRead {fileCouldNotBeReadPermissionError ? (
error={serverError} <FindFileStructurePermissionDenied />
loaded={loaded} ) : (
showEditFlyout={this.showEditFlyout} <FileCouldNotBeRead
/> error={serverError}
loaded={loaded}
showEditFlyout={this.showEditFlyout}
/>
)}
<EuiSpacer size="l" /> <EuiSpacer size="l" />
</> </>
)} )}

View file

@ -146,3 +146,26 @@ export const Explanation: FC<{ error: FindFileStructureErrorResponse }> = ({ err
</> </>
); );
}; };
export const FindFileStructurePermissionDenied: FC = () => {
return (
<>
<EuiCallOut
title={
<FormattedMessage
id="xpack.dataVisualizer.file.fileErrorCallouts.findFileStructurePermissionDenied.title"
defaultMessage="Permission denied"
/>
}
color="danger"
iconType="cross"
data-test-subj="dataVisualizerFileStructurePermissionDeniedErrorCallout"
>
<FormattedMessage
id="xpack.dataVisualizer.file.fileErrorCallouts.findFileStructurePermissionDenied.description"
defaultMessage="You do not have sufficient privileges to analyze files."
/>
</EuiCallOut>
</>
);
};

View file

@ -671,6 +671,7 @@ Array [
}, },
}, },
"api": Array [ "api": Array [
"fileUpload:analyzeFile",
"store_search_session", "store_search_session",
], ],
"app": Array [ "app": Array [
@ -1199,6 +1200,7 @@ Array [
}, },
}, },
"api": Array [ "api": Array [
"fileUpload:analyzeFile",
"store_search_session", "store_search_session",
], ],
"app": Array [ "app": Array [

View file

@ -37,6 +37,7 @@ export const buildOSSFeatures = ({
privileges: { privileges: {
all: { all: {
app: ['discover', 'kibana'], app: ['discover', 'kibana'],
api: ['fileUpload:analyzeFile'],
catalogue: ['discover'], catalogue: ['discover'],
savedObject: { savedObject: {
all: ['search', 'query', 'index-pattern'], all: ['search', 'query', 'index-pattern'],

View file

@ -141,7 +141,6 @@ export function fileUploadRoutes(coreSetup: CoreSetup<StartDeps, unknown>, logge
accepts: ['application/json'], accepts: ['application/json'],
maxBytes: MAX_FILE_SIZE_BYTES, maxBytes: MAX_FILE_SIZE_BYTES,
}, },
tags: ['access:fileUpload:import'],
}, },
}, },
async (context, request, response) => { async (context, request, response) => {
@ -185,9 +184,6 @@ export function fileUploadRoutes(coreSetup: CoreSetup<StartDeps, unknown>, logge
validate: { validate: {
body: schema.object({ index: schema.string() }), body: schema.object({ index: schema.string() }),
}, },
options: {
tags: ['access:fileUpload:import'],
},
}, },
async (context, request, response) => { async (context, request, response) => {
try { try {

View file

@ -185,7 +185,6 @@ export class MapsPlugin implements Plugin {
catalogue: [APP_ID], catalogue: [APP_ID],
privileges: { privileges: {
all: { all: {
api: ['fileUpload:import'],
app: [APP_ID, 'kibana'], app: [APP_ID, 'kibana'],
catalogue: [APP_ID], catalogue: [APP_ID],
savedObject: { savedObject: {

View file

@ -105,11 +105,7 @@ export function getPluginPrivileges() {
return { return {
admin: { admin: {
...privilege, ...privilege,
api: [ api: ['fileUpload:analyzeFile', ...allMlCapabilitiesKeys.map((k) => `ml:${k}`)],
'fileUpload:import',
'fileUpload:analyzeFile',
...allMlCapabilitiesKeys.map((k) => `ml:${k}`),
],
catalogue: [PLUGIN_ID, `${PLUGIN_ID}_file_data_visualizer`], catalogue: [PLUGIN_ID, `${PLUGIN_ID}_file_data_visualizer`],
ui: allMlCapabilitiesKeys, ui: allMlCapabilitiesKeys,
savedObject: { savedObject: {