From 688b53e6523685a5cd1162bd3f262cdecaf483ff Mon Sep 17 00:00:00 2001 From: criamico Date: Wed, 9 Aug 2023 16:36:16 +0200 Subject: [PATCH 01/26] [Fleet] Introduce API versioning for serverless --- .../plugins/fleet/common/constants/routes.ts | 6 ++++ .../server/services/security/fleet_router.ts | 30 +++++++++++++++---- .../fleet/server/services/security/types.ts | 7 ++++- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/fleet/common/constants/routes.ts b/x-pack/plugins/fleet/common/constants/routes.ts index e40b9f8606fdb..24b84a188518c 100644 --- a/x-pack/plugins/fleet/common/constants/routes.ts +++ b/x-pack/plugins/fleet/common/constants/routes.ts @@ -204,3 +204,9 @@ export const DOWNLOAD_SOURCE_API_ROUTES = { UPDATE_PATTERN: `${API_ROOT}/agent_download_sources/{sourceId}`, DELETE_PATTERN: `${API_ROOT}/agent_download_sources/{sourceId}`, }; + +// API versioning constants +export const LATEST_PUBLIC_VERSION = '2023-10-31'; +export const LATEST_INTERNAL_VERSION = '1'; +export const PUBLIC_API_ACCESS = 'public'; +export const INTERNAL_API_ACCESS = 'internal'; diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.ts index a956f1522161c..ca6e112864793 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.ts @@ -17,6 +17,15 @@ import type { RouteConfigOptions, } from '@kbn/core/server'; +import { routeValidationObject } from '@kbn/server-route-repository'; + +import type { INTERNAL_API_ACCESS } from '../../../common/constants'; +import { + LATEST_PUBLIC_VERSION, + LATEST_INTERNAL_VERSION, + PUBLIC_API_ACCESS, +} from '../../../common/constants'; + import type { FleetRequestHandlerContext } from '../..'; import { getRequestStore } from '../request_store'; @@ -39,7 +48,7 @@ function withDefaultPublicAccess( } if (!newOptions.access) { - newOptions.access = 'public'; + newOptions.access = PUBLIC_API_ACCESS; } return { ...routeConfig, @@ -124,12 +133,23 @@ export function makeRouterWithFleetAuthz + access === PUBLIC_API_ACCESS ? LATEST_PUBLIC_VERSION : LATEST_INTERNAL_VERSION; + + const versionedRouter = router.versioned; const fleetAuthzRouter: FleetAuthzRouter = { - get: ({ fleetAuthz: hasRequiredAuthz, ...options }, handler) => { - router.get(withDefaultPublicAccess(options), (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) - ); + get: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; + const defaultVersion = getDefaultVersion(access); + + return versionedRouter + .get({ access, path: options.path }) + .addVersion( + { version: version || defaultVersion, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); }, delete: ({ fleetAuthz: hasRequiredAuthz, ...options }, handler) => { router.delete(withDefaultPublicAccess(options), (context, request, response) => diff --git a/x-pack/plugins/fleet/server/services/security/types.ts b/x-pack/plugins/fleet/server/services/security/types.ts index 8559ee57b35e8..c0af89d4d3b29 100644 --- a/x-pack/plugins/fleet/server/services/security/types.ts +++ b/x-pack/plugins/fleet/server/services/security/types.ts @@ -30,8 +30,13 @@ export interface FleetAuthzRouteConfig< fleetAuthz?: T; } +export interface FleetVersionRouteConfig { + version?: string; +} + export type FleetRouteConfig = RouteConfig & - FleetAuthzRouteConfig; + FleetAuthzRouteConfig & + FleetVersionRouteConfig; // Fleet router that allow to add required access when registering route export interface FleetAuthzRouter< From 677361c601b78c930ba3d8ef0473eca8ff5f704e Mon Sep 17 00:00:00 2001 From: criamico Date: Thu, 10 Aug 2023 10:57:56 +0200 Subject: [PATCH 02/26] Add versioning to all endpoints --- .../agent_policy_delete_provider.tsx | 2 + .../package_policy_delete_provider.tsx | 3 +- .../public/hooks/use_request/agent_policy.ts | 13 +++++ .../fleet/public/hooks/use_request/agents.ts | 30 +++++++++- .../fleet/public/hooks/use_request/app.ts | 5 ++ .../public/hooks/use_request/data_stream.ts | 2 + .../hooks/use_request/download_source.ts | 6 ++ .../hooks/use_request/enrollment_api_keys.ts | 8 +++ .../fleet/public/hooks/use_request/epm.ts | 26 ++++++++- .../public/hooks/use_request/fleet_proxies.ts | 17 +++++- .../hooks/use_request/fleet_server_hosts.ts | 7 +++ .../public/hooks/use_request/health_check.ts | 2 + .../fleet/public/hooks/use_request/k8s.ts | 2 + .../fleet/public/hooks/use_request/outputs.ts | 6 ++ .../hooks/use_request/package_policy.ts | 16 ++++++ .../public/hooks/use_request/settings.ts | 6 ++ .../fleet/public/hooks/use_request/setup.ts | 4 ++ .../hooks/use_request/uninstall_tokens.ts | 5 ++ x-pack/plugins/fleet/public/plugin.ts | 14 ++++- .../server/services/security/fleet_router.ts | 57 +++++++++++++------ 20 files changed, 208 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx index 96bbc5b82565e..0a49837a947bf 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx @@ -12,6 +12,7 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { AGENTS_PREFIX } from '../../../constants'; import { sendDeleteAgentPolicy, useStartServices, useConfig, sendRequest } from '../../../hooks'; +import { LATEST_PUBLIC_VERSION } from '../../../../../../common/constants'; interface Props { children: (deleteAgentPolicy: DeleteAgentPolicy) => React.ReactElement; @@ -104,6 +105,7 @@ export const AgentPolicyDeleteProvider: React.FunctionComponent = ({ query: { kuery: `${AGENTS_PREFIX}.policy_id : ${agentPolicyToCheck}`, }, + version: LATEST_PUBLIC_VERSION, }); setAgentsCount(data?.total || 0); setIsLoadingAgentsCount(false); diff --git a/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx b/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx index 683ba398f6669..37e4fc1d17e72 100644 --- a/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx +++ b/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx @@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { useStartServices, sendRequest, sendDeletePackagePolicy, useConfig } from '../hooks'; -import { AGENT_API_ROUTES, AGENTS_PREFIX } from '../../common/constants'; +import { AGENT_API_ROUTES, AGENTS_PREFIX, LATEST_PUBLIC_VERSION } from '../../common/constants'; import type { AgentPolicy } from '../types'; interface Props { @@ -55,6 +55,7 @@ export const PackagePolicyDeleteProvider: React.FunctionComponent = ({ perPage: 1, kuery: `${AGENTS_PREFIX}.policy_id : ${agentPolicy.id}`, }, + version: LATEST_PUBLIC_VERSION, }); setAgentsCount(data?.total || 0); setIsLoadingAgentsCount(false); diff --git a/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts b/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts index 39372fcc5c508..eedd68937567a 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts @@ -7,6 +7,7 @@ import { useQuery } from '@tanstack/react-query'; import { agentPolicyRouteService } from '../../services'; +import { LATEST_PUBLIC_VERSION, LATEST_INTERNAL_VERSION } from '../../../common/constants'; import type { GetAgentPoliciesRequest, @@ -31,6 +32,7 @@ export const useGetAgentPolicies = (query?: GetAgentPoliciesRequest['query']) => path: agentPolicyRouteService.getListPath(), method: 'get', query, + version: LATEST_PUBLIC_VERSION, }); }; @@ -40,6 +42,7 @@ export const useGetAgentPoliciesQuery = (query?: GetAgentPoliciesRequest['query' path: agentPolicyRouteService.getListPath(), method: 'get', query, + version: LATEST_PUBLIC_VERSION, }) ); }; @@ -49,6 +52,7 @@ export const sendGetAgentPolicies = (query?: GetAgentPoliciesRequest['query']) = path: agentPolicyRouteService.getListPath(), method: 'get', query, + version: LATEST_PUBLIC_VERSION, }); }; @@ -57,6 +61,7 @@ export const useGetOneAgentPolicy = (agentPolicyId: string | undefined) => { path: agentPolicyId ? agentPolicyRouteService.getInfoPath(agentPolicyId) : undefined, method: 'get', shouldSendRequest: !!agentPolicyId, + version: LATEST_PUBLIC_VERSION, } as SendConditionalRequestConfig); }; @@ -64,6 +69,7 @@ export const useGetOneAgentPolicyFull = (agentPolicyId: string) => { return useRequest({ path: agentPolicyRouteService.getInfoFullPath(agentPolicyId), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; @@ -75,6 +81,7 @@ export const sendGetOneAgentPolicyFull = ( path: agentPolicyRouteService.getInfoFullPath(agentPolicyId), method: 'get', query, + version: LATEST_PUBLIC_VERSION, }); }; @@ -82,6 +89,7 @@ export const sendGetOneAgentPolicy = (agentPolicyId: string) => { return sendRequest({ path: agentPolicyRouteService.getInfoPath(agentPolicyId), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; @@ -94,6 +102,7 @@ export const sendCreateAgentPolicy = ( method: 'post', body: JSON.stringify(body), query: withSysMonitoring ? { sys_monitoring: true } : {}, + version: LATEST_PUBLIC_VERSION, }); }; @@ -105,6 +114,7 @@ export const sendUpdateAgentPolicy = ( path: agentPolicyRouteService.getUpdatePath(agentPolicyId), method: 'put', body: JSON.stringify(body), + version: LATEST_PUBLIC_VERSION, }); }; @@ -124,6 +134,7 @@ export const sendDeleteAgentPolicy = (body: DeleteAgentPolicyRequest['body']) => path: agentPolicyRouteService.getDeletePath(), method: 'post', body: JSON.stringify(body), + version: LATEST_PUBLIC_VERSION, }); }; @@ -132,6 +143,7 @@ export const sendResetOnePreconfiguredAgentPolicy = (agentPolicyId: string) => { path: agentPolicyRouteService.getResetOnePreconfiguredAgentPolicyPath(agentPolicyId), method: 'post', body: JSON.stringify({}), + version: LATEST_INTERNAL_VERSION, }); }; @@ -140,5 +152,6 @@ export const sendResetAllPreconfiguredAgentPolicies = () => { path: agentPolicyRouteService.getResetAllPreconfiguredAgentPolicyPath(), method: 'post', body: JSON.stringify({}), + version: LATEST_INTERNAL_VERSION, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/agents.ts b/x-pack/plugins/fleet/public/hooks/use_request/agents.ts index f6a132e2090f1..fd665ef889db4 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/agents.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/agents.ts @@ -18,6 +18,8 @@ import type { UpdateAgentRequest, } from '../../../common/types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + import { agentRouteService } from '../../services'; import type { @@ -62,6 +64,7 @@ export function useGetOneAgent( return useRequest({ path: agentRouteService.getInfoPath(agentId), method: 'get', + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -70,22 +73,27 @@ export function useGetAgents(query: GetAgentsRequest['query'], options?: Request return useRequest({ method: 'get', path: agentRouteService.getListPath(), + version: LATEST_PUBLIC_VERSION, query, ...options, }); } +// ADD version on headers export function useGetAgentsQuery( query: GetAgentsRequest['query'], options: Partial<{ enabled: boolean }> = {} ) { - return useQuery(['agents', query], () => sendGetAgents(query), { enabled: options.enabled }); + return useQuery(['agents', query], () => sendGetAgents(query), { + enabled: options.enabled, + }); } export function sendGetAgents(query: GetAgentsRequest['query'], options?: RequestOptions) { return sendRequest({ method: 'get', path: agentRouteService.getListPath(), + version: LATEST_PUBLIC_VERSION, query, ...options, }); @@ -95,6 +103,7 @@ export function useGetAgentStatus(query: GetAgentStatusRequest['query'], options return useRequest({ method: 'get', path: agentRouteService.getStatusPath(), + version: LATEST_PUBLIC_VERSION, query, ...options, }); @@ -104,6 +113,7 @@ export function sendGetAgentIncomingData(query: GetAgentIncomingDataRequest['que method: 'get', path: agentRouteService.getIncomingDataPath(), query, + version: LATEST_PUBLIC_VERSION, }); } @@ -115,6 +125,7 @@ export function sendGetAgentStatus( method: 'get', path: agentRouteService.getStatusPath(), query, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -124,6 +135,7 @@ export function sendGetAgentTags(query: GetAgentsRequest['query'], options?: Req method: 'get', path: agentRouteService.getListTagsPath(), query, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -137,6 +149,7 @@ export function sendPostAgentReassign( method: 'post', path: agentRouteService.getReassignPath(agentId), body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -149,6 +162,7 @@ export function sendPostBulkAgentReassign( method: 'post', path: agentRouteService.getBulkReassignPath(), body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -162,6 +176,7 @@ export function sendPostAgentUnenroll( path: agentRouteService.getUnenrollPath(agentId), method: 'post', body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -174,6 +189,7 @@ export function sendPostBulkAgentUnenroll( path: agentRouteService.getBulkUnenrollPath(), method: 'post', body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -187,6 +203,7 @@ export function sendPostAgentUpgrade( path: agentRouteService.getUpgradePath(agentId), method: 'post', body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -195,6 +212,7 @@ export function sendPostRequestDiagnostics(agentId: string, options?: RequestOpt return sendRequest({ path: agentRouteService.getRequestDiagnosticsPath(agentId), method: 'post', + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -207,6 +225,7 @@ export function sendPostBulkRequestDiagnostics( path: agentRouteService.getBulkRequestDiagnosticsPath(), method: 'post', body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -223,6 +242,7 @@ export const useGetAgentUploads = (agentId: string, options?: RequestOptions) => return useRequest({ path: agentRouteService.getListAgentUploads(agentId), method: 'get', + version: LATEST_PUBLIC_VERSION, ...options, }); }; @@ -236,6 +256,7 @@ export function sendPostAgentAction( path: agentRouteService.getCreateActionPath(agentId), method: 'post', body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -248,6 +269,7 @@ export function sendPostBulkAgentUpgrade( path: agentRouteService.getBulkUpgradePath(), method: 'post', body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -256,6 +278,7 @@ export function sendGetActionStatus() { return sendRequest({ path: agentRouteService.getActionStatusPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, }); } @@ -263,6 +286,7 @@ export function sendPostCancelAction(actionId: string) { return sendRequest({ path: agentRouteService.getCancelActionPath(actionId), method: 'post', + version: LATEST_PUBLIC_VERSION, }); } @@ -270,6 +294,7 @@ export function sendPostRetrieveAgentsByActions(body: PostRetrieveAgentsByAction return sendRequest({ path: agentRouteService.getAgentsByActionsPath(), method: 'post', + version: LATEST_PUBLIC_VERSION, body, }); } @@ -283,6 +308,7 @@ export function sendPutAgentTagsUpdate( method: 'put', path: agentRouteService.getUpdatePath(agentId), body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -295,6 +321,7 @@ export function sendPostBulkAgentTagsUpdate( method: 'post', path: agentRouteService.getBulkUpdateTagsPath(), body, + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -303,5 +330,6 @@ export function sendGetAgentsAvailableVersions() { return sendRequest({ method: 'get', path: agentRouteService.getAvailableVersionsPath(), + version: LATEST_PUBLIC_VERSION, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/app.ts b/x-pack/plugins/fleet/public/hooks/use_request/app.ts index 5236356180d83..a8e0bf34ea750 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/app.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/app.ts @@ -9,6 +9,7 @@ import { useQuery } from '@tanstack/react-query'; import { appRoutesService } from '../../services'; import type { CheckPermissionsResponse, GenerateServiceTokenResponse } from '../../types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; import { sendRequest, sendRequestForRq, useRequest } from './use_request'; @@ -17,6 +18,7 @@ export const sendGetPermissionsCheck = (fleetServerSetup?: boolean) => { path: appRoutesService.getCheckPermissionsPath(), method: 'get', query: { fleetServerSetup }, + version: LATEST_PUBLIC_VERSION, }); }; @@ -24,6 +26,7 @@ export const sendGenerateServiceToken = () => { return sendRequest({ path: appRoutesService.getRegenerateServiceTokenPath(), method: 'post', + version: LATEST_PUBLIC_VERSION, }); }; @@ -34,6 +37,7 @@ export const usePermissionCheckQuery = () => { sendRequestForRq({ path: appRoutesService.getCheckPermissionsPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, }) ); }; @@ -42,5 +46,6 @@ export const usePermissionCheck = () => { return useRequest({ path: appRoutesService.getCheckPermissionsPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts b/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts index 25215b6e623b1..3f8e4fb80961b 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts @@ -7,6 +7,7 @@ import { dataStreamRouteService } from '../../services'; import type { GetDataStreamsResponse } from '../../types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; import { useRequest, sendRequest } from './use_request'; @@ -14,6 +15,7 @@ export const useGetDataStreams = () => { return useRequest({ path: dataStreamRouteService.getListPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts b/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts index 2b213501170e1..ba04fecf7392a 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts @@ -12,12 +12,15 @@ import type { PutDownloadSourceRequest, } from '../../types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + import { useRequest, sendRequest } from './use_request'; export function useGetDownloadSources() { return useRequest({ method: 'get', path: downloadSourceRoutesService.getListPath(), + version: LATEST_PUBLIC_VERSION, }); } @@ -35,6 +38,7 @@ export function sendPutDownloadSource( return sendRequest({ method: 'put', path: downloadSourceRoutesService.getUpdatePath(downloadSourceId), + version: LATEST_PUBLIC_VERSION, body, }); } @@ -43,6 +47,7 @@ export function sendPostDownloadSource(body: PostDownloadSourceRequest['body']) return sendRequest({ method: 'post', path: downloadSourceRoutesService.getCreatePath(), + version: LATEST_PUBLIC_VERSION, body, }); } @@ -51,5 +56,6 @@ export function sendDeleteDownloadSource(downloadSourceId: string) { return sendRequest({ method: 'delete', path: downloadSourceRoutesService.getDeletePath(downloadSourceId), + version: LATEST_PUBLIC_VERSION, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts b/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts index 7b3ddaada8001..10d98a0739375 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts @@ -15,6 +15,8 @@ import type { PostEnrollmentAPIKeyResponse, } from '../../types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + import { useRequest, sendRequest, useConditionalRequest } from './use_request'; import type { UseRequestConfig, SendConditionalRequestConfig } from './use_request'; @@ -25,6 +27,7 @@ export function useGetOneEnrollmentAPIKey(keyId: string | undefined) { method: 'get', path: keyId ? enrollmentAPIKeyRouteService.getInfoPath(keyId) : undefined, shouldSendRequest: !!keyId, + version: LATEST_PUBLIC_VERSION, } as SendConditionalRequestConfig); } @@ -32,6 +35,7 @@ export function sendGetOneEnrollmentAPIKey(keyId: string, options?: RequestOptio return sendRequest({ method: 'get', path: enrollmentAPIKeyRouteService.getInfoPath(keyId), + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -40,6 +44,7 @@ export function sendDeleteOneEnrollmentAPIKey(keyId: string, options?: RequestOp return sendRequest({ method: 'delete', path: enrollmentAPIKeyRouteService.getDeletePath(keyId), + version: LATEST_PUBLIC_VERSION, ...options, }); } @@ -51,6 +56,7 @@ export function sendGetEnrollmentAPIKeys( return sendRequest({ method: 'get', path: enrollmentAPIKeyRouteService.getListPath(), + version: LATEST_PUBLIC_VERSION, query, ...options, }); @@ -63,6 +69,7 @@ export function useGetEnrollmentAPIKeys( return useRequest({ method: 'get', path: enrollmentAPIKeyRouteService.getListPath(), + version: LATEST_PUBLIC_VERSION, query, ...options, }); @@ -72,6 +79,7 @@ export function sendCreateEnrollmentAPIKey(body: PostEnrollmentAPIKeyRequest['bo return sendRequest({ method: 'post', path: enrollmentAPIKeyRouteService.getCreatePath(), + version: LATEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/epm.ts b/x-pack/plugins/fleet/public/hooks/use_request/epm.ts index cc381c20ecd97..2a3e3d69f9964 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/epm.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/epm.ts @@ -29,6 +29,7 @@ import type { GetVerificationKeyIdResponse, } from '../../types'; import type { FleetErrorResponse, GetStatsResponse } from '../../../common/types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; import { getCustomIntegrations } from '../../services/custom_integrations'; @@ -53,6 +54,7 @@ export function useGetCategoriesQuery(query: GetCategoriesRequest['query'] = {}) path: epmRouteService.getCategoriesPath(), method: 'get', query, + version: LATEST_PUBLIC_VERSION, }) ); } @@ -61,6 +63,7 @@ export const sendGetCategories = (query: GetCategoriesRequest['query'] = {}) => return sendRequest({ path: epmRouteService.getCategoriesPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, query, }); }; @@ -69,6 +72,7 @@ export const useGetPackages = (query: GetPackagesRequest['query'] = {}) => { return useRequest({ path: epmRouteService.getListPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, query, }); }; @@ -78,6 +82,7 @@ export const useGetPackagesQuery = (query: GetPackagesRequest['query']) => { sendRequestForRq({ path: epmRouteService.getListPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, query, }) ); @@ -87,6 +92,7 @@ export const sendGetPackages = (query: GetPackagesRequest['query'] = {}) => { return sendRequest({ path: epmRouteService.getListPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, query, }); }; @@ -95,6 +101,7 @@ export const useGetLimitedPackages = () => { return useRequest({ path: epmRouteService.getListLimitedPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; @@ -116,6 +123,7 @@ export const useGetPackageInfoByKeyQuery = ( sendRequestForRq({ path: epmRouteService.getInfoPath(pkgName, pkgVersion), method: 'get', + version: LATEST_PUBLIC_VERSION, query: { ...options, ...(ignoreUnverifiedQueryParam && { ignoreUnverified: ignoreUnverifiedQueryParam }), @@ -142,6 +150,7 @@ export const useGetPackageStats = (pkgName: string) => { return useRequest({ path: epmRouteService.getStatsPath(pkgName), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; @@ -152,6 +161,7 @@ export const useGetPackageVerificationKeyId = () => { sendRequestForRq({ path: epmRouteService.getVerificationKeyIdPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, }) ); @@ -173,6 +183,7 @@ export const sendGetPackageInfoByKey = ( return sendRequest({ path: epmRouteService.getInfoPath(pkgName, pkgVersion), method: 'get', + version: LATEST_PUBLIC_VERSION, query: options, }); }; @@ -181,12 +192,17 @@ export const useGetFileByPath = (filePath: string) => { return useRequest({ path: epmRouteService.getFilePath(filePath), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; export const useGetFileByPathQuery = (filePath: string) => { return useQuery, RequestError>(['get-file', filePath], () => - sendRequest({ path: epmRouteService.getFilePath(filePath), method: 'get' }) + sendRequest({ + path: epmRouteService.getFilePath(filePath), + method: 'get', + version: LATEST_PUBLIC_VERSION, + }) ); }; @@ -194,6 +210,7 @@ export const sendGetFileByPath = (filePath: string) => { return sendRequest({ path: epmRouteService.getFilePath(filePath), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; @@ -202,6 +219,7 @@ export const sendInstallPackage = (pkgName: string, pkgVersion: string, force: b return sendRequest({ path: epmRouteService.getInstallPath(pkgName, pkgVersion), method: 'post', + version: LATEST_PUBLIC_VERSION, body, }); }; @@ -212,6 +230,7 @@ export const sendBulkInstallPackages = ( return sendRequest({ path: epmRouteService.getBulkInstallPath(), method: 'post', + version: LATEST_PUBLIC_VERSION, body: { packages, }, @@ -222,6 +241,7 @@ export const sendRemovePackage = (pkgName: string, pkgVersion: string, force: bo return sendRequest({ path: epmRouteService.getRemovePath(pkgName, pkgVersion), method: 'delete', + version: LATEST_PUBLIC_VERSION, body: { force, }, @@ -236,6 +256,7 @@ export const sendRequestReauthorizeTransforms = ( return sendRequest({ path: epmRouteService.getReauthorizeTransformsPath(pkgName, pkgVersion), method: 'post', + version: LATEST_PUBLIC_VERSION, body: { transforms }, }); }; @@ -252,6 +273,7 @@ export const useUpdatePackageMutation = () => { sendRequestForRq({ path: epmRouteService.getUpdatePath(pkgName, pkgVersion), method: 'put', + version: LATEST_PUBLIC_VERSION, body, }) ); @@ -265,6 +287,7 @@ export const sendUpdatePackage = ( return sendRequest({ path: epmRouteService.getUpdatePath(pkgName, pkgVersion), method: 'put', + version: LATEST_PUBLIC_VERSION, body, }); }; @@ -273,6 +296,7 @@ export const sendGetBulkAssets = (body: GetBulkAssetsRequest['body']) => { return sendRequest({ path: epmRouteService.getBulkAssetsPath(), method: 'post', + version: LATEST_PUBLIC_VERSION, body, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts b/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts index 0e058f900c442..ff07724b725c7 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts @@ -6,6 +6,8 @@ */ import { fleetProxiesRoutesService } from '../../../common/services'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + import type { GetFleetProxiesResponse, PostFleetProxiesRequest, @@ -18,21 +20,32 @@ export function useGetFleetProxies() { return useRequest({ method: 'get', path: fleetProxiesRoutesService.getListPath(), + version: LATEST_PUBLIC_VERSION, }); } export function sendDeleteFleetProxy(proxyId: string) { - return sendRequest({ method: 'delete', path: fleetProxiesRoutesService.getDeletePath(proxyId) }); + return sendRequest({ + method: 'delete', + path: fleetProxiesRoutesService.getDeletePath(proxyId), + version: LATEST_PUBLIC_VERSION, + }); } export function sendPostFleetProxy(body: PostFleetProxiesRequest['body']) { - return sendRequest({ method: 'post', path: fleetProxiesRoutesService.getCreatePath(), body }); + return sendRequest({ + method: 'post', + path: fleetProxiesRoutesService.getCreatePath(), + body, + version: LATEST_PUBLIC_VERSION, + }); } export function sendPutFleetProxy(proxyId: string, body: PutFleetProxiesRequest['body']) { return sendRequest({ method: 'put', path: fleetProxiesRoutesService.getUpdatePath(proxyId), + version: LATEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts b/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts index f066da66dba12..401850736d1db 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts @@ -6,6 +6,9 @@ */ import { fleetServerHostsRoutesService } from '../../../common/services'; + +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + import type { GetFleetServerHostsResponse, PostFleetServerHostsRequest, @@ -19,6 +22,7 @@ export function useGetFleetServerHosts() { return useRequest({ method: 'get', path: fleetServerHostsRoutesService.getListPath(), + version: LATEST_PUBLIC_VERSION, }); } @@ -26,6 +30,7 @@ export function sendDeleteFleetServerHost(itemId: string) { return sendRequest({ method: 'delete', path: fleetServerHostsRoutesService.getDeletePath(itemId), + version: LATEST_PUBLIC_VERSION, }); } @@ -33,6 +38,7 @@ export function sendPutFleetServerHost(itemId: string, body: PutFleetServerHosts return sendRequest({ method: 'put', path: fleetServerHostsRoutesService.getUpdatePath(itemId), + version: LATEST_PUBLIC_VERSION, body, }); } @@ -41,6 +47,7 @@ export function sendPostFleetServerHost(body: PostFleetServerHostsRequest['body' return sendRequest({ method: 'post', path: fleetServerHostsRoutesService.getCreatePath(), + version: LATEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts b/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts index c5fdc7886faac..08bc02828be00 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts @@ -7,6 +7,7 @@ import type { PostHealthCheckRequest, PostHealthCheckResponse } from '../../types'; import { appRoutesService } from '../../services'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; import { sendRequest } from './use_request'; @@ -14,6 +15,7 @@ export function sendPostHealthCheck(body: PostHealthCheckRequest['body']) { return sendRequest({ method: 'post', path: appRoutesService.postHealthCheckPath(), + version: LATEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts b/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts index 2102fe6f5fe93..d8bc2a6a68e50 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts @@ -8,6 +8,7 @@ import { agentPolicyRouteService } from '../../services'; import type { GetFullAgentManifestResponse } from '../../../common/types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; import { sendRequest } from './use_request'; @@ -15,6 +16,7 @@ export const sendGetK8sManifest = (query: { fleetServer?: string; enrolToken?: s return sendRequest({ path: agentPolicyRouteService.getK8sInfoPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, query, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts b/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts index 24b36df68a5fa..337a5171ab396 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts @@ -13,6 +13,8 @@ import type { PostLogstashApiKeyResponse, } from '../../types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + import { sendRequest, useRequest } from './use_request'; export function useGetOutputs() { @@ -33,6 +35,7 @@ export function sendPutOutput(outputId: string, body: PutOutputRequest['body']) return sendRequest({ method: 'put', path: outputRoutesService.getUpdatePath(outputId), + version: LATEST_PUBLIC_VERSION, body, }); } @@ -41,6 +44,7 @@ export function sendPostLogstashApiKeys() { return sendRequest({ method: 'post', path: outputRoutesService.getCreateLogstashApiKeyPath(), + version: LATEST_PUBLIC_VERSION, }); } @@ -48,6 +52,7 @@ export function sendPostOutput(body: PostOutputRequest['body']) { return sendRequest({ method: 'post', path: outputRoutesService.getCreatePath(), + version: LATEST_PUBLIC_VERSION, body, }); } @@ -56,5 +61,6 @@ export function sendDeleteOutput(outputId: string) { return sendRequest({ method: 'delete', path: outputRoutesService.getDeletePath(outputId), + version: LATEST_PUBLIC_VERSION, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts b/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts index 4a573bb5e5883..26c86f72b316b 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts @@ -24,6 +24,8 @@ import type { UpgradePackagePolicyResponse, } from '../../../common/types/rest_spec'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + import type { RequestError } from './use_request'; import { sendRequest, sendRequestForRq, useRequest } from './use_request'; @@ -31,6 +33,7 @@ export const sendCreatePackagePolicy = (body: CreatePackagePolicyRequest['body'] return sendRequest({ path: packagePolicyRouteService.getCreatePath(), method: 'post', + version: LATEST_PUBLIC_VERSION, body: JSON.stringify(body), }); }; @@ -42,6 +45,7 @@ export const sendUpdatePackagePolicy = ( return sendRequest({ path: packagePolicyRouteService.getUpdatePath(packagePolicyId), method: 'put', + version: LATEST_PUBLIC_VERSION, body: JSON.stringify(body), }); }; @@ -50,6 +54,7 @@ export const sendDeletePackagePolicy = (body: DeletePackagePoliciesRequest['body return sendRequest({ path: packagePolicyRouteService.getDeletePath(), method: 'post', + version: LATEST_PUBLIC_VERSION, body: JSON.stringify(body), }); }; @@ -58,6 +63,7 @@ export function useGetPackagePoliciesQuery(query: GetPackagePoliciesRequest['que return useQuery(['packagePolicies'], () => sendRequestForRq({ method: 'get', + version: LATEST_PUBLIC_VERSION, path: packagePolicyRouteService.getListPath(), query, }) @@ -67,6 +73,7 @@ export function useGetPackagePoliciesQuery(query: GetPackagePoliciesRequest['que export function useGetPackagePolicies(query: GetPackagePoliciesRequest['query']) { return useRequest({ method: 'get', + version: LATEST_PUBLIC_VERSION, path: packagePolicyRouteService.getListPath(), query, }); @@ -75,6 +82,7 @@ export function useGetPackagePolicies(query: GetPackagePoliciesRequest['query']) export const sendGetPackagePolicies = (query: GetPackagePoliciesRequest['query']) => { return sendRequest({ method: 'get', + version: LATEST_PUBLIC_VERSION, path: packagePolicyRouteService.getListPath(), query, }); @@ -86,6 +94,7 @@ export const useGetOnePackagePolicyQuery = (packagePolicyId: string) => { () => sendRequestForRq({ method: 'get', + version: LATEST_PUBLIC_VERSION, path: packagePolicyRouteService.getInfoPath(packagePolicyId), }) ); @@ -95,6 +104,7 @@ export const useGetOnePackagePolicy = (packagePolicyId: string) => { return useRequest({ path: packagePolicyRouteService.getInfoPath(packagePolicyId), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; @@ -102,6 +112,7 @@ export const sendGetOnePackagePolicy = (packagePolicyId: string) => { return sendRequest({ path: packagePolicyRouteService.getInfoPath(packagePolicyId), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; @@ -124,6 +135,7 @@ export function useUpgradePackagePolicyDryRunQuery( sendRequestForRq({ path: packagePolicyRouteService.getDryRunPath(), method: 'post', + version: LATEST_PUBLIC_VERSION, body: JSON.stringify(body), }), { enabled } @@ -145,6 +157,7 @@ export function sendUpgradePackagePolicyDryRun( return sendRequest({ path: packagePolicyRouteService.getDryRunPath(), method: 'post', + version: LATEST_PUBLIC_VERSION, body: JSON.stringify(body), }); } @@ -158,6 +171,7 @@ export function useUpgradePackagePoliciesMutation() { sendRequestForRq({ path: packagePolicyRouteService.getUpgradePath(), method: 'post', + version: LATEST_PUBLIC_VERSION, body: JSON.stringify({ packagePolicyIds, }), @@ -169,6 +183,7 @@ export function sendUpgradePackagePolicy(packagePolicyIds: string[]) { return sendRequest({ path: packagePolicyRouteService.getUpgradePath(), method: 'post', + version: LATEST_PUBLIC_VERSION, body: JSON.stringify({ packagePolicyIds, }), @@ -179,5 +194,6 @@ export function sendGetOrphanedIntegrationPolicies() { return sendRequest({ path: packagePolicyRouteService.getOrphanedIntegrationPoliciesPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/settings.ts b/x-pack/plugins/fleet/public/hooks/use_request/settings.ts index 41131a32593de..5c6464b7e8bc0 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/settings.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/settings.ts @@ -10,6 +10,8 @@ import { useQuery } from '@tanstack/react-query'; import { settingsRoutesService } from '../../services'; import type { PutSettingsResponse, PutSettingsRequest, GetSettingsResponse } from '../../types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + import type { RequestError } from './use_request'; import { sendRequest, sendRequestForRq, useRequest } from './use_request'; @@ -18,6 +20,7 @@ export function useGetSettingsQuery() { sendRequestForRq({ method: 'get', path: settingsRoutesService.getInfoPath(), + version: LATEST_PUBLIC_VERSION, }) ); } @@ -26,6 +29,7 @@ export function useGetSettings() { return useRequest({ method: 'get', path: settingsRoutesService.getInfoPath(), + version: LATEST_PUBLIC_VERSION, }); } @@ -33,6 +37,7 @@ export function sendGetSettings() { return sendRequest({ method: 'get', path: settingsRoutesService.getInfoPath(), + version: LATEST_PUBLIC_VERSION, }); } @@ -40,6 +45,7 @@ export function sendPutSettings(body: PutSettingsRequest['body']) { return sendRequest({ method: 'put', path: settingsRoutesService.getUpdatePath(), + version: LATEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/setup.ts b/x-pack/plugins/fleet/public/hooks/use_request/setup.ts index 67d631d5d55bc..53236841c46ee 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/setup.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/setup.ts @@ -7,6 +7,7 @@ import { setupRouteService, fleetSetupRouteService } from '../../services'; import type { GetFleetStatusResponse } from '../../types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; import { sendRequest } from './use_request'; @@ -14,6 +15,7 @@ export const sendSetup = () => { return sendRequest({ path: setupRouteService.getSetupPath(), method: 'post', + version: LATEST_PUBLIC_VERSION, }); }; @@ -21,6 +23,7 @@ export const sendGetFleetStatus = () => { return sendRequest({ path: fleetSetupRouteService.getFleetSetupPath(), method: 'get', + version: LATEST_PUBLIC_VERSION, }); }; @@ -28,6 +31,7 @@ export const sendPostFleetSetup = ({ forceRecreate }: { forceRecreate: boolean } return sendRequest({ method: 'post', path: fleetSetupRouteService.postFleetSetupPath(), + version: LATEST_PUBLIC_VERSION, body: { forceRecreate, }, diff --git a/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts b/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts index a851c572cf21d..40abc3e1c7f9c 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts @@ -9,6 +9,8 @@ import { useQuery } from '@tanstack/react-query'; import { uninstallTokensRouteService } from '../../../common/services'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + import type { GetUninstallTokensMetadataRequest, GetUninstallTokensMetadataResponse, @@ -23,6 +25,7 @@ export const useGetUninstallTokens = (query: GetUninstallTokensMetadataRequest[' sendRequestForRq({ method: 'get', path: uninstallTokensRouteService.getListPath(), + version: LATEST_PUBLIC_VERSION, query, }) ); @@ -34,6 +37,7 @@ export const useGetUninstallToken = (uninstallTokenId: string) => sendRequestForRq({ method: 'get', path: uninstallTokensRouteService.getInfoPath(uninstallTokenId), + version: LATEST_PUBLIC_VERSION, }) ); @@ -41,4 +45,5 @@ export const sendGetUninstallToken = (uninstallTokenId: string) => sendRequest({ method: 'get', path: uninstallTokensRouteService.getInfoPath(uninstallTokenId), + version: LATEST_PUBLIC_VERSION, }); diff --git a/x-pack/plugins/fleet/public/plugin.ts b/x-pack/plugins/fleet/public/plugin.ts index a433ba3fde50d..6e6afe4214b57 100644 --- a/x-pack/plugins/fleet/public/plugin.ts +++ b/x-pack/plugins/fleet/public/plugin.ts @@ -16,6 +16,10 @@ import type { import { i18n } from '@kbn/i18n'; import type { NavigationPublicPluginStart } from '@kbn/navigation-plugin/public'; +import { + ELASTIC_HTTP_VERSION_HEADER, + X_ELASTIC_INTERNAL_ORIGIN_REQUEST, +} from '@kbn/core-http-common'; import type { CustomIntegrationsStart, @@ -58,6 +62,8 @@ import type { ExperimentalFeatures } from '../common/experimental_features'; import type { FleetConfigType } from '../common/types'; +import { LATEST_PUBLIC_VERSION } from '../common/constants'; + import { CUSTOM_LOGS_INTEGRATION_NAME, INTEGRATIONS_BASE_PATH } from './constants'; import { licenseService } from './hooks'; import { setHttpClient } from './hooks/use_request'; @@ -281,7 +287,13 @@ export class FleetPlugin implements Plugin - core.http.get(appRoutesService.getCheckPermissionsPath()) + core.http.fetch(appRoutesService.getCheckPermissionsPath(), { + headers: { + [ELASTIC_HTTP_VERSION_HEADER]: LATEST_PUBLIC_VERSION, + [X_ELASTIC_INTERNAL_ORIGIN_REQUEST]: 'kibana', + }, + version: LATEST_PUBLIC_VERSION, + }) ); // Set up license service diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.ts index ca6e112864793..fd746a96f7826 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.ts @@ -142,7 +142,6 @@ export function makeRouterWithFleetAuthz { const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; const defaultVersion = getDefaultVersion(access); - return versionedRouter .get({ access, path: options.path }) .addVersion( @@ -151,25 +150,49 @@ export function makeRouterWithFleetAuthz { - router.delete(withDefaultPublicAccess(options), (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) - ); + delete: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; + const defaultVersion = getDefaultVersion(access); + return versionedRouter + .delete({ access, path: options.path }) + .addVersion( + { version: version || defaultVersion, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); }, - post: ({ fleetAuthz: hasRequiredAuthz, ...options }, handler) => { - router.post(withDefaultPublicAccess(options), (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) - ); + post: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; + const defaultVersion = getDefaultVersion(access); + return versionedRouter + .post({ access, path: options.path }) + .addVersion( + { version: version || defaultVersion, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); }, - put: ({ fleetAuthz: hasRequiredAuthz, ...options }, handler) => { - router.put(withDefaultPublicAccess(options), (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) - ); + put: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; + const defaultVersion = getDefaultVersion(access); + return versionedRouter + .put({ access, path: options.path }) + .addVersion( + { version: version || defaultVersion, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); }, - patch: ({ fleetAuthz: hasRequiredAuthz, ...options }, handler) => { - router.patch(withDefaultPublicAccess(options), (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) - ); + patch: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; + const defaultVersion = getDefaultVersion(access); + return versionedRouter + .patch({ access, path: options.path }) + .addVersion( + { version: version || defaultVersion, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); }, handleLegacyErrors: (handler) => router.handleLegacyErrors(handler), getRoutes: () => router.getRoutes(), From 3eaaba9328e9fcb70e2d16728f9d22a0061943e5 Mon Sep 17 00:00:00 2001 From: criamico Date: Thu, 10 Aug 2023 11:11:31 +0200 Subject: [PATCH 03/26] Mark deprecated endpoints as internal only --- .../common/openapi/components/parameters/kuery.yaml | 1 - x-pack/plugins/fleet/server/routes/agent/index.ts | 3 +++ x-pack/plugins/fleet/server/routes/app/index.ts | 3 +++ .../fleet/server/routes/enrollment_api_key/index.ts | 12 ++++++++++++ x-pack/plugins/fleet/server/routes/epm/index.ts | 12 ++++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/common/openapi/components/parameters/kuery.yaml b/x-pack/plugins/fleet/common/openapi/components/parameters/kuery.yaml index 0ef22394e5198..b96ffd54d37ce 100644 --- a/x-pack/plugins/fleet/common/openapi/components/parameters/kuery.yaml +++ b/x-pack/plugins/fleet/common/openapi/components/parameters/kuery.yaml @@ -1,6 +1,5 @@ name: kuery in: query required: false -deprecated: true schema: type: string diff --git a/x-pack/plugins/fleet/server/routes/agent/index.ts b/x-pack/plugins/fleet/server/routes/agent/index.ts index 44a43ccb732bf..98bddcee2c4f6 100644 --- a/x-pack/plugins/fleet/server/routes/agent/index.ts +++ b/x-pack/plugins/fleet/server/routes/agent/index.ts @@ -280,6 +280,9 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT fleetAuthz: { fleet: { all: true }, }, + options: { + access: 'internal', + }, }, getAgentStatusForAgentPolicyHandler ); diff --git a/x-pack/plugins/fleet/server/routes/app/index.ts b/x-pack/plugins/fleet/server/routes/app/index.ts index cb0c12f9211aa..9db966d7c471c 100644 --- a/x-pack/plugins/fleet/server/routes/app/index.ts +++ b/x-pack/plugins/fleet/server/routes/app/index.ts @@ -113,6 +113,9 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { all: true }, }, + options: { + access: 'internal', + }, }, generateServiceTokenHandler ); diff --git a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts index 496ec7ae705ce..15807d93288a0 100644 --- a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts +++ b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts @@ -74,6 +74,9 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { readEnrollmentTokens: true }, }, + options: { + access: 'internal', + }, }, getOneEnrollmentApiKeyHandler ); @@ -85,6 +88,9 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { all: true }, }, + options: { + access: 'internal', + }, }, deleteEnrollmentApiKeyHandler ); @@ -96,6 +102,9 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { readEnrollmentTokens: true }, }, + options: { + access: 'internal', + }, }, getEnrollmentApiKeysHandler ); @@ -107,6 +116,9 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { all: true }, }, + options: { + access: 'internal', + }, }, postEnrollmentApiKeyHandler ); diff --git a/x-pack/plugins/fleet/server/routes/epm/index.ts b/x-pack/plugins/fleet/server/routes/epm/index.ts index 8567e1b5686f7..6776bedd96c30 100644 --- a/x-pack/plugins/fleet/server/routes/epm/index.ts +++ b/x-pack/plugins/fleet/server/routes/epm/index.ts @@ -263,6 +263,9 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz, getRouteRequiredAuthz('get', EPM_API_ROUTES.INFO_PATTERN_DEPRECATED) ).granted, + options: { + access: 'internal', + }, }, async (context, request, response) => { const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any; @@ -286,6 +289,9 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { integrations: { upgradePackages: true, writePackageSettings: true }, }, + options: { + access: 'internal', + }, }, async (context, request, response) => { const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any; @@ -308,6 +314,9 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { integrations: { installPackages: true }, }, + options: { + access: 'internal', + }, }, async (context, request, response) => { const newRequest = { @@ -334,6 +343,9 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { integrations: { removePackages: true }, }, + options: { + access: 'internal', + }, }, async (context, request, response) => { const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any; From c6528a0eddfaad0a8e10fcf47b84467665d5eeeb Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 10 Aug 2023 09:29:50 +0000 Subject: [PATCH 04/26] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/plugins/fleet/tsconfig.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/plugins/fleet/tsconfig.json b/x-pack/plugins/fleet/tsconfig.json index 82b22c90779b7..08329fe58565c 100644 --- a/x-pack/plugins/fleet/tsconfig.json +++ b/x-pack/plugins/fleet/tsconfig.json @@ -100,5 +100,7 @@ "@kbn/core-http-router-server-mocks", "@kbn/core-application-browser", "@kbn/core-saved-objects-base-server-internal", + "@kbn/core-http-common", + "@kbn/server-route-repository", ] } From 65e88ae39e5560bb3eedf08db859c9f130e61636 Mon Sep 17 00:00:00 2001 From: criamico Date: Thu, 10 Aug 2023 12:40:37 +0200 Subject: [PATCH 05/26] Add headers in fleet cypress tests --- .../plugins/fleet/cypress/e2e/a11y/home_page.cy.ts | 6 ++++-- .../cypress/e2e/agent_binary_download_source.cy.ts | 6 ++++-- .../fleet/cypress/e2e/agents/agent_list.cy.ts | 4 +++- .../fleet/cypress/e2e/enrollment_token.cy.ts | 4 +++- .../fleet/cypress/e2e/fleet_agent_flyout.cy.ts | 4 +++- .../fleet/cypress/e2e/integrations_real.cy.ts | 3 ++- ...ackage_policy_pipelines_and_mappings_real.cy.ts | 14 ++++++++------ .../fleet/cypress/e2e/uninstall_token.cy.ts | 4 +++- x-pack/plugins/fleet/cypress/plugins/index.ts | 8 +++++++- x-pack/plugins/fleet/cypress/tasks/cleanup.ts | 7 ++++--- x-pack/plugins/fleet/cypress/tasks/fleet_server.ts | 6 ++++-- x-pack/plugins/fleet/cypress/tasks/integrations.ts | 6 ++++-- .../fleet/scripts/create_agents/create_agents.ts | 2 ++ .../scripts/get_all_packages/get_all_packages.ts | 2 ++ .../install_all_packages/install_all_packages.ts | 4 ++++ .../fleet/server/routes/setup/handlers.test.ts | 3 +++ 16 files changed, 60 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts b/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts index 39debfc94662a..b6408487d348e 100644 --- a/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts @@ -33,6 +33,8 @@ import { AGENT_POLICY_NAME_LINK } from '../../screens/integrations'; import { cleanupAgentPolicies, unenrollAgent } from '../../tasks/cleanup'; import { setFleetServerHost } from '../../tasks/fleet_server'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + describe('Home page', () => { before(() => { setFleetServerHost('https://fleetserver:8220'); @@ -152,7 +154,7 @@ describe('Home page', () => { method: 'POST', url: '/api/fleet/agent_policies', body: { name: 'Agent policy for A11y test', namespace: 'default', id: 'agent-policy-a11y' }, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); }); beforeEach(() => { @@ -164,7 +166,7 @@ describe('Home page', () => { method: 'POST', url: '/api/fleet/agent_policies/delete', body: { agentPolicyId: 'agent-policy-a11y' }, - headers: { 'kbn-xsrf': 'kibana' }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); }); it('Uninstall Tokens Table', () => { diff --git a/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts b/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts index 095a87a28e130..3d07dbe49e102 100644 --- a/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts @@ -15,6 +15,8 @@ import { cleanupDownloadSources } from '../tasks/cleanup'; import { FLEET, navigateTo } from '../tasks/navigation'; import { CONFIRM_MODAL } from '../screens/navigation'; +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; + describe('Agent binary download source section', () => { beforeEach(() => { cleanupDownloadSources(); @@ -80,7 +82,7 @@ describe('Agent binary download source section', () => { id: 'fleet-local-registry', host: 'https://new-custom-host.co', }, - headers: { 'kbn-xsrf': 'kibana' }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); cy.request({ method: 'POST', @@ -93,7 +95,7 @@ describe('Agent binary download source section', () => { id: 'new-agent-policy', download_source_id: 'fleet-local-registry', }, - headers: { 'kbn-xsrf': 'kibana' }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }).then((response: any) => { navigateTo('app/fleet/policies/new-agent-policy/settings'); cy.getBySel(AGENT_POLICY_FORM.DOWNLOAD_SOURCE_SELECT).contains('Custom Host'); diff --git a/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts b/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts index fd85e05e51aec..549f552589197 100644 --- a/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts @@ -13,6 +13,8 @@ import { deleteFleetServerDocs, deleteAgentDocs, cleanupAgentPolicies } from '.. import type { CreateAgentPolicyRequest } from '../../../common/types'; import { setUISettings } from '../../tasks/ui_settings'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; + const createAgentDocs = (kibanaVersion: string) => [ createAgentDoc('agent-1', 'policy-1'), // this agent will have upgrade available createAgentDoc('agent-2', 'policy-2', 'error', kibanaVersion), @@ -66,7 +68,7 @@ function createAgentPolicy(body: CreateAgentPolicyRequest['body']) { cy.request({ method: 'POST', url: '/api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'xx' }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, body, }); } diff --git a/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts b/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts index 84b910c856dfb..9724888ae8814 100644 --- a/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts @@ -8,6 +8,8 @@ import { cleanupAgentPolicies } from '../tasks/cleanup'; import { ENROLLMENT_TOKENS } from '../screens/fleet'; +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; + describe('Enrollment token page', () => { before(() => { cy.request({ @@ -20,7 +22,7 @@ describe('Enrollment token page', () => { monitoring_enabled: ['logs', 'metrics'], id: 'agent-policy-1', }, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); }); diff --git a/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts b/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts index b907fb8ef4c79..026f5efc74e92 100644 --- a/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts @@ -11,6 +11,8 @@ import { createAgentDoc } from '../tasks/agents'; import { setFleetServerHost } from '../tasks/fleet_server'; import { FLEET, navigateTo } from '../tasks/navigation'; +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; + const FLEET_SERVER_POLICY_ID = 'fleet-server-policy'; function cleanUp() { @@ -28,7 +30,7 @@ describe('Fleet add agent flyout', () => { cy.request({ method: 'POST', url: '/api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'xx' }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, body: { id: FLEET_SERVER_POLICY_ID, name: 'Fleet Server policy', diff --git a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts index 3e570d0e76f78..6c457fb488ba6 100644 --- a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts @@ -31,6 +31,7 @@ import { import { LOADING_SPINNER, CONFIRM_MODAL } from '../screens/navigation'; import { ADD_PACKAGE_POLICY_BTN } from '../screens/fleet'; import { cleanupAgentPolicies } from '../tasks/cleanup'; +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; function setupIntegrations() { cy.intercept( @@ -113,7 +114,7 @@ describe('Add Integration - Real API', () => { namespace: 'default', monitoring_enabled: ['logs', 'metrics'], }, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); cy.request('/api/fleet/agent_policies').then((response: any) => { diff --git a/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts b/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts index 3fed3fef1d94b..f69498d0a7852 100644 --- a/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts @@ -17,6 +17,8 @@ const INPUT_TEST_PACKAGE = 'input_package-1.0.0'; const INTEGRATION_TEST_PACKAGE = 'logs_integration-1.0.0'; const INTEGRATION_TEST_PACKAGE_NO_DATASET = 'logs_int_no_dataset-1.0.0'; +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; + describe('Input package create and edit package policy', () => { const agentPolicyId = 'test-input-package-policy'; const agentPolicyName = 'Test input package policy'; @@ -45,7 +47,7 @@ describe('Input package create and edit package policy', () => { namespace: 'default', monitoring_enabled: [], }, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); }); after(() => { @@ -53,7 +55,7 @@ describe('Input package create and edit package policy', () => { cy.request({ method: 'POST', url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, body: JSON.stringify({ agentPolicyId, }), @@ -120,7 +122,7 @@ describe('Integration package with custom dataset create and edit package policy namespace: 'default', monitoring_enabled: [], }, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); }); after(() => { @@ -128,7 +130,7 @@ describe('Integration package with custom dataset create and edit package policy cy.request({ method: 'POST', url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, body: JSON.stringify({ agentPolicyId, }), @@ -184,7 +186,7 @@ describe('Integration package with fixed dataset create and edit package policy' namespace: 'default', monitoring_enabled: [], }, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); }); after(() => { @@ -192,7 +194,7 @@ describe('Integration package with fixed dataset create and edit package policy' cy.request({ method: 'POST', url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, body: JSON.stringify({ agentPolicyId, }), diff --git a/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts b/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts index 212e7aa0b3a9e..e6ec85f960fe3 100644 --- a/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts @@ -11,6 +11,8 @@ import { cleanupAgentPolicies } from '../tasks/cleanup'; import { UNINSTALL_TOKENS } from '../screens/fleet'; import type { GetUninstallTokenResponse } from '../../common/types/rest_spec/uninstall_token'; +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; + describe('Uninstall token page', () => { before(() => { cleanupAgentPolicies(); @@ -78,7 +80,7 @@ describe('Uninstall token page', () => { method: 'POST', url: '/api/fleet/agent_policies', body: { name: `Agent policy ${i}00`, namespace: 'default', id: `agent-policy-${i}00` }, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); } }; diff --git a/x-pack/plugins/fleet/cypress/plugins/index.ts b/x-pack/plugins/fleet/cypress/plugins/index.ts index ee01dd20c470c..eaf6598f0409e 100644 --- a/x-pack/plugins/fleet/cypress/plugins/index.ts +++ b/x-pack/plugins/fleet/cypress/plugins/index.ts @@ -12,6 +12,8 @@ import fs from 'fs'; import fetch from 'node-fetch'; import { createEsClientForTesting } from '@kbn/test'; +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; + const plugin: Cypress.PluginConfig = (on, config) => { const client = createEsClientForTesting({ esUrl: config.env.ELASTICSEARCH_URL, @@ -22,8 +24,9 @@ const plugin: Cypress.PluginConfig = (on, config) => { path: string; body?: any; contentType?: string; + version?: string; }) { - const { method, path, body, contentType } = opts; + const { method, path, body, contentType, version } = opts; const Authorization = `Basic ${Buffer.from( `elastic:${config.env.ELASTICSEARCH_PASSWORD}` ).toString('base64')}`; @@ -35,6 +38,7 @@ const plugin: Cypress.PluginConfig = (on, config) => { 'kbn-xsrf': 'cypress', 'Content-Type': contentType || 'application/json', Authorization, + ...(version ? { 'Elastic-Api-Version': version } : {}), }, ...(body ? { body } : {}), }); @@ -75,6 +79,7 @@ const plugin: Cypress.PluginConfig = (on, config) => { path: '/api/fleet/epm/packages', body: Buffer.from(zipContent, 'base64'), contentType: 'application/zip', + version: LATEST_PUBLIC_VERSION, }); }, @@ -82,6 +87,7 @@ const plugin: Cypress.PluginConfig = (on, config) => { return kibanaFetch({ method: 'DELETE', path: `/api/fleet/epm/packages/${packageName}`, + version: LATEST_PUBLIC_VERSION, }); }, }); diff --git a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts index 2a1e57271f08a..4e6536cc02717 100644 --- a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts +++ b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts @@ -4,6 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; export function cleanupAgentPolicies() { cy.request('/api/fleet/agent_policies').then((response: any) => { @@ -14,7 +15,7 @@ export function cleanupAgentPolicies() { method: 'POST', url: '/api/fleet/agent_policies/delete', body: { agentPolicyId: policy.id }, - headers: { 'kbn-xsrf': 'kibana' }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); }); }); @@ -28,7 +29,7 @@ export function unenrollAgent() { method: 'POST', url: `api/fleet/agents/${agent.id}/unenroll`, body: { revoke: true }, - headers: { 'kbn-xsrf': 'kibana' }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); }); } @@ -43,7 +44,7 @@ export function cleanupDownloadSources() { cy.request({ method: 'DELETE', url: `/api/fleet/agent_download_sources/${ds.id}`, - headers: { 'kbn-xsrf': 'kibana' }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); }); }); diff --git a/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts b/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts index 8ec8e75c1d13f..fe590030e9d9e 100644 --- a/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts +++ b/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts @@ -4,6 +4,8 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; + import { createAgentDoc } from './agents'; const FLEET_SERVER_POLICY_ID = 'fleet-server-policy'; @@ -16,7 +18,7 @@ export function setupFleetServer() { cy.request({ method: 'POST', url: '/api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'xx' }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, body: { id: FLEET_SERVER_POLICY_ID, name: 'Fleet Server policy', @@ -61,7 +63,7 @@ export function setFleetServerHost(host = 'https://fleetserver:8220') { cy.request({ method: 'POST', url: '/api/fleet/fleet_server_hosts', - headers: { 'kbn-xsrf': 'xx' }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, body: { name: 'Default host', host_urls: [host], diff --git a/x-pack/plugins/fleet/cypress/tasks/integrations.ts b/x-pack/plugins/fleet/cypress/tasks/integrations.ts index 71a8c3cd2f9a7..2a59f34278724 100644 --- a/x-pack/plugins/fleet/cypress/tasks/integrations.ts +++ b/x-pack/plugins/fleet/cypress/tasks/integrations.ts @@ -14,6 +14,8 @@ import { import { AGENT_POLICY_SYSTEM_MONITORING_CHECKBOX, EXISTING_HOSTS_TAB } from '../screens/fleet'; import { TOAST_CLOSE_BTN, CONFIRM_MODAL } from '../screens/navigation'; +import { LATEST_PUBLIC_VERSION } from '../../common/constants'; + export const addIntegration = ({ useExistingPolicy } = { useExistingPolicy: false }) => { cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click(); if (useExistingPolicy) { @@ -53,7 +55,7 @@ export const deleteIntegrations = async () => { response.body.items.forEach((policy: any) => ids.push(policy.id)); cy.request({ url: `/api/fleet/package_policies/delete`, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, body: `{ "packagePolicyIds": ${JSON.stringify(ids)}, "force": true }`, method: 'POST', }); @@ -63,7 +65,7 @@ export const deleteIntegrations = async () => { export const installPackageWithVersion = (integration: string, version: string) => { cy.request({ url: `/api/fleet/epm/packages/${integration}/${version}`, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, body: '{ "force": true }', method: 'POST', }); diff --git a/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts b/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts index 4436c07cc07b9..c906715e4eff6 100644 --- a/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts +++ b/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts @@ -272,6 +272,8 @@ async function createAgentPolicy(id: string) { 'Content-Type': 'application/json', 'kbn-xsrf': 'kibana', 'x-elastic-product-origin': 'fleet', + // Note: version can change in the future + 'Elastic-Api-Version': '2023-10-31', }, }); const data = await res.json(); diff --git a/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts b/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts index b29709190f15d..059e5096efad1 100644 --- a/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts +++ b/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts @@ -50,6 +50,8 @@ async function getPackage(name: string, version: string, full: boolean = false) 'kbn-xsrf': 'xyz', Authorization: 'Basic ' + Buffer.from(`${KIBANA_USERNAME}:${KIBANA_PASSWORD}`).toString('base64'), + // Note: version can change in the future + 'Elastic-Api-Version': '2023-10-31', }, method: 'GET', } diff --git a/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts b/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts index 3ff907ceff761..1135b7cc4dc42 100644 --- a/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts +++ b/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts @@ -59,6 +59,8 @@ async function installPackage(name: string, version: string) { 'content-type': 'application/json', 'kbn-xsrf': 'xyz', Authorization, + // Note: version can change in the future + 'Elastic-Api-Version': '2023-10-31', }, body: JSON.stringify({ force: true }), method: 'POST', @@ -77,6 +79,8 @@ async function deletePackage(name: string, version: string) { 'content-type': 'application/json', 'kbn-xsrf': 'xyz', Authorization, + // Note: version can change in the future + 'Elastic-Api-Version': '2023-10-31', }, method: 'DELETE', }); diff --git a/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts b/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts index acf5b1a301a60..fc7933dad2085 100644 --- a/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts +++ b/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts @@ -9,6 +9,7 @@ import type { AwaitedProperties } from '@kbn/utility-types'; import { httpServerMock, savedObjectsClientMock, coreMock } from '@kbn/core/server/mocks'; import type { PostFleetSetupResponse } from '../../../common/types'; +import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; import { RegistryError } from '../../errors'; import { createAppContextStartContractMock, @@ -62,6 +63,7 @@ describe('FleetSetupHandler', () => { request = httpServerMock.createKibanaRequest({ method: 'post', path: '/api/fleet/setup', + headers: { 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); // prevents `Logger not set.` and other appContext errors appContextService.start(createAppContextStartContractMock()); @@ -145,6 +147,7 @@ describe('FleetStatusHandler', () => { request = httpServerMock.createKibanaRequest({ method: 'post', path: '/api/fleet/status', + headers: { 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, }); // prevents `Logger not set.` and other appContext errors appContextService.start(createAppContextStartContractMock()); From 204c2a39079f2a3270c5d52528dd580c44faec15 Mon Sep 17 00:00:00 2001 From: criamico Date: Thu, 10 Aug 2023 15:50:48 +0200 Subject: [PATCH 06/26] Pass headers to api calls in other plugins --- x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts | 8 +++++++- x-pack/plugins/osquery/cypress/tasks/integrations.ts | 4 ++-- x-pack/plugins/profiling/e2e/cypress_test_runner.ts | 6 +++++- .../cypress/tasks/api_calls/fleet.ts | 12 ++++++------ .../threat_intelligence/cypress/e2e/indicators.cy.ts | 1 + .../public/modules/block_list/hooks/use_policies.ts | 1 + 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts b/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts index b125693e8b915..4d735eff5dc08 100644 --- a/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts +++ b/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts @@ -263,7 +263,13 @@ export const loadAgentPolicy = () => inactivity_timeout: 1209600, }, url: '/api/fleet/agent_policies', + headers: { 'Elastic-Api-Version': '2023-10-31' }, }).then((response) => response.body.item); export const cleanupAgentPolicy = (agentPolicyId: string) => - request({ method: 'POST', body: { agentPolicyId }, url: '/api/fleet/agent_policies/delete' }); + request({ + method: 'POST', + body: { agentPolicyId }, + url: '/api/fleet/agent_policies/delete', + headers: { 'Elastic-Api-Version': '2023-10-31' }, + }); diff --git a/x-pack/plugins/osquery/cypress/tasks/integrations.ts b/x-pack/plugins/osquery/cypress/tasks/integrations.ts index 09948eca70538..451f70a2164e4 100644 --- a/x-pack/plugins/osquery/cypress/tasks/integrations.ts +++ b/x-pack/plugins/osquery/cypress/tasks/integrations.ts @@ -125,7 +125,7 @@ export const deleteIntegrations = async (integrationName: string) => { .then(() => { cy.request({ url: `/api/fleet/package_policies/delete`, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': '2023-10-31' }, body: `{ "packagePolicyIds": ${JSON.stringify(ids)} }`, method: 'POST', }); @@ -135,7 +135,7 @@ export const deleteIntegrations = async (integrationName: string) => { export const installPackageWithVersion = (integration: string, version: string) => { cy.request({ url: `/api/fleet/epm/packages/${integration}-${version}`, - headers: { 'kbn-xsrf': 'cypress' }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': '2023-10-31' }, body: '{ "force": true }', method: 'POST', }); diff --git a/x-pack/plugins/profiling/e2e/cypress_test_runner.ts b/x-pack/plugins/profiling/e2e/cypress_test_runner.ts index 44317da9c662f..1e95412d4be24 100644 --- a/x-pack/plugins/profiling/e2e/cypress_test_runner.ts +++ b/x-pack/plugins/profiling/e2e/cypress_test_runner.ts @@ -42,7 +42,11 @@ export async function cypressTestRunner({ }); // Ensure Fleet setup is complete - await axios.post(`${kibanaUrlWithAuth}/api/fleet/setup`, {}, { headers: { 'kbn-xsrf': true } }); + await axios.post( + `${kibanaUrlWithAuth}/api/fleet/setup`, + {}, + { headers: { 'kbn-xsrf': true, 'Elastic-Api-Version': '2023-10-31' } } + ); const profilingResources = await axios.get<{ has_setup: boolean; has_data: boolean }>( `${kibanaUrlWithAuth}/internal/profiling/setup/es_resources`, diff --git a/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts b/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts index 57995a0645388..272a29884d872 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts @@ -25,13 +25,13 @@ const deleteAgentPolicies = () => { return rootRequest<{ items: Array<{ id: string }> }>({ method: 'GET', url: 'api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'cypress-creds' }, + headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, }).then((response) => { response.body.items.forEach((item: { id: string }) => { rootRequest({ method: 'POST', url: `api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress-creds' }, + headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, body: { agentPolicyId: item.id, }, @@ -44,12 +44,12 @@ const deletePackagePolicies = () => { return rootRequest<{ items: Array<{ id: string }> }>({ method: 'GET', url: 'api/fleet/package_policies', - headers: { 'kbn-xsrf': 'cypress-creds' }, + headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, }).then((response) => { rootRequest({ method: 'POST', url: `api/fleet/package_policies/delete`, - headers: { 'kbn-xsrf': 'cypress-creds' }, + headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, body: { packagePolicyIds: response.body.items.map((item: { id: string }) => item.id), }, @@ -61,14 +61,14 @@ const deletePackages = () => { return rootRequest<{ items: Array<{ status: string; name: string; version: string }> }>({ method: 'GET', url: 'api/fleet/epm/packages', - headers: { 'kbn-xsrf': 'cypress-creds' }, + headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, }).then((response) => { response.body.items.forEach((item) => { if (item.status === 'installed') { rootRequest({ method: 'DELETE', url: `api/fleet/epm/packages/${item.name}/${item.version}`, - headers: { 'kbn-xsrf': 'cypress-creds' }, + headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, }); } }); diff --git a/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts b/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts index 3b7e360813c0e..40b35a736461a 100644 --- a/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts +++ b/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts @@ -151,6 +151,7 @@ describe('Indicators', () => { cy.request({ method: 'GET', url: '/api/fleet/epm/packages', + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': '2023-10-31' }, }).should((response) => expect(response.status).to.eq(200)); }); }); diff --git a/x-pack/plugins/threat_intelligence/public/modules/block_list/hooks/use_policies.ts b/x-pack/plugins/threat_intelligence/public/modules/block_list/hooks/use_policies.ts index 6baae4a992002..9c5f3e7647669 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/block_list/hooks/use_policies.ts +++ b/x-pack/plugins/threat_intelligence/public/modules/block_list/hooks/use_policies.ts @@ -30,6 +30,7 @@ export function usePolicies() { withAgentCount: true, kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: endpoint`, }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': '2023-10-31' }, }); return useQuery(queryKey, fetchPolicies, { From 7efaa662da10543ff4da45960e7fd89e3344716c Mon Sep 17 00:00:00 2001 From: criamico Date: Fri, 11 Aug 2023 15:29:44 +0200 Subject: [PATCH 07/26] Add flag to run tests without requiring version in headers --- .../server/services/security/fleet_router.ts | 52 +++++++++---------- .../test/fleet_api_integration/config.base.ts | 2 + 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.ts index fd746a96f7826..d5a38f4e2aa53 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.ts @@ -136,60 +136,58 @@ export function makeRouterWithFleetAuthz access === PUBLIC_API_ACCESS ? LATEST_PUBLIC_VERSION : LATEST_INTERNAL_VERSION; - const versionedRouter = router.versioned; - const fleetAuthzRouter: FleetAuthzRouter = { - get: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + get: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const defaultVersion = getDefaultVersion(access); - return versionedRouter - .get({ access, path: options.path }) + const version = headerVersion || getDefaultVersion(access); + return router.versioned + .get({ access, ...options }) .addVersion( - { version: version || defaultVersion, validate: { request: routeValidationObject } }, + { version, validate: { request: routeValidationObject } }, (context, request, response) => fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); }, - delete: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + delete: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const defaultVersion = getDefaultVersion(access); - return versionedRouter - .delete({ access, path: options.path }) + const version = headerVersion || getDefaultVersion(access); + return router.versioned + .delete({ access, ...options }) .addVersion( - { version: version || defaultVersion, validate: { request: routeValidationObject } }, + { version, validate: { request: routeValidationObject } }, (context, request, response) => fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); }, - post: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + post: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const defaultVersion = getDefaultVersion(access); - return versionedRouter - .post({ access, path: options.path }) + const version = headerVersion || getDefaultVersion(access); + return router.versioned + .post({ access, ...options }) .addVersion( - { version: version || defaultVersion, validate: { request: routeValidationObject } }, + { version, validate: { request: routeValidationObject } }, (context, request, response) => fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); }, - put: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + put: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const defaultVersion = getDefaultVersion(access); - return versionedRouter - .put({ access, path: options.path }) + const version = headerVersion || getDefaultVersion(access); + return router.versioned + .put({ access, ...options }) .addVersion( - { version: version || defaultVersion, validate: { request: routeValidationObject } }, + { version, validate: { request: routeValidationObject } }, (context, request, response) => fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); }, - patch: ({ fleetAuthz: hasRequiredAuthz, version, ...options }, handler) => { + patch: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const defaultVersion = getDefaultVersion(access); - return versionedRouter - .patch({ access, path: options.path }) + const version = headerVersion || getDefaultVersion(access); + return router.versioned + .patch({ access, ...options }) .addVersion( - { version: version || defaultVersion, validate: { request: routeValidationObject } }, + { version, validate: { request: routeValidationObject } }, (context, request, response) => fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); diff --git a/x-pack/test/fleet_api_integration/config.base.ts b/x-pack/test/fleet_api_integration/config.base.ts index e5746278a26f9..7712411cf8ed5 100644 --- a/x-pack/test/fleet_api_integration/config.base.ts +++ b/x-pack/test/fleet_api_integration/config.base.ts @@ -85,6 +85,8 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { appenders: ['default'], }, ])}`, + // Don't enforce versions header validation + `--server.versioned.versionResolution=oldest`, ], }, }; From a44ee118a1ee928a05bcf2a14e4a67fb46df75b8 Mon Sep 17 00:00:00 2001 From: criamico Date: Fri, 11 Aug 2023 15:33:41 +0200 Subject: [PATCH 08/26] Removing changes in other plugins tests for now --- x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts | 2 -- x-pack/plugins/osquery/cypress/tasks/integrations.ts | 2 -- x-pack/plugins/profiling/e2e/cypress_test_runner.ts | 6 +----- .../security_solution/cypress/tasks/api_calls/fleet.ts | 3 --- .../threat_intelligence/cypress/e2e/indicators.cy.ts | 1 - .../public/modules/block_list/hooks/use_policies.ts | 1 - 6 files changed, 1 insertion(+), 14 deletions(-) diff --git a/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts b/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts index 4d735eff5dc08..d205358c65377 100644 --- a/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts +++ b/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts @@ -263,7 +263,6 @@ export const loadAgentPolicy = () => inactivity_timeout: 1209600, }, url: '/api/fleet/agent_policies', - headers: { 'Elastic-Api-Version': '2023-10-31' }, }).then((response) => response.body.item); export const cleanupAgentPolicy = (agentPolicyId: string) => @@ -271,5 +270,4 @@ export const cleanupAgentPolicy = (agentPolicyId: string) => method: 'POST', body: { agentPolicyId }, url: '/api/fleet/agent_policies/delete', - headers: { 'Elastic-Api-Version': '2023-10-31' }, }); diff --git a/x-pack/plugins/osquery/cypress/tasks/integrations.ts b/x-pack/plugins/osquery/cypress/tasks/integrations.ts index 451f70a2164e4..a8ec4b879fe78 100644 --- a/x-pack/plugins/osquery/cypress/tasks/integrations.ts +++ b/x-pack/plugins/osquery/cypress/tasks/integrations.ts @@ -125,7 +125,6 @@ export const deleteIntegrations = async (integrationName: string) => { .then(() => { cy.request({ url: `/api/fleet/package_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': '2023-10-31' }, body: `{ "packagePolicyIds": ${JSON.stringify(ids)} }`, method: 'POST', }); @@ -135,7 +134,6 @@ export const deleteIntegrations = async (integrationName: string) => { export const installPackageWithVersion = (integration: string, version: string) => { cy.request({ url: `/api/fleet/epm/packages/${integration}-${version}`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': '2023-10-31' }, body: '{ "force": true }', method: 'POST', }); diff --git a/x-pack/plugins/profiling/e2e/cypress_test_runner.ts b/x-pack/plugins/profiling/e2e/cypress_test_runner.ts index 1e95412d4be24..dba31a5800a71 100644 --- a/x-pack/plugins/profiling/e2e/cypress_test_runner.ts +++ b/x-pack/plugins/profiling/e2e/cypress_test_runner.ts @@ -42,11 +42,7 @@ export async function cypressTestRunner({ }); // Ensure Fleet setup is complete - await axios.post( - `${kibanaUrlWithAuth}/api/fleet/setup`, - {}, - { headers: { 'kbn-xsrf': true, 'Elastic-Api-Version': '2023-10-31' } } - ); + await axios.post(`${kibanaUrlWithAuth}/api/fleet/setup`, {}); const profilingResources = await axios.get<{ has_setup: boolean; has_data: boolean }>( `${kibanaUrlWithAuth}/internal/profiling/setup/es_resources`, diff --git a/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts b/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts index 272a29884d872..5680e4abf7961 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts @@ -31,7 +31,6 @@ const deleteAgentPolicies = () => { rootRequest({ method: 'POST', url: `api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, body: { agentPolicyId: item.id, }, @@ -49,7 +48,6 @@ const deletePackagePolicies = () => { rootRequest({ method: 'POST', url: `api/fleet/package_policies/delete`, - headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, body: { packagePolicyIds: response.body.items.map((item: { id: string }) => item.id), }, @@ -68,7 +66,6 @@ const deletePackages = () => { rootRequest({ method: 'DELETE', url: `api/fleet/epm/packages/${item.name}/${item.version}`, - headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, }); } }); diff --git a/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts b/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts index 40b35a736461a..3b7e360813c0e 100644 --- a/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts +++ b/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts @@ -151,7 +151,6 @@ describe('Indicators', () => { cy.request({ method: 'GET', url: '/api/fleet/epm/packages', - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': '2023-10-31' }, }).should((response) => expect(response.status).to.eq(200)); }); }); diff --git a/x-pack/plugins/threat_intelligence/public/modules/block_list/hooks/use_policies.ts b/x-pack/plugins/threat_intelligence/public/modules/block_list/hooks/use_policies.ts index 9c5f3e7647669..6baae4a992002 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/block_list/hooks/use_policies.ts +++ b/x-pack/plugins/threat_intelligence/public/modules/block_list/hooks/use_policies.ts @@ -30,7 +30,6 @@ export function usePolicies() { withAgentCount: true, kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: endpoint`, }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': '2023-10-31' }, }); return useQuery(queryKey, fetchPolicies, { From a3348d95f55273676c877e06cfa61605327d688c Mon Sep 17 00:00:00 2001 From: criamico Date: Fri, 11 Aug 2023 15:40:34 +0200 Subject: [PATCH 09/26] Undoing leftover changes --- x-pack/plugins/osquery/cypress/tasks/integrations.ts | 2 ++ x-pack/plugins/profiling/e2e/cypress_test_runner.ts | 2 +- .../security_solution/cypress/tasks/api_calls/fleet.ts | 9 ++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/osquery/cypress/tasks/integrations.ts b/x-pack/plugins/osquery/cypress/tasks/integrations.ts index a8ec4b879fe78..09948eca70538 100644 --- a/x-pack/plugins/osquery/cypress/tasks/integrations.ts +++ b/x-pack/plugins/osquery/cypress/tasks/integrations.ts @@ -125,6 +125,7 @@ export const deleteIntegrations = async (integrationName: string) => { .then(() => { cy.request({ url: `/api/fleet/package_policies/delete`, + headers: { 'kbn-xsrf': 'cypress' }, body: `{ "packagePolicyIds": ${JSON.stringify(ids)} }`, method: 'POST', }); @@ -134,6 +135,7 @@ export const deleteIntegrations = async (integrationName: string) => { export const installPackageWithVersion = (integration: string, version: string) => { cy.request({ url: `/api/fleet/epm/packages/${integration}-${version}`, + headers: { 'kbn-xsrf': 'cypress' }, body: '{ "force": true }', method: 'POST', }); diff --git a/x-pack/plugins/profiling/e2e/cypress_test_runner.ts b/x-pack/plugins/profiling/e2e/cypress_test_runner.ts index dba31a5800a71..44317da9c662f 100644 --- a/x-pack/plugins/profiling/e2e/cypress_test_runner.ts +++ b/x-pack/plugins/profiling/e2e/cypress_test_runner.ts @@ -42,7 +42,7 @@ export async function cypressTestRunner({ }); // Ensure Fleet setup is complete - await axios.post(`${kibanaUrlWithAuth}/api/fleet/setup`, {}); + await axios.post(`${kibanaUrlWithAuth}/api/fleet/setup`, {}, { headers: { 'kbn-xsrf': true } }); const profilingResources = await axios.get<{ has_setup: boolean; has_data: boolean }>( `${kibanaUrlWithAuth}/internal/profiling/setup/es_resources`, diff --git a/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts b/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts index 5680e4abf7961..069acfde44fd6 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts @@ -25,12 +25,13 @@ const deleteAgentPolicies = () => { return rootRequest<{ items: Array<{ id: string }> }>({ method: 'GET', url: 'api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, + headers: { 'kbn-xsrf': 'cypress-creds' }, }).then((response) => { response.body.items.forEach((item: { id: string }) => { rootRequest({ method: 'POST', url: `api/fleet/agent_policies/delete`, + headers: { 'kbn-xsrf': 'cypress-creds' }, body: { agentPolicyId: item.id, }, @@ -43,11 +44,12 @@ const deletePackagePolicies = () => { return rootRequest<{ items: Array<{ id: string }> }>({ method: 'GET', url: 'api/fleet/package_policies', - headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, + headers: { 'kbn-xsrf': 'cypress-creds', }, }).then((response) => { rootRequest({ method: 'POST', url: `api/fleet/package_policies/delete`, + headers: { 'kbn-xsrf': 'cypress-creds' }, body: { packagePolicyIds: response.body.items.map((item: { id: string }) => item.id), }, @@ -59,13 +61,14 @@ const deletePackages = () => { return rootRequest<{ items: Array<{ status: string; name: string; version: string }> }>({ method: 'GET', url: 'api/fleet/epm/packages', - headers: { 'kbn-xsrf': 'cypress-creds', 'Elastic-Api-Version': '2023-10-31' }, + headers: { 'kbn-xsrf': 'cypress-creds' }, }).then((response) => { response.body.items.forEach((item) => { if (item.status === 'installed') { rootRequest({ method: 'DELETE', url: `api/fleet/epm/packages/${item.name}/${item.version}`, + headers: { 'kbn-xsrf': 'cypress-creds' }, }); } }); From bd2007c3435ec5cdf6b6ddc5f3ef17227e959745 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 11 Aug 2023 13:46:28 +0000 Subject: [PATCH 10/26] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../plugins/security_solution/cypress/tasks/api_calls/fleet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts b/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts index 069acfde44fd6..57995a0645388 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/api_calls/fleet.ts @@ -44,7 +44,7 @@ const deletePackagePolicies = () => { return rootRequest<{ items: Array<{ id: string }> }>({ method: 'GET', url: 'api/fleet/package_policies', - headers: { 'kbn-xsrf': 'cypress-creds', }, + headers: { 'kbn-xsrf': 'cypress-creds' }, }).then((response) => { rootRequest({ method: 'POST', From ebbb419262824e170a2fbc87b6411ae8ac8e1b83 Mon Sep 17 00:00:00 2001 From: criamico Date: Fri, 11 Aug 2023 15:52:40 +0200 Subject: [PATCH 11/26] Rename versions to oldest --- .../plugins/fleet/common/constants/routes.ts | 4 +- .../fleet/cypress/e2e/a11y/home_page.cy.ts | 6 +-- .../e2e/agent_binary_download_source.cy.ts | 6 +-- .../fleet/cypress/e2e/agents/agent_list.cy.ts | 4 +- .../fleet/cypress/e2e/enrollment_token.cy.ts | 4 +- .../cypress/e2e/fleet_agent_flyout.cy.ts | 4 +- .../fleet/cypress/e2e/integrations_real.cy.ts | 4 +- ...e_policy_pipelines_and_mappings_real.cy.ts | 14 +++--- .../fleet/cypress/e2e/uninstall_token.cy.ts | 4 +- x-pack/plugins/fleet/cypress/plugins/index.ts | 6 +-- x-pack/plugins/fleet/cypress/tasks/cleanup.ts | 8 ++-- .../fleet/cypress/tasks/fleet_server.ts | 6 +-- .../fleet/cypress/tasks/integrations.ts | 6 +-- .../agent_policy_delete_provider.tsx | 4 +- .../package_policy_delete_provider.tsx | 4 +- .../public/hooks/use_request/agent_policy.ts | 26 +++++----- .../fleet/public/hooks/use_request/agents.ts | 48 +++++++++---------- .../fleet/public/hooks/use_request/app.ts | 10 ++-- .../public/hooks/use_request/data_stream.ts | 4 +- .../hooks/use_request/download_source.ts | 10 ++-- .../hooks/use_request/enrollment_api_keys.ts | 14 +++--- .../fleet/public/hooks/use_request/epm.ts | 42 ++++++++-------- .../public/hooks/use_request/fleet_proxies.ts | 10 ++-- .../hooks/use_request/fleet_server_hosts.ts | 10 ++-- .../public/hooks/use_request/health_check.ts | 4 +- .../fleet/public/hooks/use_request/k8s.ts | 4 +- .../fleet/public/hooks/use_request/outputs.ts | 10 ++-- .../hooks/use_request/package_policy.ts | 30 ++++++------ .../public/hooks/use_request/settings.ts | 10 ++-- .../fleet/public/hooks/use_request/setup.ts | 8 ++-- .../hooks/use_request/uninstall_tokens.ts | 8 ++-- x-pack/plugins/fleet/public/plugin.ts | 6 +-- .../scripts/create_agents/create_agents.ts | 3 +- .../get_all_packages/get_all_packages.ts | 3 +- .../install_all_packages.ts | 5 +- .../server/routes/setup/handlers.test.ts | 6 +-- .../server/services/security/fleet_router.ts | 6 +-- .../osquery/cypress/tasks/api_fixtures.ts | 6 +-- 38 files changed, 183 insertions(+), 184 deletions(-) diff --git a/x-pack/plugins/fleet/common/constants/routes.ts b/x-pack/plugins/fleet/common/constants/routes.ts index 24b84a188518c..86ca70d956f0d 100644 --- a/x-pack/plugins/fleet/common/constants/routes.ts +++ b/x-pack/plugins/fleet/common/constants/routes.ts @@ -206,7 +206,7 @@ export const DOWNLOAD_SOURCE_API_ROUTES = { }; // API versioning constants -export const LATEST_PUBLIC_VERSION = '2023-10-31'; -export const LATEST_INTERNAL_VERSION = '1'; +export const OLDEST_PUBLIC_VERSION = '2023-10-31'; +export const OLDEST_INTERNAL_VERSION = '1'; export const PUBLIC_API_ACCESS = 'public'; export const INTERNAL_API_ACCESS = 'internal'; diff --git a/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts b/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts index b6408487d348e..d16e1bfd3aa06 100644 --- a/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts @@ -33,7 +33,7 @@ import { AGENT_POLICY_NAME_LINK } from '../../screens/integrations'; import { cleanupAgentPolicies, unenrollAgent } from '../../tasks/cleanup'; import { setFleetServerHost } from '../../tasks/fleet_server'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; describe('Home page', () => { before(() => { @@ -154,7 +154,7 @@ describe('Home page', () => { method: 'POST', url: '/api/fleet/agent_policies', body: { name: 'Agent policy for A11y test', namespace: 'default', id: 'agent-policy-a11y' }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); }); beforeEach(() => { @@ -166,7 +166,7 @@ describe('Home page', () => { method: 'POST', url: '/api/fleet/agent_policies/delete', body: { agentPolicyId: 'agent-policy-a11y' }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); }); it('Uninstall Tokens Table', () => { diff --git a/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts b/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts index 3d07dbe49e102..852aa45cc5b4c 100644 --- a/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts @@ -15,7 +15,7 @@ import { cleanupDownloadSources } from '../tasks/cleanup'; import { FLEET, navigateTo } from '../tasks/navigation'; import { CONFIRM_MODAL } from '../screens/navigation'; -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; describe('Agent binary download source section', () => { beforeEach(() => { @@ -82,7 +82,7 @@ describe('Agent binary download source section', () => { id: 'fleet-local-registry', host: 'https://new-custom-host.co', }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); cy.request({ method: 'POST', @@ -95,7 +95,7 @@ describe('Agent binary download source section', () => { id: 'new-agent-policy', download_source_id: 'fleet-local-registry', }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }).then((response: any) => { navigateTo('app/fleet/policies/new-agent-policy/settings'); cy.getBySel(AGENT_POLICY_FORM.DOWNLOAD_SOURCE_SELECT).contains('Custom Host'); diff --git a/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts b/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts index 549f552589197..57045af2d286f 100644 --- a/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts @@ -13,7 +13,7 @@ import { deleteFleetServerDocs, deleteAgentDocs, cleanupAgentPolicies } from '.. import type { CreateAgentPolicyRequest } from '../../../common/types'; import { setUISettings } from '../../tasks/ui_settings'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; const createAgentDocs = (kibanaVersion: string) => [ createAgentDoc('agent-1', 'policy-1'), // this agent will have upgrade available @@ -68,7 +68,7 @@ function createAgentPolicy(body: CreateAgentPolicyRequest['body']) { cy.request({ method: 'POST', url: '/api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, body, }); } diff --git a/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts b/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts index 9724888ae8814..af4d91bd9986e 100644 --- a/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts @@ -8,7 +8,7 @@ import { cleanupAgentPolicies } from '../tasks/cleanup'; import { ENROLLMENT_TOKENS } from '../screens/fleet'; -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; describe('Enrollment token page', () => { before(() => { @@ -22,7 +22,7 @@ describe('Enrollment token page', () => { monitoring_enabled: ['logs', 'metrics'], id: 'agent-policy-1', }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); }); diff --git a/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts b/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts index 026f5efc74e92..7db31e15949ee 100644 --- a/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts @@ -11,7 +11,7 @@ import { createAgentDoc } from '../tasks/agents'; import { setFleetServerHost } from '../tasks/fleet_server'; import { FLEET, navigateTo } from '../tasks/navigation'; -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; const FLEET_SERVER_POLICY_ID = 'fleet-server-policy'; @@ -30,7 +30,7 @@ describe('Fleet add agent flyout', () => { cy.request({ method: 'POST', url: '/api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, body: { id: FLEET_SERVER_POLICY_ID, name: 'Fleet Server policy', diff --git a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts index 6c457fb488ba6..e94f40de24fc3 100644 --- a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts @@ -31,7 +31,7 @@ import { import { LOADING_SPINNER, CONFIRM_MODAL } from '../screens/navigation'; import { ADD_PACKAGE_POLICY_BTN } from '../screens/fleet'; import { cleanupAgentPolicies } from '../tasks/cleanup'; -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; function setupIntegrations() { cy.intercept( @@ -114,7 +114,7 @@ describe('Add Integration - Real API', () => { namespace: 'default', monitoring_enabled: ['logs', 'metrics'], }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); cy.request('/api/fleet/agent_policies').then((response: any) => { diff --git a/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts b/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts index f69498d0a7852..6b7f7a697e2f8 100644 --- a/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts @@ -17,7 +17,7 @@ const INPUT_TEST_PACKAGE = 'input_package-1.0.0'; const INTEGRATION_TEST_PACKAGE = 'logs_integration-1.0.0'; const INTEGRATION_TEST_PACKAGE_NO_DATASET = 'logs_int_no_dataset-1.0.0'; -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; describe('Input package create and edit package policy', () => { const agentPolicyId = 'test-input-package-policy'; @@ -47,7 +47,7 @@ describe('Input package create and edit package policy', () => { namespace: 'default', monitoring_enabled: [], }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); }); after(() => { @@ -55,7 +55,7 @@ describe('Input package create and edit package policy', () => { cy.request({ method: 'POST', url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, body: JSON.stringify({ agentPolicyId, }), @@ -122,7 +122,7 @@ describe('Integration package with custom dataset create and edit package policy namespace: 'default', monitoring_enabled: [], }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); }); after(() => { @@ -130,7 +130,7 @@ describe('Integration package with custom dataset create and edit package policy cy.request({ method: 'POST', url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, body: JSON.stringify({ agentPolicyId, }), @@ -186,7 +186,7 @@ describe('Integration package with fixed dataset create and edit package policy' namespace: 'default', monitoring_enabled: [], }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); }); after(() => { @@ -194,7 +194,7 @@ describe('Integration package with fixed dataset create and edit package policy' cy.request({ method: 'POST', url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, body: JSON.stringify({ agentPolicyId, }), diff --git a/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts b/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts index e6ec85f960fe3..c3e3e28710dc1 100644 --- a/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts @@ -11,7 +11,7 @@ import { cleanupAgentPolicies } from '../tasks/cleanup'; import { UNINSTALL_TOKENS } from '../screens/fleet'; import type { GetUninstallTokenResponse } from '../../common/types/rest_spec/uninstall_token'; -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; describe('Uninstall token page', () => { before(() => { @@ -80,7 +80,7 @@ describe('Uninstall token page', () => { method: 'POST', url: '/api/fleet/agent_policies', body: { name: `Agent policy ${i}00`, namespace: 'default', id: `agent-policy-${i}00` }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); } }; diff --git a/x-pack/plugins/fleet/cypress/plugins/index.ts b/x-pack/plugins/fleet/cypress/plugins/index.ts index eaf6598f0409e..c36577fd45a39 100644 --- a/x-pack/plugins/fleet/cypress/plugins/index.ts +++ b/x-pack/plugins/fleet/cypress/plugins/index.ts @@ -12,7 +12,7 @@ import fs from 'fs'; import fetch from 'node-fetch'; import { createEsClientForTesting } from '@kbn/test'; -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; const plugin: Cypress.PluginConfig = (on, config) => { const client = createEsClientForTesting({ @@ -79,7 +79,7 @@ const plugin: Cypress.PluginConfig = (on, config) => { path: '/api/fleet/epm/packages', body: Buffer.from(zipContent, 'base64'), contentType: 'application/zip', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }, @@ -87,7 +87,7 @@ const plugin: Cypress.PluginConfig = (on, config) => { return kibanaFetch({ method: 'DELETE', path: `/api/fleet/epm/packages/${packageName}`, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }, }); diff --git a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts index 4e6536cc02717..c1b492fa132a8 100644 --- a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts +++ b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; export function cleanupAgentPolicies() { cy.request('/api/fleet/agent_policies').then((response: any) => { @@ -15,7 +15,7 @@ export function cleanupAgentPolicies() { method: 'POST', url: '/api/fleet/agent_policies/delete', body: { agentPolicyId: policy.id }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); }); }); @@ -29,7 +29,7 @@ export function unenrollAgent() { method: 'POST', url: `api/fleet/agents/${agent.id}/unenroll`, body: { revoke: true }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); }); } @@ -44,7 +44,7 @@ export function cleanupDownloadSources() { cy.request({ method: 'DELETE', url: `/api/fleet/agent_download_sources/${ds.id}`, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); }); }); diff --git a/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts b/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts index fe590030e9d9e..1cedd585d07a6 100644 --- a/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts +++ b/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; import { createAgentDoc } from './agents'; @@ -18,7 +18,7 @@ export function setupFleetServer() { cy.request({ method: 'POST', url: '/api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, body: { id: FLEET_SERVER_POLICY_ID, name: 'Fleet Server policy', @@ -63,7 +63,7 @@ export function setFleetServerHost(host = 'https://fleetserver:8220') { cy.request({ method: 'POST', url: '/api/fleet/fleet_server_hosts', - headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, body: { name: 'Default host', host_urls: [host], diff --git a/x-pack/plugins/fleet/cypress/tasks/integrations.ts b/x-pack/plugins/fleet/cypress/tasks/integrations.ts index 2a59f34278724..a347e309bc424 100644 --- a/x-pack/plugins/fleet/cypress/tasks/integrations.ts +++ b/x-pack/plugins/fleet/cypress/tasks/integrations.ts @@ -14,7 +14,7 @@ import { import { AGENT_POLICY_SYSTEM_MONITORING_CHECKBOX, EXISTING_HOSTS_TAB } from '../screens/fleet'; import { TOAST_CLOSE_BTN, CONFIRM_MODAL } from '../screens/navigation'; -import { LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; export const addIntegration = ({ useExistingPolicy } = { useExistingPolicy: false }) => { cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click(); @@ -55,7 +55,7 @@ export const deleteIntegrations = async () => { response.body.items.forEach((policy: any) => ids.push(policy.id)); cy.request({ url: `/api/fleet/package_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, body: `{ "packagePolicyIds": ${JSON.stringify(ids)}, "force": true }`, method: 'POST', }); @@ -65,7 +65,7 @@ export const deleteIntegrations = async () => { export const installPackageWithVersion = (integration: string, version: string) => { cy.request({ url: `/api/fleet/epm/packages/${integration}/${version}`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, body: '{ "force": true }', method: 'POST', }); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx index 0a49837a947bf..58cd88438d6da 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx @@ -12,7 +12,7 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { AGENTS_PREFIX } from '../../../constants'; import { sendDeleteAgentPolicy, useStartServices, useConfig, sendRequest } from '../../../hooks'; -import { LATEST_PUBLIC_VERSION } from '../../../../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../../../../common/constants'; interface Props { children: (deleteAgentPolicy: DeleteAgentPolicy) => React.ReactElement; @@ -105,7 +105,7 @@ export const AgentPolicyDeleteProvider: React.FunctionComponent = ({ query: { kuery: `${AGENTS_PREFIX}.policy_id : ${agentPolicyToCheck}`, }, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); setAgentsCount(data?.total || 0); setIsLoadingAgentsCount(false); diff --git a/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx b/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx index 37e4fc1d17e72..a42cb9fb02f29 100644 --- a/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx +++ b/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx @@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { useStartServices, sendRequest, sendDeletePackagePolicy, useConfig } from '../hooks'; -import { AGENT_API_ROUTES, AGENTS_PREFIX, LATEST_PUBLIC_VERSION } from '../../common/constants'; +import { AGENT_API_ROUTES, AGENTS_PREFIX, OLDEST_PUBLIC_VERSION } from '../../common/constants'; import type { AgentPolicy } from '../types'; interface Props { @@ -55,7 +55,7 @@ export const PackagePolicyDeleteProvider: React.FunctionComponent = ({ perPage: 1, kuery: `${AGENTS_PREFIX}.policy_id : ${agentPolicy.id}`, }, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); setAgentsCount(data?.total || 0); setIsLoadingAgentsCount(false); diff --git a/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts b/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts index eedd68937567a..f19e72629c088 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts @@ -7,7 +7,7 @@ import { useQuery } from '@tanstack/react-query'; import { agentPolicyRouteService } from '../../services'; -import { LATEST_PUBLIC_VERSION, LATEST_INTERNAL_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION, OLDEST_INTERNAL_VERSION } from '../../../common/constants'; import type { GetAgentPoliciesRequest, @@ -32,7 +32,7 @@ export const useGetAgentPolicies = (query?: GetAgentPoliciesRequest['query']) => path: agentPolicyRouteService.getListPath(), method: 'get', query, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -42,7 +42,7 @@ export const useGetAgentPoliciesQuery = (query?: GetAgentPoliciesRequest['query' path: agentPolicyRouteService.getListPath(), method: 'get', query, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }) ); }; @@ -52,7 +52,7 @@ export const sendGetAgentPolicies = (query?: GetAgentPoliciesRequest['query']) = path: agentPolicyRouteService.getListPath(), method: 'get', query, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -61,7 +61,7 @@ export const useGetOneAgentPolicy = (agentPolicyId: string | undefined) => { path: agentPolicyId ? agentPolicyRouteService.getInfoPath(agentPolicyId) : undefined, method: 'get', shouldSendRequest: !!agentPolicyId, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, } as SendConditionalRequestConfig); }; @@ -69,7 +69,7 @@ export const useGetOneAgentPolicyFull = (agentPolicyId: string) => { return useRequest({ path: agentPolicyRouteService.getInfoFullPath(agentPolicyId), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -81,7 +81,7 @@ export const sendGetOneAgentPolicyFull = ( path: agentPolicyRouteService.getInfoFullPath(agentPolicyId), method: 'get', query, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -89,7 +89,7 @@ export const sendGetOneAgentPolicy = (agentPolicyId: string) => { return sendRequest({ path: agentPolicyRouteService.getInfoPath(agentPolicyId), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -102,7 +102,7 @@ export const sendCreateAgentPolicy = ( method: 'post', body: JSON.stringify(body), query: withSysMonitoring ? { sys_monitoring: true } : {}, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -114,7 +114,7 @@ export const sendUpdateAgentPolicy = ( path: agentPolicyRouteService.getUpdatePath(agentPolicyId), method: 'put', body: JSON.stringify(body), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -134,7 +134,7 @@ export const sendDeleteAgentPolicy = (body: DeleteAgentPolicyRequest['body']) => path: agentPolicyRouteService.getDeletePath(), method: 'post', body: JSON.stringify(body), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -143,7 +143,7 @@ export const sendResetOnePreconfiguredAgentPolicy = (agentPolicyId: string) => { path: agentPolicyRouteService.getResetOnePreconfiguredAgentPolicyPath(agentPolicyId), method: 'post', body: JSON.stringify({}), - version: LATEST_INTERNAL_VERSION, + version: OLDEST_INTERNAL_VERSION, }); }; @@ -152,6 +152,6 @@ export const sendResetAllPreconfiguredAgentPolicies = () => { path: agentPolicyRouteService.getResetAllPreconfiguredAgentPolicyPath(), method: 'post', body: JSON.stringify({}), - version: LATEST_INTERNAL_VERSION, + version: OLDEST_INTERNAL_VERSION, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/agents.ts b/x-pack/plugins/fleet/public/hooks/use_request/agents.ts index fd665ef889db4..8d4e5c3f777a7 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/agents.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/agents.ts @@ -18,7 +18,7 @@ import type { UpdateAgentRequest, } from '../../../common/types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { agentRouteService } from '../../services'; @@ -64,7 +64,7 @@ export function useGetOneAgent( return useRequest({ path: agentRouteService.getInfoPath(agentId), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -73,7 +73,7 @@ export function useGetAgents(query: GetAgentsRequest['query'], options?: Request return useRequest({ method: 'get', path: agentRouteService.getListPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, ...options, }); @@ -93,7 +93,7 @@ export function sendGetAgents(query: GetAgentsRequest['query'], options?: Reques return sendRequest({ method: 'get', path: agentRouteService.getListPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, ...options, }); @@ -103,7 +103,7 @@ export function useGetAgentStatus(query: GetAgentStatusRequest['query'], options return useRequest({ method: 'get', path: agentRouteService.getStatusPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, ...options, }); @@ -113,7 +113,7 @@ export function sendGetAgentIncomingData(query: GetAgentIncomingDataRequest['que method: 'get', path: agentRouteService.getIncomingDataPath(), query, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -125,7 +125,7 @@ export function sendGetAgentStatus( method: 'get', path: agentRouteService.getStatusPath(), query, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -135,7 +135,7 @@ export function sendGetAgentTags(query: GetAgentsRequest['query'], options?: Req method: 'get', path: agentRouteService.getListTagsPath(), query, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -149,7 +149,7 @@ export function sendPostAgentReassign( method: 'post', path: agentRouteService.getReassignPath(agentId), body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -162,7 +162,7 @@ export function sendPostBulkAgentReassign( method: 'post', path: agentRouteService.getBulkReassignPath(), body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -176,7 +176,7 @@ export function sendPostAgentUnenroll( path: agentRouteService.getUnenrollPath(agentId), method: 'post', body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -189,7 +189,7 @@ export function sendPostBulkAgentUnenroll( path: agentRouteService.getBulkUnenrollPath(), method: 'post', body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -203,7 +203,7 @@ export function sendPostAgentUpgrade( path: agentRouteService.getUpgradePath(agentId), method: 'post', body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -212,7 +212,7 @@ export function sendPostRequestDiagnostics(agentId: string, options?: RequestOpt return sendRequest({ path: agentRouteService.getRequestDiagnosticsPath(agentId), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -225,7 +225,7 @@ export function sendPostBulkRequestDiagnostics( path: agentRouteService.getBulkRequestDiagnosticsPath(), method: 'post', body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -242,7 +242,7 @@ export const useGetAgentUploads = (agentId: string, options?: RequestOptions) => return useRequest({ path: agentRouteService.getListAgentUploads(agentId), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); }; @@ -256,7 +256,7 @@ export function sendPostAgentAction( path: agentRouteService.getCreateActionPath(agentId), method: 'post', body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -269,7 +269,7 @@ export function sendPostBulkAgentUpgrade( path: agentRouteService.getBulkUpgradePath(), method: 'post', body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -278,7 +278,7 @@ export function sendGetActionStatus() { return sendRequest({ path: agentRouteService.getActionStatusPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -286,7 +286,7 @@ export function sendPostCancelAction(actionId: string) { return sendRequest({ path: agentRouteService.getCancelActionPath(actionId), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -294,7 +294,7 @@ export function sendPostRetrieveAgentsByActions(body: PostRetrieveAgentsByAction return sendRequest({ path: agentRouteService.getAgentsByActionsPath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } @@ -308,7 +308,7 @@ export function sendPutAgentTagsUpdate( method: 'put', path: agentRouteService.getUpdatePath(agentId), body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -321,7 +321,7 @@ export function sendPostBulkAgentTagsUpdate( method: 'post', path: agentRouteService.getBulkUpdateTagsPath(), body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -330,6 +330,6 @@ export function sendGetAgentsAvailableVersions() { return sendRequest({ method: 'get', path: agentRouteService.getAvailableVersionsPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/app.ts b/x-pack/plugins/fleet/public/hooks/use_request/app.ts index a8e0bf34ea750..f2866c97284c6 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/app.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/app.ts @@ -9,7 +9,7 @@ import { useQuery } from '@tanstack/react-query'; import { appRoutesService } from '../../services'; import type { CheckPermissionsResponse, GenerateServiceTokenResponse } from '../../types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { sendRequest, sendRequestForRq, useRequest } from './use_request'; @@ -18,7 +18,7 @@ export const sendGetPermissionsCheck = (fleetServerSetup?: boolean) => { path: appRoutesService.getCheckPermissionsPath(), method: 'get', query: { fleetServerSetup }, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -26,7 +26,7 @@ export const sendGenerateServiceToken = () => { return sendRequest({ path: appRoutesService.getRegenerateServiceTokenPath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -37,7 +37,7 @@ export const usePermissionCheckQuery = () => { sendRequestForRq({ path: appRoutesService.getCheckPermissionsPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }) ); }; @@ -46,6 +46,6 @@ export const usePermissionCheck = () => { return useRequest({ path: appRoutesService.getCheckPermissionsPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts b/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts index 3f8e4fb80961b..056ff36c50bef 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts @@ -7,7 +7,7 @@ import { dataStreamRouteService } from '../../services'; import type { GetDataStreamsResponse } from '../../types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { useRequest, sendRequest } from './use_request'; @@ -15,7 +15,7 @@ export const useGetDataStreams = () => { return useRequest({ path: dataStreamRouteService.getListPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts b/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts index ba04fecf7392a..0e228b25bbf74 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts @@ -12,7 +12,7 @@ import type { PutDownloadSourceRequest, } from '../../types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { useRequest, sendRequest } from './use_request'; @@ -20,7 +20,7 @@ export function useGetDownloadSources() { return useRequest({ method: 'get', path: downloadSourceRoutesService.getListPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -38,7 +38,7 @@ export function sendPutDownloadSource( return sendRequest({ method: 'put', path: downloadSourceRoutesService.getUpdatePath(downloadSourceId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } @@ -47,7 +47,7 @@ export function sendPostDownloadSource(body: PostDownloadSourceRequest['body']) return sendRequest({ method: 'post', path: downloadSourceRoutesService.getCreatePath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } @@ -56,6 +56,6 @@ export function sendDeleteDownloadSource(downloadSourceId: string) { return sendRequest({ method: 'delete', path: downloadSourceRoutesService.getDeletePath(downloadSourceId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts b/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts index 10d98a0739375..c860a56161e5f 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts @@ -15,7 +15,7 @@ import type { PostEnrollmentAPIKeyResponse, } from '../../types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { useRequest, sendRequest, useConditionalRequest } from './use_request'; import type { UseRequestConfig, SendConditionalRequestConfig } from './use_request'; @@ -27,7 +27,7 @@ export function useGetOneEnrollmentAPIKey(keyId: string | undefined) { method: 'get', path: keyId ? enrollmentAPIKeyRouteService.getInfoPath(keyId) : undefined, shouldSendRequest: !!keyId, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, } as SendConditionalRequestConfig); } @@ -35,7 +35,7 @@ export function sendGetOneEnrollmentAPIKey(keyId: string, options?: RequestOptio return sendRequest({ method: 'get', path: enrollmentAPIKeyRouteService.getInfoPath(keyId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -44,7 +44,7 @@ export function sendDeleteOneEnrollmentAPIKey(keyId: string, options?: RequestOp return sendRequest({ method: 'delete', path: enrollmentAPIKeyRouteService.getDeletePath(keyId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, ...options, }); } @@ -56,7 +56,7 @@ export function sendGetEnrollmentAPIKeys( return sendRequest({ method: 'get', path: enrollmentAPIKeyRouteService.getListPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, ...options, }); @@ -69,7 +69,7 @@ export function useGetEnrollmentAPIKeys( return useRequest({ method: 'get', path: enrollmentAPIKeyRouteService.getListPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, ...options, }); @@ -79,7 +79,7 @@ export function sendCreateEnrollmentAPIKey(body: PostEnrollmentAPIKeyRequest['bo return sendRequest({ method: 'post', path: enrollmentAPIKeyRouteService.getCreatePath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/epm.ts b/x-pack/plugins/fleet/public/hooks/use_request/epm.ts index a993b5b867886..6e84e6f4e6521 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/epm.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/epm.ts @@ -29,7 +29,7 @@ import type { GetVerificationKeyIdResponse, } from '../../types'; import type { FleetErrorResponse, GetStatsResponse } from '../../../common/types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { getCustomIntegrations } from '../../services/custom_integrations'; @@ -54,7 +54,7 @@ export function useGetCategoriesQuery(query: GetCategoriesRequest['query'] = {}) path: epmRouteService.getCategoriesPath(), method: 'get', query, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }) ); } @@ -63,7 +63,7 @@ export const sendGetCategories = (query: GetCategoriesRequest['query'] = {}) => return sendRequest({ path: epmRouteService.getCategoriesPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, }); }; @@ -72,7 +72,7 @@ export const useGetPackages = (query: GetPackagesRequest['query'] = {}) => { return useRequest({ path: epmRouteService.getListPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, }); }; @@ -82,7 +82,7 @@ export const useGetPackagesQuery = (query: GetPackagesRequest['query']) => { sendRequestForRq({ path: epmRouteService.getListPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, }) ); @@ -92,7 +92,7 @@ export const sendGetPackages = (query: GetPackagesRequest['query'] = {}) => { return sendRequest({ path: epmRouteService.getListPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, }); }; @@ -101,7 +101,7 @@ export const useGetLimitedPackages = () => { return useRequest({ path: epmRouteService.getListLimitedPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -132,7 +132,7 @@ export const useGetPackageInfoByKeyQuery = ( sendRequestForRq({ path: epmRouteService.getInfoPath(pkgName, pkgVersion), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query: { ...options, ...(ignoreUnverifiedQueryParam && { ignoreUnverified: ignoreUnverifiedQueryParam }), @@ -160,7 +160,7 @@ export const useGetPackageStats = (pkgName: string) => { return useRequest({ path: epmRouteService.getStatsPath(pkgName), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -171,7 +171,7 @@ export const useGetPackageVerificationKeyId = () => { sendRequestForRq({ path: epmRouteService.getVerificationKeyIdPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }) ); @@ -193,7 +193,7 @@ export const sendGetPackageInfoByKey = ( return sendRequest({ path: epmRouteService.getInfoPath(pkgName, pkgVersion), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query: options, }); }; @@ -202,7 +202,7 @@ export const useGetFileByPath = (filePath: string) => { return useRequest({ path: epmRouteService.getFilePath(filePath), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -211,7 +211,7 @@ export const useGetFileByPathQuery = (filePath: string) => { sendRequest({ path: epmRouteService.getFilePath(filePath), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }) ); }; @@ -220,7 +220,7 @@ export const sendGetFileByPath = (filePath: string) => { return sendRequest({ path: epmRouteService.getFilePath(filePath), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -229,7 +229,7 @@ export const sendInstallPackage = (pkgName: string, pkgVersion: string, force: b return sendRequest({ path: epmRouteService.getInstallPath(pkgName, pkgVersion), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); }; @@ -240,7 +240,7 @@ export const sendBulkInstallPackages = ( return sendRequest({ path: epmRouteService.getBulkInstallPath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: { packages, }, @@ -251,7 +251,7 @@ export const sendRemovePackage = (pkgName: string, pkgVersion: string, force: bo return sendRequest({ path: epmRouteService.getRemovePath(pkgName, pkgVersion), method: 'delete', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: { force, }, @@ -266,7 +266,7 @@ export const sendRequestReauthorizeTransforms = ( return sendRequest({ path: epmRouteService.getReauthorizeTransformsPath(pkgName, pkgVersion), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: { transforms }, }); }; @@ -283,7 +283,7 @@ export const useUpdatePackageMutation = () => { sendRequestForRq({ path: epmRouteService.getUpdatePath(pkgName, pkgVersion), method: 'put', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }) ); @@ -297,7 +297,7 @@ export const sendUpdatePackage = ( return sendRequest({ path: epmRouteService.getUpdatePath(pkgName, pkgVersion), method: 'put', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); }; @@ -306,7 +306,7 @@ export const sendGetBulkAssets = (body: GetBulkAssetsRequest['body']) => { return sendRequest({ path: epmRouteService.getBulkAssetsPath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts b/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts index ff07724b725c7..bfb3084b0e67d 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts @@ -6,7 +6,7 @@ */ import { fleetProxiesRoutesService } from '../../../common/services'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import type { GetFleetProxiesResponse, @@ -20,7 +20,7 @@ export function useGetFleetProxies() { return useRequest({ method: 'get', path: fleetProxiesRoutesService.getListPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -28,7 +28,7 @@ export function sendDeleteFleetProxy(proxyId: string) { return sendRequest({ method: 'delete', path: fleetProxiesRoutesService.getDeletePath(proxyId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -37,7 +37,7 @@ export function sendPostFleetProxy(body: PostFleetProxiesRequest['body']) { method: 'post', path: fleetProxiesRoutesService.getCreatePath(), body, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -45,7 +45,7 @@ export function sendPutFleetProxy(proxyId: string, body: PutFleetProxiesRequest[ return sendRequest({ method: 'put', path: fleetProxiesRoutesService.getUpdatePath(proxyId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts b/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts index 401850736d1db..5914d40afbe23 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts @@ -7,7 +7,7 @@ import { fleetServerHostsRoutesService } from '../../../common/services'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import type { GetFleetServerHostsResponse, @@ -22,7 +22,7 @@ export function useGetFleetServerHosts() { return useRequest({ method: 'get', path: fleetServerHostsRoutesService.getListPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -30,7 +30,7 @@ export function sendDeleteFleetServerHost(itemId: string) { return sendRequest({ method: 'delete', path: fleetServerHostsRoutesService.getDeletePath(itemId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -38,7 +38,7 @@ export function sendPutFleetServerHost(itemId: string, body: PutFleetServerHosts return sendRequest({ method: 'put', path: fleetServerHostsRoutesService.getUpdatePath(itemId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } @@ -47,7 +47,7 @@ export function sendPostFleetServerHost(body: PostFleetServerHostsRequest['body' return sendRequest({ method: 'post', path: fleetServerHostsRoutesService.getCreatePath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts b/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts index 08bc02828be00..0faf604d3c361 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts @@ -7,7 +7,7 @@ import type { PostHealthCheckRequest, PostHealthCheckResponse } from '../../types'; import { appRoutesService } from '../../services'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { sendRequest } from './use_request'; @@ -15,7 +15,7 @@ export function sendPostHealthCheck(body: PostHealthCheckRequest['body']) { return sendRequest({ method: 'post', path: appRoutesService.postHealthCheckPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts b/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts index d8bc2a6a68e50..33518f8995aac 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts @@ -8,7 +8,7 @@ import { agentPolicyRouteService } from '../../services'; import type { GetFullAgentManifestResponse } from '../../../common/types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { sendRequest } from './use_request'; @@ -16,7 +16,7 @@ export const sendGetK8sManifest = (query: { fleetServer?: string; enrolToken?: s return sendRequest({ path: agentPolicyRouteService.getK8sInfoPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts b/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts index 337a5171ab396..42b3e50cd2f45 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts @@ -13,7 +13,7 @@ import type { PostLogstashApiKeyResponse, } from '../../types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { sendRequest, useRequest } from './use_request'; @@ -35,7 +35,7 @@ export function sendPutOutput(outputId: string, body: PutOutputRequest['body']) return sendRequest({ method: 'put', path: outputRoutesService.getUpdatePath(outputId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } @@ -44,7 +44,7 @@ export function sendPostLogstashApiKeys() { return sendRequest({ method: 'post', path: outputRoutesService.getCreateLogstashApiKeyPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -52,7 +52,7 @@ export function sendPostOutput(body: PostOutputRequest['body']) { return sendRequest({ method: 'post', path: outputRoutesService.getCreatePath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } @@ -61,6 +61,6 @@ export function sendDeleteOutput(outputId: string) { return sendRequest({ method: 'delete', path: outputRoutesService.getDeletePath(outputId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts b/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts index 26c86f72b316b..04ab5de96fab1 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts @@ -24,7 +24,7 @@ import type { UpgradePackagePolicyResponse, } from '../../../common/types/rest_spec'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import type { RequestError } from './use_request'; import { sendRequest, sendRequestForRq, useRequest } from './use_request'; @@ -33,7 +33,7 @@ export const sendCreatePackagePolicy = (body: CreatePackagePolicyRequest['body'] return sendRequest({ path: packagePolicyRouteService.getCreatePath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: JSON.stringify(body), }); }; @@ -45,7 +45,7 @@ export const sendUpdatePackagePolicy = ( return sendRequest({ path: packagePolicyRouteService.getUpdatePath(packagePolicyId), method: 'put', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: JSON.stringify(body), }); }; @@ -54,7 +54,7 @@ export const sendDeletePackagePolicy = (body: DeletePackagePoliciesRequest['body return sendRequest({ path: packagePolicyRouteService.getDeletePath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: JSON.stringify(body), }); }; @@ -63,7 +63,7 @@ export function useGetPackagePoliciesQuery(query: GetPackagePoliciesRequest['que return useQuery(['packagePolicies'], () => sendRequestForRq({ method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, path: packagePolicyRouteService.getListPath(), query, }) @@ -73,7 +73,7 @@ export function useGetPackagePoliciesQuery(query: GetPackagePoliciesRequest['que export function useGetPackagePolicies(query: GetPackagePoliciesRequest['query']) { return useRequest({ method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, path: packagePolicyRouteService.getListPath(), query, }); @@ -82,7 +82,7 @@ export function useGetPackagePolicies(query: GetPackagePoliciesRequest['query']) export const sendGetPackagePolicies = (query: GetPackagePoliciesRequest['query']) => { return sendRequest({ method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, path: packagePolicyRouteService.getListPath(), query, }); @@ -94,7 +94,7 @@ export const useGetOnePackagePolicyQuery = (packagePolicyId: string) => { () => sendRequestForRq({ method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, path: packagePolicyRouteService.getInfoPath(packagePolicyId), }) ); @@ -104,7 +104,7 @@ export const useGetOnePackagePolicy = (packagePolicyId: string) => { return useRequest({ path: packagePolicyRouteService.getInfoPath(packagePolicyId), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -112,7 +112,7 @@ export const sendGetOnePackagePolicy = (packagePolicyId: string) => { return sendRequest({ path: packagePolicyRouteService.getInfoPath(packagePolicyId), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -135,7 +135,7 @@ export function useUpgradePackagePolicyDryRunQuery( sendRequestForRq({ path: packagePolicyRouteService.getDryRunPath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: JSON.stringify(body), }), { enabled } @@ -157,7 +157,7 @@ export function sendUpgradePackagePolicyDryRun( return sendRequest({ path: packagePolicyRouteService.getDryRunPath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: JSON.stringify(body), }); } @@ -171,7 +171,7 @@ export function useUpgradePackagePoliciesMutation() { sendRequestForRq({ path: packagePolicyRouteService.getUpgradePath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: JSON.stringify({ packagePolicyIds, }), @@ -183,7 +183,7 @@ export function sendUpgradePackagePolicy(packagePolicyIds: string[]) { return sendRequest({ path: packagePolicyRouteService.getUpgradePath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: JSON.stringify({ packagePolicyIds, }), @@ -194,6 +194,6 @@ export function sendGetOrphanedIntegrationPolicies() { return sendRequest({ path: packagePolicyRouteService.getOrphanedIntegrationPoliciesPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/settings.ts b/x-pack/plugins/fleet/public/hooks/use_request/settings.ts index 5c6464b7e8bc0..c2484792bfda6 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/settings.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/settings.ts @@ -10,7 +10,7 @@ import { useQuery } from '@tanstack/react-query'; import { settingsRoutesService } from '../../services'; import type { PutSettingsResponse, PutSettingsRequest, GetSettingsResponse } from '../../types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import type { RequestError } from './use_request'; import { sendRequest, sendRequestForRq, useRequest } from './use_request'; @@ -20,7 +20,7 @@ export function useGetSettingsQuery() { sendRequestForRq({ method: 'get', path: settingsRoutesService.getInfoPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }) ); } @@ -29,7 +29,7 @@ export function useGetSettings() { return useRequest({ method: 'get', path: settingsRoutesService.getInfoPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -37,7 +37,7 @@ export function sendGetSettings() { return sendRequest({ method: 'get', path: settingsRoutesService.getInfoPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); } @@ -45,7 +45,7 @@ export function sendPutSettings(body: PutSettingsRequest['body']) { return sendRequest({ method: 'put', path: settingsRoutesService.getUpdatePath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/setup.ts b/x-pack/plugins/fleet/public/hooks/use_request/setup.ts index 53236841c46ee..4708f517578bd 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/setup.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/setup.ts @@ -7,7 +7,7 @@ import { setupRouteService, fleetSetupRouteService } from '../../services'; import type { GetFleetStatusResponse } from '../../types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { sendRequest } from './use_request'; @@ -15,7 +15,7 @@ export const sendSetup = () => { return sendRequest({ path: setupRouteService.getSetupPath(), method: 'post', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -23,7 +23,7 @@ export const sendGetFleetStatus = () => { return sendRequest({ path: fleetSetupRouteService.getFleetSetupPath(), method: 'get', - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); }; @@ -31,7 +31,7 @@ export const sendPostFleetSetup = ({ forceRecreate }: { forceRecreate: boolean } return sendRequest({ method: 'post', path: fleetSetupRouteService.postFleetSetupPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, body: { forceRecreate, }, diff --git a/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts b/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts index 40abc3e1c7f9c..15d238b1f675c 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts @@ -9,7 +9,7 @@ import { useQuery } from '@tanstack/react-query'; import { uninstallTokensRouteService } from '../../../common/services'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import type { GetUninstallTokensMetadataRequest, @@ -25,7 +25,7 @@ export const useGetUninstallTokens = (query: GetUninstallTokensMetadataRequest[' sendRequestForRq({ method: 'get', path: uninstallTokensRouteService.getListPath(), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, query, }) ); @@ -37,7 +37,7 @@ export const useGetUninstallToken = (uninstallTokenId: string) => sendRequestForRq({ method: 'get', path: uninstallTokensRouteService.getInfoPath(uninstallTokenId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }) ); @@ -45,5 +45,5 @@ export const sendGetUninstallToken = (uninstallTokenId: string) => sendRequest({ method: 'get', path: uninstallTokensRouteService.getInfoPath(uninstallTokenId), - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }); diff --git a/x-pack/plugins/fleet/public/plugin.ts b/x-pack/plugins/fleet/public/plugin.ts index 6e6afe4214b57..7b0b08751c0c6 100644 --- a/x-pack/plugins/fleet/public/plugin.ts +++ b/x-pack/plugins/fleet/public/plugin.ts @@ -62,7 +62,7 @@ import type { ExperimentalFeatures } from '../common/experimental_features'; import type { FleetConfigType } from '../common/types'; -import { LATEST_PUBLIC_VERSION } from '../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../common/constants'; import { CUSTOM_LOGS_INTEGRATION_NAME, INTEGRATIONS_BASE_PATH } from './constants'; import { licenseService } from './hooks'; @@ -289,10 +289,10 @@ export class FleetPlugin implements Plugin core.http.fetch(appRoutesService.getCheckPermissionsPath(), { headers: { - [ELASTIC_HTTP_VERSION_HEADER]: LATEST_PUBLIC_VERSION, + [ELASTIC_HTTP_VERSION_HEADER]: OLDEST_PUBLIC_VERSION, [X_ELASTIC_INTERNAL_ORIGIN_REQUEST]: 'kibana', }, - version: LATEST_PUBLIC_VERSION, + version: OLDEST_PUBLIC_VERSION, }) ); diff --git a/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts b/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts index c906715e4eff6..5ba81283d3150 100644 --- a/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts +++ b/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts @@ -32,6 +32,7 @@ const printUsage = () => const DEFAULT_KIBANA_URL = 'http://localhost:5601'; const DEFAULT_KIBANA_USERNAME = 'elastic'; const DEFAULT_KIBANA_PASSWORD = 'changeme'; +const OLDEST_PUBLIC_VERSION = '2023-10-31'; const DEFAULT_UNENROLL_TIMEOUT = 300; // 5 minutes const ES_URL = 'http://localhost:9200'; @@ -273,7 +274,7 @@ async function createAgentPolicy(id: string) { 'kbn-xsrf': 'kibana', 'x-elastic-product-origin': 'fleet', // Note: version can change in the future - 'Elastic-Api-Version': '2023-10-31', + 'Elastic-Api-Version': OLDEST_PUBLIC_VERSION, }, }); const data = await res.json(); diff --git a/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts b/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts index 059e5096efad1..97deff589af4f 100644 --- a/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts +++ b/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts @@ -19,6 +19,7 @@ const KIBANA_URL = 'http://localhost:5601'; const KIBANA_USERNAME = 'elastic'; const KIBANA_PASSWORD = 'changeme'; const KIBANA_VERSION = kibanaPackageJson.version; +const OLDEST_PUBLIC_VERSION = '2023-10-31'; const { base = '', prerelease = false, batchSize = 1 } = yargs(process.argv).argv; @@ -51,7 +52,7 @@ async function getPackage(name: string, version: string, full: boolean = false) Authorization: 'Basic ' + Buffer.from(`${KIBANA_USERNAME}:${KIBANA_PASSWORD}`).toString('base64'), // Note: version can change in the future - 'Elastic-Api-Version': '2023-10-31', + 'Elastic-Api-Version': OLDEST_PUBLIC_VERSION, }, method: 'GET', } diff --git a/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts b/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts index 1135b7cc4dc42..652ad1413bb17 100644 --- a/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts +++ b/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts @@ -15,6 +15,7 @@ const DEFAULT_KIBANA_URL = 'http://localhost:5601'; const DEFAULT_KIBANA_USERNAME = 'elastic'; const DEFAULT_KIBANA_PASSWORD = 'changeme'; const KIBANA_VERSION = kibanaPackageJson.version; +const OLDEST_PUBLIC_VERSION = '2023-10-31'; const logger = new ToolingLog({ level: 'info', @@ -60,7 +61,7 @@ async function installPackage(name: string, version: string) { 'kbn-xsrf': 'xyz', Authorization, // Note: version can change in the future - 'Elastic-Api-Version': '2023-10-31', + 'Elastic-Api-Version': OLDEST_PUBLIC_VERSION, }, body: JSON.stringify({ force: true }), method: 'POST', @@ -80,7 +81,7 @@ async function deletePackage(name: string, version: string) { 'kbn-xsrf': 'xyz', Authorization, // Note: version can change in the future - 'Elastic-Api-Version': '2023-10-31', + 'Elastic-Api-Version': OLDEST_PUBLIC_VERSION, }, method: 'DELETE', }); diff --git a/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts b/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts index fc7933dad2085..ec7f0eeb76b99 100644 --- a/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts +++ b/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts @@ -9,7 +9,7 @@ import type { AwaitedProperties } from '@kbn/utility-types'; import { httpServerMock, savedObjectsClientMock, coreMock } from '@kbn/core/server/mocks'; import type { PostFleetSetupResponse } from '../../../common/types'; -import { LATEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { RegistryError } from '../../errors'; import { createAppContextStartContractMock, @@ -63,7 +63,7 @@ describe('FleetSetupHandler', () => { request = httpServerMock.createKibanaRequest({ method: 'post', path: '/api/fleet/setup', - headers: { 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); // prevents `Logger not set.` and other appContext errors appContextService.start(createAppContextStartContractMock()); @@ -147,7 +147,7 @@ describe('FleetStatusHandler', () => { request = httpServerMock.createKibanaRequest({ method: 'post', path: '/api/fleet/status', - headers: { 'Elastic-Api-Version': `${LATEST_PUBLIC_VERSION}` }, + headers: { 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, }); // prevents `Logger not set.` and other appContext errors appContextService.start(createAppContextStartContractMock()); diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.ts index d5a38f4e2aa53..498d1bc0d9716 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.ts @@ -21,8 +21,8 @@ import { routeValidationObject } from '@kbn/server-route-repository'; import type { INTERNAL_API_ACCESS } from '../../../common/constants'; import { - LATEST_PUBLIC_VERSION, - LATEST_INTERNAL_VERSION, + OLDEST_PUBLIC_VERSION, + OLDEST_INTERNAL_VERSION, PUBLIC_API_ACCESS, } from '../../../common/constants'; @@ -134,7 +134,7 @@ export function makeRouterWithFleetAuthz - access === PUBLIC_API_ACCESS ? LATEST_PUBLIC_VERSION : LATEST_INTERNAL_VERSION; + access === PUBLIC_API_ACCESS ? OLDEST_PUBLIC_VERSION : OLDEST_INTERNAL_VERSION; const fleetAuthzRouter: FleetAuthzRouter = { get: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { diff --git a/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts b/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts index d205358c65377..b125693e8b915 100644 --- a/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts +++ b/x-pack/plugins/osquery/cypress/tasks/api_fixtures.ts @@ -266,8 +266,4 @@ export const loadAgentPolicy = () => }).then((response) => response.body.item); export const cleanupAgentPolicy = (agentPolicyId: string) => - request({ - method: 'POST', - body: { agentPolicyId }, - url: '/api/fleet/agent_policies/delete', - }); + request({ method: 'POST', body: { agentPolicyId }, url: '/api/fleet/agent_policies/delete' }); From d99bcf94c8cda269fe23ebc7b0561bc2f7da524e Mon Sep 17 00:00:00 2001 From: criamico Date: Wed, 23 Aug 2023 11:59:56 +0200 Subject: [PATCH 12/26] fix tests for internal version --- .../reset_preconfiguration.test.ts | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/fleet/server/integration_tests/reset_preconfiguration.test.ts b/x-pack/plugins/fleet/server/integration_tests/reset_preconfiguration.test.ts index a30f0a47304a3..2eb39dc1d922c 100644 --- a/x-pack/plugins/fleet/server/integration_tests/reset_preconfiguration.test.ts +++ b/x-pack/plugins/fleet/server/integration_tests/reset_preconfiguration.test.ts @@ -16,6 +16,7 @@ import { import type { AgentPolicySOAttributes } from '../types'; import { PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE } from '../../common'; +import { OLDEST_INTERNAL_VERSION } from '../../common/constants'; import { useDockerRegistry, waitForFleetSetup, getSupertestWithAdminUser } from './helpers'; @@ -184,7 +185,11 @@ describe('Fleet preconfiguration reset', () => { 'post', '/internal/fleet/reset_preconfigured_agent_policies' ); - await resetAPI.set('kbn-sxrf', 'xx').expect(200).send(); + await resetAPI + .set('kbn-sxrf', 'xx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .expect(200) + .send(); const agentPolicies = await kbnServer.coreStart.savedObjects .createInternalRepository() @@ -226,7 +231,11 @@ describe('Fleet preconfiguration reset', () => { 'post', '/internal/fleet/reset_preconfigured_agent_policies/test-12345' ); - await resetAPI.set('kbn-sxrf', 'xx').expect(200).send(); + await resetAPI + .set('kbn-sxrf', 'xx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .expect(200) + .send(); const agentPolicies = await kbnServer.coreStart.savedObjects .createInternalRepository() @@ -260,7 +269,11 @@ describe('Fleet preconfiguration reset', () => { 'post', '/internal/fleet/reset_preconfigured_agent_policies/test-12345' ); - await resetAPI.set('kbn-sxrf', 'xx').expect(200).send(); + await resetAPI + .set('kbn-sxrf', 'xx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .expect(200) + .send(); const agentPolicies = await soClient.find({ type: 'ingest-agent-policies', @@ -292,7 +305,11 @@ describe('Fleet preconfiguration reset', () => { 'post', `/internal/fleet/reset_preconfigured_agent_policies/${POLICY_ID}` ); - await resetAPI.set('kbn-sxrf', 'xx').expect(200).send(); + await resetAPI + .set('kbn-sxrf', 'xx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .expect(200) + .send(); const agentPolicies = await kbnServer.coreStart.savedObjects .createInternalRepository() From 8a167170468b43635f84e93416b7ecc78dae7d7f Mon Sep 17 00:00:00 2001 From: criamico Date: Thu, 24 Aug 2023 17:54:27 +0200 Subject: [PATCH 13/26] Refactor router with versioned router decorator --- .../fleet/server/routes/agent/index.ts | 451 +++++++++++------- .../server/services/security/fleet_router.ts | 182 ++++--- .../fleet/server/services/security/types.ts | 68 ++- 3 files changed, 446 insertions(+), 255 deletions(-) diff --git a/x-pack/plugins/fleet/server/routes/agent/index.ts b/x-pack/plugins/fleet/server/routes/agent/index.ts index 98bddcee2c4f6..0c451abf26e60 100644 --- a/x-pack/plugins/fleet/server/routes/agent/index.ts +++ b/x-pack/plugins/fleet/server/routes/agent/index.ts @@ -6,6 +6,7 @@ */ import type { FleetAuthz } from '../../../common'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { getRouteRequiredAuthz, type FleetAuthzRouter } from '../../services/security'; @@ -72,300 +73,430 @@ import { export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigType) => { // Get one - router.get( - { + router.versioned + .get({ + access: 'public', path: AGENT_API_ROUTES.INFO_PATTERN, - validate: GetOneAgentRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getAgentHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneAgentRequestSchema }, + }, + getAgentHandler + ); + // Update - router.put( - { + router.versioned + .put({ + access: 'public', path: AGENT_API_ROUTES.UPDATE_PATTERN, - validate: UpdateAgentRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - updateAgentHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: UpdateAgentRequestSchema }, + }, + updateAgentHandler + ); + // Bulk Update Tags - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.BULK_UPDATE_AGENT_TAGS_PATTERN, - validate: PostBulkUpdateAgentTagsRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - bulkUpdateAgentTagsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostBulkUpdateAgentTagsRequestSchema }, + }, + bulkUpdateAgentTagsHandler + ); + // Delete - router.delete( - { + router.versioned + .delete({ + access: 'public', path: AGENT_API_ROUTES.DELETE_PATTERN, - validate: DeleteAgentRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - deleteAgentHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeleteAgentRequestSchema }, + }, + deleteAgentHandler + ); + // List - router.get( - { + router.versioned + .get({ + access: 'public', path: AGENT_API_ROUTES.LIST_PATTERN, - validate: GetAgentsRequestSchema, + fleetAuthz: { fleet: { all: true }, }, - }, - getAgentsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetAgentsRequestSchema }, + }, + getAgentsHandler + ); + // List Agent Tags - router.get( - { + router.versioned + .get({ + access: 'public', path: AGENT_API_ROUTES.LIST_TAGS_PATTERN, - validate: GetTagsRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getAgentTagsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetTagsRequestSchema }, + }, + getAgentTagsHandler + ); // Agent actions - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.ACTIONS_PATTERN, - validate: PostNewAgentActionRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postNewAgentActionHandlerBuilder({ - getAgent: AgentService.getAgentById, - cancelAgentAction: AgentService.cancelAgentAction, - createAgentAction: AgentService.createAgentAction, - getAgentActions: AgentService.getAgentActions, }) - ); + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostNewAgentActionRequestSchema }, + }, + postNewAgentActionHandlerBuilder({ + getAgent: AgentService.getAgentById, + cancelAgentAction: AgentService.cancelAgentAction, + createAgentAction: AgentService.createAgentAction, + getAgentActions: AgentService.getAgentActions, + }) + ); - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.CANCEL_ACTIONS_PATTERN, - validate: PostCancelActionRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postCancelActionHandlerBuilder({ - getAgent: AgentService.getAgentById, - cancelAgentAction: AgentService.cancelAgentAction, - createAgentAction: AgentService.createAgentAction, - getAgentActions: AgentService.getAgentActions, }) - ); + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostCancelActionRequestSchema }, + }, + postCancelActionHandlerBuilder({ + getAgent: AgentService.getAgentById, + cancelAgentAction: AgentService.cancelAgentAction, + createAgentAction: AgentService.createAgentAction, + getAgentActions: AgentService.getAgentActions, + }) + ); + // Get agents by Action_Ids - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.LIST_PATTERN, - validate: PostRetrieveAgentsByActionsRequestSchema, fleetAuthz: { fleet: { all: true }, // Authorizations? }, - }, - postRetrieveAgentsByActionsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostRetrieveAgentsByActionsRequestSchema }, + }, + postRetrieveAgentsByActionsHandler + ); - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.UNENROLL_PATTERN, - validate: PostAgentUnenrollRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postAgentUnenrollHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostAgentUnenrollRequestSchema }, + }, + postAgentUnenrollHandler + ); // mark as deprecated - router.put( - { + router.versioned + .put({ + access: 'public', path: AGENT_API_ROUTES.REASSIGN_PATTERN, - validate: PutAgentReassignRequestSchemaDeprecated, fleetAuthz: { fleet: { all: true }, }, - }, - putAgentsReassignHandlerDeprecated - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PutAgentReassignRequestSchemaDeprecated }, + }, + putAgentsReassignHandlerDeprecated + ); - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.REASSIGN_PATTERN, - validate: PostAgentReassignRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postAgentsReassignHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostAgentReassignRequestSchema }, + }, + postAgentsReassignHandler + ); - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.REQUEST_DIAGNOSTICS_PATTERN, - validate: PostRequestDiagnosticsActionRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - requestDiagnosticsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostRequestDiagnosticsActionRequestSchema }, + }, + requestDiagnosticsHandler + ); - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.BULK_REQUEST_DIAGNOSTICS_PATTERN, - validate: PostBulkRequestDiagnosticsActionRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - bulkRequestDiagnosticsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostBulkRequestDiagnosticsActionRequestSchema }, + }, + bulkRequestDiagnosticsHandler + ); - router.get( - { + router.versioned + .get({ + access: 'public', path: AGENT_API_ROUTES.LIST_UPLOADS_PATTERN, - validate: ListAgentUploadsRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getAgentUploadsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: ListAgentUploadsRequestSchema }, + }, + getAgentUploadsHandler + ); - router.get( - { + router.versioned + .get({ + access: 'public', path: AGENT_API_ROUTES.GET_UPLOAD_FILE_PATTERN, - validate: GetAgentUploadFileRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getAgentUploadFileHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetAgentUploadFileRequestSchema }, + }, + getAgentUploadFileHandler + ); // Get agent status for policy - router.get( - { + router.versioned + .get({ + access: 'public', path: AGENT_API_ROUTES.STATUS_PATTERN, - validate: GetAgentStatusRequestSchema, fleetAuthz: (fleetAuthz: FleetAuthz): boolean => calculateRouteAuthz( fleetAuthz, getRouteRequiredAuthz('get', AGENT_API_ROUTES.STATUS_PATTERN) ).granted, - }, - getAgentStatusForAgentPolicyHandler - ); - router.get( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetAgentStatusRequestSchema }, + }, + getAgentStatusForAgentPolicyHandler + ); + router.versioned + .get({ + access: 'internal', path: AGENT_API_ROUTES.STATUS_PATTERN_DEPRECATED, - validate: GetAgentStatusRequestSchema, fleetAuthz: { fleet: { all: true }, }, - options: { - access: 'internal', + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetAgentStatusRequestSchema }, }, - }, - getAgentStatusForAgentPolicyHandler - ); + getAgentStatusForAgentPolicyHandler + ); // Agent data - router.get( - { + router.versioned + .get({ + access: 'public', path: AGENT_API_ROUTES.DATA_PATTERN, - validate: GetAgentDataRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getAgentDataHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetAgentDataRequestSchema }, + }, + getAgentDataHandler + ); // upgrade agent - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.UPGRADE_PATTERN, - validate: PostAgentUpgradeRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postAgentUpgradeHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostAgentUpgradeRequestSchema }, + }, + postAgentUpgradeHandler + ); // bulk upgrade - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.BULK_UPGRADE_PATTERN, - validate: PostBulkAgentUpgradeRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postBulkAgentsUpgradeHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostBulkAgentUpgradeRequestSchema }, + }, + postBulkAgentsUpgradeHandler + ); // Current actions - router.get( - { + router.versioned + .get({ + access: 'public', path: AGENT_API_ROUTES.ACTION_STATUS_PATTERN, - validate: GetActionStatusRequestSchema, + fleetAuthz: { fleet: { all: true }, }, - }, - getActionStatusHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetActionStatusRequestSchema }, + }, + getActionStatusHandler + ); // Bulk reassign - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.BULK_REASSIGN_PATTERN, - validate: PostBulkAgentReassignRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postBulkAgentsReassignHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostBulkAgentReassignRequestSchema }, + }, + postBulkAgentsReassignHandler + ); // Bulk unenroll - router.post( - { + router.versioned + .post({ + access: 'public', path: AGENT_API_ROUTES.BULK_UNENROLL_PATTERN, - validate: PostBulkAgentUnenrollRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postBulkAgentsUnenrollHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostBulkAgentUnenrollRequestSchema }, + }, + postBulkAgentsUnenrollHandler + ); // Available versions for upgrades - router.get( - { + router.versioned + .get({ + access: 'public', path: AGENT_API_ROUTES.AVAILABLE_VERSIONS_PATTERN, - validate: false, fleetAuthz: { fleet: { all: true }, }, - }, - getAvailableVersionsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, + }, + getAvailableVersionsHandler + ); }; diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.ts index 498d1bc0d9716..256fc8d7b49b5 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.ts @@ -13,47 +13,40 @@ import type { Logger, RequestHandler, RouteMethod, - RouteConfig, - RouteConfigOptions, } from '@kbn/core/server'; +import type { VersionedRouteConfig } from '@kbn/core-http-server'; import { routeValidationObject } from '@kbn/server-route-repository'; -import type { INTERNAL_API_ACCESS } from '../../../common/constants'; -import { - OLDEST_PUBLIC_VERSION, - OLDEST_INTERNAL_VERSION, - PUBLIC_API_ACCESS, -} from '../../../common/constants'; +import { PUBLIC_API_ACCESS } from '../../../common/constants'; import type { FleetRequestHandlerContext } from '../..'; import { getRequestStore } from '../request_store'; -import type { FleetAuthzRouteConfig, FleetAuthzRouter } from './types'; +import type { + FleetAuthzRouteConfig, + FleetAuthzRouter, + FleetAddVersionOpts, + FleetHandler, +} from './types'; import { checkSecurityEnabled, getAuthzFromRequest, doesNotHaveRequiredFleetAuthz, } from './security'; -function withDefaultPublicAccess( - routeConfig: RouteConfig -): RouteConfig { - let newOptions: RouteConfigOptions; - if (routeConfig?.options) { - newOptions = { ...routeConfig?.options }; +function withDefaultPublicAccess( + options: VersionedRouteConfig +): VersionedRouteConfig { + if (options?.access) { + return options; } else { - newOptions = {}; - } - - if (!newOptions.access) { - newOptions.access = PUBLIC_API_ACCESS; + return { + ...options, + access: PUBLIC_API_ACCESS, + }; } - return { - ...routeConfig, - options: newOptions, - }; } export function makeRouterWithFleetAuthz( @@ -133,69 +126,100 @@ export function makeRouterWithFleetAuthz - access === PUBLIC_API_ACCESS ? OLDEST_PUBLIC_VERSION : OLDEST_INTERNAL_VERSION; const fleetAuthzRouter: FleetAuthzRouter = { - get: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { - const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const version = headerVersion || getDefaultVersion(access); - return router.versioned - .get({ access, ...options }) - .addVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + versioned: { + get: ({ fleetAuthz, ...options }) => { + const { addVersion: originalAddVersion } = router.versioned.get( + withDefaultPublicAccess(options) ); - }, - delete: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { - const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const version = headerVersion || getDefaultVersion(access); - return router.versioned - .delete({ access, ...options }) - .addVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + + function addVersion( + { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + handler: FleetHandler + ) { + originalAddVersion( + { version, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); + return { addVersion }; + } + return { addVersion }; + }, + delete: ({ fleetAuthz, ...options }) => { + const { addVersion: originalAddVersion } = router.versioned.delete( + withDefaultPublicAccess(options) ); - }, - post: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { - const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const version = headerVersion || getDefaultVersion(access); - return router.versioned - .post({ access, ...options }) - .addVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + + function addVersion( + { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + handler: FleetHandler + ) { + originalAddVersion( + { version, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); + return { addVersion }; + } + return { addVersion }; + }, + put: ({ fleetAuthz, ...options }) => { + const { addVersion: originalAddVersion } = router.versioned.put( + withDefaultPublicAccess(options) ); - }, - put: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { - const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const version = headerVersion || getDefaultVersion(access); - return router.versioned - .put({ access, ...options }) - .addVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + + function addVersion( + { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + handler: FleetHandler + ) { + originalAddVersion( + { version, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); + return { addVersion }; + } + return { addVersion }; + }, + post: ({ fleetAuthz, ...options }) => { + const { addVersion: originalAddVersion } = router.versioned.post( + withDefaultPublicAccess(options) ); - }, - patch: ({ fleetAuthz: hasRequiredAuthz, version: headerVersion, ...options }, handler) => { - const access = withDefaultPublicAccess(options).options?.access || PUBLIC_API_ACCESS; - const version = headerVersion || getDefaultVersion(access); - return router.versioned - .patch({ access, ...options }) - .addVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + + function addVersion( + { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + handler: FleetHandler + ) { + originalAddVersion( + { version, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); + return { addVersion }; + } + return { addVersion }; + }, + patch: ({ fleetAuthz, ...options }) => { + const { addVersion: originalAddVersion } = router.versioned.patch( + withDefaultPublicAccess(options) ); + + function addVersion( + { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + handler: FleetHandler + ) { + originalAddVersion( + { version, validate: { request: routeValidationObject } }, + (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + ); + return { addVersion }; + } + return { addVersion }; + }, }, - handleLegacyErrors: (handler) => router.handleLegacyErrors(handler), - getRoutes: () => router.getRoutes(), - routerPath: router.routerPath, - versioned: router.versioned, }; return fleetAuthzRouter; diff --git a/x-pack/plugins/fleet/server/services/security/types.ts b/x-pack/plugins/fleet/server/services/security/types.ts index c0af89d4d3b29..78259aad6cd89 100644 --- a/x-pack/plugins/fleet/server/services/security/types.ts +++ b/x-pack/plugins/fleet/server/services/security/types.ts @@ -5,9 +5,15 @@ * 2.0. */ -import type { RouteConfig, RouteMethod } from '@kbn/core-http-server'; +import type { + RouteMethod, + VersionedRouteConfig, + AddVersionOpts, + IKibanaResponse, +} from '@kbn/core-http-server'; import type { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; -import type { IRouter, RequestHandler } from '@kbn/core/server'; +import type { RequestHandler } from '@kbn/core/server'; +import type { MaybePromise } from '@kbn/utility-types'; import type { FleetRequestHandlerContext } from '../..'; @@ -19,10 +25,7 @@ type FleetAuthzRouterConfigParam = FleetAuthzRequirements | ((userAuthz: FleetAu type FleetAuthzRouteRegistrar< Method extends RouteMethod, Context extends RequestHandlerContext = RequestHandlerContext -> = ( - route: FleetRouteConfig, - handler: RequestHandler -) => void; +> = (config: FleetRouteConfig) => FleetVersionedRoute; export interface FleetAuthzRouteConfig< T extends FleetAuthzRouterConfigParam = FleetAuthzRouterConfigParam @@ -30,18 +33,18 @@ export interface FleetAuthzRouteConfig< fleetAuthz?: T; } -export interface FleetVersionRouteConfig { - version?: string; -} - -export type FleetRouteConfig = RouteConfig & - FleetAuthzRouteConfig & - FleetVersionRouteConfig; +/** + * Interface replacing the native VersionedRouteConfig to accept fleetAuthz + */ +export type FleetRouteConfig = VersionedRouteConfig & + FleetAuthzRouteConfig; -// Fleet router that allow to add required access when registering route -export interface FleetAuthzRouter< +/** + * Interface replacing the native VersionedRouter to handle fleetAuthz + */ +export interface FleetVersionedRouter< TContext extends FleetRequestHandlerContext = FleetRequestHandlerContext -> extends IRouter { +> { get: FleetAuthzRouteRegistrar<'get', TContext>; delete: FleetAuthzRouteRegistrar<'delete', TContext>; post: FleetAuthzRouteRegistrar<'post', TContext>; @@ -49,6 +52,15 @@ export interface FleetAuthzRouter< patch: FleetAuthzRouteRegistrar<'patch', TContext>; } +/** + * Fleet router that handles versions and authorizations when registering routes + */ +export interface FleetAuthzRouter< + TContext extends FleetRequestHandlerContext = FleetRequestHandlerContext +> { + versioned: FleetVersionedRouter; +} + type DeepPartialTruthy = { [P in keyof T]?: T[P] extends boolean ? true : DeepPartialTruthy; }; @@ -65,3 +77,27 @@ export type FleetRouteRequiredAuthz = Partial<{ any: FleetAuthzRequirements; all: FleetAuthzRequirements; }>; + +/** + * Interface used to extend Core native addVersionOpts interface to accept fleetAuthz + */ +export interface FleetAddVersionOpts extends AddVersionOpts { + fleetAuthz?: FleetAuthzRouteConfig['fleetAuthz']; +} + +export type FleetHandler = ( + ...params: Parameters> +) => MaybePromise; + +/** + * Interface that redefines Core native VersionedRoute interface to accept Fleet custom types + */ +export interface FleetVersionedRoute< + Method extends RouteMethod = RouteMethod, + Context extends RequestHandlerContext = RequestHandlerContext +> { + addVersion

( + options: FleetAddVersionOpts, + handler: FleetHandler + ): FleetVersionedRoute; +} From ee0eeaa82dd173d52bd07a59a8f0a0fe82355223 Mon Sep 17 00:00:00 2001 From: criamico Date: Fri, 25 Aug 2023 11:27:38 +0200 Subject: [PATCH 14/26] Update endpoints --- .../fleet/server/routes/agent/index.ts | 28 +- .../fleet/server/routes/agent_policy/index.ts | 179 ++++--- .../plugins/fleet/server/routes/app/index.ts | 53 ++- .../fleet/server/routes/data_streams/index.ts | 18 +- .../server/routes/download_source/index.tsx | 84 ++-- .../server/routes/enrollment_api_key/index.ts | 138 +++--- .../plugins/fleet/server/routes/epm/index.ts | 436 +++++++++++------- .../server/routes/fleet_proxies/index.ts | 81 ++-- .../server/routes/fleet_server_hosts/index.ts | 82 ++-- .../fleet/server/routes/health_check/index.ts | 17 +- .../routes/message_signing_service/index.ts | 17 +- .../fleet/server/routes/output/index.ts | 98 ++-- .../server/routes/package_policy/index.ts | 162 ++++--- .../server/routes/preconfiguration/index.ts | 43 +- .../fleet/server/routes/settings/index.ts | 33 +- .../fleet/server/routes/setup/index.ts | 50 +- .../server/routes/uninstall_token/index.ts | 34 +- .../server/services/security/fleet_router.ts | 6 +- .../fleet/server/services/security/types.ts | 12 +- 19 files changed, 955 insertions(+), 616 deletions(-) diff --git a/x-pack/plugins/fleet/server/routes/agent/index.ts b/x-pack/plugins/fleet/server/routes/agent/index.ts index 0c451abf26e60..38537a84be479 100644 --- a/x-pack/plugins/fleet/server/routes/agent/index.ts +++ b/x-pack/plugins/fleet/server/routes/agent/index.ts @@ -6,7 +6,7 @@ */ import type { FleetAuthz } from '../../../common'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_PUBLIC_VERSION, INTERNAL_API_ACCESS } from '../../../common/constants'; import { getRouteRequiredAuthz, type FleetAuthzRouter } from '../../services/security'; @@ -75,7 +75,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Get one router.versioned .get({ - access: 'public', path: AGENT_API_ROUTES.INFO_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -92,7 +91,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Update router.versioned .put({ - access: 'public', path: AGENT_API_ROUTES.UPDATE_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -109,7 +107,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Bulk Update Tags router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.BULK_UPDATE_AGENT_TAGS_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -126,7 +123,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Delete router.versioned .delete({ - access: 'public', path: AGENT_API_ROUTES.DELETE_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -143,7 +139,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // List router.versioned .get({ - access: 'public', path: AGENT_API_ROUTES.LIST_PATTERN, fleetAuthz: { @@ -161,7 +156,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // List Agent Tags router.versioned .get({ - access: 'public', path: AGENT_API_ROUTES.LIST_TAGS_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -178,7 +172,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Agent actions router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.ACTIONS_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -199,7 +192,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.CANCEL_ACTIONS_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -221,7 +213,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Get agents by Action_Ids router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.LIST_PATTERN, fleetAuthz: { fleet: { all: true }, // Authorizations? @@ -237,7 +228,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.UNENROLL_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -254,7 +244,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // mark as deprecated router.versioned .put({ - access: 'public', path: AGENT_API_ROUTES.REASSIGN_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -270,7 +259,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.REASSIGN_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -286,7 +274,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.REQUEST_DIAGNOSTICS_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -302,7 +289,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.BULK_REQUEST_DIAGNOSTICS_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -318,7 +304,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT router.versioned .get({ - access: 'public', path: AGENT_API_ROUTES.LIST_UPLOADS_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -334,7 +319,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT router.versioned .get({ - access: 'public', path: AGENT_API_ROUTES.GET_UPLOAD_FILE_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -351,7 +335,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Get agent status for policy router.versioned .get({ - access: 'public', path: AGENT_API_ROUTES.STATUS_PATTERN, fleetAuthz: (fleetAuthz: FleetAuthz): boolean => calculateRouteAuthz( @@ -368,7 +351,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT ); router.versioned .get({ - access: 'internal', + access: INTERNAL_API_ACCESS, path: AGENT_API_ROUTES.STATUS_PATTERN_DEPRECATED, fleetAuthz: { fleet: { all: true }, @@ -384,7 +367,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Agent data router.versioned .get({ - access: 'public', path: AGENT_API_ROUTES.DATA_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -401,7 +383,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // upgrade agent router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.UPGRADE_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -417,7 +398,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // bulk upgrade router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.BULK_UPGRADE_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -434,7 +414,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Current actions router.versioned .get({ - access: 'public', path: AGENT_API_ROUTES.ACTION_STATUS_PATTERN, fleetAuthz: { @@ -452,7 +431,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Bulk reassign router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.BULK_REASSIGN_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -469,7 +447,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Bulk unenroll router.versioned .post({ - access: 'public', path: AGENT_API_ROUTES.BULK_UNENROLL_PATTERN, fleetAuthz: { fleet: { all: true }, @@ -486,7 +463,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT // Available versions for upgrades router.versioned .get({ - access: 'public', path: AGENT_API_ROUTES.AVAILABLE_VERSIONS_PATTERN, fleetAuthz: { fleet: { all: true }, diff --git a/x-pack/plugins/fleet/server/routes/agent_policy/index.ts b/x-pack/plugins/fleet/server/routes/agent_policy/index.ts index 4482d02119887..7ba9207672fcd 100644 --- a/x-pack/plugins/fleet/server/routes/agent_policy/index.ts +++ b/x-pack/plugins/fleet/server/routes/agent_policy/index.ts @@ -7,6 +7,8 @@ import type { FleetAuthzRouter } from '../../services/security'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; + import { AGENT_POLICY_API_ROUTES } from '../../constants'; import { GetAgentPoliciesRequestSchema, @@ -38,135 +40,178 @@ import { export const registerRoutes = (router: FleetAuthzRouter) => { // List - Fleet Server needs access to run setup - router.get( - { + router.versioned + .get({ path: AGENT_POLICY_API_ROUTES.LIST_PATTERN, - validate: GetAgentPoliciesRequestSchema, - options: { access: 'public' }, fleetAuthz: { fleet: { readAgentPolicies: true }, }, - }, - getAgentPoliciesHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetAgentPoliciesRequestSchema }, + }, + getAgentPoliciesHandler + ); // Bulk GET - router.post( - { + router.versioned + .post({ path: AGENT_POLICY_API_ROUTES.BULK_GET_PATTERN, - validate: BulkGetAgentPoliciesRequestSchema, fleetAuthz: { fleet: { readAgentPolicies: true }, }, - }, - bulkGetAgentPoliciesHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: BulkGetAgentPoliciesRequestSchema }, + }, + bulkGetAgentPoliciesHandler + ); // Get one - router.get( - { + router.versioned + .get({ path: AGENT_POLICY_API_ROUTES.INFO_PATTERN, - validate: GetOneAgentPolicyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getOneAgentPolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneAgentPolicyRequestSchema }, + }, + getOneAgentPolicyHandler + ); // Create - router.post( - { + router.versioned + .post({ path: AGENT_POLICY_API_ROUTES.CREATE_PATTERN, - validate: CreateAgentPolicyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - createAgentPolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: CreateAgentPolicyRequestSchema }, + }, + createAgentPolicyHandler + ); // Update - router.put( - { + router.versioned + .put({ path: AGENT_POLICY_API_ROUTES.UPDATE_PATTERN, - validate: UpdateAgentPolicyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - updateAgentPolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: UpdateAgentPolicyRequestSchema }, + }, + updateAgentPolicyHandler + ); // Copy - router.post( - { + router.versioned + .post({ path: AGENT_POLICY_API_ROUTES.COPY_PATTERN, - validate: CopyAgentPolicyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - copyAgentPolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: CopyAgentPolicyRequestSchema }, + }, + copyAgentPolicyHandler + ); // Delete - router.post( - { + router.versioned + .post({ path: AGENT_POLICY_API_ROUTES.DELETE_PATTERN, - validate: DeleteAgentPolicyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - deleteAgentPoliciesHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeleteAgentPolicyRequestSchema }, + }, + deleteAgentPoliciesHandler + ); // Get one full agent policy - router.get( - { + router.versioned + .get({ path: AGENT_POLICY_API_ROUTES.FULL_INFO_PATTERN, - validate: GetFullAgentPolicyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getFullAgentPolicy - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetFullAgentPolicyRequestSchema }, + }, + getFullAgentPolicy + ); // Download one full agent policy - router.get( - { + router.versioned + .get({ path: AGENT_POLICY_API_ROUTES.FULL_INFO_DOWNLOAD_PATTERN, - validate: GetFullAgentPolicyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - downloadFullAgentPolicy - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetFullAgentPolicyRequestSchema }, + }, + downloadFullAgentPolicy + ); // Get agent manifest - router.get( - { + router.versioned + .get({ path: K8S_API_ROUTES.K8S_INFO_PATTERN, - validate: GetK8sManifestRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getK8sManifest - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetK8sManifestRequestSchema }, + }, + getK8sManifest + ); // Download agent manifest - router.get( - { + router.versioned + .get({ path: K8S_API_ROUTES.K8S_DOWNLOAD_PATTERN, - validate: GetK8sManifestRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - downloadK8sManifest - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetK8sManifestRequestSchema }, + }, + downloadK8sManifest + ); }; diff --git a/x-pack/plugins/fleet/server/routes/app/index.ts b/x-pack/plugins/fleet/server/routes/app/index.ts index 9db966d7c471c..e872243e09c95 100644 --- a/x-pack/plugins/fleet/server/routes/app/index.ts +++ b/x-pack/plugins/fleet/server/routes/app/index.ts @@ -11,6 +11,8 @@ import type { TypeOf } from '@kbn/config-schema'; import type { FleetAuthzRouter } from '../../services/security'; import { APP_API_ROUTES } from '../../constants'; +import { OLDEST_PUBLIC_VERSION, INTERNAL_API_ACCESS } from '../../../common/constants'; + import { appContextService } from '../../services'; import type { CheckPermissionsResponse, GenerateServiceTokenResponse } from '../../../common/types'; import { defaultFleetErrorHandler, GenerateServiceTokenError } from '../../errors'; @@ -87,36 +89,47 @@ export const generateServiceTokenHandler: RequestHandler = async (context, reque }; export const registerRoutes = (router: FleetAuthzRouter) => { - router.get( - { + router.versioned + .get({ path: APP_API_ROUTES.CHECK_PERMISSIONS_PATTERN, - validate: CheckPermissionsRequestSchema, - }, - getCheckPermissionsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: CheckPermissionsRequestSchema }, + }, + getCheckPermissionsHandler + ); - router.post( - { + router.versioned + .post({ path: APP_API_ROUTES.GENERATE_SERVICE_TOKEN_PATTERN, - validate: {}, fleetAuthz: { fleet: { all: true }, }, - }, - generateServiceTokenHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: {}, + }, + + generateServiceTokenHandler + ); - router.post( - { + router.versioned + .post({ path: APP_API_ROUTES.GENERATE_SERVICE_TOKEN_PATTERN_DEPRECATED, - validate: {}, fleetAuthz: { fleet: { all: true }, }, - options: { - access: 'internal', + access: INTERNAL_API_ACCESS, + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: {}, }, - }, - generateServiceTokenHandler - ); + generateServiceTokenHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/data_streams/index.ts b/x-pack/plugins/fleet/server/routes/data_streams/index.ts index 861ade8771922..8e68601f8b033 100644 --- a/x-pack/plugins/fleet/server/routes/data_streams/index.ts +++ b/x-pack/plugins/fleet/server/routes/data_streams/index.ts @@ -7,20 +7,26 @@ import type { FleetAuthzRouter } from '../../services/security'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; + import { DATA_STREAM_API_ROUTES } from '../../constants'; import { getListHandler } from './handlers'; export const registerRoutes = (router: FleetAuthzRouter) => { // List of data streams - router.get( - { + router.versioned + .get({ path: DATA_STREAM_API_ROUTES.LIST_PATTERN, - validate: false, fleetAuthz: { fleet: { all: true }, }, - }, - getListHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, + }, + getListHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/download_source/index.tsx b/x-pack/plugins/fleet/server/routes/download_source/index.tsx index 135cbf5700784..9616ab13556e4 100644 --- a/x-pack/plugins/fleet/server/routes/download_source/index.tsx +++ b/x-pack/plugins/fleet/server/routes/download_source/index.tsx @@ -7,6 +7,8 @@ import type { FleetAuthzRouter } from '../../services/security'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; + import { DOWNLOAD_SOURCE_API_ROUTES } from '../../constants'; import { getDownloadSourcesRequestSchema, @@ -25,56 +27,78 @@ import { } from './handler'; export const registerRoutes = (router: FleetAuthzRouter) => { - router.get( - { + router.versioned + .get({ path: DOWNLOAD_SOURCE_API_ROUTES.LIST_PATTERN, - validate: getDownloadSourcesRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getDownloadSourcesHandler - ); - router.get( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: getDownloadSourcesRequestSchema }, + }, + getDownloadSourcesHandler + ); + + router.versioned + .get({ path: DOWNLOAD_SOURCE_API_ROUTES.INFO_PATTERN, - validate: GetOneDownloadSourcesRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getOneDownloadSourcesHandler - ); - router.put( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneDownloadSourcesRequestSchema }, + }, + getOneDownloadSourcesHandler + ); + + router.versioned + .put({ path: DOWNLOAD_SOURCE_API_ROUTES.UPDATE_PATTERN, - validate: PutDownloadSourcesRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - putDownloadSourcesHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PutDownloadSourcesRequestSchema }, + }, + putDownloadSourcesHandler + ); - router.post( - { + router.versioned + .post({ path: DOWNLOAD_SOURCE_API_ROUTES.CREATE_PATTERN, - validate: PostDownloadSourcesRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postDownloadSourcesHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostDownloadSourcesRequestSchema }, + }, + postDownloadSourcesHandler + ); - router.delete( - { + router.versioned + .delete({ path: DOWNLOAD_SOURCE_API_ROUTES.DELETE_PATTERN, - validate: DeleteDownloadSourcesRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - deleteDownloadSourcesHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeleteDownloadSourcesRequestSchema }, + }, + deleteDownloadSourcesHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts index 15807d93288a0..d17a0c17b8829 100644 --- a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts +++ b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts @@ -8,6 +8,8 @@ import type { FleetAuthzRouter } from '../../services/security'; import { ENROLLMENT_API_KEY_ROUTES } from '../../constants'; +import { OLDEST_PUBLIC_VERSION, INTERNAL_API_ACCESS } from '../../../common/constants'; + import { GetEnrollmentAPIKeysRequestSchema, GetOneEnrollmentAPIKeyRequestSchema, @@ -23,103 +25,127 @@ import { } from './handler'; export const registerRoutes = (router: FleetAuthzRouter) => { - router.get( - { + router.versioned + .get({ path: ENROLLMENT_API_KEY_ROUTES.INFO_PATTERN, - validate: GetOneEnrollmentAPIKeyRequestSchema, fleetAuthz: { fleet: { readEnrollmentTokens: true }, }, - }, - getOneEnrollmentApiKeyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneEnrollmentAPIKeyRequestSchema }, + }, + getOneEnrollmentApiKeyHandler + ); - router.delete( - { + router.versioned + .delete({ path: ENROLLMENT_API_KEY_ROUTES.DELETE_PATTERN, - validate: DeleteEnrollmentAPIKeyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - deleteEnrollmentApiKeyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeleteEnrollmentAPIKeyRequestSchema }, + }, + deleteEnrollmentApiKeyHandler + ); - router.get( - { + router.versioned + .get({ path: ENROLLMENT_API_KEY_ROUTES.LIST_PATTERN, - validate: GetEnrollmentAPIKeysRequestSchema, fleetAuthz: { fleet: { readEnrollmentTokens: true }, }, - }, - getEnrollmentApiKeysHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetEnrollmentAPIKeysRequestSchema }, + }, + getEnrollmentApiKeysHandler + ); - router.post( - { + router.versioned + .post({ path: ENROLLMENT_API_KEY_ROUTES.CREATE_PATTERN, - validate: PostEnrollmentAPIKeyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postEnrollmentApiKeyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostEnrollmentAPIKeyRequestSchema }, + }, + postEnrollmentApiKeyHandler + ); - router.get( - { + router.versioned + .get({ path: ENROLLMENT_API_KEY_ROUTES.INFO_PATTERN_DEPRECATED, - validate: GetOneEnrollmentAPIKeyRequestSchema, fleetAuthz: { fleet: { readEnrollmentTokens: true }, }, - options: { - access: 'internal', + access: INTERNAL_API_ACCESS, + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneEnrollmentAPIKeyRequestSchema }, }, - }, - getOneEnrollmentApiKeyHandler - ); + getOneEnrollmentApiKeyHandler + ); - router.delete( - { + router.versioned + .delete({ path: ENROLLMENT_API_KEY_ROUTES.DELETE_PATTERN_DEPRECATED, - validate: DeleteEnrollmentAPIKeyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - options: { - access: 'internal', + access: INTERNAL_API_ACCESS, + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeleteEnrollmentAPIKeyRequestSchema }, }, - }, - deleteEnrollmentApiKeyHandler - ); + deleteEnrollmentApiKeyHandler + ); - router.get( - { + router.versioned + .get({ path: ENROLLMENT_API_KEY_ROUTES.LIST_PATTERN_DEPRECATED, - validate: GetEnrollmentAPIKeysRequestSchema, fleetAuthz: { fleet: { readEnrollmentTokens: true }, }, - options: { - access: 'internal', + access: INTERNAL_API_ACCESS, + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetEnrollmentAPIKeysRequestSchema }, }, - }, - getEnrollmentApiKeysHandler - ); + getEnrollmentApiKeysHandler + ); - router.post( - { + router.versioned + .post({ path: ENROLLMENT_API_KEY_ROUTES.CREATE_PATTERN_DEPRECATED, - validate: PostEnrollmentAPIKeyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - options: { - access: 'internal', + access: INTERNAL_API_ACCESS, + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostEnrollmentAPIKeyRequestSchema }, }, - }, - postEnrollmentApiKeyHandler - ); + postEnrollmentApiKeyHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/epm/index.ts b/x-pack/plugins/fleet/server/routes/epm/index.ts index 8d2b07edcf206..6572837c0d3ae 100644 --- a/x-pack/plugins/fleet/server/routes/epm/index.ts +++ b/x-pack/plugins/fleet/server/routes/epm/index.ts @@ -7,6 +7,8 @@ import type { IKibanaResponse } from '@kbn/core/server'; +import { OLDEST_PUBLIC_VERSION, INTERNAL_API_ACCESS } from '../../../common/constants'; + import type { FleetAuthz } from '../../../common'; import { @@ -78,107 +80,146 @@ export const READ_PACKAGE_INFO_AUTHZ: FleetAuthzRouteConfig['fleetAuthz'] = { }; export const registerRoutes = (router: FleetAuthzRouter) => { - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.CATEGORIES_PATTERN, - validate: GetCategoriesRequestSchema, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - }, - getCategoriesHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetCategoriesRequestSchema }, + }, + getCategoriesHandler + ); - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.LIST_PATTERN, - validate: GetPackagesRequestSchema, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - }, - getListHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetPackagesRequestSchema }, + }, + getListHandler + ); - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.INSTALLED_LIST_PATTERN, - validate: GetInstalledPackagesRequestSchema, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - }, - getInstalledListHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetInstalledPackagesRequestSchema }, + }, + getInstalledListHandler + ); - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.LIMITED_LIST_PATTERN, - validate: false, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - }, - getLimitedListHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, + }, + getLimitedListHandler + ); - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.STATS_PATTERN, - validate: GetStatsRequestSchema, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - }, - getStatsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetStatsRequestSchema }, + }, + getStatsHandler + ); - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.FILEPATH_PATTERN, - validate: GetFileRequestSchema, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - }, - getFileHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetFileRequestSchema }, + }, + getFileHandler + ); - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.INFO_PATTERN, - validate: GetInfoRequestSchema, fleetAuthz: (fleetAuthz: FleetAuthz): boolean => calculateRouteAuthz(fleetAuthz, getRouteRequiredAuthz('get', EPM_API_ROUTES.INFO_PATTERN)) .granted, - }, - getInfoHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetInfoRequestSchema }, + }, + getInfoHandler + ); - router.put( - { + router.versioned + .put({ path: EPM_API_ROUTES.INFO_PATTERN, - validate: UpdatePackageRequestSchema, fleetAuthz: { integrations: { upgradePackages: true, writePackageSettings: true }, }, - }, - updatePackageHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: UpdatePackageRequestSchema }, + }, + updatePackageHandler + ); - router.post( - { + router.versioned + .post({ path: EPM_API_ROUTES.INSTALL_FROM_REGISTRY_PATTERN, - validate: InstallPackageFromRegistryRequestSchema, fleetAuthz: INSTALL_PACKAGES_AUTHZ, - }, - installPackageFromRegistryHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: InstallPackageFromRegistryRequestSchema }, + }, + installPackageFromRegistryHandler + ); - router.post( - { + router.versioned + .post({ path: EPM_API_ROUTES.BULK_INSTALL_PATTERN, - validate: BulkInstallPackagesFromRegistryRequestSchema, fleetAuthz: { integrations: { installPackages: true, upgradePackages: true }, }, - }, - bulkInstallPackagesFromRegistryHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: BulkInstallPackagesFromRegistryRequestSchema }, + }, + bulkInstallPackagesFromRegistryHandler + ); // Only allow upload for superuser - router.post( - { + router.versioned + .post({ path: EPM_API_ROUTES.INSTALL_BY_UPLOAD_PATTERN, - validate: InstallPackageByUploadRequestSchema, options: { body: { accepts: ['application/gzip', 'application/zip'], @@ -189,169 +230,201 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { integrations: { uploadPackages: true }, }, - }, - installPackageByUploadHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: InstallPackageByUploadRequestSchema }, + }, + installPackageByUploadHandler + ); - router.post( - { + router.versioned + .post({ path: EPM_API_ROUTES.CUSTOM_INTEGRATIONS_PATTERN, - validate: CreateCustomIntegrationRequestSchema, fleetAuthz: INSTALL_PACKAGES_AUTHZ, - }, - createCustomIntegrationHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: CreateCustomIntegrationRequestSchema }, + }, + createCustomIntegrationHandler + ); - router.delete( - { + router.versioned + .delete({ path: EPM_API_ROUTES.DELETE_PATTERN, - validate: DeletePackageRequestSchema, fleetAuthz: { integrations: { removePackages: true }, }, - }, - deletePackageHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeletePackageRequestSchema }, + }, + + deletePackageHandler + ); - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.VERIFICATION_KEY_ID, - validate: false, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - }, - getVerificationKeyIdHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, + }, + getVerificationKeyIdHandler + ); - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.DATA_STREAMS_PATTERN, - validate: GetDataStreamsRequestSchema, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - }, - getDataStreamsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetDataStreamsRequestSchema }, + }, + getDataStreamsHandler + ); - router.post( - { + router.versioned + .post({ path: EPM_API_ROUTES.BULK_ASSETS_PATTERN, - validate: GetBulkAssetsRequestSchema, fleetAuthz: READ_PACKAGE_INFO_AUTHZ, - }, - getBulkAssetsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetBulkAssetsRequestSchema }, + }, + getBulkAssetsHandler + ); // deprecated since 8.0 - router.get( - { + router.versioned + .get({ path: EPM_API_ROUTES.INFO_PATTERN_DEPRECATED, - validate: GetInfoRequestSchemaDeprecated, fleetAuthz: (fleetAuthz: FleetAuthz): boolean => calculateRouteAuthz( fleetAuthz, getRouteRequiredAuthz('get', EPM_API_ROUTES.INFO_PATTERN_DEPRECATED) ).granted, - options: { - access: 'internal', + access: INTERNAL_API_ACCESS, + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetInfoRequestSchemaDeprecated }, }, - }, - async (context, request, response) => { - const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any; - const resp: IKibanaResponse = await getInfoHandler( - context, - newRequest, - response - ); - if (resp.payload?.item) { - // returning item as well here, because pkgVersion is optional in new GET endpoint, and if not specified, the router selects the deprecated route - return response.ok({ body: { item: resp.payload.item, response: resp.payload.item } }); + async (context, request, response) => { + const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any; + const resp: IKibanaResponse = await getInfoHandler( + context, + newRequest, + response + ); + if (resp.payload?.item) { + // returning item as well here, because pkgVersion is optional in new GET endpoint, and if not specified, the router selects the deprecated route + return response.ok({ body: { item: resp.payload.item, response: resp.payload.item } }); + } + return resp; } - return resp; - } - ); + ); - router.put( - { + router.versioned + .put({ path: EPM_API_ROUTES.INFO_PATTERN_DEPRECATED, - validate: UpdatePackageRequestSchemaDeprecated, + fleetAuthz: { integrations: { upgradePackages: true, writePackageSettings: true }, }, - options: { - access: 'internal', + access: INTERNAL_API_ACCESS, + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: UpdatePackageRequestSchemaDeprecated }, }, - }, - async (context, request, response) => { - const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any; - const resp: IKibanaResponse = await updatePackageHandler( - context, - newRequest, - response - ); - if (resp.payload?.item) { - return response.ok({ body: { response: resp.payload.item } }); + async (context, request, response) => { + const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any; + const resp: IKibanaResponse = await updatePackageHandler( + context, + newRequest, + response + ); + if (resp.payload?.item) { + return response.ok({ body: { response: resp.payload.item } }); + } + return resp; } - return resp; - } - ); + ); - router.post( - { + router.versioned + .post({ path: EPM_API_ROUTES.INSTALL_FROM_REGISTRY_PATTERN_DEPRECATED, - validate: InstallPackageFromRegistryRequestSchemaDeprecated, fleetAuthz: INSTALL_PACKAGES_AUTHZ, - options: { - access: 'internal', + access: INTERNAL_API_ACCESS, + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: InstallPackageFromRegistryRequestSchemaDeprecated }, }, - }, - async (context, request, response) => { - const newRequest = { - ...request, - params: splitPkgKey(request.params.pkgkey), - query: request.query, - } as any; - const resp: IKibanaResponse = await installPackageFromRegistryHandler( - context, - newRequest, - response - ); - if (resp.payload?.items) { - return response.ok({ body: { ...resp.payload, response: resp.payload.items } }); + async (context, request, response) => { + const newRequest = { + ...request, + params: splitPkgKey(request.params.pkgkey), + query: request.query, + } as any; + const resp: IKibanaResponse = + await installPackageFromRegistryHandler(context, newRequest, response); + if (resp.payload?.items) { + return response.ok({ body: { ...resp.payload, response: resp.payload.items } }); + } + return resp; } - return resp; - } - ); + ); - router.delete( - { + router.versioned + .delete({ path: EPM_API_ROUTES.DELETE_PATTERN_DEPRECATED, - validate: DeletePackageRequestSchemaDeprecated, + fleetAuthz: { integrations: { removePackages: true }, }, - options: { - access: 'internal', + access: INTERNAL_API_ACCESS, + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeletePackageRequestSchemaDeprecated }, }, - }, - async (context, request, response) => { - const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any; - const resp: IKibanaResponse = await deletePackageHandler( - context, - newRequest, - response - ); - if (resp.payload?.items) { - return response.ok({ body: { response: resp.payload.items } }); + async (context, request, response) => { + const newRequest = { ...request, params: splitPkgKey(request.params.pkgkey) } as any; + const resp: IKibanaResponse = await deletePackageHandler( + context, + newRequest, + response + ); + if (resp.payload?.items) { + return response.ok({ body: { response: resp.payload.items } }); + } + return resp; } - return resp; - } - ); + ); // Update transforms with es-secondary-authorization headers, // append authorized_by to transform's _meta, and start transforms - router.post( - { + router.versioned + .post({ path: EPM_API_ROUTES.REAUTHORIZE_TRANSFORMS, - validate: ReauthorizeTransformRequestSchema, fleetAuthz: { ...INSTALL_PACKAGES_AUTHZ, packagePrivileges: { @@ -364,7 +437,12 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }, }, }, - }, - reauthorizeTransformsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: ReauthorizeTransformRequestSchema }, + }, + reauthorizeTransformsHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/fleet_proxies/index.ts b/x-pack/plugins/fleet/server/routes/fleet_proxies/index.ts index 079b475e4f533..c23700a810bee 100644 --- a/x-pack/plugins/fleet/server/routes/fleet_proxies/index.ts +++ b/x-pack/plugins/fleet/server/routes/fleet_proxies/index.ts @@ -5,6 +5,7 @@ * 2.0. */ import type { FleetAuthzRouter } from '../../services/security'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { FLEET_PROXY_API_ROUTES } from '../../../common/constants'; import { @@ -22,58 +23,78 @@ import { } from './handler'; export const registerRoutes = (router: FleetAuthzRouter) => { - router.get( - { + router.versioned + .get({ path: FLEET_PROXY_API_ROUTES.LIST_PATTERN, - validate: false, fleetAuthz: { fleet: { all: true }, }, - }, - getAllFleetProxyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, + }, + getAllFleetProxyHandler + ); - router.post( - { + router.versioned + .post({ path: FLEET_PROXY_API_ROUTES.CREATE_PATTERN, - validate: PostFleetProxyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postFleetProxyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostFleetProxyRequestSchema }, + }, + postFleetProxyHandler + ); - router.put( - { + router.versioned + .put({ path: FLEET_PROXY_API_ROUTES.UPDATE_PATTERN, - validate: PutFleetProxyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - putFleetProxyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PutFleetProxyRequestSchema }, + }, + putFleetProxyHandler + ); - router.get( - { + router.versioned + .get({ path: FLEET_PROXY_API_ROUTES.DELETE_PATTERN, - validate: GetOneFleetProxyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getFleetProxyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneFleetProxyRequestSchema }, + }, + getFleetProxyHandler + ); - router.delete( - { + router.versioned + .delete({ path: FLEET_PROXY_API_ROUTES.DELETE_PATTERN, - validate: GetOneFleetProxyRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - deleteFleetProxyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneFleetProxyRequestSchema }, + }, + deleteFleetProxyHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/index.ts b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/index.ts index 6132216846824..0519183db7374 100644 --- a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/index.ts +++ b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/index.ts @@ -7,6 +7,8 @@ import type { FleetAuthzRouter } from '../../services/security'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; + import { FLEET_SERVER_HOST_API_ROUTES } from '../../../common/constants'; import { GetAllFleetServerHostRequestSchema, @@ -24,54 +26,74 @@ import { } from './handler'; export const registerRoutes = (router: FleetAuthzRouter) => { - router.get( - { + router.versioned + .get({ path: FLEET_SERVER_HOST_API_ROUTES.LIST_PATTERN, - validate: GetAllFleetServerHostRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getAllFleetServerHostsHandler - ); - router.post( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetAllFleetServerHostRequestSchema }, + }, + getAllFleetServerHostsHandler + ); + router.versioned + .post({ path: FLEET_SERVER_HOST_API_ROUTES.CREATE_PATTERN, - validate: PostFleetServerHostRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postFleetServerHost - ); - router.get( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostFleetServerHostRequestSchema }, + }, + postFleetServerHost + ); + router.versioned + .get({ path: FLEET_SERVER_HOST_API_ROUTES.INFO_PATTERN, - validate: GetOneFleetServerHostRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getFleetServerHostHandler - ); - router.delete( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneFleetServerHostRequestSchema }, + }, + getFleetServerHostHandler + ); + router.versioned + .delete({ path: FLEET_SERVER_HOST_API_ROUTES.DELETE_PATTERN, - validate: GetOneFleetServerHostRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - deleteFleetServerHostHandler - ); - router.put( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneFleetServerHostRequestSchema }, + }, + deleteFleetServerHostHandler + ); + router.versioned + .put({ path: FLEET_SERVER_HOST_API_ROUTES.UPDATE_PATTERN, - validate: PutFleetServerHostRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - putFleetServerHostHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PutFleetServerHostRequestSchema }, + }, + putFleetServerHostHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/health_check/index.ts b/x-pack/plugins/fleet/server/routes/health_check/index.ts index 55bd4bf7029ee..fa70a1636c8cc 100644 --- a/x-pack/plugins/fleet/server/routes/health_check/index.ts +++ b/x-pack/plugins/fleet/server/routes/health_check/index.ts @@ -9,6 +9,7 @@ import https from 'https'; import type { TypeOf } from '@kbn/config-schema'; import fetch from 'node-fetch'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import type { FleetAuthzRouter } from '../../services/security'; import { APP_API_ROUTES } from '../../constants'; @@ -18,16 +19,20 @@ import { PostHealthCheckRequestSchema } from '../../types'; export const registerRoutes = (router: FleetAuthzRouter) => { // get fleet server health check by host - router.post( - { + router.versioned + .post({ path: APP_API_ROUTES.HEALTH_CHECK_PATTERN, - validate: PostHealthCheckRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postHealthCheckHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostHealthCheckRequestSchema }, + }, + postHealthCheckHandler + ); }; export const postHealthCheckHandler: FleetRequestHandler< diff --git a/x-pack/plugins/fleet/server/routes/message_signing_service/index.ts b/x-pack/plugins/fleet/server/routes/message_signing_service/index.ts index 56c64fb2b4ddf..e79a3c811443c 100644 --- a/x-pack/plugins/fleet/server/routes/message_signing_service/index.ts +++ b/x-pack/plugins/fleet/server/routes/message_signing_service/index.ts @@ -6,6 +6,7 @@ */ import type { FleetAuthzRouter } from '../../services/security'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { MESSAGE_SIGNING_SERVICE_API_ROUTES } from '../../constants'; import { RotateKeyPairSchema } from '../../types'; @@ -13,14 +14,18 @@ import { rotateKeyPairHandler } from './handlers'; export const registerRoutes = (router: FleetAuthzRouter) => { // Rotate fleet message signing key pair - router.post( - { + router.versioned + .post({ path: MESSAGE_SIGNING_SERVICE_API_ROUTES.ROTATE_KEY_PAIR, - validate: RotateKeyPairSchema, fleetAuthz: { fleet: { all: true }, }, - }, - rotateKeyPairHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: RotateKeyPairSchema }, + }, + rotateKeyPairHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/output/index.ts b/x-pack/plugins/fleet/server/routes/output/index.ts index 330d9f57cc653..f8aa49af8c2bd 100644 --- a/x-pack/plugins/fleet/server/routes/output/index.ts +++ b/x-pack/plugins/fleet/server/routes/output/index.ts @@ -7,6 +7,8 @@ import type { FleetAuthzRouter } from '../../services/security'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; + import { OUTPUT_API_ROUTES } from '../../constants'; import { DeleteOutputRequestSchema, @@ -26,67 +28,91 @@ import { } from './handler'; export const registerRoutes = (router: FleetAuthzRouter) => { - router.get( - { + router.versioned + .get({ path: OUTPUT_API_ROUTES.LIST_PATTERN, - validate: GetOutputsRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getOutputsHandler - ); - router.get( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOutputsRequestSchema }, + }, + getOutputsHandler + ); + router.versioned + .get({ path: OUTPUT_API_ROUTES.INFO_PATTERN, - validate: GetOneOutputRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getOneOuputHandler - ); - router.put( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOneOutputRequestSchema }, + }, + getOneOuputHandler + ); + router.versioned + .put({ path: OUTPUT_API_ROUTES.UPDATE_PATTERN, - validate: PutOutputRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - putOutputHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PutOutputRequestSchema }, + }, + putOutputHandler + ); - router.post( - { + router.versioned + .post({ path: OUTPUT_API_ROUTES.CREATE_PATTERN, - validate: PostOutputRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - postOutputHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostOutputRequestSchema }, + }, + postOutputHandler + ); - router.delete( - { + router.versioned + .delete({ path: OUTPUT_API_ROUTES.DELETE_PATTERN, - validate: DeleteOutputRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - deleteOutputHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeleteOutputRequestSchema }, + }, + deleteOutputHandler + ); - router.post( - { + router.versioned + .post({ path: OUTPUT_API_ROUTES.LOGSTASH_API_KEY_PATTERN, - validate: false, fleetAuthz: { fleet: { all: true }, }, - }, - postLogstashApiKeyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, + }, + postLogstashApiKeyHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/package_policy/index.ts b/x-pack/plugins/fleet/server/routes/package_policy/index.ts index 393bbb2fd982b..83cb9779cf058 100644 --- a/x-pack/plugins/fleet/server/routes/package_policy/index.ts +++ b/x-pack/plugins/fleet/server/routes/package_policy/index.ts @@ -10,6 +10,7 @@ import { getRouteRequiredAuthz } from '../../services/security'; import type { FleetAuthzRouter } from '../../services/security'; import type { FleetAuthz } from '../../../common'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import { PACKAGE_POLICY_API_ROUTES } from '../../constants'; import { GetPackagePoliciesRequestSchema, @@ -39,125 +40,166 @@ import { export const registerRoutes = (router: FleetAuthzRouter) => { // List - router.get( - { + router.versioned + .get({ path: PACKAGE_POLICY_API_ROUTES.LIST_PATTERN, - validate: GetPackagePoliciesRequestSchema, fleetAuthz: (fleetAuthz: FleetAuthz): boolean => calculateRouteAuthz( fleetAuthz, getRouteRequiredAuthz('get', PACKAGE_POLICY_API_ROUTES.LIST_PATTERN) ).granted, - }, - getPackagePoliciesHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetPackagePoliciesRequestSchema }, + }, + getPackagePoliciesHandler + ); // Get bulk - router.post( - { + router.versioned + .post({ path: PACKAGE_POLICY_API_ROUTES.BULK_GET_PATTERN, - validate: BulkGetPackagePoliciesRequestSchema, fleetAuthz: (fleetAuthz: FleetAuthz): boolean => calculateRouteAuthz( fleetAuthz, getRouteRequiredAuthz('post', PACKAGE_POLICY_API_ROUTES.BULK_GET_PATTERN) ).granted, - }, - bulkGetPackagePoliciesHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: BulkGetPackagePoliciesRequestSchema }, + }, + bulkGetPackagePoliciesHandler + ); // Get one - router.get( - { + router.versioned + .get({ path: PACKAGE_POLICY_API_ROUTES.INFO_PATTERN, - validate: GetOnePackagePolicyRequestSchema, fleetAuthz: (fleetAuthz: FleetAuthz): boolean => calculateRouteAuthz( fleetAuthz, getRouteRequiredAuthz('get', PACKAGE_POLICY_API_ROUTES.INFO_PATTERN) ).granted, - }, - getOnePackagePolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetOnePackagePolicyRequestSchema }, + }, + getOnePackagePolicyHandler + ); - router.get( - { + router.versioned + .get({ path: PACKAGE_POLICY_API_ROUTES.ORPHANED_INTEGRATION_POLICIES, - validate: {}, fleetAuthz: { integrations: { readIntegrationPolicies: true }, }, - }, - getOrphanedPackagePolicies - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: {}, + }, + getOrphanedPackagePolicies + ); // Create - router.post( - { + router.versioned + .post({ path: PACKAGE_POLICY_API_ROUTES.CREATE_PATTERN, - validate: CreatePackagePolicyRequestSchema, - }, - createPackagePolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: CreatePackagePolicyRequestSchema }, + }, + createPackagePolicyHandler + ); // Update - router.put( - { + router.versioned + .put({ path: PACKAGE_POLICY_API_ROUTES.UPDATE_PATTERN, - validate: UpdatePackagePolicyRequestSchema, fleetAuthz: (fleetAuthz: FleetAuthz): boolean => calculateRouteAuthz( fleetAuthz, getRouteRequiredAuthz('put', PACKAGE_POLICY_API_ROUTES.UPDATE_PATTERN) ).granted, - }, - updatePackagePolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: UpdatePackagePolicyRequestSchema }, + }, + + updatePackagePolicyHandler + ); // Delete (bulk) - router.post( - { + router.versioned + .post({ path: PACKAGE_POLICY_API_ROUTES.DELETE_PATTERN, - validate: DeletePackagePoliciesRequestSchema, fleetAuthz: { integrations: { writeIntegrationPolicies: true }, }, - }, - deletePackagePolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeletePackagePoliciesRequestSchema }, + }, + deletePackagePolicyHandler + ); - router.delete( - { + router.versioned + .delete({ path: PACKAGE_POLICY_API_ROUTES.INFO_PATTERN, - validate: DeleteOnePackagePolicyRequestSchema, fleetAuthz: { integrations: { writeIntegrationPolicies: true }, }, - }, - deleteOnePackagePolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DeleteOnePackagePolicyRequestSchema }, + }, + deleteOnePackagePolicyHandler + ); // Upgrade - router.post( - { + router.versioned + .post({ path: PACKAGE_POLICY_API_ROUTES.UPGRADE_PATTERN, - validate: UpgradePackagePoliciesRequestSchema, fleetAuthz: { integrations: { writeIntegrationPolicies: true }, }, - }, - upgradePackagePolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: UpgradePackagePoliciesRequestSchema }, + }, + upgradePackagePolicyHandler + ); // Upgrade - DryRun - router.post( - { + router.versioned + .post({ path: PACKAGE_POLICY_API_ROUTES.DRYRUN_PATTERN, - validate: DryRunPackagePoliciesRequestSchema, fleetAuthz: { integrations: { readIntegrationPolicies: true }, }, - }, - dryRunUpgradePackagePolicyHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: DryRunPackagePoliciesRequestSchema }, + }, + dryRunUpgradePackagePolicyHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts b/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts index 2d46599988f1a..af2d746e58c24 100644 --- a/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts +++ b/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts @@ -7,36 +7,43 @@ import type { FleetAuthzRouter } from '../../services/security'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; + import { PRECONFIGURATION_API_ROUTES } from '../../constants'; import { PostResetOnePreconfiguredAgentPoliciesSchema } from '../../types'; import { resetPreconfigurationHandler, resetOnePreconfigurationHandler } from './handler'; export const registerRoutes = (router: FleetAuthzRouter) => { - router.post( - { + router.versioned + .post({ path: PRECONFIGURATION_API_ROUTES.RESET_PATTERN, - validate: false, - options: { - access: 'internal', - }, + access: 'internal', fleetAuthz: { fleet: { all: true }, }, - }, - resetPreconfigurationHandler - ); - router.post( - { - path: PRECONFIGURATION_API_ROUTES.RESET_ONE_PATTERN, - validate: PostResetOnePreconfiguredAgentPoliciesSchema, - options: { - access: 'internal', + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, }, + + resetPreconfigurationHandler + ); + router.versioned + .post({ + path: PRECONFIGURATION_API_ROUTES.RESET_ONE_PATTERN, + access: 'internal', fleetAuthz: { fleet: { all: true }, }, - }, - resetOnePreconfigurationHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PostResetOnePreconfiguredAgentPoliciesSchema }, + }, + resetOnePreconfigurationHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/settings/index.ts b/x-pack/plugins/fleet/server/routes/settings/index.ts index 881541b569805..0d823e1216405 100644 --- a/x-pack/plugins/fleet/server/routes/settings/index.ts +++ b/x-pack/plugins/fleet/server/routes/settings/index.ts @@ -7,6 +7,7 @@ import type { TypeOf } from '@kbn/config-schema'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import type { FleetAuthzRouter } from '../../services/security'; import { SETTINGS_API_ROUTES } from '../../constants'; @@ -65,24 +66,32 @@ export const putSettingsHandler: FleetRequestHandler< }; export const registerRoutes = (router: FleetAuthzRouter) => { - router.get( - { + router.versioned + .get({ path: SETTINGS_API_ROUTES.INFO_PATTERN, - validate: GetSettingsRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getSettingsHandler - ); - router.put( - { + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetSettingsRequestSchema }, + }, + getSettingsHandler + ); + router.versioned + .put({ path: SETTINGS_API_ROUTES.UPDATE_PATTERN, - validate: PutSettingsRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - putSettingsHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: PutSettingsRequestSchema }, + }, + putSettingsHandler + ); }; diff --git a/x-pack/plugins/fleet/server/routes/setup/index.ts b/x-pack/plugins/fleet/server/routes/setup/index.ts index b4470e648dcab..28f4629bd53f5 100644 --- a/x-pack/plugins/fleet/server/routes/setup/index.ts +++ b/x-pack/plugins/fleet/server/routes/setup/index.ts @@ -8,48 +8,62 @@ import type { FleetAuthzRouter } from '../../services/security'; import { AGENTS_SETUP_API_ROUTES, SETUP_API_ROUTE } from '../../constants'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; + import type { FleetConfigType } from '../../../common/types'; import { getFleetStatusHandler, fleetSetupHandler } from './handlers'; export const registerFleetSetupRoute = (router: FleetAuthzRouter) => { - router.post( - { + router.versioned + .post({ path: SETUP_API_ROUTE, - validate: false, fleetAuthz: { fleet: { setup: true }, }, - }, - fleetSetupHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, + }, + fleetSetupHandler + ); }; // That route is used by agent to setup Fleet export const registerCreateFleetSetupRoute = (router: FleetAuthzRouter) => { - router.post( - { + router.versioned + .post({ path: AGENTS_SETUP_API_ROUTES.CREATE_PATTERN, - validate: false, fleetAuthz: { fleet: { setup: true }, }, - }, - fleetSetupHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, + }, + fleetSetupHandler + ); }; export const registerGetFleetStatusRoute = (router: FleetAuthzRouter) => { - router.get( - { + router.versioned + .get({ path: AGENTS_SETUP_API_ROUTES.INFO_PATTERN, - validate: false, fleetAuthz: { fleet: { setup: true }, }, - }, - getFleetStatusHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: false, + }, + getFleetStatusHandler + ); }; export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType) => { diff --git a/x-pack/plugins/fleet/server/routes/uninstall_token/index.ts b/x-pack/plugins/fleet/server/routes/uninstall_token/index.ts index f22d77f70385e..7d6034d121830 100644 --- a/x-pack/plugins/fleet/server/routes/uninstall_token/index.ts +++ b/x-pack/plugins/fleet/server/routes/uninstall_token/index.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { UNINSTALL_TOKEN_ROUTES } from '../../../common/constants'; +import { UNINSTALL_TOKEN_ROUTES, OLDEST_PUBLIC_VERSION } from '../../../common/constants'; import type { FleetConfigType } from '../../config'; import type { FleetAuthzRouter } from '../../services/security'; @@ -20,26 +20,34 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType const experimentalFeatures = parseExperimentalConfigValue(config.enableExperimental); if (experimentalFeatures.agentTamperProtectionEnabled) { - router.get( - { + router.versioned + .get({ path: UNINSTALL_TOKEN_ROUTES.LIST_PATTERN, - validate: GetUninstallTokensMetadataRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getUninstallTokensMetadataHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetUninstallTokensMetadataRequestSchema }, + }, + getUninstallTokensMetadataHandler + ); - router.get( - { + router.versioned + .get({ path: UNINSTALL_TOKEN_ROUTES.INFO_PATTERN, - validate: GetUninstallTokenRequestSchema, fleetAuthz: { fleet: { all: true }, }, - }, - getUninstallTokenHandler - ); + }) + .addVersion( + { + version: OLDEST_PUBLIC_VERSION, + validate: { request: GetUninstallTokenRequestSchema }, + }, + getUninstallTokenHandler + ); } }; diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.ts index 256fc8d7b49b5..9e878af1651b0 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.ts @@ -24,6 +24,8 @@ import type { FleetRequestHandlerContext } from '../..'; import { getRequestStore } from '../request_store'; +import type { FleetVersionedRouteConfig } from './types'; + import type { FleetAuthzRouteConfig, FleetAuthzRouter, @@ -37,10 +39,10 @@ import { } from './security'; function withDefaultPublicAccess( - options: VersionedRouteConfig + options: FleetVersionedRouteConfig ): VersionedRouteConfig { if (options?.access) { - return options; + return options as VersionedRouteConfig; } else { return { ...options, diff --git a/x-pack/plugins/fleet/server/services/security/types.ts b/x-pack/plugins/fleet/server/services/security/types.ts index 78259aad6cd89..258872388c505 100644 --- a/x-pack/plugins/fleet/server/services/security/types.ts +++ b/x-pack/plugins/fleet/server/services/security/types.ts @@ -10,6 +10,7 @@ import type { VersionedRouteConfig, AddVersionOpts, IKibanaResponse, + RouteConfigOptions, } from '@kbn/core-http-server'; import type { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; import type { RequestHandler } from '@kbn/core/server'; @@ -33,10 +34,19 @@ export interface FleetAuthzRouteConfig< fleetAuthz?: T; } +/** + * Internal type necessary to make access in VersionedRouteConfig optional + */ +export type FleetVersionedRouteConfig = Omit< + VersionedRouteConfig, + 'access' +> & { + access?: Exclude['access'], undefined>; +}; /** * Interface replacing the native VersionedRouteConfig to accept fleetAuthz */ -export type FleetRouteConfig = VersionedRouteConfig & +export type FleetRouteConfig = FleetVersionedRouteConfig & FleetAuthzRouteConfig; /** From 1fd693c176e9d4f1f3c610cf85a3fb7dcfafb212 Mon Sep 17 00:00:00 2001 From: criamico Date: Fri, 25 Aug 2023 16:18:40 +0200 Subject: [PATCH 15/26] Small change to router --- .../server/services/security/fleet_router.ts | 44 +++++++------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.ts index 9e878af1651b0..39aa6b1d255b4 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.ts @@ -16,8 +16,6 @@ import type { } from '@kbn/core/server'; import type { VersionedRouteConfig } from '@kbn/core-http-server'; -import { routeValidationObject } from '@kbn/server-route-repository'; - import { PUBLIC_API_ACCESS } from '../../../common/constants'; import type { FleetRequestHandlerContext } from '../..'; @@ -137,17 +135,15 @@ export function makeRouterWithFleetAuthz( - { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { - originalAddVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + originalAddVersion({ ...opts }, (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); return { addVersion }; } - return { addVersion }; + return { addVersion: addVersion.bind(router.versioned) }; }, delete: ({ fleetAuthz, ...options }) => { const { addVersion: originalAddVersion } = router.versioned.delete( @@ -155,13 +151,11 @@ export function makeRouterWithFleetAuthz( - { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { - originalAddVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + originalAddVersion({ ...opts }, (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); return { addVersion }; } @@ -173,13 +167,11 @@ export function makeRouterWithFleetAuthz( - { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { - originalAddVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + originalAddVersion({ ...opts }, (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); return { addVersion }; } @@ -191,13 +183,11 @@ export function makeRouterWithFleetAuthz( - { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { - originalAddVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + originalAddVersion({ ...opts }, (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); return { addVersion }; } @@ -209,13 +199,11 @@ export function makeRouterWithFleetAuthz( - { fleetAuthz: hasRequiredAuthz, version }: FleetAddVersionOpts, + { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { - originalAddVersion( - { version, validate: { request: routeValidationObject } }, - (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + originalAddVersion({ ...opts }, (context, request, response) => + fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) ); return { addVersion }; } From fee33ee5026875b7f8fc051225099de6bc2c5bc2 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 25 Aug 2023 14:26:02 +0000 Subject: [PATCH 16/26] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/plugins/fleet/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/fleet/tsconfig.json b/x-pack/plugins/fleet/tsconfig.json index b7ba400dc1915..265b5c4af5949 100644 --- a/x-pack/plugins/fleet/tsconfig.json +++ b/x-pack/plugins/fleet/tsconfig.json @@ -101,7 +101,6 @@ "@kbn/core-application-browser", "@kbn/core-saved-objects-base-server-internal", "@kbn/core-http-common", - "@kbn/server-route-repository", "@kbn/dashboard-plugin", ] } From ee6503dedcbabdda3a487aaf442d5058f8779e7a Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Fri, 25 Aug 2023 10:51:39 -0400 Subject: [PATCH 17/26] Try fixing router --- .../fleet/server/routes/agent/index.ts | 8 +- .../plugins/fleet/server/routes/app/index.ts | 8 +- .../server/routes/enrollment_api_key/index.ts | 14 ++-- .../plugins/fleet/server/routes/epm/index.ts | 14 ++-- .../server/routes/preconfiguration/index.ts | 6 +- .../server/services/security/fleet_router.ts | 77 ++++++++++++------- 6 files changed, 84 insertions(+), 43 deletions(-) diff --git a/x-pack/plugins/fleet/server/routes/agent/index.ts b/x-pack/plugins/fleet/server/routes/agent/index.ts index 38537a84be479..a9cea420ccddd 100644 --- a/x-pack/plugins/fleet/server/routes/agent/index.ts +++ b/x-pack/plugins/fleet/server/routes/agent/index.ts @@ -6,7 +6,11 @@ */ import type { FleetAuthz } from '../../../common'; -import { OLDEST_PUBLIC_VERSION, INTERNAL_API_ACCESS } from '../../../common/constants'; +import { + OLDEST_PUBLIC_VERSION, + OLDEST_INTERNAL_VERSION, + INTERNAL_API_ACCESS, +} from '../../../common/constants'; import { getRouteRequiredAuthz, type FleetAuthzRouter } from '../../services/security'; @@ -359,7 +363,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: GetAgentStatusRequestSchema }, }, getAgentStatusForAgentPolicyHandler diff --git a/x-pack/plugins/fleet/server/routes/app/index.ts b/x-pack/plugins/fleet/server/routes/app/index.ts index e872243e09c95..56f50aa2b1dfe 100644 --- a/x-pack/plugins/fleet/server/routes/app/index.ts +++ b/x-pack/plugins/fleet/server/routes/app/index.ts @@ -11,7 +11,11 @@ import type { TypeOf } from '@kbn/config-schema'; import type { FleetAuthzRouter } from '../../services/security'; import { APP_API_ROUTES } from '../../constants'; -import { OLDEST_PUBLIC_VERSION, INTERNAL_API_ACCESS } from '../../../common/constants'; +import { + OLDEST_PUBLIC_VERSION, + OLDEST_INTERNAL_VERSION, + INTERNAL_API_ACCESS, +} from '../../../common/constants'; import { appContextService } from '../../services'; import type { CheckPermissionsResponse, GenerateServiceTokenResponse } from '../../../common/types'; @@ -127,7 +131,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: {}, }, generateServiceTokenHandler diff --git a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts index d17a0c17b8829..feacb977c71c1 100644 --- a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts +++ b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts @@ -8,7 +8,11 @@ import type { FleetAuthzRouter } from '../../services/security'; import { ENROLLMENT_API_KEY_ROUTES } from '../../constants'; -import { OLDEST_PUBLIC_VERSION, INTERNAL_API_ACCESS } from '../../../common/constants'; +import { + OLDEST_PUBLIC_VERSION, + OLDEST_INTERNAL_VERSION, + INTERNAL_API_ACCESS, +} from '../../../common/constants'; import { GetEnrollmentAPIKeysRequestSchema, @@ -95,7 +99,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: GetOneEnrollmentAPIKeyRequestSchema }, }, getOneEnrollmentApiKeyHandler @@ -111,7 +115,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: DeleteEnrollmentAPIKeyRequestSchema }, }, deleteEnrollmentApiKeyHandler @@ -127,7 +131,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: GetEnrollmentAPIKeysRequestSchema }, }, getEnrollmentApiKeysHandler @@ -143,7 +147,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: PostEnrollmentAPIKeyRequestSchema }, }, postEnrollmentApiKeyHandler diff --git a/x-pack/plugins/fleet/server/routes/epm/index.ts b/x-pack/plugins/fleet/server/routes/epm/index.ts index 6572837c0d3ae..2a820b8e2b36e 100644 --- a/x-pack/plugins/fleet/server/routes/epm/index.ts +++ b/x-pack/plugins/fleet/server/routes/epm/index.ts @@ -7,7 +7,11 @@ import type { IKibanaResponse } from '@kbn/core/server'; -import { OLDEST_PUBLIC_VERSION, INTERNAL_API_ACCESS } from '../../../common/constants'; +import { + OLDEST_PUBLIC_VERSION, + OLDEST_INTERNAL_VERSION, + INTERNAL_API_ACCESS, +} from '../../../common/constants'; import type { FleetAuthz } from '../../../common'; @@ -320,7 +324,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: GetInfoRequestSchemaDeprecated }, }, async (context, request, response) => { @@ -349,7 +353,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: UpdatePackageRequestSchemaDeprecated }, }, async (context, request, response) => { @@ -374,7 +378,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: InstallPackageFromRegistryRequestSchemaDeprecated }, }, async (context, request, response) => { @@ -403,7 +407,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: DeletePackageRequestSchemaDeprecated }, }, async (context, request, response) => { diff --git a/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts b/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts index af2d746e58c24..4f7a97c6fd5f9 100644 --- a/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts +++ b/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts @@ -7,7 +7,7 @@ import type { FleetAuthzRouter } from '../../services/security'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { OLDEST_INTERNAL_VERSION } from '../../../common/constants'; import { PRECONFIGURATION_API_ROUTES } from '../../constants'; import { PostResetOnePreconfiguredAgentPoliciesSchema } from '../../types'; @@ -25,7 +25,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: false, }, @@ -41,7 +41,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: OLDEST_INTERNAL_VERSION, validate: { request: PostResetOnePreconfiguredAgentPoliciesSchema }, }, resetOnePreconfigurationHandler diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.ts index 39aa6b1d255b4..f8e374c458344 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.ts @@ -130,80 +130,105 @@ export function makeRouterWithFleetAuthz = { versioned: { get: ({ fleetAuthz, ...options }) => { - const { addVersion: originalAddVersion } = router.versioned.get( - withDefaultPublicAccess(options) - ); + const res = router.versioned.get(withDefaultPublicAccess(options)); + const originalAddVersion = res.addVersion.bind(res); function addVersion( - { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, + { fleetAuthz: versionAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { originalAddVersion({ ...opts }, (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + fleetHandlerWrapper({ + context, + request, + response, + handler, + hasRequiredAuthz: versionAuthz || fleetAuthz, + }) ); return { addVersion }; } - return { addVersion: addVersion.bind(router.versioned) }; + return { addVersion }; }, delete: ({ fleetAuthz, ...options }) => { - const { addVersion: originalAddVersion } = router.versioned.delete( - withDefaultPublicAccess(options) - ); + const res = router.versioned.delete(withDefaultPublicAccess(options)); + const originalAddVersion = res.addVersion.bind(res); function addVersion( - { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, + { fleetAuthz: versionAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { originalAddVersion({ ...opts }, (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + fleetHandlerWrapper({ + context, + request, + response, + handler, + hasRequiredAuthz: versionAuthz || fleetAuthz, + }) ); return { addVersion }; } return { addVersion }; }, put: ({ fleetAuthz, ...options }) => { - const { addVersion: originalAddVersion } = router.versioned.put( - withDefaultPublicAccess(options) - ); + const res = router.versioned.put(withDefaultPublicAccess(options)); + const originalAddVersion = res.addVersion.bind(res); function addVersion( - { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, + { fleetAuthz: versionAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { originalAddVersion({ ...opts }, (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + fleetHandlerWrapper({ + context, + request, + response, + handler, + hasRequiredAuthz: versionAuthz || fleetAuthz, + }) ); return { addVersion }; } return { addVersion }; }, post: ({ fleetAuthz, ...options }) => { - const { addVersion: originalAddVersion } = router.versioned.post( - withDefaultPublicAccess(options) - ); + const res = router.versioned.post(withDefaultPublicAccess(options)); + const originalAddVersion = res.addVersion.bind(res); function addVersion( - { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, + { fleetAuthz: versionAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { originalAddVersion({ ...opts }, (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + fleetHandlerWrapper({ + context, + request, + response, + handler, + hasRequiredAuthz: versionAuthz || fleetAuthz, + }) ); return { addVersion }; } return { addVersion }; }, patch: ({ fleetAuthz, ...options }) => { - const { addVersion: originalAddVersion } = router.versioned.patch( - withDefaultPublicAccess(options) - ); + const res = router.versioned.patch(withDefaultPublicAccess(options)); + const originalAddVersion = res.addVersion.bind(res); function addVersion( - { fleetAuthz: hasRequiredAuthz, ...opts }: FleetAddVersionOpts, + { fleetAuthz: versionAuthz, ...opts }: FleetAddVersionOpts, handler: FleetHandler ) { originalAddVersion({ ...opts }, (context, request, response) => - fleetHandlerWrapper({ context, request, response, handler, hasRequiredAuthz }) + fleetHandlerWrapper({ + context, + request, + response, + handler, + hasRequiredAuthz: versionAuthz || fleetAuthz, + }) ); return { addVersion }; } From 0bc3c0c3abcbe32b108c2aeed6ec1a91bd0e9359 Mon Sep 17 00:00:00 2001 From: criamico Date: Tue, 29 Aug 2023 12:34:29 +0200 Subject: [PATCH 18/26] Fix unit tests --- .../routes/package_policy/handlers.test.ts | 6 +- .../routes/uninstall_token/handlers.test.ts | 45 ++++--- .../services/security/fleet_router.test.ts | 122 ++++++++++++------ 3 files changed, 117 insertions(+), 56 deletions(-) diff --git a/x-pack/plugins/fleet/server/routes/package_policy/handlers.test.ts b/x-pack/plugins/fleet/server/routes/package_policy/handlers.test.ts index 92ab414eab2b1..b4fb34ef377fa 100644 --- a/x-pack/plugins/fleet/server/routes/package_policy/handlers.test.ts +++ b/x-pack/plugins/fleet/server/routes/package_policy/handlers.test.ts @@ -187,9 +187,13 @@ describe('When calling package policy', () => { }; beforeEach(() => { - [routeConfig, routeHandler] = routerMock.put.mock.calls.find(([{ path }]) => + // @ts-ignore + const putMock = routerMock.versioned.put.mock; + // @ts-ignore + routeConfig = putMock.calls.find(([{ path }]) => path.startsWith(PACKAGE_POLICY_API_ROUTES.UPDATE_PATTERN) )!; + routeHandler = putMock.results[0].value.addVersion.mock.calls[0][1]; }); beforeEach(() => { diff --git a/x-pack/plugins/fleet/server/routes/uninstall_token/handlers.test.ts b/x-pack/plugins/fleet/server/routes/uninstall_token/handlers.test.ts index d69cef4a14042..3767c9a8d66ee 100644 --- a/x-pack/plugins/fleet/server/routes/uninstall_token/handlers.test.ts +++ b/x-pack/plugins/fleet/server/routes/uninstall_token/handlers.test.ts @@ -6,11 +6,12 @@ */ import type { TypeOf } from '@kbn/config-schema'; -import type { KibanaRequest } from '@kbn/core-http-server'; -import { httpServerMock, coreMock } from '@kbn/core/server/mocks'; +import type { KibanaRequest, VersionedRouter } from '@kbn/core-http-server'; +import { httpServerMock, coreMock, loggingSystemMock } from '@kbn/core/server/mocks'; +import type { RequestHandler } from '@kbn/core/server'; -import type { RouterMock } from '@kbn/core-http-router-server-mocks'; -import { mockRouter } from '@kbn/core-http-router-server-mocks'; +import { makeRouterWithFleetAuthz } from '../../services/security/fleet_router'; +import type { FleetAuthzRouter } from '../../services/security/types'; import type { UninstallToken, @@ -185,30 +186,44 @@ describe('uninstall token handlers', () => { describe('Agent Tamper Protection feature flag', () => { let config: { enableExperimental: string[] }; - let router: RouterMock; + let fakeRouter: jest.Mocked>; + let fleetAuthzRouter: FleetAuthzRouter; beforeEach(() => { - router = mockRouter.create(); + fakeRouter = { + versioned: { + get: jest.fn().mockImplementation(() => { + return { + addVersion: jest + .fn() + .mockImplementation((options: any, handler: RequestHandler) => Promise.resolve()), + }; + }), + }, + } as unknown as jest.Mocked>; + + const mockLogger = loggingSystemMock.createLogger(); + fleetAuthzRouter = makeRouterWithFleetAuthz(fakeRouter as any, mockLogger); }); it('should register handlers if feature flag is enabled', () => { config = { enableExperimental: ['agentTamperProtectionEnabled'] }; - registerRoutes(router, config); + registerRoutes(fleetAuthzRouter, config); + const wrappedHandler = + // @ts-ignore + fakeRouter.versioned.get.mock.results[0].value.addVersion; - expect(router.get).toHaveBeenCalledWith( - expect.any(Object), - getUninstallTokensMetadataHandler - ); - expect(router.get).toHaveBeenCalledWith(expect.any(Object), getUninstallTokenHandler); + expect(wrappedHandler).toHaveBeenCalled(); }); it('should NOT register handlers if feature flag is disabled', async () => { config = { enableExperimental: [] }; + registerRoutes(fleetAuthzRouter, config); + // @ts-ignore + const mockGet = fakeRouter.versioned.get; - registerRoutes(router, config); - - expect(router.get).not.toHaveBeenCalled(); + expect(mockGet).not.toHaveBeenCalled(); }); }); }); diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.test.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.test.ts index bb6ea59eeec82..cc835793fce88 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.test.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.test.ts @@ -6,7 +6,8 @@ */ import type { CheckPrivilegesDynamically } from '@kbn/security-plugin/server/authorization/check_privileges_dynamically'; -import type { IRouter, RequestHandler, RouteConfig } from '@kbn/core/server'; +import type { RequestHandler } from '@kbn/core/server'; +import type { VersionedRouter } from '@kbn/core-http-server'; import { loggingSystemMock } from '@kbn/core/server/mocks'; import type { AuthenticatedUser } from '@kbn/security-plugin/common'; @@ -17,6 +18,8 @@ import type { CheckPrivilegesPayload } from '@kbn/security-plugin/server'; import type { CheckPrivilegesResponse } from '@kbn/security-plugin/server/authorization/types'; +import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; + import type { FleetRequestHandlerContext } from '../..'; import { createAppContextStartContractMock } from '../../mocks'; import { appContextService } from '..'; @@ -64,8 +67,16 @@ describe('FleetAuthzRouter', () => { routeConfig?: any; }) => { const fakeRouter = { - get: jest.fn(), - } as unknown as jest.Mocked>; + versioned: { + get: jest.fn().mockImplementation(() => { + return { + addVersion: jest + .fn() + .mockImplementation((options: any, handler: RequestHandler) => Promise.resolve()), + }; + }), + }, + } as unknown as jest.Mocked>; const fakeHandler: RequestHandler = jest.fn((ctx, req, res) => res.ok()); const mockContext = createAppContextStartContractMock(); @@ -92,10 +103,15 @@ describe('FleetAuthzRouter', () => { appContextService.start(mockContext); - const fleetAuthzRouter = makeRouterWithFleetAuthz(fakeRouter, mockLogger); - fleetAuthzRouter.get({ ...routeConfig } as RouteConfig, fakeHandler); - const wrappedHandler = fakeRouter.get.mock.calls[0][1]; - const wrappedRouteConfig = fakeRouter.get.mock.calls[0][0]; + const fleetAuthzRouter = makeRouterWithFleetAuthz(fakeRouter as any, mockLogger); + fleetAuthzRouter.versioned + .get({ ...routeConfig }) + .addVersion({ version: OLDEST_PUBLIC_VERSION, validate: false }, fakeHandler); + // @ts-ignore + const wrappedRouteConfig = fakeRouter.versioned.get.mock.calls[0][0]; + const wrappedHandler = + // @ts-ignore + fakeRouter.versioned.get.mock.results[0].value.addVersion.mock.calls[0][1]; const resFactory = { forbidden: jest.fn(() => 'forbidden'), ok: jest.fn(() => 'ok') }; const fakeReq = { @@ -203,15 +219,48 @@ describe('FleetAuthzRouter', () => { }); describe('default access', () => { - let fakeRouter: jest.Mocked>; + let fakeRouter: jest.Mocked>; + beforeEach(() => { fakeRouter = { - get: jest.fn(), - post: jest.fn(), - delete: jest.fn(), - put: jest.fn(), - patch: jest.fn(), - } as unknown as jest.Mocked>; + versioned: { + get: jest.fn().mockImplementation(() => { + return { + addVersion: jest + .fn() + .mockImplementation((options: any, handler: RequestHandler) => Promise.resolve()), + }; + }), + post: jest.fn().mockImplementation(() => { + return { + addVersion: jest + .fn() + .mockImplementation((options: any, handler: RequestHandler) => Promise.resolve()), + }; + }), + delete: jest.fn().mockImplementation(() => { + return { + addVersion: jest + .fn() + .mockImplementation((options: any, handler: RequestHandler) => Promise.resolve()), + }; + }), + put: jest.fn().mockImplementation(() => { + return { + addVersion: jest + .fn() + .mockImplementation((options: any, handler: RequestHandler) => Promise.resolve()), + }; + }), + patch: jest.fn().mockImplementation(() => { + return { + addVersion: jest + .fn() + .mockImplementation((options: any, handler: RequestHandler) => Promise.resolve()), + }; + }), + }, + } as unknown as jest.Mocked>; }); const METHODS: Array<'get' | 'post' | 'delete' | 'put' | 'patch'> = [ @@ -225,37 +274,30 @@ describe('FleetAuthzRouter', () => { for (const method of METHODS) { describe(`${method}`, () => { it('should set default access to public', () => { - const fleetAuthzRouter = makeRouterWithFleetAuthz(fakeRouter, mockLogger); - fleetAuthzRouter[method]( - { - path: '/test', - validate: false, - }, - (() => {}) as any - ); - expect(fakeRouter[method]).toBeCalledWith( + const fleetAuthzRouter = makeRouterWithFleetAuthz(fakeRouter as any, mockLogger); + + fleetAuthzRouter.versioned[method]({ + path: '/test', + }); + // @ts-ignore + expect(fakeRouter.versioned[method]).toBeCalledWith( expect.objectContaining({ - options: { access: 'public' }, - }), - expect.anything() + access: 'public', + }) ); }); - it('should not allow to define internal routes', () => { - const fleetAuthzRouter = makeRouterWithFleetAuthz(fakeRouter, mockLogger); - fleetAuthzRouter[method]( - { - path: '/test', - validate: false, - options: { access: 'internal' }, - }, - (() => {}) as any - ); - expect(fakeRouter[method]).toBeCalledWith( + it('should allow to define internal routes when called with access: internal', () => { + const fleetAuthzRouter = makeRouterWithFleetAuthz(fakeRouter as any, mockLogger); + fleetAuthzRouter.versioned[method]({ + path: '/test', + access: 'internal', + }); + // @ts-ignore + expect(fakeRouter.versioned[method]).toBeCalledWith( expect.objectContaining({ - options: { access: 'internal' }, - }), - expect.anything() + access: 'internal', + }) ); }); }); From 196953df677df7ca14f453aaad6f73e027563105 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 29 Aug 2023 10:40:17 +0000 Subject: [PATCH 19/26] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/plugins/fleet/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/fleet/tsconfig.json b/x-pack/plugins/fleet/tsconfig.json index 265b5c4af5949..b3f8a96417f9a 100644 --- a/x-pack/plugins/fleet/tsconfig.json +++ b/x-pack/plugins/fleet/tsconfig.json @@ -97,7 +97,6 @@ "@kbn/core-http-router-server-internal", "@kbn/safer-lodash-set", "@kbn/shared-ux-file-types", - "@kbn/core-http-router-server-mocks", "@kbn/core-application-browser", "@kbn/core-saved-objects-base-server-internal", "@kbn/core-http-common", From 011ddcc2da95407ff13611b0cfb96313c398aa9b Mon Sep 17 00:00:00 2001 From: criamico Date: Tue, 29 Aug 2023 17:00:22 +0200 Subject: [PATCH 20/26] Fix fleet integration tests --- .../client/apm_synthtrace_kibana_client.ts | 2 ++ .../apis/agent_policy/agent_policy.ts | 35 ++++++++++--------- .../fleet_api_integration/apis/agents/list.ts | 1 + .../apis/agents/status.ts | 8 ++++- .../apis/enrollment_api_keys/crud.ts | 15 ++++++-- .../fleet_api_integration/apis/epm/get.ts | 9 +++-- .../apis/epm/install_prerelease.ts | 7 ++-- .../apis/package_policy/get.ts | 29 ++++++--------- .../apis/service_tokens.ts | 7 +++- 9 files changed, 71 insertions(+), 42 deletions(-) diff --git a/packages/kbn-apm-synthtrace/src/lib/apm/client/apm_synthtrace_kibana_client.ts b/packages/kbn-apm-synthtrace/src/lib/apm/client/apm_synthtrace_kibana_client.ts index bfae0c76d76a8..b2690829de450 100644 --- a/packages/kbn-apm-synthtrace/src/lib/apm/client/apm_synthtrace_kibana_client.ts +++ b/packages/kbn-apm-synthtrace/src/lib/apm/client/apm_synthtrace_kibana_client.ts @@ -8,6 +8,7 @@ import fetch from 'node-fetch'; import pRetry from 'p-retry'; +import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import { Logger } from '../../utils/create_logger'; export class ApmSynthtraceKibanaClient { @@ -69,5 +70,6 @@ function kibanaHeaders() { Accept: 'application/json', 'Content-Type': 'application/json', 'kbn-xsrf': 'kibana', + 'Elastic-Api-Version': `${OLDEST_INTERNAL_VERSION}`, }; } diff --git a/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts b/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts index 25eb5e5994083..842049c36db34 100644 --- a/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts +++ b/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts @@ -7,6 +7,7 @@ import expect from '@kbn/expect'; import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common'; +import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import { FLEET_AGENT_POLICIES_SCHEMA_VERSION } from '@kbn/fleet-plugin/server/constants'; import { skipIfNoDockerRegistry } from '../../helpers'; import { setupFleetAndAgents } from '../agents/services'; @@ -19,6 +20,16 @@ export default function (providerContext: FtrProviderContext) { const kibanaServer = getService('kibanaServer'); const es = getService('es'); + const epmInstallDeprecated = async (pkgName: string) => { + // This endpoint is currently deprecated and marked as internal + const getPkgRes = await supertest + .get(`/api/fleet/epm/packages/${pkgName}`) + .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .expect(200); + return getPkgRes; + }; + describe('fleet_agent_policies', () => { skipIfNoDockerRegistry(providerContext); @@ -301,15 +312,13 @@ export default function (providerContext: FtrProviderContext) { // load a bunch of fake system integration policy const policyIds = new Array(10).fill(null).map((_, i) => `package-policy-test-${i}`); packagePoliciesToDeleteIds = packagePoliciesToDeleteIds.concat(policyIds); - const getPkRes = await supertest - .get(`/api/fleet/epm/packages/system`) - .set('kbn-xsrf', 'xxxx') - .expect(200); + const getPkRes = await epmInstallDeprecated('system'); systemPkgVersion = getPkRes.body.item.version; // we must first force install the system package to override package verification error on policy create const installPromise = supertest .post(`/api/fleet/epm/packages/system-${systemPkgVersion}`) .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .send({ force: true }) .expect(200); @@ -500,15 +509,13 @@ export default function (providerContext: FtrProviderContext) { const policyId = 'package-policy-test-'; packagePoliciesToDeleteIds.push(policyId); - const getPkRes = await supertest - .get(`/api/fleet/epm/packages/system`) - .set('kbn-xsrf', 'xxxx') - .expect(200); + const getPkRes = await epmInstallDeprecated('system'); systemPkgVersion = getPkRes.body.item.version; // we must first force install the system package to override package verification error on policy create const installPromise = supertest .post(`/api/fleet/epm/packages/system-${systemPkgVersion}`) .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .send({ force: true }) .expect(200); @@ -591,15 +598,13 @@ export default function (providerContext: FtrProviderContext) { it('should work with package policy with space in name', async () => { const policyId = 'package-policy-test-1'; packagePoliciesToDeleteIds.push(policyId); - const getPkRes = await supertest - .get(`/api/fleet/epm/packages/system`) - .set('kbn-xsrf', 'xxxx') - .expect(200); + const getPkRes = await epmInstallDeprecated('system'); systemPkgVersion = getPkRes.body.item.version; // we must first force install the system package to override package verification error on policy create const installPromise = supertest .post(`/api/fleet/epm/packages/system-${systemPkgVersion}`) .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .send({ force: true }) .expect(200); @@ -1101,15 +1106,13 @@ export default function (providerContext: FtrProviderContext) { }); setupFleetAndAgents(providerContext); before(async () => { - const getPkRes = await supertest - .get(`/api/fleet/epm/packages/system`) - .set('kbn-xsrf', 'xxxx') - .expect(200); + const getPkRes = await epmInstallDeprecated('system'); // we must first force install the system package to override package verification error on policy create await supertest .post(`/api/fleet/epm/packages/system-${getPkRes.body.item.version}`) .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .send({ force: true }) .expect(200); diff --git a/x-pack/test/fleet_api_integration/apis/agents/list.ts b/x-pack/test/fleet_api_integration/apis/agents/list.ts index 328e4a240e77c..845a0b1a83659 100644 --- a/x-pack/test/fleet_api_integration/apis/agents/list.ts +++ b/x-pack/test/fleet_api_integration/apis/agents/list.ts @@ -216,6 +216,7 @@ export default function ({ getService }: FtrProviderContext) { it('should return a status summary if getStatusSummary provided', async () => { const { body: apiResponse } = await supertest .get('/api/fleet/agents?getStatusSummary=true&perPage=0') + .set('kbn-xsrf', 'xxxx') .expect(200); expect(apiResponse.items).to.eql([]); diff --git a/x-pack/test/fleet_api_integration/apis/agents/status.ts b/x-pack/test/fleet_api_integration/apis/agents/status.ts index 498fbe7c42bce..f49446f29ecdb 100644 --- a/x-pack/test/fleet_api_integration/apis/agents/status.ts +++ b/x-pack/test/fleet_api_integration/apis/agents/status.ts @@ -8,6 +8,8 @@ import expect from '@kbn/expect'; import { INGEST_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server'; +import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; + import { AGENTS_INDEX } from '@kbn/fleet-plugin/common'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { testUsers } from '../test_users'; @@ -230,7 +232,11 @@ export default function ({ getService }: FtrProviderContext) { }); it('should work with deprecated api', async () => { - await supertest.get(`/api/fleet/agent-status`).expect(200); + await supertest + .get(`/api/fleet/agent-status`) + .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .expect(200); }); it('should work with adequate package privileges', async () => { diff --git a/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts b/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts index d717c6e285c04..9247feada5acb 100644 --- a/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts +++ b/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts @@ -7,6 +7,7 @@ import expect from '@kbn/expect'; +import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { setupFleetAndAgents, getEsClientForAPIKey } from '../agents/services'; import { skipIfNoDockerRegistry } from '../../helpers'; @@ -324,6 +325,7 @@ export default function (providerContext: FtrProviderContext) { const { body: apiResponse } = await supertest .post(`/api/fleet/enrollment-api-keys`) .set('kbn-xsrf', 'xxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .send({ policy_id: 'policy1', }) @@ -332,11 +334,20 @@ export default function (providerContext: FtrProviderContext) { }); it('should get and delete with deprecated API', async () => { - await supertest.get(`/api/fleet/enrollment-api-keys`).expect(200); - await supertest.get(`/api/fleet/enrollment-api-keys/${ENROLLMENT_KEY_ID}`).expect(200); + await supertest + .get(`/api/fleet/enrollment-api-keys`) + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('kbn-xsrf', 'xxx') + .expect(200); + await supertest + .get(`/api/fleet/enrollment-api-keys/${ENROLLMENT_KEY_ID}`) + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('kbn-xsrf', 'xxx') + .expect(200); await supertest .delete(`/api/fleet/enrollment-api-keys/${keyId}`) + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .set('kbn-xsrf', 'xxx') .expect(200); }); diff --git a/x-pack/test/fleet_api_integration/apis/epm/get.ts b/x-pack/test/fleet_api_integration/apis/epm/get.ts index fb15de6847952..d895507acb27d 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/get.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/get.ts @@ -7,6 +7,7 @@ import expect from '@kbn/expect'; import { PackageInfo } from '@kbn/fleet-plugin/common/types/models/epm'; +import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import fs from 'fs'; import path from 'path'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; @@ -197,10 +198,14 @@ export default function (providerContext: FtrProviderContext) { .expect(200); }); - it('returns package info in item field when calling without version', async function () { + it('returns package info in item field when calling without version (deprecated endpoint)', async function () { // this will install through the registry by default await installPackage(testPkgName, testPkgVersion); - const res = await supertest.get(`/api/fleet/epm/packages/${testPkgName}`).expect(200); + const res = await supertest + .get(`/api/fleet/epm/packages/${testPkgName}`) + .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .expect(200); const packageInfo = res.body.item; // the uploaded version will have this description expect(packageInfo.name).to.equal('apache'); diff --git a/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts b/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts index f9d72c62e2738..6da6bead191cb 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts @@ -5,6 +5,7 @@ * 2.0. */ import expect from '@kbn/expect'; +import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { skipIfNoDockerRegistry } from '../../helpers'; import { setupFleetAndAgents } from '../agents/services'; @@ -60,20 +61,22 @@ export default function (providerContext: FtrProviderContext) { expect(response.body.items.find((item: any) => item.id.includes(gaVersion))); }); - it('should install the GA package when no version is provided', async function () { + it('should install the GA package when no version is provided - deprecated endpoint', async function () { const response = await supertest .post(`/api/fleet/epm/packages/${testPackage}`) .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .send({ force: true }) .expect(200); expect(response.body.items.find((item: any) => item.id.includes(gaVersion))); }); - it('should install the beta package when no version is provided and prerelease is true', async function () { + it('should install the beta package when no version is provided and prerelease is true - deprecated endpoint', async function () { const response = await supertest .post(`/api/fleet/epm/packages/${testPackage}?prerelease=true`) .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .send({ force: true }) // using force to ignore package verification error .expect(200); diff --git a/x-pack/test/fleet_api_integration/apis/package_policy/get.ts b/x-pack/test/fleet_api_integration/apis/package_policy/get.ts index ce0a7a1f219c6..6801c3908e658 100644 --- a/x-pack/test/fleet_api_integration/apis/package_policy/get.ts +++ b/x-pack/test/fleet_api_integration/apis/package_policy/get.ts @@ -24,6 +24,14 @@ export default function (providerContext: FtrProviderContext) { // because `this` has to point to the Mocha context // see https://mochajs.org/#arrow-functions + const deleteEndpointPackage = async () => { + await supertest + .delete(`/api/fleet/epm/packages/endpoint/8.6.1`) + .set('kbn-xsrf', 'xxxx') + .send({ force: true }) + .expect(200); + }; + describe('Package Policy APIs', () => { skipIfNoDockerRegistry(providerContext); @@ -111,12 +119,7 @@ export default function (providerContext: FtrProviderContext) { .send({ packagePolicyIds: [packagePolicyId, endpointPackagePolicyId] }) .expect(200); - // uninstall endpoint package - await supertest - .delete(`/api/fleet/epm/packages/endpoint-8.6.1`) - .set('kbn-xsrf', 'xxxx') - .send({ force: true }) - .expect(200); + await deleteEndpointPackage(); }); it('should succeed with a valid id', async function () { @@ -254,12 +257,7 @@ export default function (providerContext: FtrProviderContext) { .send({ packagePolicyIds: [packagePolicyId, endpointPackagePolicyId] }) .expect(200); - // uninstall endpoint package - await supertest - .delete(`/api/fleet/epm/packages/endpoint-8.6.1`) - .set('kbn-xsrf', 'xxxx') - .send({ force: true }) - .expect(200); + await deleteEndpointPackage(); }); it('should succeed with valid ids', async function () { @@ -476,12 +474,7 @@ export default function (providerContext: FtrProviderContext) { .send({ packagePolicyIds: [endpointPackagePolicyId] }) .expect(200); - // uninstall endpoint package - await supertest - .delete(`/api/fleet/epm/packages/endpoint-8.6.1`) - .set('kbn-xsrf', 'xxxx') - .send({ force: true }) - .expect(200); + await deleteEndpointPackage(); }); it('should return 200 if the passed kuery is correct', async () => { diff --git a/x-pack/test/fleet_api_integration/apis/service_tokens.ts b/x-pack/test/fleet_api_integration/apis/service_tokens.ts index bd13c3f5b8ca8..6d1bd5b870046 100644 --- a/x-pack/test/fleet_api_integration/apis/service_tokens.ts +++ b/x-pack/test/fleet_api_integration/apis/service_tokens.ts @@ -6,6 +6,7 @@ */ import expect from '@kbn/expect'; +import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import { FtrProviderContext } from '../../api_integration/ftr_provider_context'; export default function (providerContext: FtrProviderContext) { @@ -46,7 +47,11 @@ export default function (providerContext: FtrProviderContext) { }); it('should work with deprecated api', async () => { - await supertest.post(`/api/fleet/service-tokens`).set('kbn-xsrf', 'xxxx').expect(200); + await supertest + .post(`/api/fleet/service-tokens`) + .set('kbn-xsrf', 'xxxx') + .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .expect(200); }); }); } From e781cf94bbd8277af840d85556cf555e8f97abb9 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:07:23 +0000 Subject: [PATCH 21/26] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- packages/kbn-apm-synthtrace/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kbn-apm-synthtrace/tsconfig.json b/packages/kbn-apm-synthtrace/tsconfig.json index 22ff0442879ab..dae190285be5a 100644 --- a/packages/kbn-apm-synthtrace/tsconfig.json +++ b/packages/kbn-apm-synthtrace/tsconfig.json @@ -8,6 +8,7 @@ "kbn_references": [ "@kbn/datemath", "@kbn/apm-synthtrace-client", + "@kbn/fleet-plugin", ], "exclude": [ "target/**/*", From 455b092baa1d7da5df2cdebf1464bc622a838891 Mon Sep 17 00:00:00 2001 From: criamico Date: Wed, 30 Aug 2023 12:47:20 +0200 Subject: [PATCH 22/26] Make deprecated epm endpoint public to solve related tests failures --- .../client/apm_synthtrace_kibana_client.ts | 2 - .../plugins/fleet/server/routes/epm/index.ts | 5 +- .../apis/agent_policy/agent_policy.ts | 49 +++++++------------ .../fleet_api_integration/apis/epm/get.ts | 4 +- .../apis/epm/install_prerelease.ts | 7 +-- 5 files changed, 23 insertions(+), 44 deletions(-) diff --git a/packages/kbn-apm-synthtrace/src/lib/apm/client/apm_synthtrace_kibana_client.ts b/packages/kbn-apm-synthtrace/src/lib/apm/client/apm_synthtrace_kibana_client.ts index b2690829de450..bfae0c76d76a8 100644 --- a/packages/kbn-apm-synthtrace/src/lib/apm/client/apm_synthtrace_kibana_client.ts +++ b/packages/kbn-apm-synthtrace/src/lib/apm/client/apm_synthtrace_kibana_client.ts @@ -8,7 +8,6 @@ import fetch from 'node-fetch'; import pRetry from 'p-retry'; -import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import { Logger } from '../../utils/create_logger'; export class ApmSynthtraceKibanaClient { @@ -70,6 +69,5 @@ function kibanaHeaders() { Accept: 'application/json', 'Content-Type': 'application/json', 'kbn-xsrf': 'kibana', - 'Elastic-Api-Version': `${OLDEST_INTERNAL_VERSION}`, }; } diff --git a/x-pack/plugins/fleet/server/routes/epm/index.ts b/x-pack/plugins/fleet/server/routes/epm/index.ts index 2a820b8e2b36e..4dbe6119718f1 100644 --- a/x-pack/plugins/fleet/server/routes/epm/index.ts +++ b/x-pack/plugins/fleet/server/routes/epm/index.ts @@ -312,6 +312,8 @@ export const registerRoutes = (router: FleetAuthzRouter) => { ); // deprecated since 8.0 + // This endpoint should be marked as internal but the router selects this endpoint over the new GET one + // For now keeping it public router.versioned .get({ path: EPM_API_ROUTES.INFO_PATTERN_DEPRECATED, @@ -320,11 +322,10 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz, getRouteRequiredAuthz('get', EPM_API_ROUTES.INFO_PATTERN_DEPRECATED) ).granted, - access: INTERNAL_API_ACCESS, }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: OLDEST_PUBLIC_VERSION, validate: { request: GetInfoRequestSchemaDeprecated }, }, async (context, request, response) => { diff --git a/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts b/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts index 842049c36db34..01d85d9d11905 100644 --- a/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts +++ b/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts @@ -7,7 +7,6 @@ import expect from '@kbn/expect'; import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common'; -import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import { FLEET_AGENT_POLICIES_SCHEMA_VERSION } from '@kbn/fleet-plugin/server/constants'; import { skipIfNoDockerRegistry } from '../../helpers'; import { setupFleetAndAgents } from '../agents/services'; @@ -20,12 +19,18 @@ export default function (providerContext: FtrProviderContext) { const kibanaServer = getService('kibanaServer'); const es = getService('es'); - const epmInstallDeprecated = async (pkgName: string) => { - // This endpoint is currently deprecated and marked as internal + const epmInstall = async (pkgName: string) => { const getPkgRes = await supertest .get(`/api/fleet/epm/packages/${pkgName}`) .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .expect(200); + return getPkgRes; + }; + const epmForceInstall = async (pkgName: string) => { + const getPkgRes = await supertest + .get(`/api/fleet/epm/packages/${pkgName}`) + .set('kbn-xsrf', 'xxxx') + .send({ force: true }) .expect(200); return getPkgRes; }; @@ -312,15 +317,10 @@ export default function (providerContext: FtrProviderContext) { // load a bunch of fake system integration policy const policyIds = new Array(10).fill(null).map((_, i) => `package-policy-test-${i}`); packagePoliciesToDeleteIds = packagePoliciesToDeleteIds.concat(policyIds); - const getPkRes = await epmInstallDeprecated('system'); + const getPkRes = await epmInstall('system'); systemPkgVersion = getPkRes.body.item.version; // we must first force install the system package to override package verification error on policy create - const installPromise = supertest - .post(`/api/fleet/epm/packages/system-${systemPkgVersion}`) - .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) - .send({ force: true }) - .expect(200); + const installPromise = await epmForceInstall(`system-${systemPkgVersion}`); await Promise.all([ installPromise, @@ -509,15 +509,10 @@ export default function (providerContext: FtrProviderContext) { const policyId = 'package-policy-test-'; packagePoliciesToDeleteIds.push(policyId); - const getPkRes = await epmInstallDeprecated('system'); + const getPkRes = await epmInstall('system'); systemPkgVersion = getPkRes.body.item.version; // we must first force install the system package to override package verification error on policy create - const installPromise = supertest - .post(`/api/fleet/epm/packages/system-${systemPkgVersion}`) - .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) - .send({ force: true }) - .expect(200); + const installPromise = await epmForceInstall(`system-${systemPkgVersion}`); await Promise.all([ installPromise, @@ -598,15 +593,10 @@ export default function (providerContext: FtrProviderContext) { it('should work with package policy with space in name', async () => { const policyId = 'package-policy-test-1'; packagePoliciesToDeleteIds.push(policyId); - const getPkRes = await epmInstallDeprecated('system'); + const getPkRes = await epmInstall('system'); systemPkgVersion = getPkRes.body.item.version; // we must first force install the system package to override package verification error on policy create - const installPromise = supertest - .post(`/api/fleet/epm/packages/system-${systemPkgVersion}`) - .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) - .send({ force: true }) - .expect(200); + const installPromise = await epmForceInstall(`system-${systemPkgVersion}`); await Promise.all([ installPromise, @@ -1106,15 +1096,10 @@ export default function (providerContext: FtrProviderContext) { }); setupFleetAndAgents(providerContext); before(async () => { - const getPkRes = await epmInstallDeprecated('system'); + const getPkRes = await epmInstall('system'); // we must first force install the system package to override package verification error on policy create - await supertest - .post(`/api/fleet/epm/packages/system-${getPkRes.body.item.version}`) - .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) - .send({ force: true }) - .expect(200); + await epmForceInstall(`system-${getPkRes.body.item.version}`); const { body: { item: createdPolicy }, diff --git a/x-pack/test/fleet_api_integration/apis/epm/get.ts b/x-pack/test/fleet_api_integration/apis/epm/get.ts index d895507acb27d..2ca984ceb67dd 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/get.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/get.ts @@ -7,7 +7,6 @@ import expect from '@kbn/expect'; import { PackageInfo } from '@kbn/fleet-plugin/common/types/models/epm'; -import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import fs from 'fs'; import path from 'path'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; @@ -198,13 +197,12 @@ export default function (providerContext: FtrProviderContext) { .expect(200); }); - it('returns package info in item field when calling without version (deprecated endpoint)', async function () { + it('returns package info in item field when calling without version', async function () { // this will install through the registry by default await installPackage(testPkgName, testPkgVersion); const res = await supertest .get(`/api/fleet/epm/packages/${testPkgName}`) .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .expect(200); const packageInfo = res.body.item; // the uploaded version will have this description diff --git a/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts b/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts index 6da6bead191cb..f9d72c62e2738 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts @@ -5,7 +5,6 @@ * 2.0. */ import expect from '@kbn/expect'; -import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { skipIfNoDockerRegistry } from '../../helpers'; import { setupFleetAndAgents } from '../agents/services'; @@ -61,22 +60,20 @@ export default function (providerContext: FtrProviderContext) { expect(response.body.items.find((item: any) => item.id.includes(gaVersion))); }); - it('should install the GA package when no version is provided - deprecated endpoint', async function () { + it('should install the GA package when no version is provided', async function () { const response = await supertest .post(`/api/fleet/epm/packages/${testPackage}`) .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .send({ force: true }) .expect(200); expect(response.body.items.find((item: any) => item.id.includes(gaVersion))); }); - it('should install the beta package when no version is provided and prerelease is true - deprecated endpoint', async function () { + it('should install the beta package when no version is provided and prerelease is true', async function () { const response = await supertest .post(`/api/fleet/epm/packages/${testPackage}?prerelease=true`) .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) .send({ force: true }) // using force to ignore package verification error .expect(200); From 89aeed9244a7a8fd3ddd519a53359f9542818ae6 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 30 Aug 2023 10:54:19 +0000 Subject: [PATCH 23/26] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- packages/kbn-apm-synthtrace/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/kbn-apm-synthtrace/tsconfig.json b/packages/kbn-apm-synthtrace/tsconfig.json index dae190285be5a..22ff0442879ab 100644 --- a/packages/kbn-apm-synthtrace/tsconfig.json +++ b/packages/kbn-apm-synthtrace/tsconfig.json @@ -8,7 +8,6 @@ "kbn_references": [ "@kbn/datemath", "@kbn/apm-synthtrace-client", - "@kbn/fleet-plugin", ], "exclude": [ "target/**/*", From 3049d71b314721341c8919305cfa491c54a67258 Mon Sep 17 00:00:00 2001 From: criamico Date: Wed, 30 Aug 2023 16:25:44 +0200 Subject: [PATCH 24/26] Fix ML integration test --- x-pack/test/functional/services/ml/test_resources.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/functional/services/ml/test_resources.ts b/x-pack/test/functional/services/ml/test_resources.ts index bf5f6aed44789..f07e9338c3c80 100644 --- a/x-pack/test/functional/services/ml/test_resources.ts +++ b/x-pack/test/functional/services/ml/test_resources.ts @@ -567,7 +567,7 @@ export function MachineLearningTestResourcesProvider( await retry.tryForTime(2 * 60 * 1000, async () => { const { body, status } = await supertest .post(`/api/fleet/setup`) - .set(getCommonRequestHeader('1')); + .set(getCommonRequestHeader('2023-10-31')); mlApi.assertResponseStatusCode(200, status, body); }); log.debug(` > Setup done`); From 65581517eee01b2530de8086421a5a34fcade60b Mon Sep 17 00:00:00 2001 From: criamico Date: Mon, 4 Sep 2023 11:11:31 +0200 Subject: [PATCH 25/26] Use better naming for constants --- .../plugins/fleet/common/constants/routes.ts | 11 +++- .../fleet/cypress/e2e/a11y/home_page.cy.ts | 6 +- .../e2e/agent_binary_download_source.cy.ts | 6 +- .../fleet/cypress/e2e/agents/agent_list.cy.ts | 4 +- .../fleet/cypress/e2e/enrollment_token.cy.ts | 4 +- .../cypress/e2e/fleet_agent_flyout.cy.ts | 4 +- .../fleet/cypress/e2e/integrations_real.cy.ts | 4 +- ...e_policy_pipelines_and_mappings_real.cy.ts | 14 ++--- .../fleet/cypress/e2e/uninstall_token.cy.ts | 4 +- x-pack/plugins/fleet/cypress/plugins/index.ts | 6 +- x-pack/plugins/fleet/cypress/tasks/cleanup.ts | 8 +-- .../fleet/cypress/tasks/fleet_server.ts | 4 +- .../fleet/cypress/tasks/integrations.ts | 6 +- .../agent_policy_delete_provider.tsx | 4 +- .../package_policy_delete_provider.tsx | 4 +- .../public/hooks/use_request/agent_policy.ts | 26 ++++----- .../fleet/public/hooks/use_request/agents.ts | 50 ++++++++--------- .../fleet/public/hooks/use_request/app.ts | 10 ++-- .../public/hooks/use_request/data_stream.ts | 4 +- .../hooks/use_request/download_source.ts | 10 ++-- .../hooks/use_request/enrollment_api_keys.ts | 14 ++--- .../fleet/public/hooks/use_request/epm.ts | 42 +++++++------- .../public/hooks/use_request/fleet_proxies.ts | 10 ++-- .../hooks/use_request/fleet_server_hosts.ts | 10 ++-- .../public/hooks/use_request/health_check.ts | 4 +- .../fleet/public/hooks/use_request/k8s.ts | 4 +- .../fleet/public/hooks/use_request/outputs.ts | 10 ++-- .../hooks/use_request/package_policy.ts | 30 +++++----- .../public/hooks/use_request/settings.ts | 10 ++-- .../fleet/public/hooks/use_request/setup.ts | 8 +-- .../hooks/use_request/uninstall_tokens.ts | 8 +-- x-pack/plugins/fleet/public/plugin.ts | 12 ++-- .../scripts/create_agents/create_agents.ts | 4 +- .../get_all_packages/get_all_packages.ts | 4 +- .../install_all_packages.ts | 6 +- .../reset_preconfiguration.test.ts | 10 ++-- .../fleet/server/routes/agent/index.ts | 56 +++++++++---------- .../fleet/server/routes/agent_policy/index.ts | 24 ++++---- .../plugins/fleet/server/routes/app/index.ts | 12 ++-- .../fleet/server/routes/data_streams/index.ts | 4 +- .../server/routes/download_source/index.tsx | 12 ++-- .../server/routes/enrollment_api_key/index.ts | 22 +++----- .../plugins/fleet/server/routes/epm/index.ts | 48 ++++++++-------- .../server/routes/fleet_proxies/index.ts | 12 ++-- .../server/routes/fleet_server_hosts/index.ts | 12 ++-- .../fleet/server/routes/health_check/index.ts | 4 +- .../routes/message_signing_service/index.ts | 4 +- .../fleet/server/routes/output/index.ts | 14 ++--- .../server/routes/package_policy/index.ts | 22 ++++---- .../server/routes/preconfiguration/index.ts | 6 +- .../fleet/server/routes/settings/index.ts | 6 +- .../server/routes/setup/handlers.test.ts | 6 +- .../fleet/server/routes/setup/index.ts | 8 +-- .../server/routes/uninstall_token/index.ts | 6 +- .../services/security/fleet_router.test.ts | 4 +- .../test/fleet_api_integration/config.base.ts | 2 - 56 files changed, 321 insertions(+), 338 deletions(-) diff --git a/x-pack/plugins/fleet/common/constants/routes.ts b/x-pack/plugins/fleet/common/constants/routes.ts index 86ca70d956f0d..d675b1b42bb36 100644 --- a/x-pack/plugins/fleet/common/constants/routes.ts +++ b/x-pack/plugins/fleet/common/constants/routes.ts @@ -206,7 +206,14 @@ export const DOWNLOAD_SOURCE_API_ROUTES = { }; // API versioning constants -export const OLDEST_PUBLIC_VERSION = '2023-10-31'; -export const OLDEST_INTERNAL_VERSION = '1'; +export const API_VERSIONS = { + public: { + v1: '2023-10-31', + }, + internal: { + v1: '1', + }, +}; + export const PUBLIC_API_ACCESS = 'public'; export const INTERNAL_API_ACCESS = 'internal'; diff --git a/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts b/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts index d16e1bfd3aa06..7af771d60f9ef 100644 --- a/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts @@ -33,7 +33,7 @@ import { AGENT_POLICY_NAME_LINK } from '../../screens/integrations'; import { cleanupAgentPolicies, unenrollAgent } from '../../tasks/cleanup'; import { setFleetServerHost } from '../../tasks/fleet_server'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; describe('Home page', () => { before(() => { @@ -154,7 +154,7 @@ describe('Home page', () => { method: 'POST', url: '/api/fleet/agent_policies', body: { name: 'Agent policy for A11y test', namespace: 'default', id: 'agent-policy-a11y' }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); beforeEach(() => { @@ -166,7 +166,7 @@ describe('Home page', () => { method: 'POST', url: '/api/fleet/agent_policies/delete', body: { agentPolicyId: 'agent-policy-a11y' }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); it('Uninstall Tokens Table', () => { diff --git a/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts b/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts index 852aa45cc5b4c..3d5fa3f98fe25 100644 --- a/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/agent_binary_download_source.cy.ts @@ -15,7 +15,7 @@ import { cleanupDownloadSources } from '../tasks/cleanup'; import { FLEET, navigateTo } from '../tasks/navigation'; import { CONFIRM_MODAL } from '../screens/navigation'; -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; describe('Agent binary download source section', () => { beforeEach(() => { @@ -82,7 +82,7 @@ describe('Agent binary download source section', () => { id: 'fleet-local-registry', host: 'https://new-custom-host.co', }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); cy.request({ method: 'POST', @@ -95,7 +95,7 @@ describe('Agent binary download source section', () => { id: 'new-agent-policy', download_source_id: 'fleet-local-registry', }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }).then((response: any) => { navigateTo('app/fleet/policies/new-agent-policy/settings'); cy.getBySel(AGENT_POLICY_FORM.DOWNLOAD_SOURCE_SELECT).contains('Custom Host'); diff --git a/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts b/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts index 57045af2d286f..1e3bf95bb2356 100644 --- a/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/agents/agent_list.cy.ts @@ -13,7 +13,7 @@ import { deleteFleetServerDocs, deleteAgentDocs, cleanupAgentPolicies } from '.. import type { CreateAgentPolicyRequest } from '../../../common/types'; import { setUISettings } from '../../tasks/ui_settings'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; const createAgentDocs = (kibanaVersion: string) => [ createAgentDoc('agent-1', 'policy-1'), // this agent will have upgrade available @@ -68,7 +68,7 @@ function createAgentPolicy(body: CreateAgentPolicyRequest['body']) { cy.request({ method: 'POST', url: '/api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body, }); } diff --git a/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts b/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts index af4d91bd9986e..57149b435e433 100644 --- a/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/enrollment_token.cy.ts @@ -8,7 +8,7 @@ import { cleanupAgentPolicies } from '../tasks/cleanup'; import { ENROLLMENT_TOKENS } from '../screens/fleet'; -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; describe('Enrollment token page', () => { before(() => { @@ -22,7 +22,7 @@ describe('Enrollment token page', () => { monitoring_enabled: ['logs', 'metrics'], id: 'agent-policy-1', }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); diff --git a/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts b/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts index 7db31e15949ee..6ca1eb669da19 100644 --- a/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/fleet_agent_flyout.cy.ts @@ -11,7 +11,7 @@ import { createAgentDoc } from '../tasks/agents'; import { setFleetServerHost } from '../tasks/fleet_server'; import { FLEET, navigateTo } from '../tasks/navigation'; -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; const FLEET_SERVER_POLICY_ID = 'fleet-server-policy'; @@ -30,7 +30,7 @@ describe('Fleet add agent flyout', () => { cy.request({ method: 'POST', url: '/api/fleet/agent_policies', - headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body: { id: FLEET_SERVER_POLICY_ID, name: 'Fleet Server policy', diff --git a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts index 8992cd1b3f576..1ce6636198fe7 100644 --- a/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/integrations_real.cy.ts @@ -31,7 +31,7 @@ import { import { LOADING_SPINNER, CONFIRM_MODAL } from '../screens/navigation'; import { ADD_PACKAGE_POLICY_BTN } from '../screens/fleet'; import { cleanupAgentPolicies } from '../tasks/cleanup'; -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; function setupIntegrations() { cy.intercept( @@ -136,7 +136,7 @@ describe('Add Integration - Real API', () => { namespace: 'default', monitoring_enabled: ['logs', 'metrics'], }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); cy.request('/api/fleet/agent_policies').then((response: any) => { diff --git a/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts b/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts index 6b7f7a697e2f8..60c75327f06ad 100644 --- a/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/package_policy_pipelines_and_mappings_real.cy.ts @@ -17,7 +17,7 @@ const INPUT_TEST_PACKAGE = 'input_package-1.0.0'; const INTEGRATION_TEST_PACKAGE = 'logs_integration-1.0.0'; const INTEGRATION_TEST_PACKAGE_NO_DATASET = 'logs_int_no_dataset-1.0.0'; -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; describe('Input package create and edit package policy', () => { const agentPolicyId = 'test-input-package-policy'; @@ -47,7 +47,7 @@ describe('Input package create and edit package policy', () => { namespace: 'default', monitoring_enabled: [], }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); after(() => { @@ -55,7 +55,7 @@ describe('Input package create and edit package policy', () => { cy.request({ method: 'POST', url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body: JSON.stringify({ agentPolicyId, }), @@ -122,7 +122,7 @@ describe('Integration package with custom dataset create and edit package policy namespace: 'default', monitoring_enabled: [], }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); after(() => { @@ -130,7 +130,7 @@ describe('Integration package with custom dataset create and edit package policy cy.request({ method: 'POST', url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body: JSON.stringify({ agentPolicyId, }), @@ -186,7 +186,7 @@ describe('Integration package with fixed dataset create and edit package policy' namespace: 'default', monitoring_enabled: [], }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); after(() => { @@ -194,7 +194,7 @@ describe('Integration package with fixed dataset create and edit package policy' cy.request({ method: 'POST', url: `/api/fleet/agent_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body: JSON.stringify({ agentPolicyId, }), diff --git a/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts b/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts index c3e3e28710dc1..3832feefe10e1 100644 --- a/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts +++ b/x-pack/plugins/fleet/cypress/e2e/uninstall_token.cy.ts @@ -11,7 +11,7 @@ import { cleanupAgentPolicies } from '../tasks/cleanup'; import { UNINSTALL_TOKENS } from '../screens/fleet'; import type { GetUninstallTokenResponse } from '../../common/types/rest_spec/uninstall_token'; -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; describe('Uninstall token page', () => { before(() => { @@ -80,7 +80,7 @@ describe('Uninstall token page', () => { method: 'POST', url: '/api/fleet/agent_policies', body: { name: `Agent policy ${i}00`, namespace: 'default', id: `agent-policy-${i}00` }, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); } }; diff --git a/x-pack/plugins/fleet/cypress/plugins/index.ts b/x-pack/plugins/fleet/cypress/plugins/index.ts index c36577fd45a39..23f50d0e23197 100644 --- a/x-pack/plugins/fleet/cypress/plugins/index.ts +++ b/x-pack/plugins/fleet/cypress/plugins/index.ts @@ -12,7 +12,7 @@ import fs from 'fs'; import fetch from 'node-fetch'; import { createEsClientForTesting } from '@kbn/test'; -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; const plugin: Cypress.PluginConfig = (on, config) => { const client = createEsClientForTesting({ @@ -79,7 +79,7 @@ const plugin: Cypress.PluginConfig = (on, config) => { path: '/api/fleet/epm/packages', body: Buffer.from(zipContent, 'base64'), contentType: 'application/zip', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }, @@ -87,7 +87,7 @@ const plugin: Cypress.PluginConfig = (on, config) => { return kibanaFetch({ method: 'DELETE', path: `/api/fleet/epm/packages/${packageName}`, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }, }); diff --git a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts index c1b492fa132a8..8ca9a1cb32d25 100644 --- a/x-pack/plugins/fleet/cypress/tasks/cleanup.ts +++ b/x-pack/plugins/fleet/cypress/tasks/cleanup.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; export function cleanupAgentPolicies() { cy.request('/api/fleet/agent_policies').then((response: any) => { @@ -15,7 +15,7 @@ export function cleanupAgentPolicies() { method: 'POST', url: '/api/fleet/agent_policies/delete', body: { agentPolicyId: policy.id }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); }); @@ -29,7 +29,7 @@ export function unenrollAgent() { method: 'POST', url: `api/fleet/agents/${agent.id}/unenroll`, body: { revoke: true }, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); } @@ -44,7 +44,7 @@ export function cleanupDownloadSources() { cy.request({ method: 'DELETE', url: `/api/fleet/agent_download_sources/${ds.id}`, - headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'kibana', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); }); }); diff --git a/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts b/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts index 6be0cf2f0324d..4f9df31eeba60 100644 --- a/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts +++ b/x-pack/plugins/fleet/cypress/tasks/fleet_server.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; import { createAgentDoc } from './agents'; @@ -68,7 +68,7 @@ export function setFleetServerHost(host = 'https://fleetserver:8220') { cy.request({ method: 'POST', url: '/api/fleet/fleet_server_hosts', - headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'xx', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body: { name: 'Default host', host_urls: [host], diff --git a/x-pack/plugins/fleet/cypress/tasks/integrations.ts b/x-pack/plugins/fleet/cypress/tasks/integrations.ts index a40fb55da5311..1cbb68cd58bff 100644 --- a/x-pack/plugins/fleet/cypress/tasks/integrations.ts +++ b/x-pack/plugins/fleet/cypress/tasks/integrations.ts @@ -15,7 +15,7 @@ import { import { AGENT_POLICY_SYSTEM_MONITORING_CHECKBOX, EXISTING_HOSTS_TAB } from '../screens/fleet'; import { TOAST_CLOSE_BTN, CONFIRM_MODAL } from '../screens/navigation'; -import { OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; export const addIntegration = ({ useExistingPolicy } = { useExistingPolicy: false }) => { cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click(); @@ -56,7 +56,7 @@ export const deleteIntegrations = async () => { response.body.items.forEach((policy: any) => ids.push(policy.id)); cy.request({ url: `/api/fleet/package_policies/delete`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body: `{ "packagePolicyIds": ${JSON.stringify(ids)}, "force": true }`, method: 'POST', }); @@ -66,7 +66,7 @@ export const deleteIntegrations = async () => { export const installPackageWithVersion = (integration: string, version: string) => { cy.request({ url: `/api/fleet/epm/packages/${integration}/${version}`, - headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'kbn-xsrf': 'cypress', 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, body: '{ "force": true }', method: 'POST', }); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx index 58cd88438d6da..5a1ca420a6227 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx @@ -12,7 +12,7 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { AGENTS_PREFIX } from '../../../constants'; import { sendDeleteAgentPolicy, useStartServices, useConfig, sendRequest } from '../../../hooks'; -import { OLDEST_PUBLIC_VERSION } from '../../../../../../common/constants'; +import { API_VERSIONS } from '../../../../../../common/constants'; interface Props { children: (deleteAgentPolicy: DeleteAgentPolicy) => React.ReactElement; @@ -105,7 +105,7 @@ export const AgentPolicyDeleteProvider: React.FunctionComponent = ({ query: { kuery: `${AGENTS_PREFIX}.policy_id : ${agentPolicyToCheck}`, }, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); setAgentsCount(data?.total || 0); setIsLoadingAgentsCount(false); diff --git a/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx b/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx index a42cb9fb02f29..5e5a657e0d4b8 100644 --- a/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx +++ b/x-pack/plugins/fleet/public/components/package_policy_delete_provider.tsx @@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { useStartServices, sendRequest, sendDeletePackagePolicy, useConfig } from '../hooks'; -import { AGENT_API_ROUTES, AGENTS_PREFIX, OLDEST_PUBLIC_VERSION } from '../../common/constants'; +import { AGENT_API_ROUTES, AGENTS_PREFIX, API_VERSIONS } from '../../common/constants'; import type { AgentPolicy } from '../types'; interface Props { @@ -55,7 +55,7 @@ export const PackagePolicyDeleteProvider: React.FunctionComponent = ({ perPage: 1, kuery: `${AGENTS_PREFIX}.policy_id : ${agentPolicy.id}`, }, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); setAgentsCount(data?.total || 0); setIsLoadingAgentsCount(false); diff --git a/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts b/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts index f19e72629c088..ee0481bd373af 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/agent_policy.ts @@ -7,7 +7,7 @@ import { useQuery } from '@tanstack/react-query'; import { agentPolicyRouteService } from '../../services'; -import { OLDEST_PUBLIC_VERSION, OLDEST_INTERNAL_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { GetAgentPoliciesRequest, @@ -32,7 +32,7 @@ export const useGetAgentPolicies = (query?: GetAgentPoliciesRequest['query']) => path: agentPolicyRouteService.getListPath(), method: 'get', query, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -42,7 +42,7 @@ export const useGetAgentPoliciesQuery = (query?: GetAgentPoliciesRequest['query' path: agentPolicyRouteService.getListPath(), method: 'get', query, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }) ); }; @@ -52,7 +52,7 @@ export const sendGetAgentPolicies = (query?: GetAgentPoliciesRequest['query']) = path: agentPolicyRouteService.getListPath(), method: 'get', query, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -61,7 +61,7 @@ export const useGetOneAgentPolicy = (agentPolicyId: string | undefined) => { path: agentPolicyId ? agentPolicyRouteService.getInfoPath(agentPolicyId) : undefined, method: 'get', shouldSendRequest: !!agentPolicyId, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, } as SendConditionalRequestConfig); }; @@ -69,7 +69,7 @@ export const useGetOneAgentPolicyFull = (agentPolicyId: string) => { return useRequest({ path: agentPolicyRouteService.getInfoFullPath(agentPolicyId), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -81,7 +81,7 @@ export const sendGetOneAgentPolicyFull = ( path: agentPolicyRouteService.getInfoFullPath(agentPolicyId), method: 'get', query, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -89,7 +89,7 @@ export const sendGetOneAgentPolicy = (agentPolicyId: string) => { return sendRequest({ path: agentPolicyRouteService.getInfoPath(agentPolicyId), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -102,7 +102,7 @@ export const sendCreateAgentPolicy = ( method: 'post', body: JSON.stringify(body), query: withSysMonitoring ? { sys_monitoring: true } : {}, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -114,7 +114,7 @@ export const sendUpdateAgentPolicy = ( path: agentPolicyRouteService.getUpdatePath(agentPolicyId), method: 'put', body: JSON.stringify(body), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -134,7 +134,7 @@ export const sendDeleteAgentPolicy = (body: DeleteAgentPolicyRequest['body']) => path: agentPolicyRouteService.getDeletePath(), method: 'post', body: JSON.stringify(body), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -143,7 +143,7 @@ export const sendResetOnePreconfiguredAgentPolicy = (agentPolicyId: string) => { path: agentPolicyRouteService.getResetOnePreconfiguredAgentPolicyPath(agentPolicyId), method: 'post', body: JSON.stringify({}), - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, }); }; @@ -152,6 +152,6 @@ export const sendResetAllPreconfiguredAgentPolicies = () => { path: agentPolicyRouteService.getResetAllPreconfiguredAgentPolicyPath(), method: 'post', body: JSON.stringify({}), - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/agents.ts b/x-pack/plugins/fleet/public/hooks/use_request/agents.ts index 8d4e5c3f777a7..9b43a600b62b8 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/agents.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/agents.ts @@ -18,7 +18,7 @@ import type { UpdateAgentRequest, } from '../../../common/types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { agentRouteService } from '../../services'; @@ -64,7 +64,7 @@ export function useGetOneAgent( return useRequest({ path: agentRouteService.getInfoPath(agentId), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -73,13 +73,11 @@ export function useGetAgents(query: GetAgentsRequest['query'], options?: Request return useRequest({ method: 'get', path: agentRouteService.getListPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, ...options, }); } - -// ADD version on headers export function useGetAgentsQuery( query: GetAgentsRequest['query'], options: Partial<{ enabled: boolean }> = {} @@ -93,7 +91,7 @@ export function sendGetAgents(query: GetAgentsRequest['query'], options?: Reques return sendRequest({ method: 'get', path: agentRouteService.getListPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, ...options, }); @@ -103,7 +101,7 @@ export function useGetAgentStatus(query: GetAgentStatusRequest['query'], options return useRequest({ method: 'get', path: agentRouteService.getStatusPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, ...options, }); @@ -113,7 +111,7 @@ export function sendGetAgentIncomingData(query: GetAgentIncomingDataRequest['que method: 'get', path: agentRouteService.getIncomingDataPath(), query, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -125,7 +123,7 @@ export function sendGetAgentStatus( method: 'get', path: agentRouteService.getStatusPath(), query, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -135,7 +133,7 @@ export function sendGetAgentTags(query: GetAgentsRequest['query'], options?: Req method: 'get', path: agentRouteService.getListTagsPath(), query, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -149,7 +147,7 @@ export function sendPostAgentReassign( method: 'post', path: agentRouteService.getReassignPath(agentId), body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -162,7 +160,7 @@ export function sendPostBulkAgentReassign( method: 'post', path: agentRouteService.getBulkReassignPath(), body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -176,7 +174,7 @@ export function sendPostAgentUnenroll( path: agentRouteService.getUnenrollPath(agentId), method: 'post', body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -189,7 +187,7 @@ export function sendPostBulkAgentUnenroll( path: agentRouteService.getBulkUnenrollPath(), method: 'post', body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -203,7 +201,7 @@ export function sendPostAgentUpgrade( path: agentRouteService.getUpgradePath(agentId), method: 'post', body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -212,7 +210,7 @@ export function sendPostRequestDiagnostics(agentId: string, options?: RequestOpt return sendRequest({ path: agentRouteService.getRequestDiagnosticsPath(agentId), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -225,7 +223,7 @@ export function sendPostBulkRequestDiagnostics( path: agentRouteService.getBulkRequestDiagnosticsPath(), method: 'post', body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -242,7 +240,7 @@ export const useGetAgentUploads = (agentId: string, options?: RequestOptions) => return useRequest({ path: agentRouteService.getListAgentUploads(agentId), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); }; @@ -256,7 +254,7 @@ export function sendPostAgentAction( path: agentRouteService.getCreateActionPath(agentId), method: 'post', body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -269,7 +267,7 @@ export function sendPostBulkAgentUpgrade( path: agentRouteService.getBulkUpgradePath(), method: 'post', body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -278,7 +276,7 @@ export function sendGetActionStatus() { return sendRequest({ path: agentRouteService.getActionStatusPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -286,7 +284,7 @@ export function sendPostCancelAction(actionId: string) { return sendRequest({ path: agentRouteService.getCancelActionPath(actionId), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -294,7 +292,7 @@ export function sendPostRetrieveAgentsByActions(body: PostRetrieveAgentsByAction return sendRequest({ path: agentRouteService.getAgentsByActionsPath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } @@ -308,7 +306,7 @@ export function sendPutAgentTagsUpdate( method: 'put', path: agentRouteService.getUpdatePath(agentId), body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -321,7 +319,7 @@ export function sendPostBulkAgentTagsUpdate( method: 'post', path: agentRouteService.getBulkUpdateTagsPath(), body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -330,6 +328,6 @@ export function sendGetAgentsAvailableVersions() { return sendRequest({ method: 'get', path: agentRouteService.getAvailableVersionsPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/app.ts b/x-pack/plugins/fleet/public/hooks/use_request/app.ts index f2866c97284c6..321e296a1e584 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/app.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/app.ts @@ -9,7 +9,7 @@ import { useQuery } from '@tanstack/react-query'; import { appRoutesService } from '../../services'; import type { CheckPermissionsResponse, GenerateServiceTokenResponse } from '../../types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { sendRequest, sendRequestForRq, useRequest } from './use_request'; @@ -18,7 +18,7 @@ export const sendGetPermissionsCheck = (fleetServerSetup?: boolean) => { path: appRoutesService.getCheckPermissionsPath(), method: 'get', query: { fleetServerSetup }, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -26,7 +26,7 @@ export const sendGenerateServiceToken = () => { return sendRequest({ path: appRoutesService.getRegenerateServiceTokenPath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -37,7 +37,7 @@ export const usePermissionCheckQuery = () => { sendRequestForRq({ path: appRoutesService.getCheckPermissionsPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }) ); }; @@ -46,6 +46,6 @@ export const usePermissionCheck = () => { return useRequest({ path: appRoutesService.getCheckPermissionsPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts b/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts index 056ff36c50bef..7f136f628bafc 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/data_stream.ts @@ -7,7 +7,7 @@ import { dataStreamRouteService } from '../../services'; import type { GetDataStreamsResponse } from '../../types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { useRequest, sendRequest } from './use_request'; @@ -15,7 +15,7 @@ export const useGetDataStreams = () => { return useRequest({ path: dataStreamRouteService.getListPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts b/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts index 0e228b25bbf74..672fc6beddf09 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/download_source.ts @@ -12,7 +12,7 @@ import type { PutDownloadSourceRequest, } from '../../types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { useRequest, sendRequest } from './use_request'; @@ -20,7 +20,7 @@ export function useGetDownloadSources() { return useRequest({ method: 'get', path: downloadSourceRoutesService.getListPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -38,7 +38,7 @@ export function sendPutDownloadSource( return sendRequest({ method: 'put', path: downloadSourceRoutesService.getUpdatePath(downloadSourceId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } @@ -47,7 +47,7 @@ export function sendPostDownloadSource(body: PostDownloadSourceRequest['body']) return sendRequest({ method: 'post', path: downloadSourceRoutesService.getCreatePath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } @@ -56,6 +56,6 @@ export function sendDeleteDownloadSource(downloadSourceId: string) { return sendRequest({ method: 'delete', path: downloadSourceRoutesService.getDeletePath(downloadSourceId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts b/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts index c860a56161e5f..c63360a73474d 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/enrollment_api_keys.ts @@ -15,7 +15,7 @@ import type { PostEnrollmentAPIKeyResponse, } from '../../types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { useRequest, sendRequest, useConditionalRequest } from './use_request'; import type { UseRequestConfig, SendConditionalRequestConfig } from './use_request'; @@ -27,7 +27,7 @@ export function useGetOneEnrollmentAPIKey(keyId: string | undefined) { method: 'get', path: keyId ? enrollmentAPIKeyRouteService.getInfoPath(keyId) : undefined, shouldSendRequest: !!keyId, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, } as SendConditionalRequestConfig); } @@ -35,7 +35,7 @@ export function sendGetOneEnrollmentAPIKey(keyId: string, options?: RequestOptio return sendRequest({ method: 'get', path: enrollmentAPIKeyRouteService.getInfoPath(keyId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -44,7 +44,7 @@ export function sendDeleteOneEnrollmentAPIKey(keyId: string, options?: RequestOp return sendRequest({ method: 'delete', path: enrollmentAPIKeyRouteService.getDeletePath(keyId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, ...options, }); } @@ -56,7 +56,7 @@ export function sendGetEnrollmentAPIKeys( return sendRequest({ method: 'get', path: enrollmentAPIKeyRouteService.getListPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, ...options, }); @@ -69,7 +69,7 @@ export function useGetEnrollmentAPIKeys( return useRequest({ method: 'get', path: enrollmentAPIKeyRouteService.getListPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, ...options, }); @@ -79,7 +79,7 @@ export function sendCreateEnrollmentAPIKey(body: PostEnrollmentAPIKeyRequest['bo return sendRequest({ method: 'post', path: enrollmentAPIKeyRouteService.getCreatePath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/epm.ts b/x-pack/plugins/fleet/public/hooks/use_request/epm.ts index a0ebf37ba51fe..24a36f969247d 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/epm.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/epm.ts @@ -28,7 +28,7 @@ import type { GetVerificationKeyIdResponse, } from '../../types'; import type { FleetErrorResponse, GetStatsResponse } from '../../../common/types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { getCustomIntegrations } from '../../services/custom_integrations'; @@ -57,7 +57,7 @@ export function useGetCategoriesQuery(query: GetCategoriesRequest['query'] = {}) path: epmRouteService.getCategoriesPath(), method: 'get', query, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }) ); } @@ -66,7 +66,7 @@ export const sendGetCategories = (query: GetCategoriesRequest['query'] = {}) => return sendRequest({ path: epmRouteService.getCategoriesPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, }); }; @@ -75,7 +75,7 @@ export const useGetPackages = (query: GetPackagesRequest['query'] = {}) => { return useRequest({ path: epmRouteService.getListPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, }); }; @@ -85,7 +85,7 @@ export const useGetPackagesQuery = (query: GetPackagesRequest['query']) => { sendRequestForRq({ path: epmRouteService.getListPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, }) ); @@ -95,7 +95,7 @@ export const sendGetPackages = (query: GetPackagesRequest['query'] = {}) => { return sendRequest({ path: epmRouteService.getListPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, }); }; @@ -104,7 +104,7 @@ export const useGetLimitedPackages = () => { return useRequest({ path: epmRouteService.getListLimitedPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -135,7 +135,7 @@ export const useGetPackageInfoByKeyQuery = ( sendRequestForRq({ path: epmRouteService.getInfoPath(pkgName, pkgVersion), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query: { ...options, ...(ignoreUnverifiedQueryParam && { ignoreUnverified: ignoreUnverifiedQueryParam }), @@ -163,7 +163,7 @@ export const useGetPackageStats = (pkgName: string) => { return useRequest({ path: epmRouteService.getStatsPath(pkgName), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -174,7 +174,7 @@ export const useGetPackageVerificationKeyId = () => { sendRequestForRq({ path: epmRouteService.getVerificationKeyIdPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }) ); @@ -196,7 +196,7 @@ export const sendGetPackageInfoByKey = ( return sendRequest({ path: epmRouteService.getInfoPath(pkgName, pkgVersion), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query: options, }); }; @@ -205,7 +205,7 @@ export const useGetFileByPath = (filePath: string) => { return useRequest({ path: epmRouteService.getFilePath(filePath), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -214,7 +214,7 @@ export const useGetFileByPathQuery = (filePath: string) => { sendRequest({ path: epmRouteService.getFilePath(filePath), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }) ); }; @@ -223,7 +223,7 @@ export const sendGetFileByPath = (filePath: string) => { return sendRequest({ path: epmRouteService.getFilePath(filePath), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -232,7 +232,7 @@ export const sendInstallPackage = (pkgName: string, pkgVersion: string, force: b return sendRequest({ path: epmRouteService.getInstallPath(pkgName, pkgVersion), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); }; @@ -243,7 +243,7 @@ export const sendBulkInstallPackages = ( return sendRequest({ path: epmRouteService.getBulkInstallPath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: { packages, }, @@ -254,7 +254,7 @@ export const sendRemovePackage = (pkgName: string, pkgVersion: string, force: bo return sendRequest({ path: epmRouteService.getRemovePath(pkgName, pkgVersion), method: 'delete', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: { force, }, @@ -269,7 +269,7 @@ export const sendRequestReauthorizeTransforms = ( return sendRequest({ path: epmRouteService.getReauthorizeTransformsPath(pkgName, pkgVersion), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: { transforms }, }); }; @@ -286,7 +286,7 @@ export const useUpdatePackageMutation = () => { sendRequestForRq({ path: epmRouteService.getUpdatePath(pkgName, pkgVersion), method: 'put', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }) ); @@ -300,7 +300,7 @@ export const sendUpdatePackage = ( return sendRequest({ path: epmRouteService.getUpdatePath(pkgName, pkgVersion), method: 'put', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); }; @@ -309,7 +309,7 @@ export const sendGetBulkAssets = (body: GetBulkAssetsRequest['body']) => { return sendRequest({ path: epmRouteService.getBulkAssetsPath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts b/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts index bfb3084b0e67d..9cb09486980d3 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/fleet_proxies.ts @@ -6,7 +6,7 @@ */ import { fleetProxiesRoutesService } from '../../../common/services'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { GetFleetProxiesResponse, @@ -20,7 +20,7 @@ export function useGetFleetProxies() { return useRequest({ method: 'get', path: fleetProxiesRoutesService.getListPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -28,7 +28,7 @@ export function sendDeleteFleetProxy(proxyId: string) { return sendRequest({ method: 'delete', path: fleetProxiesRoutesService.getDeletePath(proxyId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -37,7 +37,7 @@ export function sendPostFleetProxy(body: PostFleetProxiesRequest['body']) { method: 'post', path: fleetProxiesRoutesService.getCreatePath(), body, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -45,7 +45,7 @@ export function sendPutFleetProxy(proxyId: string, body: PutFleetProxiesRequest[ return sendRequest({ method: 'put', path: fleetProxiesRoutesService.getUpdatePath(proxyId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts b/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts index 5914d40afbe23..db1968332d6b4 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/fleet_server_hosts.ts @@ -7,7 +7,7 @@ import { fleetServerHostsRoutesService } from '../../../common/services'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { GetFleetServerHostsResponse, @@ -22,7 +22,7 @@ export function useGetFleetServerHosts() { return useRequest({ method: 'get', path: fleetServerHostsRoutesService.getListPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -30,7 +30,7 @@ export function sendDeleteFleetServerHost(itemId: string) { return sendRequest({ method: 'delete', path: fleetServerHostsRoutesService.getDeletePath(itemId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -38,7 +38,7 @@ export function sendPutFleetServerHost(itemId: string, body: PutFleetServerHosts return sendRequest({ method: 'put', path: fleetServerHostsRoutesService.getUpdatePath(itemId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } @@ -47,7 +47,7 @@ export function sendPostFleetServerHost(body: PostFleetServerHostsRequest['body' return sendRequest({ method: 'post', path: fleetServerHostsRoutesService.getCreatePath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts b/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts index 0faf604d3c361..e9cfe36c66062 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/health_check.ts @@ -7,7 +7,7 @@ import type { PostHealthCheckRequest, PostHealthCheckResponse } from '../../types'; import { appRoutesService } from '../../services'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { sendRequest } from './use_request'; @@ -15,7 +15,7 @@ export function sendPostHealthCheck(body: PostHealthCheckRequest['body']) { return sendRequest({ method: 'post', path: appRoutesService.postHealthCheckPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts b/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts index 33518f8995aac..1f725ea3e8c5a 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/k8s.ts @@ -8,7 +8,7 @@ import { agentPolicyRouteService } from '../../services'; import type { GetFullAgentManifestResponse } from '../../../common/types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { sendRequest } from './use_request'; @@ -16,7 +16,7 @@ export const sendGetK8sManifest = (query: { fleetServer?: string; enrolToken?: s return sendRequest({ path: agentPolicyRouteService.getK8sInfoPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, }); }; diff --git a/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts b/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts index 42b3e50cd2f45..ccd6f2364250c 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/outputs.ts @@ -13,7 +13,7 @@ import type { PostLogstashApiKeyResponse, } from '../../types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { sendRequest, useRequest } from './use_request'; @@ -35,7 +35,7 @@ export function sendPutOutput(outputId: string, body: PutOutputRequest['body']) return sendRequest({ method: 'put', path: outputRoutesService.getUpdatePath(outputId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } @@ -44,7 +44,7 @@ export function sendPostLogstashApiKeys() { return sendRequest({ method: 'post', path: outputRoutesService.getCreateLogstashApiKeyPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -52,7 +52,7 @@ export function sendPostOutput(body: PostOutputRequest['body']) { return sendRequest({ method: 'post', path: outputRoutesService.getCreatePath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } @@ -61,6 +61,6 @@ export function sendDeleteOutput(outputId: string) { return sendRequest({ method: 'delete', path: outputRoutesService.getDeletePath(outputId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts b/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts index 04ab5de96fab1..fb23f740ed0bc 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/package_policy.ts @@ -24,7 +24,7 @@ import type { UpgradePackagePolicyResponse, } from '../../../common/types/rest_spec'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { RequestError } from './use_request'; import { sendRequest, sendRequestForRq, useRequest } from './use_request'; @@ -33,7 +33,7 @@ export const sendCreatePackagePolicy = (body: CreatePackagePolicyRequest['body'] return sendRequest({ path: packagePolicyRouteService.getCreatePath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: JSON.stringify(body), }); }; @@ -45,7 +45,7 @@ export const sendUpdatePackagePolicy = ( return sendRequest({ path: packagePolicyRouteService.getUpdatePath(packagePolicyId), method: 'put', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: JSON.stringify(body), }); }; @@ -54,7 +54,7 @@ export const sendDeletePackagePolicy = (body: DeletePackagePoliciesRequest['body return sendRequest({ path: packagePolicyRouteService.getDeletePath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: JSON.stringify(body), }); }; @@ -63,7 +63,7 @@ export function useGetPackagePoliciesQuery(query: GetPackagePoliciesRequest['que return useQuery(['packagePolicies'], () => sendRequestForRq({ method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, path: packagePolicyRouteService.getListPath(), query, }) @@ -73,7 +73,7 @@ export function useGetPackagePoliciesQuery(query: GetPackagePoliciesRequest['que export function useGetPackagePolicies(query: GetPackagePoliciesRequest['query']) { return useRequest({ method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, path: packagePolicyRouteService.getListPath(), query, }); @@ -82,7 +82,7 @@ export function useGetPackagePolicies(query: GetPackagePoliciesRequest['query']) export const sendGetPackagePolicies = (query: GetPackagePoliciesRequest['query']) => { return sendRequest({ method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, path: packagePolicyRouteService.getListPath(), query, }); @@ -94,7 +94,7 @@ export const useGetOnePackagePolicyQuery = (packagePolicyId: string) => { () => sendRequestForRq({ method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, path: packagePolicyRouteService.getInfoPath(packagePolicyId), }) ); @@ -104,7 +104,7 @@ export const useGetOnePackagePolicy = (packagePolicyId: string) => { return useRequest({ path: packagePolicyRouteService.getInfoPath(packagePolicyId), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -112,7 +112,7 @@ export const sendGetOnePackagePolicy = (packagePolicyId: string) => { return sendRequest({ path: packagePolicyRouteService.getInfoPath(packagePolicyId), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -135,7 +135,7 @@ export function useUpgradePackagePolicyDryRunQuery( sendRequestForRq({ path: packagePolicyRouteService.getDryRunPath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: JSON.stringify(body), }), { enabled } @@ -157,7 +157,7 @@ export function sendUpgradePackagePolicyDryRun( return sendRequest({ path: packagePolicyRouteService.getDryRunPath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: JSON.stringify(body), }); } @@ -171,7 +171,7 @@ export function useUpgradePackagePoliciesMutation() { sendRequestForRq({ path: packagePolicyRouteService.getUpgradePath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: JSON.stringify({ packagePolicyIds, }), @@ -183,7 +183,7 @@ export function sendUpgradePackagePolicy(packagePolicyIds: string[]) { return sendRequest({ path: packagePolicyRouteService.getUpgradePath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: JSON.stringify({ packagePolicyIds, }), @@ -194,6 +194,6 @@ export function sendGetOrphanedIntegrationPolicies() { return sendRequest({ path: packagePolicyRouteService.getOrphanedIntegrationPoliciesPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/settings.ts b/x-pack/plugins/fleet/public/hooks/use_request/settings.ts index c2484792bfda6..d074644a9d26a 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/settings.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/settings.ts @@ -10,7 +10,7 @@ import { useQuery } from '@tanstack/react-query'; import { settingsRoutesService } from '../../services'; import type { PutSettingsResponse, PutSettingsRequest, GetSettingsResponse } from '../../types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { RequestError } from './use_request'; import { sendRequest, sendRequestForRq, useRequest } from './use_request'; @@ -20,7 +20,7 @@ export function useGetSettingsQuery() { sendRequestForRq({ method: 'get', path: settingsRoutesService.getInfoPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }) ); } @@ -29,7 +29,7 @@ export function useGetSettings() { return useRequest({ method: 'get', path: settingsRoutesService.getInfoPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -37,7 +37,7 @@ export function sendGetSettings() { return sendRequest({ method: 'get', path: settingsRoutesService.getInfoPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); } @@ -45,7 +45,7 @@ export function sendPutSettings(body: PutSettingsRequest['body']) { return sendRequest({ method: 'put', path: settingsRoutesService.getUpdatePath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body, }); } diff --git a/x-pack/plugins/fleet/public/hooks/use_request/setup.ts b/x-pack/plugins/fleet/public/hooks/use_request/setup.ts index 4708f517578bd..59e5692df966f 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/setup.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/setup.ts @@ -7,7 +7,7 @@ import { setupRouteService, fleetSetupRouteService } from '../../services'; import type { GetFleetStatusResponse } from '../../types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { sendRequest } from './use_request'; @@ -15,7 +15,7 @@ export const sendSetup = () => { return sendRequest({ path: setupRouteService.getSetupPath(), method: 'post', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -23,7 +23,7 @@ export const sendGetFleetStatus = () => { return sendRequest({ path: fleetSetupRouteService.getFleetSetupPath(), method: 'get', - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); }; @@ -31,7 +31,7 @@ export const sendPostFleetSetup = ({ forceRecreate }: { forceRecreate: boolean } return sendRequest({ method: 'post', path: fleetSetupRouteService.postFleetSetupPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, body: { forceRecreate, }, diff --git a/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts b/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts index 15d238b1f675c..5ba60daea0cc1 100644 --- a/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts +++ b/x-pack/plugins/fleet/public/hooks/use_request/uninstall_tokens.ts @@ -9,7 +9,7 @@ import { useQuery } from '@tanstack/react-query'; import { uninstallTokensRouteService } from '../../../common/services'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { GetUninstallTokensMetadataRequest, @@ -25,7 +25,7 @@ export const useGetUninstallTokens = (query: GetUninstallTokensMetadataRequest[' sendRequestForRq({ method: 'get', path: uninstallTokensRouteService.getListPath(), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, query, }) ); @@ -37,7 +37,7 @@ export const useGetUninstallToken = (uninstallTokenId: string) => sendRequestForRq({ method: 'get', path: uninstallTokensRouteService.getInfoPath(uninstallTokenId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }) ); @@ -45,5 +45,5 @@ export const sendGetUninstallToken = (uninstallTokenId: string) => sendRequest({ method: 'get', path: uninstallTokensRouteService.getInfoPath(uninstallTokenId), - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }); diff --git a/x-pack/plugins/fleet/public/plugin.ts b/x-pack/plugins/fleet/public/plugin.ts index b12d4de790b0c..eb087b257bc1e 100644 --- a/x-pack/plugins/fleet/public/plugin.ts +++ b/x-pack/plugins/fleet/public/plugin.ts @@ -16,10 +16,7 @@ import type { import { i18n } from '@kbn/i18n'; import type { NavigationPublicPluginStart } from '@kbn/navigation-plugin/public'; -import { - ELASTIC_HTTP_VERSION_HEADER, - X_ELASTIC_INTERNAL_ORIGIN_REQUEST, -} from '@kbn/core-http-common'; +import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; import type { CustomIntegrationsStart, @@ -64,7 +61,7 @@ import type { ExperimentalFeatures } from '../common/experimental_features'; import type { FleetConfigType } from '../common/types'; -import { OLDEST_PUBLIC_VERSION } from '../common/constants'; +import { API_VERSIONS } from '../common/constants'; import { CUSTOM_LOGS_INTEGRATION_NAME, INTEGRATIONS_BASE_PATH } from './constants'; import { licenseService } from './hooks'; @@ -295,10 +292,9 @@ export class FleetPlugin implements Plugin core.http.fetch(appRoutesService.getCheckPermissionsPath(), { headers: { - [ELASTIC_HTTP_VERSION_HEADER]: OLDEST_PUBLIC_VERSION, - [X_ELASTIC_INTERNAL_ORIGIN_REQUEST]: 'kibana', + [ELASTIC_HTTP_VERSION_HEADER]: API_VERSIONS.public.v1, }, - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, }) ); diff --git a/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts b/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts index d298349eb1722..206d30cabbb79 100644 --- a/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts +++ b/x-pack/plugins/fleet/scripts/create_agents/create_agents.ts @@ -34,7 +34,7 @@ const printUsage = () => const DEFAULT_KIBANA_URL = 'http://localhost:5601'; const DEFAULT_KIBANA_USERNAME = 'elastic'; const DEFAULT_KIBANA_PASSWORD = 'changeme'; -const OLDEST_PUBLIC_VERSION = '2023-10-31'; +const PUBLIC_VERSION_V1 = '2023-10-31'; const DEFAULT_UNENROLL_TIMEOUT = 300; // 5 minutes const ES_URL = 'http://localhost:9200'; @@ -302,7 +302,7 @@ async function createAgentPolicy(id: string, name: string) { 'kbn-xsrf': 'kibana', 'x-elastic-product-origin': 'fleet', // Note: version can change in the future - 'Elastic-Api-Version': OLDEST_PUBLIC_VERSION, + 'Elastic-Api-Version': PUBLIC_VERSION_V1, }, }); const data = await res.json(); diff --git a/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts b/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts index 97deff589af4f..e8950be1a57b8 100644 --- a/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts +++ b/x-pack/plugins/fleet/scripts/get_all_packages/get_all_packages.ts @@ -19,7 +19,7 @@ const KIBANA_URL = 'http://localhost:5601'; const KIBANA_USERNAME = 'elastic'; const KIBANA_PASSWORD = 'changeme'; const KIBANA_VERSION = kibanaPackageJson.version; -const OLDEST_PUBLIC_VERSION = '2023-10-31'; +const PUBLIC_VERSION_V1 = '2023-10-31'; const { base = '', prerelease = false, batchSize = 1 } = yargs(process.argv).argv; @@ -52,7 +52,7 @@ async function getPackage(name: string, version: string, full: boolean = false) Authorization: 'Basic ' + Buffer.from(`${KIBANA_USERNAME}:${KIBANA_PASSWORD}`).toString('base64'), // Note: version can change in the future - 'Elastic-Api-Version': OLDEST_PUBLIC_VERSION, + 'Elastic-Api-Version': PUBLIC_VERSION_V1, }, method: 'GET', } diff --git a/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts b/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts index 652ad1413bb17..afd874264a7f4 100644 --- a/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts +++ b/x-pack/plugins/fleet/scripts/install_all_packages/install_all_packages.ts @@ -15,7 +15,7 @@ const DEFAULT_KIBANA_URL = 'http://localhost:5601'; const DEFAULT_KIBANA_USERNAME = 'elastic'; const DEFAULT_KIBANA_PASSWORD = 'changeme'; const KIBANA_VERSION = kibanaPackageJson.version; -const OLDEST_PUBLIC_VERSION = '2023-10-31'; +const PUBLIC_VERSION_V1 = '2023-10-31'; const logger = new ToolingLog({ level: 'info', @@ -61,7 +61,7 @@ async function installPackage(name: string, version: string) { 'kbn-xsrf': 'xyz', Authorization, // Note: version can change in the future - 'Elastic-Api-Version': OLDEST_PUBLIC_VERSION, + 'Elastic-Api-Version': PUBLIC_VERSION_V1, }, body: JSON.stringify({ force: true }), method: 'POST', @@ -81,7 +81,7 @@ async function deletePackage(name: string, version: string) { 'kbn-xsrf': 'xyz', Authorization, // Note: version can change in the future - 'Elastic-Api-Version': OLDEST_PUBLIC_VERSION, + 'Elastic-Api-Version': PUBLIC_VERSION_V1, }, method: 'DELETE', }); diff --git a/x-pack/plugins/fleet/server/integration_tests/reset_preconfiguration.test.ts b/x-pack/plugins/fleet/server/integration_tests/reset_preconfiguration.test.ts index 2eb39dc1d922c..97a5af5f8b6d5 100644 --- a/x-pack/plugins/fleet/server/integration_tests/reset_preconfiguration.test.ts +++ b/x-pack/plugins/fleet/server/integration_tests/reset_preconfiguration.test.ts @@ -16,7 +16,7 @@ import { import type { AgentPolicySOAttributes } from '../types'; import { PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE } from '../../common'; -import { OLDEST_INTERNAL_VERSION } from '../../common/constants'; +import { API_VERSIONS } from '../../common/constants'; import { useDockerRegistry, waitForFleetSetup, getSupertestWithAdminUser } from './helpers'; @@ -187,7 +187,7 @@ describe('Fleet preconfiguration reset', () => { ); await resetAPI .set('kbn-sxrf', 'xx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .expect(200) .send(); @@ -233,7 +233,7 @@ describe('Fleet preconfiguration reset', () => { ); await resetAPI .set('kbn-sxrf', 'xx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .expect(200) .send(); @@ -271,7 +271,7 @@ describe('Fleet preconfiguration reset', () => { ); await resetAPI .set('kbn-sxrf', 'xx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .expect(200) .send(); @@ -307,7 +307,7 @@ describe('Fleet preconfiguration reset', () => { ); await resetAPI .set('kbn-sxrf', 'xx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .expect(200) .send(); diff --git a/x-pack/plugins/fleet/server/routes/agent/index.ts b/x-pack/plugins/fleet/server/routes/agent/index.ts index a9cea420ccddd..0d261fc24a16e 100644 --- a/x-pack/plugins/fleet/server/routes/agent/index.ts +++ b/x-pack/plugins/fleet/server/routes/agent/index.ts @@ -6,11 +6,7 @@ */ import type { FleetAuthz } from '../../../common'; -import { - OLDEST_PUBLIC_VERSION, - OLDEST_INTERNAL_VERSION, - INTERNAL_API_ACCESS, -} from '../../../common/constants'; +import { API_VERSIONS, INTERNAL_API_ACCESS } from '../../../common/constants'; import { getRouteRequiredAuthz, type FleetAuthzRouter } from '../../services/security'; @@ -86,7 +82,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOneAgentRequestSchema }, }, getAgentHandler @@ -102,7 +98,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: UpdateAgentRequestSchema }, }, updateAgentHandler @@ -118,7 +114,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostBulkUpdateAgentTagsRequestSchema }, }, bulkUpdateAgentTagsHandler @@ -134,7 +130,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: DeleteAgentRequestSchema }, }, deleteAgentHandler @@ -151,7 +147,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetAgentsRequestSchema }, }, getAgentsHandler @@ -167,7 +163,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetTagsRequestSchema }, }, getAgentTagsHandler @@ -183,7 +179,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostNewAgentActionRequestSchema }, }, postNewAgentActionHandlerBuilder({ @@ -203,7 +199,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostCancelActionRequestSchema }, }, postCancelActionHandlerBuilder({ @@ -224,7 +220,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostRetrieveAgentsByActionsRequestSchema }, }, postRetrieveAgentsByActionsHandler @@ -239,7 +235,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostAgentUnenrollRequestSchema }, }, postAgentUnenrollHandler @@ -255,7 +251,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PutAgentReassignRequestSchemaDeprecated }, }, putAgentsReassignHandlerDeprecated @@ -270,7 +266,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostAgentReassignRequestSchema }, }, postAgentsReassignHandler @@ -285,7 +281,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostRequestDiagnosticsActionRequestSchema }, }, requestDiagnosticsHandler @@ -300,7 +296,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostBulkRequestDiagnosticsActionRequestSchema }, }, bulkRequestDiagnosticsHandler @@ -315,7 +311,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: ListAgentUploadsRequestSchema }, }, getAgentUploadsHandler @@ -330,7 +326,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetAgentUploadFileRequestSchema }, }, getAgentUploadFileHandler @@ -348,7 +344,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetAgentStatusRequestSchema }, }, getAgentStatusForAgentPolicyHandler @@ -363,7 +359,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: { request: GetAgentStatusRequestSchema }, }, getAgentStatusForAgentPolicyHandler @@ -378,7 +374,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetAgentDataRequestSchema }, }, getAgentDataHandler @@ -394,7 +390,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostAgentUpgradeRequestSchema }, }, postAgentUpgradeHandler @@ -409,7 +405,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostBulkAgentUpgradeRequestSchema }, }, postBulkAgentsUpgradeHandler @@ -426,7 +422,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetActionStatusRequestSchema }, }, getActionStatusHandler @@ -442,7 +438,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostBulkAgentReassignRequestSchema }, }, postBulkAgentsReassignHandler @@ -458,7 +454,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostBulkAgentUnenrollRequestSchema }, }, postBulkAgentsUnenrollHandler @@ -474,7 +470,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: false, }, getAvailableVersionsHandler diff --git a/x-pack/plugins/fleet/server/routes/agent_policy/index.ts b/x-pack/plugins/fleet/server/routes/agent_policy/index.ts index 7ba9207672fcd..7ca3409f72b88 100644 --- a/x-pack/plugins/fleet/server/routes/agent_policy/index.ts +++ b/x-pack/plugins/fleet/server/routes/agent_policy/index.ts @@ -7,7 +7,7 @@ import type { FleetAuthzRouter } from '../../services/security'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { AGENT_POLICY_API_ROUTES } from '../../constants'; import { @@ -49,7 +49,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetAgentPoliciesRequestSchema }, }, getAgentPoliciesHandler @@ -65,7 +65,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: BulkGetAgentPoliciesRequestSchema }, }, bulkGetAgentPoliciesHandler @@ -81,7 +81,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOneAgentPolicyRequestSchema }, }, getOneAgentPolicyHandler @@ -97,7 +97,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: CreateAgentPolicyRequestSchema }, }, createAgentPolicyHandler @@ -113,7 +113,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: UpdateAgentPolicyRequestSchema }, }, updateAgentPolicyHandler @@ -129,7 +129,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: CopyAgentPolicyRequestSchema }, }, copyAgentPolicyHandler @@ -145,7 +145,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: DeleteAgentPolicyRequestSchema }, }, deleteAgentPoliciesHandler @@ -161,7 +161,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetFullAgentPolicyRequestSchema }, }, getFullAgentPolicy @@ -177,7 +177,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetFullAgentPolicyRequestSchema }, }, downloadFullAgentPolicy @@ -193,7 +193,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetK8sManifestRequestSchema }, }, getK8sManifest @@ -209,7 +209,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetK8sManifestRequestSchema }, }, downloadK8sManifest diff --git a/x-pack/plugins/fleet/server/routes/app/index.ts b/x-pack/plugins/fleet/server/routes/app/index.ts index 56f50aa2b1dfe..cb7b5f284962d 100644 --- a/x-pack/plugins/fleet/server/routes/app/index.ts +++ b/x-pack/plugins/fleet/server/routes/app/index.ts @@ -11,11 +11,7 @@ import type { TypeOf } from '@kbn/config-schema'; import type { FleetAuthzRouter } from '../../services/security'; import { APP_API_ROUTES } from '../../constants'; -import { - OLDEST_PUBLIC_VERSION, - OLDEST_INTERNAL_VERSION, - INTERNAL_API_ACCESS, -} from '../../../common/constants'; +import { API_VERSIONS, INTERNAL_API_ACCESS } from '../../../common/constants'; import { appContextService } from '../../services'; import type { CheckPermissionsResponse, GenerateServiceTokenResponse } from '../../../common/types'; @@ -99,7 +95,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: CheckPermissionsRequestSchema }, }, getCheckPermissionsHandler @@ -114,7 +110,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: {}, }, @@ -131,7 +127,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: {}, }, generateServiceTokenHandler diff --git a/x-pack/plugins/fleet/server/routes/data_streams/index.ts b/x-pack/plugins/fleet/server/routes/data_streams/index.ts index 8e68601f8b033..cb2af8be110f8 100644 --- a/x-pack/plugins/fleet/server/routes/data_streams/index.ts +++ b/x-pack/plugins/fleet/server/routes/data_streams/index.ts @@ -7,7 +7,7 @@ import type { FleetAuthzRouter } from '../../services/security'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { DATA_STREAM_API_ROUTES } from '../../constants'; @@ -24,7 +24,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: false, }, getListHandler diff --git a/x-pack/plugins/fleet/server/routes/download_source/index.tsx b/x-pack/plugins/fleet/server/routes/download_source/index.tsx index 9616ab13556e4..a307d5a3296da 100644 --- a/x-pack/plugins/fleet/server/routes/download_source/index.tsx +++ b/x-pack/plugins/fleet/server/routes/download_source/index.tsx @@ -7,7 +7,7 @@ import type { FleetAuthzRouter } from '../../services/security'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { DOWNLOAD_SOURCE_API_ROUTES } from '../../constants'; import { @@ -36,7 +36,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: getDownloadSourcesRequestSchema }, }, getDownloadSourcesHandler @@ -51,7 +51,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOneDownloadSourcesRequestSchema }, }, getOneDownloadSourcesHandler @@ -66,7 +66,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PutDownloadSourcesRequestSchema }, }, putDownloadSourcesHandler @@ -81,7 +81,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostDownloadSourcesRequestSchema }, }, postDownloadSourcesHandler @@ -96,7 +96,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: DeleteDownloadSourcesRequestSchema }, }, deleteDownloadSourcesHandler diff --git a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts index feacb977c71c1..222e5752abe49 100644 --- a/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts +++ b/x-pack/plugins/fleet/server/routes/enrollment_api_key/index.ts @@ -8,11 +8,7 @@ import type { FleetAuthzRouter } from '../../services/security'; import { ENROLLMENT_API_KEY_ROUTES } from '../../constants'; -import { - OLDEST_PUBLIC_VERSION, - OLDEST_INTERNAL_VERSION, - INTERNAL_API_ACCESS, -} from '../../../common/constants'; +import { API_VERSIONS, INTERNAL_API_ACCESS } from '../../../common/constants'; import { GetEnrollmentAPIKeysRequestSchema, @@ -38,7 +34,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOneEnrollmentAPIKeyRequestSchema }, }, getOneEnrollmentApiKeyHandler @@ -53,7 +49,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: DeleteEnrollmentAPIKeyRequestSchema }, }, deleteEnrollmentApiKeyHandler @@ -68,7 +64,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetEnrollmentAPIKeysRequestSchema }, }, getEnrollmentApiKeysHandler @@ -83,7 +79,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostEnrollmentAPIKeyRequestSchema }, }, postEnrollmentApiKeyHandler @@ -99,7 +95,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: { request: GetOneEnrollmentAPIKeyRequestSchema }, }, getOneEnrollmentApiKeyHandler @@ -115,7 +111,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: { request: DeleteEnrollmentAPIKeyRequestSchema }, }, deleteEnrollmentApiKeyHandler @@ -131,7 +127,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: { request: GetEnrollmentAPIKeysRequestSchema }, }, getEnrollmentApiKeysHandler @@ -147,7 +143,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: { request: PostEnrollmentAPIKeyRequestSchema }, }, postEnrollmentApiKeyHandler diff --git a/x-pack/plugins/fleet/server/routes/epm/index.ts b/x-pack/plugins/fleet/server/routes/epm/index.ts index 4dbe6119718f1..5af7d4607f2f8 100644 --- a/x-pack/plugins/fleet/server/routes/epm/index.ts +++ b/x-pack/plugins/fleet/server/routes/epm/index.ts @@ -7,11 +7,7 @@ import type { IKibanaResponse } from '@kbn/core/server'; -import { - OLDEST_PUBLIC_VERSION, - OLDEST_INTERNAL_VERSION, - INTERNAL_API_ACCESS, -} from '../../../common/constants'; +import { API_VERSIONS, INTERNAL_API_ACCESS } from '../../../common/constants'; import type { FleetAuthz } from '../../../common'; @@ -91,7 +87,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetCategoriesRequestSchema }, }, getCategoriesHandler @@ -104,7 +100,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetPackagesRequestSchema }, }, getListHandler @@ -117,7 +113,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetInstalledPackagesRequestSchema }, }, getInstalledListHandler @@ -130,7 +126,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: false, }, getLimitedListHandler @@ -143,7 +139,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetStatsRequestSchema }, }, getStatsHandler @@ -156,7 +152,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetFileRequestSchema }, }, getFileHandler @@ -171,7 +167,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetInfoRequestSchema }, }, getInfoHandler @@ -186,7 +182,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: UpdatePackageRequestSchema }, }, updatePackageHandler @@ -199,7 +195,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: InstallPackageFromRegistryRequestSchema }, }, installPackageFromRegistryHandler @@ -214,7 +210,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: BulkInstallPackagesFromRegistryRequestSchema }, }, bulkInstallPackagesFromRegistryHandler @@ -237,7 +233,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: InstallPackageByUploadRequestSchema }, }, installPackageByUploadHandler @@ -250,7 +246,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: CreateCustomIntegrationRequestSchema }, }, createCustomIntegrationHandler @@ -265,7 +261,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: DeletePackageRequestSchema }, }, @@ -279,7 +275,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: false, }, getVerificationKeyIdHandler @@ -292,7 +288,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetDataStreamsRequestSchema }, }, getDataStreamsHandler @@ -305,7 +301,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetBulkAssetsRequestSchema }, }, getBulkAssetsHandler @@ -325,7 +321,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetInfoRequestSchemaDeprecated }, }, async (context, request, response) => { @@ -354,7 +350,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: { request: UpdatePackageRequestSchemaDeprecated }, }, async (context, request, response) => { @@ -379,7 +375,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: { request: InstallPackageFromRegistryRequestSchemaDeprecated }, }, async (context, request, response) => { @@ -408,7 +404,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: { request: DeletePackageRequestSchemaDeprecated }, }, async (context, request, response) => { @@ -445,7 +441,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: ReauthorizeTransformRequestSchema }, }, reauthorizeTransformsHandler diff --git a/x-pack/plugins/fleet/server/routes/fleet_proxies/index.ts b/x-pack/plugins/fleet/server/routes/fleet_proxies/index.ts index c23700a810bee..5cd35e027275a 100644 --- a/x-pack/plugins/fleet/server/routes/fleet_proxies/index.ts +++ b/x-pack/plugins/fleet/server/routes/fleet_proxies/index.ts @@ -5,7 +5,7 @@ * 2.0. */ import type { FleetAuthzRouter } from '../../services/security'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { FLEET_PROXY_API_ROUTES } from '../../../common/constants'; import { @@ -32,7 +32,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: false, }, getAllFleetProxyHandler @@ -47,7 +47,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostFleetProxyRequestSchema }, }, postFleetProxyHandler @@ -62,7 +62,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PutFleetProxyRequestSchema }, }, putFleetProxyHandler @@ -77,7 +77,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOneFleetProxyRequestSchema }, }, getFleetProxyHandler @@ -92,7 +92,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOneFleetProxyRequestSchema }, }, deleteFleetProxyHandler diff --git a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/index.ts b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/index.ts index 0519183db7374..5dddc693206b0 100644 --- a/x-pack/plugins/fleet/server/routes/fleet_server_hosts/index.ts +++ b/x-pack/plugins/fleet/server/routes/fleet_server_hosts/index.ts @@ -7,7 +7,7 @@ import type { FleetAuthzRouter } from '../../services/security'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { FLEET_SERVER_HOST_API_ROUTES } from '../../../common/constants'; import { @@ -35,7 +35,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetAllFleetServerHostRequestSchema }, }, getAllFleetServerHostsHandler @@ -49,7 +49,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostFleetServerHostRequestSchema }, }, postFleetServerHost @@ -63,7 +63,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOneFleetServerHostRequestSchema }, }, getFleetServerHostHandler @@ -77,7 +77,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOneFleetServerHostRequestSchema }, }, deleteFleetServerHostHandler @@ -91,7 +91,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PutFleetServerHostRequestSchema }, }, putFleetServerHostHandler diff --git a/x-pack/plugins/fleet/server/routes/health_check/index.ts b/x-pack/plugins/fleet/server/routes/health_check/index.ts index fa70a1636c8cc..44f26e2a66167 100644 --- a/x-pack/plugins/fleet/server/routes/health_check/index.ts +++ b/x-pack/plugins/fleet/server/routes/health_check/index.ts @@ -9,7 +9,7 @@ import https from 'https'; import type { TypeOf } from '@kbn/config-schema'; import fetch from 'node-fetch'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { FleetAuthzRouter } from '../../services/security'; import { APP_API_ROUTES } from '../../constants'; @@ -28,7 +28,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostHealthCheckRequestSchema }, }, postHealthCheckHandler diff --git a/x-pack/plugins/fleet/server/routes/message_signing_service/index.ts b/x-pack/plugins/fleet/server/routes/message_signing_service/index.ts index e79a3c811443c..c2d7f125bd082 100644 --- a/x-pack/plugins/fleet/server/routes/message_signing_service/index.ts +++ b/x-pack/plugins/fleet/server/routes/message_signing_service/index.ts @@ -6,7 +6,7 @@ */ import type { FleetAuthzRouter } from '../../services/security'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { MESSAGE_SIGNING_SERVICE_API_ROUTES } from '../../constants'; import { RotateKeyPairSchema } from '../../types'; @@ -23,7 +23,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: RotateKeyPairSchema }, }, rotateKeyPairHandler diff --git a/x-pack/plugins/fleet/server/routes/output/index.ts b/x-pack/plugins/fleet/server/routes/output/index.ts index f8aa49af8c2bd..3b769118da5a3 100644 --- a/x-pack/plugins/fleet/server/routes/output/index.ts +++ b/x-pack/plugins/fleet/server/routes/output/index.ts @@ -7,7 +7,7 @@ import type { FleetAuthzRouter } from '../../services/security'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { OUTPUT_API_ROUTES } from '../../constants'; import { @@ -37,7 +37,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOutputsRequestSchema }, }, getOutputsHandler @@ -51,7 +51,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOneOutputRequestSchema }, }, getOneOuputHandler @@ -65,7 +65,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PutOutputRequestSchema }, }, putOutputHandler @@ -80,7 +80,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PostOutputRequestSchema }, }, postOutputHandler @@ -95,7 +95,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: DeleteOutputRequestSchema }, }, deleteOutputHandler @@ -110,7 +110,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: false, }, postLogstashApiKeyHandler diff --git a/x-pack/plugins/fleet/server/routes/package_policy/index.ts b/x-pack/plugins/fleet/server/routes/package_policy/index.ts index 83cb9779cf058..893eb37a9b1bc 100644 --- a/x-pack/plugins/fleet/server/routes/package_policy/index.ts +++ b/x-pack/plugins/fleet/server/routes/package_policy/index.ts @@ -10,7 +10,7 @@ import { getRouteRequiredAuthz } from '../../services/security'; import type { FleetAuthzRouter } from '../../services/security'; import type { FleetAuthz } from '../../../common'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { PACKAGE_POLICY_API_ROUTES } from '../../constants'; import { GetPackagePoliciesRequestSchema, @@ -51,7 +51,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetPackagePoliciesRequestSchema }, }, getPackagePoliciesHandler @@ -69,7 +69,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: BulkGetPackagePoliciesRequestSchema }, }, bulkGetPackagePoliciesHandler @@ -87,7 +87,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetOnePackagePolicyRequestSchema }, }, getOnePackagePolicyHandler @@ -102,7 +102,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: {}, }, getOrphanedPackagePolicies @@ -115,7 +115,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: CreatePackagePolicyRequestSchema }, }, createPackagePolicyHandler @@ -133,7 +133,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: UpdatePackagePolicyRequestSchema }, }, @@ -150,7 +150,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: DeletePackagePoliciesRequestSchema }, }, deletePackagePolicyHandler @@ -165,7 +165,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: DeleteOnePackagePolicyRequestSchema }, }, deleteOnePackagePolicyHandler @@ -181,7 +181,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: UpgradePackagePoliciesRequestSchema }, }, upgradePackagePolicyHandler @@ -197,7 +197,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: DryRunPackagePoliciesRequestSchema }, }, dryRunUpgradePackagePolicyHandler diff --git a/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts b/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts index 4f7a97c6fd5f9..e78396005d4c2 100644 --- a/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts +++ b/x-pack/plugins/fleet/server/routes/preconfiguration/index.ts @@ -7,7 +7,7 @@ import type { FleetAuthzRouter } from '../../services/security'; -import { OLDEST_INTERNAL_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { PRECONFIGURATION_API_ROUTES } from '../../constants'; import { PostResetOnePreconfiguredAgentPoliciesSchema } from '../../types'; @@ -25,7 +25,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: false, }, @@ -41,7 +41,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_INTERNAL_VERSION, + version: API_VERSIONS.internal.v1, validate: { request: PostResetOnePreconfiguredAgentPoliciesSchema }, }, resetOnePreconfigurationHandler diff --git a/x-pack/plugins/fleet/server/routes/settings/index.ts b/x-pack/plugins/fleet/server/routes/settings/index.ts index 0d823e1216405..89da7496dc0c2 100644 --- a/x-pack/plugins/fleet/server/routes/settings/index.ts +++ b/x-pack/plugins/fleet/server/routes/settings/index.ts @@ -7,7 +7,7 @@ import type { TypeOf } from '@kbn/config-schema'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { FleetAuthzRouter } from '../../services/security'; import { SETTINGS_API_ROUTES } from '../../constants'; @@ -75,7 +75,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetSettingsRequestSchema }, }, getSettingsHandler @@ -89,7 +89,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: PutSettingsRequestSchema }, }, putSettingsHandler diff --git a/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts b/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts index ec7f0eeb76b99..3a38d30b1da9f 100644 --- a/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts +++ b/x-pack/plugins/fleet/server/routes/setup/handlers.test.ts @@ -9,7 +9,7 @@ import type { AwaitedProperties } from '@kbn/utility-types'; import { httpServerMock, savedObjectsClientMock, coreMock } from '@kbn/core/server/mocks'; import type { PostFleetSetupResponse } from '../../../common/types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { RegistryError } from '../../errors'; import { createAppContextStartContractMock, @@ -63,7 +63,7 @@ describe('FleetSetupHandler', () => { request = httpServerMock.createKibanaRequest({ method: 'post', path: '/api/fleet/setup', - headers: { 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); // prevents `Logger not set.` and other appContext errors appContextService.start(createAppContextStartContractMock()); @@ -147,7 +147,7 @@ describe('FleetStatusHandler', () => { request = httpServerMock.createKibanaRequest({ method: 'post', path: '/api/fleet/status', - headers: { 'Elastic-Api-Version': `${OLDEST_PUBLIC_VERSION}` }, + headers: { 'Elastic-Api-Version': `${API_VERSIONS.public.v1}` }, }); // prevents `Logger not set.` and other appContext errors appContextService.start(createAppContextStartContractMock()); diff --git a/x-pack/plugins/fleet/server/routes/setup/index.ts b/x-pack/plugins/fleet/server/routes/setup/index.ts index 28f4629bd53f5..f09ff70e145aa 100644 --- a/x-pack/plugins/fleet/server/routes/setup/index.ts +++ b/x-pack/plugins/fleet/server/routes/setup/index.ts @@ -8,7 +8,7 @@ import type { FleetAuthzRouter } from '../../services/security'; import { AGENTS_SETUP_API_ROUTES, SETUP_API_ROUTE } from '../../constants'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { FleetConfigType } from '../../../common/types'; @@ -24,7 +24,7 @@ export const registerFleetSetupRoute = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: false, }, fleetSetupHandler @@ -42,7 +42,7 @@ export const registerCreateFleetSetupRoute = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: false, }, fleetSetupHandler @@ -59,7 +59,7 @@ export const registerGetFleetStatusRoute = (router: FleetAuthzRouter) => { }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: false, }, getFleetStatusHandler diff --git a/x-pack/plugins/fleet/server/routes/uninstall_token/index.ts b/x-pack/plugins/fleet/server/routes/uninstall_token/index.ts index 7d6034d121830..a7214607cb309 100644 --- a/x-pack/plugins/fleet/server/routes/uninstall_token/index.ts +++ b/x-pack/plugins/fleet/server/routes/uninstall_token/index.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { UNINSTALL_TOKEN_ROUTES, OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { UNINSTALL_TOKEN_ROUTES, API_VERSIONS } from '../../../common/constants'; import type { FleetConfigType } from '../../config'; import type { FleetAuthzRouter } from '../../services/security'; @@ -29,7 +29,7 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetUninstallTokensMetadataRequestSchema }, }, getUninstallTokensMetadataHandler @@ -44,7 +44,7 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType }) .addVersion( { - version: OLDEST_PUBLIC_VERSION, + version: API_VERSIONS.public.v1, validate: { request: GetUninstallTokenRequestSchema }, }, getUninstallTokenHandler diff --git a/x-pack/plugins/fleet/server/services/security/fleet_router.test.ts b/x-pack/plugins/fleet/server/services/security/fleet_router.test.ts index cc835793fce88..1e7d09f261603 100644 --- a/x-pack/plugins/fleet/server/services/security/fleet_router.test.ts +++ b/x-pack/plugins/fleet/server/services/security/fleet_router.test.ts @@ -18,7 +18,7 @@ import type { CheckPrivilegesPayload } from '@kbn/security-plugin/server'; import type { CheckPrivilegesResponse } from '@kbn/security-plugin/server/authorization/types'; -import { OLDEST_PUBLIC_VERSION } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { FleetRequestHandlerContext } from '../..'; import { createAppContextStartContractMock } from '../../mocks'; @@ -106,7 +106,7 @@ describe('FleetAuthzRouter', () => { const fleetAuthzRouter = makeRouterWithFleetAuthz(fakeRouter as any, mockLogger); fleetAuthzRouter.versioned .get({ ...routeConfig }) - .addVersion({ version: OLDEST_PUBLIC_VERSION, validate: false }, fakeHandler); + .addVersion({ version: API_VERSIONS.public.v1, validate: false }, fakeHandler); // @ts-ignore const wrappedRouteConfig = fakeRouter.versioned.get.mock.calls[0][0]; const wrappedHandler = diff --git a/x-pack/test/fleet_api_integration/config.base.ts b/x-pack/test/fleet_api_integration/config.base.ts index ef4a50853f9ee..3e4b35988efba 100644 --- a/x-pack/test/fleet_api_integration/config.base.ts +++ b/x-pack/test/fleet_api_integration/config.base.ts @@ -84,8 +84,6 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { appenders: ['default'], }, ])}`, - // Don't enforce versions header validation - `--server.versioned.versionResolution=oldest`, ], }, }; From 65fb288378478b9844f1ced3ceab26c246030b7d Mon Sep 17 00:00:00 2001 From: criamico Date: Mon, 4 Sep 2023 12:40:35 +0200 Subject: [PATCH 26/26] Fix integration tests --- .../plugins/fleet/server/routes/epm/index.ts | 4 +-- .../apis/agent_policy/agent_policy.ts | 28 +++++++++---------- .../apis/agents/status.ts | 4 +-- .../apis/enrollment_api_keys/crud.ts | 10 +++---- .../apis/epm/install_prerelease.ts | 13 +++++++-- .../input_package_create_upgrade.ts | 2 +- .../apis/package_policy/update.ts | 6 ++-- .../apis/package_policy/upgrade.ts | 2 +- .../apis/service_tokens.ts | 4 +-- .../functional/services/ml/test_resources.ts | 9 +++--- 10 files changed, 45 insertions(+), 37 deletions(-) diff --git a/x-pack/plugins/fleet/server/routes/epm/index.ts b/x-pack/plugins/fleet/server/routes/epm/index.ts index 5af7d4607f2f8..4f354ae77d7f0 100644 --- a/x-pack/plugins/fleet/server/routes/epm/index.ts +++ b/x-pack/plugins/fleet/server/routes/epm/index.ts @@ -367,15 +367,15 @@ export const registerRoutes = (router: FleetAuthzRouter) => { } ); + // This endpoint should be marked as internal but the router selects this endpoint over the new POST router.versioned .post({ path: EPM_API_ROUTES.INSTALL_FROM_REGISTRY_PATTERN_DEPRECATED, fleetAuthz: INSTALL_PACKAGES_AUTHZ, - access: INTERNAL_API_ACCESS, }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, validate: { request: InstallPackageFromRegistryRequestSchemaDeprecated }, }, async (context, request, response) => { diff --git a/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts b/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts index 4850ee3d33aef..6cf131939807c 100644 --- a/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts +++ b/x-pack/test/fleet_api_integration/apis/agent_policy/agent_policy.ts @@ -19,16 +19,16 @@ export default function (providerContext: FtrProviderContext) { const kibanaServer = getService('kibanaServer'); const es = getService('es'); - const epmInstall = async (pkgName: string) => { + const getPackage = async (pkgName: string) => { const getPkgRes = await supertest .get(`/api/fleet/epm/packages/${pkgName}`) .set('kbn-xsrf', 'xxxx') .expect(200); return getPkgRes; }; - const epmForceInstall = async (pkgName: string) => { + const epmInstall = async (pkgName: string, pkgVersion: string) => { const getPkgRes = await supertest - .get(`/api/fleet/epm/packages/${pkgName}`) + .post(`/api/fleet/epm/packages/${pkgName}/${pkgVersion}`) .set('kbn-xsrf', 'xxxx') .send({ force: true }) .expect(200); @@ -105,7 +105,7 @@ export default function (providerContext: FtrProviderContext) { let packagePoliciesToDeleteIds: string[] = []; after(async () => { if (systemPkgVersion) { - await supertest.delete(`/api/fleet/epm/packages/system-${systemPkgVersion}`); + await supertest.delete(`/api/fleet/epm/packages/system/${systemPkgVersion}`); } if (packagePoliciesToDeleteIds.length > 0) { await kibanaServer.savedObjects.bulkDelete({ @@ -313,14 +313,14 @@ export default function (providerContext: FtrProviderContext) { .expect(409); }); - it('should allow to create policy with the system integration policy and increment correctly the name if there is more than 10 package policy', async () => { + it('should allow to create policy with the system integration policy and increment correctly the name if package policies are more than 10', async () => { // load a bunch of fake system integration policy const policyIds = new Array(10).fill(null).map((_, i) => `package-policy-test-${i}`); packagePoliciesToDeleteIds = packagePoliciesToDeleteIds.concat(policyIds); - const getPkRes = await epmInstall('system'); + const getPkRes = await getPackage('system'); systemPkgVersion = getPkRes.body.item.version; // we must first force install the system package to override package verification error on policy create - const installPromise = await epmForceInstall(`system-${systemPkgVersion}`); + const installPromise = await epmInstall('system', `${systemPkgVersion}`); await Promise.all([ installPromise, @@ -428,7 +428,7 @@ export default function (providerContext: FtrProviderContext) { await Promise.all(deletedPromises); await esArchiver.unload('x-pack/test/functional/es_archives/fleet/agents'); if (systemPkgVersion) { - await supertest.delete(`/api/fleet/epm/packages/system-${systemPkgVersion}`); + await supertest.delete(`/api/fleet/epm/packages/system/${systemPkgVersion}`); } if (packagePoliciesToDeleteIds.length > 0) { await kibanaServer.savedObjects.bulkDelete({ @@ -600,10 +600,10 @@ export default function (providerContext: FtrProviderContext) { const policyId = 'package-policy-test-'; packagePoliciesToDeleteIds.push(policyId); - const getPkRes = await epmInstall('system'); + const getPkRes = await getPackage('system'); systemPkgVersion = getPkRes.body.item.version; // we must first force install the system package to override package verification error on policy create - const installPromise = await epmForceInstall(`system-${systemPkgVersion}`); + const installPromise = await epmInstall('system', `${systemPkgVersion}`); await Promise.all([ installPromise, @@ -684,10 +684,10 @@ export default function (providerContext: FtrProviderContext) { it('should work with package policy with space in name', async () => { const policyId = 'package-policy-test-1'; packagePoliciesToDeleteIds.push(policyId); - const getPkRes = await epmInstall('system'); + const getPkRes = await getPackage('system'); systemPkgVersion = getPkRes.body.item.version; // we must first force install the system package to override package verification error on policy create - const installPromise = await epmForceInstall(`system-${systemPkgVersion}`); + const installPromise = await epmInstall('system', `${systemPkgVersion}`); await Promise.all([ installPromise, @@ -1187,10 +1187,10 @@ export default function (providerContext: FtrProviderContext) { }); setupFleetAndAgents(providerContext); before(async () => { - const getPkRes = await epmInstall('system'); + const getPkRes = await getPackage('system'); // we must first force install the system package to override package verification error on policy create - await epmForceInstall(`system-${getPkRes.body.item.version}`); + await epmInstall('system', `${getPkRes.body.item.version}`); const { body: { item: createdPolicy }, diff --git a/x-pack/test/fleet_api_integration/apis/agents/status.ts b/x-pack/test/fleet_api_integration/apis/agents/status.ts index f49446f29ecdb..b0879afc5ccb7 100644 --- a/x-pack/test/fleet_api_integration/apis/agents/status.ts +++ b/x-pack/test/fleet_api_integration/apis/agents/status.ts @@ -8,7 +8,7 @@ import expect from '@kbn/expect'; import { INGEST_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server'; -import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; +import { API_VERSIONS } from '@kbn/fleet-plugin/common/constants'; import { AGENTS_INDEX } from '@kbn/fleet-plugin/common'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; @@ -235,7 +235,7 @@ export default function ({ getService }: FtrProviderContext) { await supertest .get(`/api/fleet/agent-status`) .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .expect(200); }); diff --git a/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts b/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts index 9247feada5acb..47c4d7ecd9f7b 100644 --- a/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts +++ b/x-pack/test/fleet_api_integration/apis/enrollment_api_keys/crud.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; -import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; +import { API_VERSIONS } from '@kbn/fleet-plugin/common/constants'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { setupFleetAndAgents, getEsClientForAPIKey } from '../agents/services'; import { skipIfNoDockerRegistry } from '../../helpers'; @@ -325,7 +325,7 @@ export default function (providerContext: FtrProviderContext) { const { body: apiResponse } = await supertest .post(`/api/fleet/enrollment-api-keys`) .set('kbn-xsrf', 'xxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .send({ policy_id: 'policy1', }) @@ -336,18 +336,18 @@ export default function (providerContext: FtrProviderContext) { it('should get and delete with deprecated API', async () => { await supertest .get(`/api/fleet/enrollment-api-keys`) - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .set('kbn-xsrf', 'xxx') .expect(200); await supertest .get(`/api/fleet/enrollment-api-keys/${ENROLLMENT_KEY_ID}`) - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .set('kbn-xsrf', 'xxx') .expect(200); await supertest .delete(`/api/fleet/enrollment-api-keys/${keyId}`) - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .set('kbn-xsrf', 'xxx') .expect(200); }); diff --git a/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts b/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts index f9d72c62e2738..7b300c271e304 100644 --- a/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts +++ b/x-pack/test/fleet_api_integration/apis/epm/install_prerelease.ts @@ -22,7 +22,6 @@ export default function (providerContext: FtrProviderContext) { await supertest.delete(`/api/fleet/epm/packages/${pkg}/${version}`).set('kbn-xsrf', 'xxxx'); }; - // Failing: See https://github.com/elastic/kibana/issues/150343 describe('installs package that has a prerelease version', async () => { skipIfNoDockerRegistry(providerContext); setupFleetAndAgents(providerContext); @@ -70,13 +69,21 @@ export default function (providerContext: FtrProviderContext) { expect(response.body.items.find((item: any) => item.id.includes(gaVersion))); }); - it('should install the beta package when no version is provided and prerelease is true', async function () { + it('should install the beta package when prerelease is true', async function () { const response = await supertest - .post(`/api/fleet/epm/packages/${testPackage}?prerelease=true`) + .post(`/api/fleet/epm/packages/${testPackage}/${testPackageVersion}?prerelease=true`) .set('kbn-xsrf', 'xxxx') .send({ force: true }) // using force to ignore package verification error .expect(200); + expect(response.body.items.find((item: any) => item.id.includes(betaVersion))); + }); + it('should install the beta package when no version is provided and prerelease is true', async function () { + const response = await supertest + .post(`/api/fleet/epm/packages/${testPackage}/${testPackageVersion}?prerelease=true`) + .set('kbn-xsrf', 'xxxx') + .send({ force: true }) // using force to ignore package verification error + .expect(200); expect(response.body.items.find((item: any) => item.id.includes(betaVersion))); }); diff --git a/x-pack/test/fleet_api_integration/apis/package_policy/input_package_create_upgrade.ts b/x-pack/test/fleet_api_integration/apis/package_policy/input_package_create_upgrade.ts index 263b9ac88adac..a1e6fe5d5556f 100644 --- a/x-pack/test/fleet_api_integration/apis/package_policy/input_package_create_upgrade.ts +++ b/x-pack/test/fleet_api_integration/apis/package_policy/input_package_create_upgrade.ts @@ -33,7 +33,7 @@ export default function (providerContext: FtrProviderContext) { }; const getInstallationSavedObject = async (name: string, version: string) => { - const res = await supertest.get(`/api/fleet/epm/packages/${name}-${version}`).expect(200); + const res = await supertest.get(`/api/fleet/epm/packages/${name}/${version}`).expect(200); return res.body.item.savedObject.attributes; }; diff --git a/x-pack/test/fleet_api_integration/apis/package_policy/update.ts b/x-pack/test/fleet_api_integration/apis/package_policy/update.ts index 15ad0a82b4359..865341abc5bcc 100644 --- a/x-pack/test/fleet_api_integration/apis/package_policy/update.ts +++ b/x-pack/test/fleet_api_integration/apis/package_policy/update.ts @@ -25,7 +25,7 @@ export default function (providerContext: FtrProviderContext) { }; const getInstallationSavedObject = async (name: string, version: string) => { - const res = await supertest.get(`/api/fleet/epm/packages/${name}-${version}`).expect(200); + const res = await supertest.get(`/api/fleet/epm/packages/${name}/${version}`).expect(200); return res.body.item.savedObject.attributes; }; @@ -229,11 +229,11 @@ export default function (providerContext: FtrProviderContext) { .send({ agentPolicyId }); // uninstall endpoint package await supertest - .delete(`/api/fleet/epm/packages/endpoint-8.6.1`) + .delete(`/api/fleet/epm/packages/endpoint/8.6.1`) .set('kbn-xsrf', 'xxxx') .expect(200); await supertest - .delete(`/api/fleet/epm/packages/input_package-1.0.0`) + .delete(`/api/fleet/epm/packages/input_package/1.0.0`) .set('kbn-xsrf', 'xxxx') .expect(200); }); diff --git a/x-pack/test/fleet_api_integration/apis/package_policy/upgrade.ts b/x-pack/test/fleet_api_integration/apis/package_policy/upgrade.ts index 557d5a9b4d9b2..c5c3d6a67a829 100644 --- a/x-pack/test/fleet_api_integration/apis/package_policy/upgrade.ts +++ b/x-pack/test/fleet_api_integration/apis/package_policy/upgrade.ts @@ -36,7 +36,7 @@ export default function (providerContext: FtrProviderContext) { } const getInstallationSavedObject = async (name: string, version: string) => { - const res = await supertest.get(`/api/fleet/epm/packages/${name}-${version}`).expect(200); + const res = await supertest.get(`/api/fleet/epm/packages/${name}/${version}`).expect(200); return res.body.item.savedObject.attributes; }; diff --git a/x-pack/test/fleet_api_integration/apis/service_tokens.ts b/x-pack/test/fleet_api_integration/apis/service_tokens.ts index 6d1bd5b870046..e1830a8ac7f97 100644 --- a/x-pack/test/fleet_api_integration/apis/service_tokens.ts +++ b/x-pack/test/fleet_api_integration/apis/service_tokens.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { OLDEST_INTERNAL_VERSION } from '@kbn/fleet-plugin/common/constants'; +import { API_VERSIONS } from '@kbn/fleet-plugin/common/constants'; import { FtrProviderContext } from '../../api_integration/ftr_provider_context'; export default function (providerContext: FtrProviderContext) { @@ -50,7 +50,7 @@ export default function (providerContext: FtrProviderContext) { await supertest .post(`/api/fleet/service-tokens`) .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${OLDEST_INTERNAL_VERSION}`) + .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .expect(200); }); }); diff --git a/x-pack/test/functional/services/ml/test_resources.ts b/x-pack/test/functional/services/ml/test_resources.ts index f07e9338c3c80..a256c623adbe0 100644 --- a/x-pack/test/functional/services/ml/test_resources.ts +++ b/x-pack/test/functional/services/ml/test_resources.ts @@ -8,6 +8,7 @@ import expect from '@kbn/expect'; import { ProvidedType } from '@kbn/test'; import { JobType } from '@kbn/ml-plugin/common/types/saved_objects'; +import { API_VERSIONS } from '@kbn/fleet-plugin/common/constants'; import { savedSearches, dashboards } from './test_resources_data'; import { getCommonRequestHeader } from './common_api'; import { MlApi } from './api'; @@ -567,7 +568,7 @@ export function MachineLearningTestResourcesProvider( await retry.tryForTime(2 * 60 * 1000, async () => { const { body, status } = await supertest .post(`/api/fleet/setup`) - .set(getCommonRequestHeader('2023-10-31')); + .set(getCommonRequestHeader(`${API_VERSIONS.public.v1}`)); mlApi.assertResponseStatusCode(200, status, body); }); log.debug(` > Setup done`); @@ -581,7 +582,7 @@ export function MachineLearningTestResourcesProvider( await retry.tryForTime(30 * 1000, async () => { const { body, status } = await supertest .post(`/api/fleet/epm/packages/${packageName}/${version}`) - .set(getCommonRequestHeader('1')); + .set(getCommonRequestHeader(`${API_VERSIONS.public.v1}`)); mlApi.assertResponseStatusCode(200, status, body); }); @@ -595,7 +596,7 @@ export function MachineLearningTestResourcesProvider( await retry.tryForTime(30 * 1000, async () => { const { body, status } = await supertest .delete(`/api/fleet/epm/packages/${packageName}/${version}`) - .set(getCommonRequestHeader('1')); + .set(getCommonRequestHeader(`${API_VERSIONS.public.v1}`)); mlApi.assertResponseStatusCode(200, status, body); }); @@ -609,7 +610,7 @@ export function MachineLearningTestResourcesProvider( await retry.tryForTime(10 * 1000, async () => { const { body, status } = await supertest .get(`/api/fleet/epm/packages?experimental=true`) - .set(getCommonRequestHeader('1')); + .set(getCommonRequestHeader(`${API_VERSIONS.public.v1}`)); mlApi.assertResponseStatusCode(200, status, body); packageVersion =