[Fleet] Added required_versions to agent policy and API with validation (#206600)

## Summary

Part of https://github.com/elastic/ingest-dev/issues/4721

Added `required_versions` to agent policy and API with validation, added
unit tests for the validation.

UI change will come in another pr

To test:
- enable FF in `kibana.dev.yml`
  - `xpack.fleet.enableExperimental: ['enableAutomaticAgentUpgrades']`
- create/update an agent policy with `required_versions`
- add to preconfiguration
- `required_versions` is not added to the full agent policy in
`.fleet-policies`

```
POST kbn:/api/fleet/agent_policies
{
  "name": "Test versions",
  "namespace": "default",
    "required_versions": [
      {
        "version": "9.0.0",
        "percentage": 5
      }
    ]
}

POST kbn:/api/fleet/agent_policies
{
  "name": "Test versions 2",
  "namespace": "default",
    "required_versions": [
      {
        "version": "9.0.0",
        "percentage": 5
      },
      {
        "version": "9.0.0",
        "percentage": 5
      }
    ]
}

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": """Policy "Test versions 2" failed validation: duplicate versions not allowed in required_versions"""
}

PUT kbn:/api/fleet/agent_policies/fleet-first-agent-policy
{
  "name": "My first agent policy",
  "namespace": "default",
    "required_versions": [
      {
        "version": "8.18.0",
        "percentage": 10
      },
      {
        "version": "8.19.0",
        "percentage": 5
      }
    ]
}

GET kbn:/api/fleet/agent_policies/test-preconfigured

GET .fleet-policies/_search?q=policy_id:fleet-first-agent-policy
{
  "size": 1, 
  "sort": [
    {
      "revision_idx": {
        "order": "desc"
      }
    }
  ]
}


# test preconfigured policy

xpack.fleet.agentPolicies:

  - name: Test preconfigured
    id: test-preconfigured
    is_managed: true
    namespace: default
    monitoring_enabled: []
    package_policies: []
    required_versions:
      - version: "9.0.0"
        percentage: 10
      - version: "9.1.0"
        percentage: 5
```

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Julia Bardi 2025-01-16 09:18:34 +01:00 committed by GitHub
parent 362f2dd9b0
commit c272951bfb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 933 additions and 9 deletions

View file

@ -9848,6 +9848,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -10204,6 +10228,30 @@
"nullable": true,
"type": "object"
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"space_ids": {
"items": {
"type": "string"
@ -10861,6 +10909,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -11646,6 +11718,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -12667,6 +12763,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -13021,6 +13141,30 @@
"nullable": true,
"type": "object"
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"space_ids": {
"items": {
"type": "string"
@ -13678,6 +13822,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -14463,6 +14631,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},

View file

@ -9848,6 +9848,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -10204,6 +10228,30 @@
"nullable": true,
"type": "object"
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"space_ids": {
"items": {
"type": "string"
@ -10861,6 +10909,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -11646,6 +11718,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -12667,6 +12763,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -13021,6 +13141,30 @@
"nullable": true,
"type": "object"
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"space_ids": {
"items": {
"type": "string"
@ -13678,6 +13822,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},
@ -14463,6 +14631,30 @@
}
]
},
"required_versions": {
"items": {
"additionalProperties": false,
"properties": {
"percentage": {
"description": "Target percentage of agents to auto upgrade",
"maximum": 100,
"minimum": 0,
"type": "number"
},
"version": {
"description": "Target version for automatic agent upgrade",
"type": "string"
}
},
"required": [
"version",
"percentage"
],
"type": "object"
},
"nullable": true,
"type": "array"
},
"revision": {
"type": "number"
},

View file

@ -12116,6 +12116,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -12360,6 +12378,24 @@ paths:
description: Override settings that are defined in the agent policy. Input settings cannot be overridden. The override option should be used only in unusual circumstances and not as a routine procedure.
nullable: true
type: object
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
space_ids:
items:
type: string
@ -12819,6 +12855,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -13364,6 +13418,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -13888,6 +13960,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -14130,6 +14220,24 @@ paths:
description: Override settings that are defined in the agent policy. Input settings cannot be overridden. The override option should be used only in unusual circumstances and not as a routine procedure.
nullable: true
type: object
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
space_ids:
items:
type: string
@ -14589,6 +14697,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -15133,6 +15259,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:

View file

@ -14257,6 +14257,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -14500,6 +14518,24 @@ paths:
description: Override settings that are defined in the agent policy. Input settings cannot be overridden. The override option should be used only in unusual circumstances and not as a routine procedure.
nullable: true
type: object
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
space_ids:
items:
type: string
@ -14959,6 +14995,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -15503,6 +15557,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -16026,6 +16098,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -16267,6 +16357,24 @@ paths:
description: Override settings that are defined in the agent policy. Input settings cannot be overridden. The override option should be used only in unusual circumstances and not as a routine procedure.
nullable: true
type: object
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
space_ids:
items:
type: string
@ -16726,6 +16834,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:
@ -17269,6 +17395,24 @@ paths:
- created_at
- created_by
type: array
required_versions:
items:
additionalProperties: false
type: object
properties:
percentage:
description: Target percentage of agents to auto upgrade
maximum: 100
minimum: 0
type: number
version:
description: Target version for automatic agent upgrade
type: string
required:
- version
- percentage
nullable: true
type: array
revision:
type: number
schema_version:

View file

@ -10,6 +10,7 @@ export type ExperimentalFeatures = typeof allowedExperimentalValues;
const _allowedExperimentalValues = {
showExperimentalShipperOptions: false,
useSpaceAwareness: false,
enableAutomaticAgentUpgrades: false,
};
/**

View file

@ -64,6 +64,12 @@ export interface NewAgentPolicy {
max_dur?: string;
};
};
required_versions?: AgentTargetVersion[] | null;
}
export interface AgentTargetVersion {
version: string;
percentage: number;
}
export interface GlobalDataTag {

View file

@ -13,8 +13,6 @@ At the time of writing, this can be achieved by adding the following to your `ki
# Emulate cloud
xpack.cloud.id: "123456789"
# Enable agentless experimental feature flag in Fleet
xpack.fleet.enableExperimental: ['agentless']
# Agentless Fleet config
xpack.fleet.agentless.enabled: true
xpack.fleet.agentless.api.url: 'https://api.agentless.url/api/v1/ess'

View file

@ -11,3 +11,4 @@ export {
storedPackagePoliciesToAgentInputs,
} from './package_policies_to_agent_inputs';
export { getDataOutputForAgentPolicy, validateOutputForPolicy } from './outputs_helpers';
export { validateRequiredVersions } from './required_versions';

View file

@ -0,0 +1,85 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { appContextService } from '..';
import { AgentPolicyInvalidError } from '../../errors';
import { validateRequiredVersions } from './required_versions';
describe('validateRequiredVersions', () => {
it('should throw error if feature flag is disabled', () => {
jest
.spyOn(appContextService, 'getExperimentalFeatures')
.mockReturnValue({ enableAutomaticAgentUpgrades: false } as any);
expect(() => {
validateRequiredVersions('test policy', [{ version: '9.0.0', percentage: 100 }]);
}).toThrow(
new AgentPolicyInvalidError(
`Policy "test policy" failed validation: required_versions are not allowed when automatic upgrades feature is disabled`
)
);
});
describe('feature flag enabled', () => {
beforeEach(() => {
jest
.spyOn(appContextService, 'getExperimentalFeatures')
.mockReturnValue({ enableAutomaticAgentUpgrades: true } as any);
});
it('should throw error if duplicate versions', () => {
expect(() => {
validateRequiredVersions('test policy', [
{ version: '9.0.0', percentage: 10 },
{ version: '9.0.0', percentage: 10 },
]);
}).toThrow(
new AgentPolicyInvalidError(
`Policy "test policy" failed validation: duplicate versions not allowed in required_versions`
)
);
});
it('should throw error if has invalid semver version', () => {
expect(() => {
validateRequiredVersions('test policy', [
{ version: '9.0.0', percentage: 10 },
{ version: '9.0.0invalid', percentage: 10 },
]);
}).toThrow(
new AgentPolicyInvalidError(
`Policy "test policy" failed validation: invalid semver version 9.0.0invalid in required_versions`
)
);
});
it('should throw error if sum of percentages exceeds 100', () => {
expect(() => {
validateRequiredVersions('test policy', [
{ version: '9.0.0', percentage: 100 },
{ version: '9.1.0', percentage: 10 },
]);
}).toThrow(
new AgentPolicyInvalidError(
`Policy "test policy" failed validation: sum of required_versions percentages cannot exceed 100`
)
);
});
it('should not throw error if valid required_versions', () => {
validateRequiredVersions('test policy', [
{ version: '9.0.0', percentage: 90 },
{ version: '9.1.0', percentage: 10 },
]);
});
it('should not throw error if required_versions undefined', () => {
validateRequiredVersions('test policy');
});
});
});

View file

@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import semverValid from 'semver/functions/valid';
import type { AgentTargetVersion } from '../../../common/types';
import { AgentPolicyInvalidError } from '../../errors';
import { appContextService } from '..';
export function validateRequiredVersions(
name: string,
requiredVersions?: AgentTargetVersion[] | null
): void {
if (!requiredVersions) {
return;
}
if (!appContextService.getExperimentalFeatures().enableAutomaticAgentUpgrades) {
throw new AgentPolicyInvalidError(
`Policy "${name}" failed validation: required_versions are not allowed when automatic upgrades feature is disabled`
);
}
const versions = requiredVersions.map((v) => v.version);
const uniqueVersions = new Set(versions);
if (versions.length !== uniqueVersions.size) {
throw new AgentPolicyInvalidError(
`Policy "${name}" failed validation: duplicate versions not allowed in required_versions`
);
}
versions.forEach((version) => {
if (!semverValid(version)) {
throw new AgentPolicyInvalidError(
`Policy "${name}" failed validation: invalid semver version ${version} in required_versions`
);
}
});
const sumOfPercentages = requiredVersions.reduce((acc, v) => acc + v.percentage, 0);
if (sumOfPercentages > 100) {
throw new AgentPolicyInvalidError(
`Policy "${name}" failed validation: sum of required_versions percentages cannot exceed 100`
);
}
}

View file

@ -116,7 +116,11 @@ import { incrementPackagePolicyCopyName } from './package_policies';
import { outputService } from './output';
import { agentPolicyUpdateEventHandler } from './agent_policy_update';
import { escapeSearchQueryPhrase, normalizeKuery as _normalizeKuery } from './saved_object';
import { getFullAgentPolicy, validateOutputForPolicy } from './agent_policies';
import {
getFullAgentPolicy,
validateOutputForPolicy,
validateRequiredVersions,
} from './agent_policies';
import { auditLoggingService } from './audit_logging';
import { licenseService } from './license';
import { createSoFindIterable } from './utils/create_so_find_iterable';
@ -409,6 +413,7 @@ class AgentPolicyService {
namespace: agentPolicy.namespace,
});
await validateOutputForPolicy(soClient, agentPolicy);
validateRequiredVersions(agentPolicy.name, agentPolicy.required_versions);
const newSo = await soClient.create<AgentPolicySOAttributes>(
savedObjectType,
@ -709,6 +714,7 @@ class AgentPolicyService {
namespace: agentPolicy.namespace,
});
}
validateRequiredVersions(agentPolicy.name ?? id, agentPolicy.required_versions);
const existingAgentPolicy = await this.get(soClient, id, true);

View file

@ -158,6 +158,27 @@ export const AgentPolicyBaseSchema = {
),
})
),
required_versions: schema.maybe(
schema.oneOf([
schema.literal(null),
schema.arrayOf(
schema.object({
version: schema.string({
meta: {
description: 'Target version for automatic agent upgrade',
},
}),
percentage: schema.number({
min: 0,
max: 100,
meta: {
description: 'Target percentage of agents to auto upgrade',
},
}),
})
),
])
),
};
function validateGlobalDataTagInput(tags: GlobalDataTag[]): string | undefined {

View file

@ -1536,6 +1536,98 @@ export default function (providerContext: FtrProviderContext) {
expect(updatedPolicy.global_data_tags).to.eql([{ name: 'newTag', value: 'newValue' }]);
});
it('should allow to set required_versions', async () => {
const {
body: { item: originalPolicy },
} = await supertest
.post(`/api/fleet/agent_policies`)
.set('kbn-xsrf', 'xxxx')
.send({
name: `Override Test ${Date.now()}`,
description: 'Initial description',
namespace: 'default',
})
.expect(200);
agentPolicyId = originalPolicy.id;
createdPolicyIds.push(agentPolicyId as string);
const {
body: { item: updatedPolicy },
} = await supertest
.put(`/api/fleet/agent_policies/${agentPolicyId}`)
.set('kbn-xsrf', 'xxxx')
.send({
name: originalPolicy.name,
description: originalPolicy.description,
namespace: 'default',
required_versions: [
{
version: '9.0.0',
percentage: 10,
},
],
})
.expect(200);
// eslint-disable-next-line @typescript-eslint/naming-convention
const { id, updated_at, version, ...newPolicy } = updatedPolicy;
expect(newPolicy).to.eql({
status: 'active',
name: originalPolicy.name,
description: originalPolicy.description,
namespace: 'default',
is_managed: false,
revision: 2,
schema_version: FLEET_AGENT_POLICIES_SCHEMA_VERSION,
updated_by: 'elastic',
inactivity_timeout: 1209600,
package_policies: [],
is_protected: false,
space_ids: [],
required_versions: [
{
version: '9.0.0',
percentage: 10,
},
],
});
});
it('should not allow to set invalid required_versions', async () => {
const {
body: { item: originalPolicy },
} = await supertest
.post(`/api/fleet/agent_policies`)
.set('kbn-xsrf', 'xxxx')
.send({
name: `Override Test ${Date.now()}`,
description: 'Initial description',
namespace: 'default',
})
.expect(200);
agentPolicyId = originalPolicy.id;
createdPolicyIds.push(agentPolicyId as string);
await supertest
.put(`/api/fleet/agent_policies/${agentPolicyId}`)
.set('kbn-xsrf', 'xxxx')
.send({
name: `Override Test ${Date.now()}`,
description: 'Updated description',
namespace: 'default',
required_versions: [
{
version: '9.0.0',
percentage: 50,
},
{
version: '9.1.0',
percentage: 60,
},
],
})
.expect(400);
});
});
describe('POST /api/fleet/agent_policies/delete', () => {

View file

@ -83,12 +83,7 @@ export default async function ({ readConfigFile, log }: FtrConfigProviderContext
'./apis/fixtures/package_verification/signatures/fleet_test_key_public.asc'
)}`,
`--xpack.securitySolution.enableExperimental=${JSON.stringify(['endpointRbacEnabled'])}`,
`--xpack.fleet.enableExperimental=${JSON.stringify([
'outputSecretsStorage',
'agentTamperProtectionEnabled',
'enableStrictKQLValidation',
'subfeaturePrivileges',
])}`,
`--xpack.fleet.enableExperimental=${JSON.stringify(['enableAutomaticAgentUpgrades'])}`,
`--xpack.cloud.id='123456789'`,
`--xpack.fleet.agentless.enabled=true`,
`--xpack.fleet.agentless.api.url=https://api.agentless.url/api/v1/ess`,