diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/index.tsx index 3e6ca5944c380..65cf62a279a22 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/index.tsx @@ -106,9 +106,9 @@ export const AgentPolicyDetailsPage: React.FunctionComponent = () => { {agentPolicy?.is_managed && ( = () => { if (!agent.policy_id) return true; const agentPolicy = agentPoliciesIndexedById[agent.policy_id]; - const isManaged = agentPolicy?.is_managed === true; - return !isManaged; + const isHosted = agentPolicy?.is_managed === true; + return !isHosted; }; const columns = [ diff --git a/x-pack/plugins/fleet/server/services/agent_policy.ts b/x-pack/plugins/fleet/server/services/agent_policy.ts index e398eb4527f52..6237951805547 100644 --- a/x-pack/plugins/fleet/server/services/agent_policy.ts +++ b/x-pack/plugins/fleet/server/services/agent_policy.ts @@ -476,7 +476,7 @@ class AgentPolicyService { } if (oldAgentPolicy.is_managed && !options?.force) { - throw new IngestManagerError(`Cannot update integrations of managed policy ${id}`); + throw new IngestManagerError(`Cannot update integrations of hosted agent policy ${id}`); } return await this._update( @@ -507,7 +507,7 @@ class AgentPolicyService { } if (oldAgentPolicy.is_managed && !options?.force) { - throw new IngestManagerError(`Cannot remove integrations of managed policy ${id}`); + throw new IngestManagerError(`Cannot remove integrations of hosted agent policy ${id}`); } return await this._update( @@ -550,7 +550,7 @@ class AgentPolicyService { } if (agentPolicy.is_managed) { - throw new AgentPolicyDeletionError(`Cannot delete managed policy ${id}`); + throw new AgentPolicyDeletionError(`Cannot delete hosted agent policy ${id}`); } const { diff --git a/x-pack/plugins/fleet/server/services/agents/crud.ts b/x-pack/plugins/fleet/server/services/agents/crud.ts index a23efa1e50fc0..b8ce7c36e507f 100644 --- a/x-pack/plugins/fleet/server/services/agents/crud.ts +++ b/x-pack/plugins/fleet/server/services/agents/crud.ts @@ -255,9 +255,10 @@ export async function getAgentByAccessAPIKeyId( q: `access_api_key_id:${escapeSearchQueryPhrase(accessAPIKeyId)}`, }); - const agent = searchHitToAgent(res.body.hits.hits[0]); + const searchHit = res.body.hits.hits[0]; + const agent = searchHit && searchHitToAgent(searchHit); - if (!agent) { + if (!searchHit || !agent) { throw new AgentNotFoundError('Agent not found'); } if (agent.access_api_key_id !== accessAPIKeyId) { diff --git a/x-pack/plugins/fleet/server/services/agents/reassign.test.ts b/x-pack/plugins/fleet/server/services/agents/reassign.test.ts index f040ba57c38be..4dfc29df8c398 100644 --- a/x-pack/plugins/fleet/server/services/agents/reassign.test.ts +++ b/x-pack/plugins/fleet/server/services/agents/reassign.test.ts @@ -13,63 +13,63 @@ import { AgentReassignmentError } from '../../errors'; import { reassignAgent, reassignAgents } from './reassign'; -const agentInManagedDoc = { - _id: 'agent-in-managed-policy', - _source: { policy_id: 'managed-agent-policy' }, +const agentInHostedDoc = { + _id: 'agent-in-hosted-policy', + _source: { policy_id: 'hosted-agent-policy' }, }; -const agentInManagedDoc2 = { - _id: 'agent-in-managed-policy2', - _source: { policy_id: 'managed-agent-policy' }, +const agentInHostedDoc2 = { + _id: 'agent-in-hosted-policy2', + _source: { policy_id: 'hosted-agent-policy' }, }; -const agentInUnmanagedDoc = { - _id: 'agent-in-unmanaged-policy', - _source: { policy_id: 'unmanaged-agent-policy' }, +const agentInRegularDoc = { + _id: 'agent-in-regular-policy', + _source: { policy_id: 'regular-agent-policy' }, }; -const unmanagedAgentPolicySO = { - id: 'unmanaged-agent-policy', +const regularAgentPolicySO = { + id: 'regular-agent-policy', attributes: { is_managed: false }, } as SavedObject; -const unmanagedAgentPolicySO2 = { - id: 'unmanaged-agent-policy-2', +const regularAgentPolicySO2 = { + id: 'regular-agent-policy-2', attributes: { is_managed: false }, } as SavedObject; -const managedAgentPolicySO = { - id: 'managed-agent-policy', +const hostedAgentPolicySO = { + id: 'hosted-agent-policy', attributes: { is_managed: true }, } as SavedObject; describe('reassignAgent (singular)', () => { - it('can reassign from unmanaged policy to unmanaged', async () => { + it('can reassign from regular agent policy to regular', async () => { const { soClient, esClient } = createClientsMock(); - await reassignAgent(soClient, esClient, agentInUnmanagedDoc._id, unmanagedAgentPolicySO.id); + await reassignAgent(soClient, esClient, agentInRegularDoc._id, regularAgentPolicySO.id); // calls ES update with correct values expect(esClient.update).toBeCalledTimes(1); const calledWith = esClient.update.mock.calls[0]; - expect(calledWith[0]?.id).toBe(agentInUnmanagedDoc._id); - expect(calledWith[0]?.body?.doc).toHaveProperty('policy_id', unmanagedAgentPolicySO.id); + expect(calledWith[0]?.id).toBe(agentInRegularDoc._id); + expect(calledWith[0]?.body?.doc).toHaveProperty('policy_id', regularAgentPolicySO.id); }); - it('cannot reassign from unmanaged policy to managed', async () => { + it('cannot reassign from regular agent policy to hosted', async () => { const { soClient, esClient } = createClientsMock(); await expect( - reassignAgent(soClient, esClient, agentInUnmanagedDoc._id, managedAgentPolicySO.id) + reassignAgent(soClient, esClient, agentInRegularDoc._id, hostedAgentPolicySO.id) ).rejects.toThrowError(AgentReassignmentError); // does not call ES update expect(esClient.update).toBeCalledTimes(0); }); - it('cannot reassign from managed policy', async () => { + it('cannot reassign from hosted agent policy', async () => { const { soClient, esClient } = createClientsMock(); await expect( - reassignAgent(soClient, esClient, agentInManagedDoc._id, unmanagedAgentPolicySO.id) + reassignAgent(soClient, esClient, agentInHostedDoc._id, regularAgentPolicySO.id) ).rejects.toThrowError(AgentReassignmentError); // does not call ES update expect(esClient.update).toBeCalledTimes(0); await expect( - reassignAgent(soClient, esClient, agentInManagedDoc._id, managedAgentPolicySO.id) + reassignAgent(soClient, esClient, agentInHostedDoc._id, hostedAgentPolicySO.id) ).rejects.toThrowError(AgentReassignmentError); // does not call ES update expect(esClient.update).toBeCalledTimes(0); @@ -77,22 +77,17 @@ describe('reassignAgent (singular)', () => { }); describe('reassignAgents (plural)', () => { - it('agents in managed policies are not updated', async () => { + it('agents in hosted policies are not updated', async () => { const { soClient, esClient } = createClientsMock(); - const idsToReassign = [agentInUnmanagedDoc._id, agentInManagedDoc._id, agentInManagedDoc2._id]; - await reassignAgents( - soClient, - esClient, - { agentIds: idsToReassign }, - unmanagedAgentPolicySO2.id - ); + const idsToReassign = [agentInRegularDoc._id, agentInHostedDoc._id, agentInHostedDoc2._id]; + await reassignAgents(soClient, esClient, { agentIds: idsToReassign }, regularAgentPolicySO2.id); // calls ES update with correct values const calledWith = esClient.bulk.mock.calls[0][0]; - // only 1 are unmanaged and bulk write two line per update + // only 1 are regular and bulk write two line per update expect(calledWith.body.length).toBe(2); // @ts-expect-error - expect(calledWith.body[0].update._id).toEqual(agentInUnmanagedDoc._id); + expect(calledWith.body[0].update._id).toEqual(agentInRegularDoc._id); }); }); @@ -112,12 +107,12 @@ function createClientsMock() { }); soClientMock.get.mockImplementation(async (_, id) => { switch (id) { - case unmanagedAgentPolicySO.id: - return unmanagedAgentPolicySO; - case managedAgentPolicySO.id: - return managedAgentPolicySO; - case unmanagedAgentPolicySO2.id: - return unmanagedAgentPolicySO2; + case regularAgentPolicySO.id: + return regularAgentPolicySO; + case hostedAgentPolicySO.id: + return hostedAgentPolicySO; + case regularAgentPolicySO2.id: + return regularAgentPolicySO2; default: throw new Error(`${id} not found`); } @@ -133,17 +128,17 @@ function createClientsMock() { esClientMock.mget.mockImplementation(async () => { return { body: { - docs: [agentInManagedDoc, agentInUnmanagedDoc, agentInManagedDoc2], + docs: [agentInHostedDoc, agentInRegularDoc, agentInHostedDoc2], }, }; }); // @ts-expect-error esClientMock.get.mockImplementation(async ({ id }) => { switch (id) { - case agentInManagedDoc._id: - return { body: agentInManagedDoc }; - case agentInUnmanagedDoc._id: - return { body: agentInUnmanagedDoc }; + case agentInHostedDoc._id: + return { body: agentInHostedDoc }; + case agentInRegularDoc._id: + return { body: agentInRegularDoc }; default: throw new Error(`${id} not found`); } diff --git a/x-pack/plugins/fleet/server/services/agents/reassign.ts b/x-pack/plugins/fleet/server/services/agents/reassign.ts index 2d94e8b9e9247..4c95d19e2f13a 100644 --- a/x-pack/plugins/fleet/server/services/agents/reassign.ts +++ b/x-pack/plugins/fleet/server/services/agents/reassign.ts @@ -57,14 +57,14 @@ export async function reassignAgentIsAllowed( const agentPolicy = await getAgentPolicyForAgent(soClient, esClient, agentId); if (agentPolicy?.is_managed) { throw new AgentReassignmentError( - `Cannot reassign an agent from managed agent policy ${agentPolicy.id}` + `Cannot reassign an agent from hosted agent policy ${agentPolicy.id}` ); } const newAgentPolicy = await agentPolicyService.get(soClient, newAgentPolicyId); if (newAgentPolicy?.is_managed) { throw new AgentReassignmentError( - `Cannot reassign an agent to managed agent policy ${newAgentPolicy.id}` + `Cannot reassign an agent to hosted agent policy ${newAgentPolicy.id}` ); } diff --git a/x-pack/plugins/fleet/server/services/agents/unenroll.test.ts b/x-pack/plugins/fleet/server/services/agents/unenroll.test.ts index 938ece1364b40..24a3dea3bcb91 100644 --- a/x-pack/plugins/fleet/server/services/agents/unenroll.test.ts +++ b/x-pack/plugins/fleet/server/services/agents/unenroll.test.ts @@ -13,82 +13,82 @@ import { AgentUnenrollmentError } from '../../errors'; import { unenrollAgent, unenrollAgents } from './unenroll'; -const agentInManagedDoc = { - _id: 'agent-in-managed-policy', - _source: { policy_id: 'managed-agent-policy' }, +const agentInHostedDoc = { + _id: 'agent-in-hosted-policy', + _source: { policy_id: 'hosted-agent-policy' }, }; -const agentInUnmanagedDoc = { - _id: 'agent-in-unmanaged-policy', - _source: { policy_id: 'unmanaged-agent-policy' }, +const agentInRegularDoc = { + _id: 'agent-in-regular-policy', + _source: { policy_id: 'regular-agent-policy' }, }; -const agentInUnmanagedDoc2 = { - _id: 'agent-in-unmanaged-policy2', - _source: { policy_id: 'unmanaged-agent-policy' }, +const agentInRegularDoc2 = { + _id: 'agent-in-regular-policy2', + _source: { policy_id: 'regular-agent-policy' }, }; -const unmanagedAgentPolicySO = { - id: 'unmanaged-agent-policy', +const regularAgentPolicySO = { + id: 'regular-agent-policy', attributes: { is_managed: false }, } as SavedObject; -const managedAgentPolicySO = { - id: 'managed-agent-policy', +const hostedAgentPolicySO = { + id: 'hosted-agent-policy', attributes: { is_managed: true }, } as SavedObject; describe('unenrollAgent (singular)', () => { - it('can unenroll from unmanaged policy', async () => { + it('can unenroll from regular agent policy', async () => { const { soClient, esClient } = createClientMock(); - await unenrollAgent(soClient, esClient, agentInUnmanagedDoc._id); + await unenrollAgent(soClient, esClient, agentInRegularDoc._id); // calls ES update with correct values expect(esClient.update).toBeCalledTimes(1); const calledWith = esClient.update.mock.calls[0]; - expect(calledWith[0]?.id).toBe(agentInUnmanagedDoc._id); + expect(calledWith[0]?.id).toBe(agentInRegularDoc._id); expect(calledWith[0]?.body).toHaveProperty('doc.unenrollment_started_at'); }); - it('cannot unenroll from managed policy by default', async () => { + it('cannot unenroll from hosted agent policy by default', async () => { const { soClient, esClient } = createClientMock(); - await expect(unenrollAgent(soClient, esClient, agentInManagedDoc._id)).rejects.toThrowError( + await expect(unenrollAgent(soClient, esClient, agentInHostedDoc._id)).rejects.toThrowError( AgentUnenrollmentError ); // does not call ES update expect(esClient.update).toBeCalledTimes(0); }); - it('cannot unenroll from managed policy with revoke=true', async () => { + it('cannot unenroll from hosted agent policy with revoke=true', async () => { const { soClient, esClient } = createClientMock(); await expect( - unenrollAgent(soClient, esClient, agentInManagedDoc._id, { revoke: true }) + unenrollAgent(soClient, esClient, agentInHostedDoc._id, { revoke: true }) ).rejects.toThrowError(AgentUnenrollmentError); // does not call ES update expect(esClient.update).toBeCalledTimes(0); }); - it('can unenroll from managed policy with force=true', async () => { + it('can unenroll from hosted agent policy with force=true', async () => { const { soClient, esClient } = createClientMock(); - await unenrollAgent(soClient, esClient, agentInManagedDoc._id, { force: true }); + await unenrollAgent(soClient, esClient, agentInHostedDoc._id, { force: true }); // calls ES update with correct values expect(esClient.update).toBeCalledTimes(1); const calledWith = esClient.update.mock.calls[0]; - expect(calledWith[0]?.id).toBe(agentInManagedDoc._id); + expect(calledWith[0]?.id).toBe(agentInHostedDoc._id); expect(calledWith[0]?.body).toHaveProperty('doc.unenrollment_started_at'); }); - it('can unenroll from managed policy with force=true and revoke=true', async () => { + it('can unenroll from hosted agent policy with force=true and revoke=true', async () => { const { soClient, esClient } = createClientMock(); - await unenrollAgent(soClient, esClient, agentInManagedDoc._id, { force: true, revoke: true }); + await unenrollAgent(soClient, esClient, agentInHostedDoc._id, { force: true, revoke: true }); // calls ES update with correct values expect(esClient.update).toBeCalledTimes(1); const calledWith = esClient.update.mock.calls[0]; - expect(calledWith[0]?.id).toBe(agentInManagedDoc._id); + expect(calledWith[0]?.id).toBe(agentInHostedDoc._id); expect(calledWith[0]?.body).toHaveProperty('doc.unenrolled_at'); }); }); describe('unenrollAgents (plural)', () => { - it('can unenroll from an unmanaged policy', async () => { + it('can unenroll from an regular agent policy', async () => { const { soClient, esClient } = createClientMock(); - const idsToUnenroll = [agentInUnmanagedDoc._id, agentInUnmanagedDoc2._id]; + const idsToUnenroll = [agentInRegularDoc._id, agentInRegularDoc2._id]; await unenrollAgents(soClient, esClient, { agentIds: idsToUnenroll }); // calls ES update with correct values @@ -102,37 +102,29 @@ describe('unenrollAgents (plural)', () => { expect(doc).toHaveProperty('unenrollment_started_at'); } }); - it('cannot unenroll from a managed policy by default', async () => { + it('cannot unenroll from a hosted agent policy by default', async () => { const { soClient, esClient } = createClientMock(); - const idsToUnenroll = [ - agentInUnmanagedDoc._id, - agentInManagedDoc._id, - agentInUnmanagedDoc2._id, - ]; + const idsToUnenroll = [agentInRegularDoc._id, agentInHostedDoc._id, agentInRegularDoc2._id]; await unenrollAgents(soClient, esClient, { agentIds: idsToUnenroll }); // calls ES update with correct values - const onlyUnmanaged = [agentInUnmanagedDoc._id, agentInUnmanagedDoc2._id]; + const onlyRegular = [agentInRegularDoc._id, agentInRegularDoc2._id]; const calledWith = esClient.bulk.mock.calls[1][0]; const ids = calledWith?.body .filter((i: any) => i.update !== undefined) .map((i: any) => i.update._id); const docs = calledWith?.body.filter((i: any) => i.doc).map((i: any) => i.doc); - expect(ids).toEqual(onlyUnmanaged); + expect(ids).toEqual(onlyRegular); for (const doc of docs) { expect(doc).toHaveProperty('unenrollment_started_at'); } }); - it('cannot unenroll from a managed policy with revoke=true', async () => { + it('cannot unenroll from a hosted agent policy with revoke=true', async () => { const { soClient, esClient } = createClientMock(); - const idsToUnenroll = [ - agentInUnmanagedDoc._id, - agentInManagedDoc._id, - agentInUnmanagedDoc2._id, - ]; + const idsToUnenroll = [agentInRegularDoc._id, agentInHostedDoc._id, agentInRegularDoc2._id]; const unenrolledResponse = await unenrollAgents(soClient, esClient, { agentIds: idsToUnenroll, @@ -141,39 +133,35 @@ describe('unenrollAgents (plural)', () => { expect(unenrolledResponse.items).toMatchObject([ { - id: 'agent-in-unmanaged-policy', + id: 'agent-in-regular-policy', success: true, }, { - id: 'agent-in-managed-policy', + id: 'agent-in-hosted-policy', success: false, }, { - id: 'agent-in-unmanaged-policy2', + id: 'agent-in-regular-policy2', success: true, }, ]); // calls ES update with correct values - const onlyUnmanaged = [agentInUnmanagedDoc._id, agentInUnmanagedDoc2._id]; + const onlyRegular = [agentInRegularDoc._id, agentInRegularDoc2._id]; const calledWith = esClient.bulk.mock.calls[0][0]; const ids = calledWith?.body .filter((i: any) => i.update !== undefined) .map((i: any) => i.update._id); const docs = calledWith?.body.filter((i: any) => i.doc).map((i: any) => i.doc); - expect(ids).toEqual(onlyUnmanaged); + expect(ids).toEqual(onlyRegular); for (const doc of docs) { expect(doc).toHaveProperty('unenrolled_at'); } }); - it('can unenroll from managed policy with force=true', async () => { + it('can unenroll from hosted agent policy with force=true', async () => { const { soClient, esClient } = createClientMock(); - const idsToUnenroll = [ - agentInUnmanagedDoc._id, - agentInManagedDoc._id, - agentInUnmanagedDoc2._id, - ]; + const idsToUnenroll = [agentInRegularDoc._id, agentInHostedDoc._id, agentInRegularDoc2._id]; await unenrollAgents(soClient, esClient, { agentIds: idsToUnenroll, force: true }); // calls ES update with correct values @@ -188,14 +176,10 @@ describe('unenrollAgents (plural)', () => { } }); - it('can unenroll from managed policy with force=true and revoke=true', async () => { + it('can unenroll from hosted agent policy with force=true and revoke=true', async () => { const { soClient, esClient } = createClientMock(); - const idsToUnenroll = [ - agentInUnmanagedDoc._id, - agentInManagedDoc._id, - agentInUnmanagedDoc2._id, - ]; + const idsToUnenroll = [agentInRegularDoc._id, agentInHostedDoc._id, agentInRegularDoc2._id]; const unenrolledResponse = await unenrollAgents(soClient, esClient, { agentIds: idsToUnenroll, @@ -205,15 +189,15 @@ describe('unenrollAgents (plural)', () => { expect(unenrolledResponse.items).toMatchObject([ { - id: 'agent-in-unmanaged-policy', + id: 'agent-in-regular-policy', success: true, }, { - id: 'agent-in-managed-policy', + id: 'agent-in-hosted-policy', success: true, }, { - id: 'agent-in-unmanaged-policy2', + id: 'agent-in-regular-policy2', success: true, }, ]); @@ -248,10 +232,10 @@ function createClientMock() { soClientMock.get.mockImplementation(async (_, id) => { switch (id) { - case unmanagedAgentPolicySO.id: - return unmanagedAgentPolicySO; - case managedAgentPolicySO.id: - return managedAgentPolicySO; + case regularAgentPolicySO.id: + return regularAgentPolicySO; + case hostedAgentPolicySO.id: + return hostedAgentPolicySO; default: throw new Error('not found'); } @@ -267,12 +251,12 @@ function createClientMock() { // @ts-expect-error esClientMock.get.mockImplementation(async ({ id }) => { switch (id) { - case agentInManagedDoc._id: - return { body: agentInManagedDoc }; - case agentInUnmanagedDoc2._id: - return { body: agentInUnmanagedDoc2 }; - case agentInUnmanagedDoc._id: - return { body: agentInUnmanagedDoc }; + case agentInHostedDoc._id: + return { body: agentInHostedDoc }; + case agentInRegularDoc2._id: + return { body: agentInRegularDoc2 }; + case agentInRegularDoc._id: + return { body: agentInRegularDoc }; default: throw new Error('not found'); } @@ -287,12 +271,12 @@ function createClientMock() { // @ts-expect-error const docs = params?.body.docs.map(({ _id }) => { switch (_id) { - case agentInManagedDoc._id: - return agentInManagedDoc; - case agentInUnmanagedDoc2._id: - return agentInUnmanagedDoc2; - case agentInUnmanagedDoc._id: - return agentInUnmanagedDoc; + case agentInHostedDoc._id: + return agentInHostedDoc; + case agentInRegularDoc2._id: + return agentInRegularDoc2; + case agentInRegularDoc._id: + return agentInRegularDoc; default: throw new Error('not found'); } diff --git a/x-pack/plugins/fleet/server/services/agents/unenroll.ts b/x-pack/plugins/fleet/server/services/agents/unenroll.ts index c97dc128de591..fc1f80fe7521b 100644 --- a/x-pack/plugins/fleet/server/services/agents/unenroll.ts +++ b/x-pack/plugins/fleet/server/services/agents/unenroll.ts @@ -29,7 +29,7 @@ async function unenrollAgentIsAllowed( const agentPolicy = await getAgentPolicyForAgent(soClient, esClient, agentId); if (agentPolicy?.is_managed) { throw new AgentUnenrollmentError( - `Cannot unenroll ${agentId} from a managed agent policy ${agentPolicy.id}` + `Cannot unenroll ${agentId} from a hosted agent policy ${agentPolicy.id}` ); } diff --git a/x-pack/plugins/fleet/server/services/agents/upgrade.ts b/x-pack/plugins/fleet/server/services/agents/upgrade.ts index c791a5b7c10ce..61e785828bf23 100644 --- a/x-pack/plugins/fleet/server/services/agents/upgrade.ts +++ b/x-pack/plugins/fleet/server/services/agents/upgrade.ts @@ -47,7 +47,7 @@ export async function sendUpgradeAgentAction({ const agentPolicy = await getAgentPolicyForAgent(soClient, esClient, agentId); if (agentPolicy?.is_managed) { throw new IngestManagerError( - `Cannot upgrade agent ${agentId} in managed policy ${agentPolicy.id}` + `Cannot upgrade agent ${agentId} in hosted agent policy ${agentPolicy.id}` ); } @@ -119,17 +119,17 @@ export async function sendUpgradeAgentsActions( const agentPolicies = await agentPolicyService.getByIDs(soClient, Array.from(policyIdsToGet), { fields: ['is_managed'], }); - const managedPolicies = agentPolicies.reduce>((acc, policy) => { + const hostedPolicies = agentPolicies.reduce>((acc, policy) => { acc[policy.id] = policy.is_managed; return acc; }, {}); - const isManagedAgent = (agent: Agent) => agent.policy_id && managedPolicies[agent.policy_id]; + const isHostedAgent = (agent: Agent) => agent.policy_id && hostedPolicies[agent.policy_id]; - // results from getAgents with options.kuery '' (or even 'active:false') may include managed agents + // results from getAgents with options.kuery '' (or even 'active:false') may include hosted agents // filter them out unless options.force const agentsToCheckUpgradeable = 'kuery' in options && !options.force - ? givenAgents.filter((agent: Agent) => !isManagedAgent(agent)) + ? givenAgents.filter((agent: Agent) => !isHostedAgent(agent)) : givenAgents; const kibanaVersion = appContextService.getKibanaVersion(); @@ -141,8 +141,10 @@ export async function sendUpgradeAgentsActions( throw new IngestManagerError(`${agent.id} is not upgradeable`); } - if (!options.force && isManagedAgent(agent)) { - throw new IngestManagerError(`Cannot upgrade agent in managed policy ${agent.policy_id}`); + if (!options.force && isHostedAgent(agent)) { + throw new IngestManagerError( + `Cannot upgrade agent in hosted agent policy ${agent.policy_id}` + ); } return agent; }) diff --git a/x-pack/plugins/fleet/server/services/package_policy.ts b/x-pack/plugins/fleet/server/services/package_policy.ts index 0857338469794..7c009299a3de3 100644 --- a/x-pack/plugins/fleet/server/services/package_policy.ts +++ b/x-pack/plugins/fleet/server/services/package_policy.ts @@ -76,7 +76,7 @@ class PackagePolicyService { } if (parentAgentPolicy.is_managed && !options?.force) { throw new IngestManagerError( - `Cannot add integrations to managed policy ${parentAgentPolicy.id}` + `Cannot add integrations to hosted agent policy ${parentAgentPolicy.id}` ); } if ( diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 4aeb79384bcfb..fea58eaa05d07 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -23475,4 +23475,4 @@ "xpack.watcher.watchEdit.thresholdWatchExpression.aggType.fieldIsRequiredValidationMessage": "フィールドを選択してください。", "xpack.watcher.watcherDescription": "アラートの作成、管理、監視によりデータへの変更を検知します。" } -} \ No newline at end of file +} diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index f87f793ec1326..d8404a8d282bb 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -23842,4 +23842,4 @@ "xpack.watcher.watchEdit.thresholdWatchExpression.aggType.fieldIsRequiredValidationMessage": "此字段必填。", "xpack.watcher.watcherDescription": "通过创建、管理和监测警报来检测数据中的更改。" } -} \ No newline at end of file +} 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 8dcc3049ccd3a..779c4d767c000 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 @@ -327,37 +327,37 @@ export default function ({ getService }: FtrProviderContext) { after(async () => { await esArchiver.unload('fleet/empty_fleet_server'); }); - let managedPolicy: any | undefined; - it('should prevent managed policies being deleted', async () => { + let hostedPolicy: any | undefined; + it('should prevent hosted policies being deleted', async () => { const { body: { item: createdPolicy }, } = await supertest .post(`/api/fleet/agent_policies`) .set('kbn-xsrf', 'xxxx') .send({ - name: 'Managed policy', + name: 'Hosted policy', namespace: 'default', is_managed: true, }) .expect(200); - managedPolicy = createdPolicy; + hostedPolicy = createdPolicy; const { body } = await supertest .post('/api/fleet/agent_policies/delete') .set('kbn-xsrf', 'xxx') - .send({ agentPolicyId: managedPolicy.id }) + .send({ agentPolicyId: hostedPolicy.id }) .expect(400); - expect(body.message).to.contain('Cannot delete managed policy'); + expect(body.message).to.contain('Cannot delete hosted agent policy'); }); - it('should allow unmanaged policies being deleted', async () => { + it('should allow regular policies being deleted', async () => { const { - body: { item: unmanagedPolicy }, + body: { item: regularPolicy }, } = await supertest - .put(`/api/fleet/agent_policies/${managedPolicy.id}`) + .put(`/api/fleet/agent_policies/${hostedPolicy.id}`) .set('kbn-xsrf', 'xxxx') .send({ - name: 'Unmanaged policy', + name: 'Regular policy', namespace: 'default', is_managed: false, }) @@ -366,11 +366,11 @@ export default function ({ getService }: FtrProviderContext) { const { body } = await supertest .post('/api/fleet/agent_policies/delete') .set('kbn-xsrf', 'xxx') - .send({ agentPolicyId: unmanagedPolicy.id }); + .send({ agentPolicyId: regularPolicy.id }); expect(body).to.eql({ - id: unmanagedPolicy.id, - name: 'Unmanaged policy', + id: regularPolicy.id, + name: 'Regular policy', }); }); }); diff --git a/x-pack/test/fleet_api_integration/apis/agents/reassign.ts b/x-pack/test/fleet_api_integration/apis/agents/reassign.ts index 47bafd57ea3ad..ad3c224bb9236 100644 --- a/x-pack/test/fleet_api_integration/apis/agents/reassign.ts +++ b/x-pack/test/fleet_api_integration/apis/agents/reassign.ts @@ -55,8 +55,8 @@ export default function (providerContext: FtrProviderContext) { .expect(404); }); - it('can reassign from unmanaged policy to unmanaged', async () => { - // policy2 is not managed + it('can reassign from regular agent policy to regular', async () => { + // policy2 is not hosted // reassign succeeds await supertest .put(`/api/fleet/agents/agent1/reassign`) @@ -67,8 +67,8 @@ export default function (providerContext: FtrProviderContext) { .expect(200); }); - it('cannot reassign from unmanaged policy to managed', async () => { - // agent1 is enrolled in policy1. set policy1 to managed + it('cannot reassign from regular agent policy to hosted', async () => { + // agent1 is enrolled in policy1. set policy1 to hosted await supertest .put(`/api/fleet/agent_policies/policy1`) .set('kbn-xsrf', 'xxx') @@ -138,8 +138,8 @@ export default function (providerContext: FtrProviderContext) { expect(agent3data.body.item.policy_id).to.eql('policy2'); }); - it('should allow to reassign multiple agents by id -- mixed invalid, managed, etc', async () => { - // agent1 is enrolled in policy1. set policy1 to managed + it('should allow to reassign multiple agents by id -- mixed invalid, hosted, etc', async () => { + // agent1 is enrolled in policy1. set policy1 to hosted await supertest .put(`/api/fleet/agent_policies/policy1`) .set('kbn-xsrf', 'xxx') @@ -157,7 +157,7 @@ export default function (providerContext: FtrProviderContext) { expect(body).to.eql({ agent2: { success: false, - error: 'Cannot reassign an agent from managed agent policy policy1', + error: 'Cannot reassign an agent from hosted agent policy policy1', }, INVALID_ID: { success: false, @@ -165,7 +165,7 @@ export default function (providerContext: FtrProviderContext) { }, agent3: { success: false, - error: 'Cannot reassign an agent from managed agent policy policy1', + error: 'Cannot reassign an agent from hosted agent policy policy1', }, }); diff --git a/x-pack/test/fleet_api_integration/apis/agents/unenroll.ts b/x-pack/test/fleet_api_integration/apis/agents/unenroll.ts index 60a588090048a..f0e41d75136c3 100644 --- a/x-pack/test/fleet_api_integration/apis/agents/unenroll.ts +++ b/x-pack/test/fleet_api_integration/apis/agents/unenroll.ts @@ -74,8 +74,8 @@ export default function (providerContext: FtrProviderContext) { await esArchiver.unload('fleet/empty_fleet_server'); }); - it('/agents/{agent_id}/unenroll should fail for managed policy', async () => { - // set policy to managed + it('/agents/{agent_id}/unenroll should fail for hosted agent policy', async () => { + // set policy to hosted await supertest .put(`/api/fleet/agent_policies/policy1`) .set('kbn-xsrf', 'xxx') @@ -85,8 +85,8 @@ export default function (providerContext: FtrProviderContext) { await supertest.post(`/api/fleet/agents/agent1/unenroll`).set('kbn-xsrf', 'xxx').expect(400); }); - it('/agents/{agent_id}/unenroll should allow from unmanaged policy', async () => { - // set policy to unmanaged + it('/agents/{agent_id}/unenroll should allow from regular agent policy', async () => { + // set policy to regular await supertest .put(`/api/fleet/agent_policies/policy1`) .set('kbn-xsrf', 'xxx') @@ -117,8 +117,8 @@ export default function (providerContext: FtrProviderContext) { expect(outputAPIKeys[0].invalidated).eql(true); }); - it('/agents/bulk_unenroll should not allow unenroll from managed policy', async () => { - // set policy to managed + it('/agents/bulk_unenroll should not allow unenroll from hosted agent policy', async () => { + // set policy to hosted await supertest .put(`/api/fleet/agent_policies/policy1`) .set('kbn-xsrf', 'xxx') @@ -138,11 +138,11 @@ export default function (providerContext: FtrProviderContext) { expect(unenrolledBody).to.eql({ agent2: { success: false, - error: 'Cannot unenroll agent2 from a managed agent policy policy1', + error: 'Cannot unenroll agent2 from a hosted agent policy policy1', }, agent3: { success: false, - error: 'Cannot unenroll agent3 from a managed agent policy policy1', + error: 'Cannot unenroll agent3 from a hosted agent policy policy1', }, }); // but agents are still enrolled @@ -158,8 +158,8 @@ export default function (providerContext: FtrProviderContext) { expect(agent2data.body.item.active).to.eql(true); }); - it('/agents/bulk_unenroll should allow to unenroll multiple agents by id from an unmanaged policy', async () => { - // set policy to unmanaged + it('/agents/bulk_unenroll should allow to unenroll multiple agents by id from an regular agent policy', async () => { + // set policy to regular await supertest .put(`/api/fleet/agent_policies/policy1`) .set('kbn-xsrf', 'xxx') diff --git a/x-pack/test/fleet_api_integration/apis/agents/upgrade.ts b/x-pack/test/fleet_api_integration/apis/agents/upgrade.ts index 545399134c79d..142c360e9232a 100644 --- a/x-pack/test/fleet_api_integration/apis/agents/upgrade.ts +++ b/x-pack/test/fleet_api_integration/apis/agents/upgrade.ts @@ -210,8 +210,8 @@ export default function (providerContext: FtrProviderContext) { expect(res.body.message).to.equal('agent agent1 is not upgradeable'); }); - it('enrolled in a managed policy should respond 400 to upgrade and not update the agent SOs', async () => { - // update enrolled policy to managed + it('enrolled in a hosted agent policy should respond 400 to upgrade and not update the agent SOs', async () => { + // update enrolled policy to hosted await supertest.put(`/api/fleet/agent_policies/policy1`).set('kbn-xsrf', 'xxxx').send({ name: 'Test policy', namespace: 'default', @@ -229,13 +229,15 @@ export default function (providerContext: FtrProviderContext) { }, }, }); - // attempt to upgrade agent in managed policy + // attempt to upgrade agent in hosted agent policy const { body } = await supertest .post(`/api/fleet/agents/agent1/upgrade`) .set('kbn-xsrf', 'xxx') .send({ version: kibanaVersion }) .expect(400); - expect(body.message).to.contain('Cannot upgrade agent agent1 in managed policy policy1'); + expect(body.message).to.contain( + 'Cannot upgrade agent agent1 in hosted agent policy policy1' + ); const agent1data = await supertest.get(`/api/fleet/agents/agent1`); expect(typeof agent1data.body.item.upgrade_started_at).to.be('undefined'); @@ -543,12 +545,12 @@ export default function (providerContext: FtrProviderContext) { .expect(400); }); - it('enrolled in a managed policy bulk upgrade should respond with 200 and object of results. Should not update the managed agent SOs', async () => { - // move agent2 to policy2 to keep it unmanaged + it('enrolled in a hosted agent policy bulk upgrade should respond with 200 and object of results. Should not update the hosted agent SOs', async () => { + // move agent2 to policy2 to keep it regular await supertest.put(`/api/fleet/agents/agent2/reassign`).set('kbn-xsrf', 'xxx').send({ policy_id: 'policy2', }); - // update enrolled policy to managed + // update enrolled policy to hosted await supertest.put(`/api/fleet/agent_policies/policy1`).set('kbn-xsrf', 'xxxx').send({ name: 'Test policy', namespace: 'default', @@ -580,7 +582,7 @@ export default function (providerContext: FtrProviderContext) { }, }, }); - // attempt to upgrade agent in managed policy + // attempt to upgrade agent in hosted agent policy const { body } = await supertest .post(`/api/fleet/agents/bulk_upgrade`) .set('kbn-xsrf', 'xxx') @@ -591,7 +593,7 @@ export default function (providerContext: FtrProviderContext) { .expect(200); expect(body).to.eql({ - agent1: { success: false, error: 'Cannot upgrade agent in managed policy policy1' }, + agent1: { success: false, error: 'Cannot upgrade agent in hosted agent policy policy1' }, agent2: { success: true }, }); @@ -604,8 +606,8 @@ export default function (providerContext: FtrProviderContext) { expect(typeof agent2data.body.item.upgrade_started_at).to.be('string'); }); - it('enrolled in a managed policy bulk upgrade with force flag should respond with 200 and update the agent SOs', async () => { - // update enrolled policy to managed + it('enrolled in a hosted agent policy bulk upgrade with force flag should respond with 200 and update the agent SOs', async () => { + // update enrolled policy to hosted await supertest.put(`/api/fleet/agent_policies/policy1`).set('kbn-xsrf', 'xxxx').send({ name: 'Test policy', namespace: 'default', @@ -637,7 +639,7 @@ export default function (providerContext: FtrProviderContext) { }, }, }); - // attempt to upgrade agent in managed policy + // attempt to upgrade agent in hosted agent policy const { body } = await supertest .post(`/api/fleet/agents/bulk_upgrade`) .set('kbn-xsrf', 'xxx') diff --git a/x-pack/test/fleet_api_integration/apis/package_policy/create.ts b/x-pack/test/fleet_api_integration/apis/package_policy/create.ts index e2e1cc2f584bb..27c5328b3ab08 100644 --- a/x-pack/test/fleet_api_integration/apis/package_policy/create.ts +++ b/x-pack/test/fleet_api_integration/apis/package_policy/create.ts @@ -46,20 +46,20 @@ export default function (providerContext: FtrProviderContext) { .send({ agentPolicyId }); }); - it('can only add to managed agent policies using the force parameter', async function () { - // get a managed policy + it('can only add to hosted agent policies using the force parameter', async function () { + // get a hosted policy const { - body: { item: managedPolicy }, + body: { item: hostedPolicy }, } = await supertest .post(`/api/fleet/agent_policies`) .set('kbn-xsrf', 'xxxx') .send({ - name: `Managed policy from ${Date.now()}`, + name: `Hosted policy from ${Date.now()}`, namespace: 'default', is_managed: true, }); - // try to add an integration to the managed policy + // try to add an integration to the hosted policy const { body: responseWithoutForce } = await supertest .post(`/api/fleet/package_policies`) .set('kbn-xsrf', 'xxxx') @@ -67,7 +67,7 @@ export default function (providerContext: FtrProviderContext) { name: 'filetest-1', description: '', namespace: 'default', - policy_id: managedPolicy.id, + policy_id: hostedPolicy.id, enabled: true, output_id: '', inputs: [], @@ -80,7 +80,9 @@ export default function (providerContext: FtrProviderContext) { .expect(400); expect(responseWithoutForce.statusCode).to.be(400); - expect(responseWithoutForce.message).to.contain('Cannot add integrations to managed policy'); + expect(responseWithoutForce.message).to.contain( + 'Cannot add integrations to hosted agent policy' + ); // try same request with `force: true` const { body: responseWithForce } = await supertest @@ -91,7 +93,7 @@ export default function (providerContext: FtrProviderContext) { name: 'filetest-1', description: '', namespace: 'default', - policy_id: managedPolicy.id, + policy_id: hostedPolicy.id, enabled: true, output_id: '', inputs: [], @@ -107,7 +109,7 @@ export default function (providerContext: FtrProviderContext) { // delete policy we just made await supertest.post(`/api/fleet/agent_policies/delete`).set('kbn-xsrf', 'xxxx').send({ - agentPolicyId: managedPolicy.id, + agentPolicyId: hostedPolicy.id, }); }); diff --git a/x-pack/test/fleet_api_integration/apis/package_policy/delete.ts b/x-pack/test/fleet_api_integration/apis/package_policy/delete.ts index 15aba758c85d0..5889349f57fa0 100644 --- a/x-pack/test/fleet_api_integration/apis/package_policy/delete.ts +++ b/x-pack/test/fleet_api_integration/apis/package_policy/delete.ts @@ -87,8 +87,8 @@ export default function (providerContext: FtrProviderContext) { await getService('esArchiver').unload('fleet/empty_fleet_server'); }); - it('should fail on managed agent policies', async function () { - // update existing policy to managed + it('should fail on hosted agent policies', async function () { + // update existing policy to hosted await supertest .put(`/api/fleet/agent_policies/${agentPolicy.id}`) .set('kbn-xsrf', 'xxxx') @@ -110,7 +110,9 @@ export default function (providerContext: FtrProviderContext) { expect(Array.isArray(results)); expect(results.length).to.be(1); expect(results[0].success).to.be(false); - expect(results[0].body.message).to.contain('Cannot remove integrations of managed policy'); + expect(results[0].body.message).to.contain( + 'Cannot remove integrations of hosted agent policy' + ); // same, but with force const { body: resultsWithForce } = await supertest @@ -124,7 +126,7 @@ export default function (providerContext: FtrProviderContext) { expect(resultsWithForce.length).to.be(1); expect(resultsWithForce[0].success).to.be(true); - // revert existing policy to unmanaged + // revert existing policy to regular await supertest .put(`/api/fleet/agent_policies/${agentPolicy.id}`) .set('kbn-xsrf', 'xxxx') @@ -136,7 +138,7 @@ export default function (providerContext: FtrProviderContext) { .expect(200); }); - it('should work for unmanaged policies', async function () { + it('should work for regular policies', async function () { await supertest .post(`/api/fleet/package_policies/delete`) .set('kbn-xsrf', 'xxxx') 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 6e6a475cd4824..5a0ff90669def 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 @@ -46,7 +46,7 @@ export default function (providerContext: FtrProviderContext) { .post(`/api/fleet/agent_policies`) .set('kbn-xsrf', 'xxxx') .send({ - name: 'Test managed policy', + name: 'Test hosted agent policy', namespace: 'default', is_managed: true, });