mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Fleet] Fix privileges to delete request diagnostics (#187678)
This commit is contained in:
parent
ae802a5776
commit
6590457792
3 changed files with 113 additions and 26 deletions
|
@ -232,32 +232,39 @@ export const AgentDiagnosticsTab: React.FunctionComponent<AgentDiagnosticsProps>
|
|||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: i18n.translate('xpack.fleet.requestDiagnostics.tableColumns.actionsLabelText', {
|
||||
defaultMessage: 'Actions',
|
||||
}),
|
||||
width: '70px',
|
||||
actions: [
|
||||
{
|
||||
type: 'icon',
|
||||
icon: 'trash',
|
||||
color: 'danger',
|
||||
name: i18n.translate('xpack.fleet.requestDiagnostics.tableColumns.deleteButtonText', {
|
||||
defaultMessage: 'Delete',
|
||||
}),
|
||||
available: (item: AgentDiagnostics) => item.status === 'READY',
|
||||
description: i18n.translate(
|
||||
'xpack.fleet.requestDiagnostics.tableColumns.deleteButtonDesc',
|
||||
{
|
||||
defaultMessage: 'Delete diagnostics file',
|
||||
}
|
||||
),
|
||||
onClick: (item: AgentDiagnostics) => {
|
||||
deleteFile(item.id);
|
||||
...((authz.fleet.allAgents
|
||||
? [
|
||||
{
|
||||
name: i18n.translate('xpack.fleet.requestDiagnostics.tableColumns.actionsLabelText', {
|
||||
defaultMessage: 'Actions',
|
||||
}),
|
||||
width: '70px',
|
||||
actions: [
|
||||
{
|
||||
type: 'icon',
|
||||
icon: 'trash',
|
||||
color: 'danger',
|
||||
name: i18n.translate(
|
||||
'xpack.fleet.requestDiagnostics.tableColumns.deleteButtonText',
|
||||
{
|
||||
defaultMessage: 'Delete',
|
||||
}
|
||||
),
|
||||
available: (item: AgentDiagnostics) => item.status === 'READY',
|
||||
description: i18n.translate(
|
||||
'xpack.fleet.requestDiagnostics.tableColumns.deleteButtonDesc',
|
||||
{
|
||||
defaultMessage: 'Delete diagnostics file',
|
||||
}
|
||||
),
|
||||
onClick: (item: AgentDiagnostics) => {
|
||||
deleteFile(item.id);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
: []) as Array<EuiBasicTableColumn<AgentDiagnostics>>),
|
||||
];
|
||||
|
||||
const requestDiagnosticsButton = (
|
||||
|
|
|
@ -338,7 +338,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT
|
|||
.delete({
|
||||
path: AGENT_API_ROUTES.DELETE_UPLOAD_FILE_PATTERN,
|
||||
fleetAuthz: {
|
||||
fleet: { readAgents: true },
|
||||
fleet: { allAgents: true },
|
||||
},
|
||||
})
|
||||
.addVersion(
|
||||
|
|
|
@ -10,12 +10,18 @@ import {
|
|||
AGENTS_INDEX,
|
||||
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
|
||||
} from '@kbn/fleet-plugin/common';
|
||||
import {
|
||||
FILE_STORAGE_DATA_AGENT_INDEX,
|
||||
FILE_STORAGE_METADATA_AGENT_INDEX,
|
||||
} from '@kbn/fleet-plugin/server/constants';
|
||||
|
||||
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
|
||||
import { generateAgent } from '../../helpers';
|
||||
import { runPrivilegeTests } from '../../privileges_helpers';
|
||||
import { testUsers } from '../test_users';
|
||||
|
||||
const ES_INDEX_OPTIONS = { headers: { 'X-elastic-product-origin': 'fleet' } };
|
||||
|
||||
export default function (providerContext: FtrProviderContext) {
|
||||
const { getService } = providerContext;
|
||||
const esArchiver = getService('esArchiver');
|
||||
|
@ -177,6 +183,66 @@ export default function (providerContext: FtrProviderContext) {
|
|||
});
|
||||
};
|
||||
|
||||
const createFileBeforeEach = async () => {
|
||||
await es.index(
|
||||
{
|
||||
id: 'file1.0',
|
||||
refresh: 'wait_for',
|
||||
op_type: 'create',
|
||||
index: FILE_STORAGE_DATA_AGENT_INDEX,
|
||||
document: {
|
||||
bid: 'file1',
|
||||
'@timestamp': new Date().toISOString(),
|
||||
last: true,
|
||||
data: 'test',
|
||||
},
|
||||
},
|
||||
ES_INDEX_OPTIONS
|
||||
);
|
||||
|
||||
await es.index(
|
||||
{
|
||||
index: FILE_STORAGE_METADATA_AGENT_INDEX,
|
||||
id: 'file1',
|
||||
refresh: true,
|
||||
op_type: 'create',
|
||||
body: {
|
||||
'@timestamp': new Date().toISOString(),
|
||||
upload_id: 'file1',
|
||||
action_id: `fleet_uploads_test-file1-action`,
|
||||
agent_id: 'agent1',
|
||||
file: {
|
||||
ChunkSize: 4194304,
|
||||
extension: 'zip',
|
||||
hash: {},
|
||||
mime_type: 'application/zip',
|
||||
mode: '0644',
|
||||
name: `elastic-agent-diagnostics-file-name.zip`,
|
||||
path: `/agent/elastic-agent-diagnostics-file-name.zip`,
|
||||
size: 24917,
|
||||
Status: 'READY',
|
||||
type: 'file',
|
||||
},
|
||||
},
|
||||
},
|
||||
ES_INDEX_OPTIONS
|
||||
);
|
||||
};
|
||||
|
||||
const deleteFileAfterEach = async () => {
|
||||
await es.deleteByQuery(
|
||||
{
|
||||
index: `${FILE_STORAGE_DATA_AGENT_INDEX},${FILE_STORAGE_METADATA_AGENT_INDEX}`,
|
||||
refresh: true,
|
||||
ignore_unavailable: true,
|
||||
query: {
|
||||
match_all: {},
|
||||
},
|
||||
},
|
||||
ES_INDEX_OPTIONS
|
||||
);
|
||||
};
|
||||
|
||||
const ROUTES = [
|
||||
// READ scenarios
|
||||
{
|
||||
|
@ -204,6 +270,13 @@ export default function (providerContext: FtrProviderContext) {
|
|||
path: '/api/fleet/agents/agent1/request_diagnostics',
|
||||
scenarios: READ_SCENARIOS,
|
||||
},
|
||||
{
|
||||
method: 'GET',
|
||||
path: '/api/fleet/agents/files/file1/elastic-agent-diagnostics-file-name.zip',
|
||||
scenarios: READ_SCENARIOS,
|
||||
beforeEach: createFileBeforeEach,
|
||||
afterEach: deleteFileAfterEach,
|
||||
},
|
||||
|
||||
// ALL scenarios
|
||||
{
|
||||
|
@ -238,6 +311,13 @@ export default function (providerContext: FtrProviderContext) {
|
|||
beforeEach: updateAgentBeforeEach,
|
||||
afterEach: updateAgentAfterEach,
|
||||
},
|
||||
{
|
||||
method: 'DELETE',
|
||||
path: '/api/fleet/agents/files/file1',
|
||||
scenarios: ALL_SCENARIOS,
|
||||
beforeEach: createFileBeforeEach,
|
||||
afterEach: deleteFileAfterEach,
|
||||
},
|
||||
];
|
||||
before(async () => {
|
||||
// Make agent 1 upgradeable
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue