[Osquery] Fix internal requests (#122081) (#122084)

Co-authored-by: Patryk Kopyciński <patryk.kopycinski@elastic.co>
This commit is contained in:
Kibana Machine 2021-12-28 12:03:38 -05:00 committed by GitHub
parent 081fd3267d
commit a5fa683afc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 17 deletions

View file

@ -6,7 +6,7 @@
*/
import { uniq } from 'lodash';
import type { KibanaRequest, SavedObjectsClientContract } from 'src/core/server';
import type { SavedObjectsClientContract } from 'src/core/server';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../fleet/common';
import { OSQUERY_INTEGRATION_NAME } from '../../common';
import { OsqueryAppContext } from './osquery_app_context_services';
@ -34,7 +34,6 @@ const aggregateResults = async (
};
export const parseAgentSelection = async (
request: KibanaRequest,
soClient: SavedObjectsClientContract,
context: OsqueryAppContext,
agentSelection: AgentSelection
@ -42,7 +41,7 @@ export const parseAgentSelection = async (
const selectedAgents: Set<string> = new Set();
const addAgent = selectedAgents.add.bind(selectedAgents);
const { allAgentsSelected, platformsSelected, policiesSelected, agents } = agentSelection;
const agentService = context.service.getAgentService()?.asScoped(request);
const agentService = context.service.getAgentService()?.asInternalUser;
const packagePolicyService = context.service.getPackagePolicyService();
const kueryFragments = [];

View file

@ -45,12 +45,7 @@ export const createActionRoute = (router: IRouter, osqueryContext: OsqueryAppCon
);
const { agentSelection } = request.body as { agentSelection: AgentSelection };
const selectedAgents = await parseAgentSelection(
request,
soClient,
osqueryContext,
agentSelection
);
const selectedAgents = await parseAgentSelection(soClient, osqueryContext, agentSelection);
incrementCount(internalSavedObjectsClient, 'live_query');
if (!selectedAgents.length) {
incrementCount(internalSavedObjectsClient, 'live_query', 'errors');

View file

@ -20,15 +20,13 @@ export const getAgentDetailsRoute = (router: IRouter, osqueryContext: OsqueryApp
options: { tags: [`access:${PLUGIN_ID}-read`] },
},
async (context, request, response) => {
const esClient = context.core.elasticsearch.client.asInternalUser;
let agent;
try {
agent = await osqueryContext.service
.getAgentService()
// @ts-expect-error update types
?.getAgent(esClient, request.params.id);
?.asInternalUser // @ts-expect-error update types
?.getAgent(request.params.id);
} catch (err) {
return response.notFound();
}

View file

@ -49,8 +49,7 @@ export const getAgentPoliciesRoute = (router: IRouter, osqueryContext: OsqueryAp
await bluebird.map(
agentPolicies,
(agentPolicy: GetAgentPoliciesResponseItem) =>
agentService
?.asScoped(request)
agentService?.asInternalUser
.getAgentStatusForAgentPolicy(agentPolicy.id)
.then(({ total: agentTotal }) => (agentPolicy.agents = agentTotal)),
{ concurrency: 10 }

View file

@ -24,8 +24,7 @@ export const getAgentsRoute = (router: IRouter, osqueryContext: OsqueryAppContex
try {
agents = await osqueryContext.service
.getAgentService()
?.asScoped(request)
// @ts-expect-error update types
?.asInternalUser // @ts-expect-error update types
.listAgents(request.query);
} catch (error) {
return response.badRequest({ body: error });