From f189ca526ed399f5931b5f533d1701e906ddacf8 Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Wed, 17 Jan 2024 16:25:33 +0100 Subject: [PATCH 1/4] make deprecated paths public --- x-pack/plugins/fleet/server/routes/agent/index.ts | 5 ++--- x-pack/plugins/fleet/server/routes/app/index.ts | 5 ++--- .../server/routes/enrollment_api_key/index.ts | 14 +++++--------- x-pack/plugins/fleet/server/routes/epm/index.ts | 8 +++----- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/fleet/server/routes/agent/index.ts b/x-pack/plugins/fleet/server/routes/agent/index.ts index 0d261fc24a16e..ca37cc76c3381 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 { API_VERSIONS, INTERNAL_API_ACCESS } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { getRouteRequiredAuthz, type FleetAuthzRouter } from '../../services/security'; @@ -351,7 +351,6 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT ); router.versioned .get({ - access: INTERNAL_API_ACCESS, path: AGENT_API_ROUTES.STATUS_PATTERN_DEPRECATED, fleetAuthz: { fleet: { all: true }, @@ -359,7 +358,7 @@ export const registerAPIRoutes = (router: FleetAuthzRouter, config: FleetConfigT }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, 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 8d8ae60ad0225..e9266df0f95bc 100644 --- a/x-pack/plugins/fleet/server/routes/app/index.ts +++ b/x-pack/plugins/fleet/server/routes/app/index.ts @@ -11,7 +11,7 @@ import type { TypeOf } from '@kbn/config-schema'; import type { FleetAuthzRouter } from '../../services/security'; import { APP_API_ROUTES } from '../../constants'; -import { API_VERSIONS, INTERNAL_API_ACCESS } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { appContextService } from '../../services'; import type { CheckPermissionsResponse, GenerateServiceTokenResponse } from '../../../common/types'; @@ -141,11 +141,10 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { all: true }, }, - access: INTERNAL_API_ACCESS, }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, 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 222e5752abe49..3623fb24b451d 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,7 @@ import type { FleetAuthzRouter } from '../../services/security'; import { ENROLLMENT_API_KEY_ROUTES } from '../../constants'; -import { API_VERSIONS, INTERNAL_API_ACCESS } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import { GetEnrollmentAPIKeysRequestSchema, @@ -91,11 +91,10 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { readEnrollmentTokens: true }, }, - access: INTERNAL_API_ACCESS, }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, validate: { request: GetOneEnrollmentAPIKeyRequestSchema }, }, getOneEnrollmentApiKeyHandler @@ -107,11 +106,10 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { all: true }, }, - access: INTERNAL_API_ACCESS, }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, validate: { request: DeleteEnrollmentAPIKeyRequestSchema }, }, deleteEnrollmentApiKeyHandler @@ -123,11 +121,10 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { readEnrollmentTokens: true }, }, - access: INTERNAL_API_ACCESS, }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, validate: { request: GetEnrollmentAPIKeysRequestSchema }, }, getEnrollmentApiKeysHandler @@ -139,11 +136,10 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { fleet: { all: true }, }, - access: INTERNAL_API_ACCESS, }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.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 5245381a409da..7d2a756ffd6de 100644 --- a/x-pack/plugins/fleet/server/routes/epm/index.ts +++ b/x-pack/plugins/fleet/server/routes/epm/index.ts @@ -7,7 +7,7 @@ import type { IKibanaResponse } from '@kbn/core/server'; -import { API_VERSIONS, INTERNAL_API_ACCESS } from '../../../common/constants'; +import { API_VERSIONS } from '../../../common/constants'; import type { FleetAuthz } from '../../../common'; @@ -361,11 +361,10 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { integrations: { upgradePackages: true, writePackageSettings: true }, }, - access: INTERNAL_API_ACCESS, }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, validate: { request: UpdatePackageRequestSchemaDeprecated }, }, async (context, request, response) => { @@ -415,11 +414,10 @@ export const registerRoutes = (router: FleetAuthzRouter) => { fleetAuthz: { integrations: { removePackages: true }, }, - access: INTERNAL_API_ACCESS, }) .addVersion( { - version: API_VERSIONS.internal.v1, + version: API_VERSIONS.public.v1, validate: { request: DeletePackageRequestSchemaDeprecated }, }, async (context, request, response) => { From 87241064cf573345cad19c44feb924f96194dedf Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 18 Jan 2024 09:41:52 +0100 Subject: [PATCH 2/4] fix tests --- .../test/fleet_api_integration/apis/agents/status.ts | 7 +------ .../apis/enrollment_api_keys/crud.ts | 10 +--------- 2 files changed, 2 insertions(+), 15 deletions(-) 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 b0879afc5ccb7..742d5d6d3be7d 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,6 @@ import expect from '@kbn/expect'; import { INGEST_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server'; -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'; @@ -232,11 +231,7 @@ export default function ({ getService }: FtrProviderContext) { }); it('should work with deprecated api', async () => { - await supertest - .get(`/api/fleet/agent-status`) - .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) - .expect(200); + await supertest.get(`/api/fleet/agent-status`).set('kbn-xsrf', 'xxxx').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 7d8cc253fa0e2..087218bf4727e 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,6 @@ import expect from '@kbn/expect'; -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 +324,6 @@ export default function (providerContext: FtrProviderContext) { const { body: apiResponse } = await supertest .post(`/api/fleet/enrollment-api-keys`) .set('kbn-xsrf', 'xxx') - .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) .send({ policy_id: 'policy1', }) @@ -334,20 +332,14 @@ 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', `${API_VERSIONS.internal.v1}`) - .set('kbn-xsrf', 'xxx') - .expect(200); + await supertest.get(`/api/fleet/enrollment-api-keys`).set('kbn-xsrf', 'xxx').expect(200); await supertest .get(`/api/fleet/enrollment-api-keys/${ENROLLMENT_KEY_ID}`) - .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', `${API_VERSIONS.internal.v1}`) .set('kbn-xsrf', 'xxx') .expect(200); }); From 6c2393df5b76c8ec7e47fb4fdb869299d420bdc4 Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 18 Jan 2024 12:13:48 +0100 Subject: [PATCH 3/4] fixed test --- x-pack/test/fleet_api_integration/apis/service_tokens.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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 5d5dc8b414756..aab8c2884c8dc 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,6 @@ */ import expect from '@kbn/expect'; -import { API_VERSIONS } from '@kbn/fleet-plugin/common/constants'; import { FtrProviderContext } from '../../api_integration/ftr_provider_context'; export default function (providerContext: FtrProviderContext) { @@ -47,11 +46,7 @@ export default function (providerContext: FtrProviderContext) { }); it('should work with deprecated api', async () => { - await supertest - .post(`/api/fleet/service-tokens`) - .set('kbn-xsrf', 'xxxx') - .set('Elastic-Api-Version', `${API_VERSIONS.internal.v1}`) - .expect(200); + await supertest.post(`/api/fleet/service-tokens`).set('kbn-xsrf', 'xxxx').expect(200); }); it('should create a valid remote service account token', async () => { From 1f0cec118300b99f2f25afe3c8158d72f760507d Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 18 Jan 2024 13:21:37 +0100 Subject: [PATCH 4/4] fix cypress tests --- .../observability_onboarding/e2e/cypress/support/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/observability_onboarding/e2e/cypress/support/commands.ts b/x-pack/plugins/observability_onboarding/e2e/cypress/support/commands.ts index e989089f491eb..02b77061ef688 100644 --- a/x-pack/plugins/observability_onboarding/e2e/cypress/support/commands.ts +++ b/x-pack/plugins/observability_onboarding/e2e/cypress/support/commands.ts @@ -144,7 +144,7 @@ Cypress.Commands.add('deleteIntegration', (integrationName: string) => { }, headers: { 'kbn-xsrf': 'e2e_test', - 'Elastic-Api-Version': '1', + 'Elastic-Api-Version': '2023-10-31', }, auth: { user: 'editor', pass: 'changeme' }, });