mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 19:13:14 -04:00
## 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>
106 lines
4.2 KiB
TypeScript
106 lines
4.2 KiB
TypeScript
/*
|
|
* 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 path from 'path';
|
|
|
|
import {
|
|
fleetPackageRegistryDockerImage,
|
|
FtrConfigProviderContext,
|
|
defineDockerServersConfig,
|
|
getKibanaCliLoggers,
|
|
} from '@kbn/test';
|
|
|
|
const getFullPath = (relativePath: string) => path.join(path.dirname(__filename), relativePath);
|
|
|
|
export const BUNDLED_PACKAGE_DIR = '/tmp/fleet_bundled_packages';
|
|
|
|
export default async function ({ readConfigFile, log }: FtrConfigProviderContext) {
|
|
const xPackAPITestsConfig = await readConfigFile(require.resolve('../api_integration/config.ts'));
|
|
|
|
const registryPort: string | undefined = process.env.FLEET_PACKAGE_REGISTRY_PORT;
|
|
const skipRunningDockerRegistry =
|
|
process.env.FLEET_SKIP_RUNNING_PACKAGE_REGISTRY === 'true' ? true : false;
|
|
|
|
// mount the config file for the package registry as well as
|
|
// the directories containing additional packages into the container
|
|
const volumes = {
|
|
// src : dest
|
|
'./apis/fixtures/package_registry_config.yml': '/package-registry/config.yml',
|
|
'./apis/fixtures/test_packages': '/packages/test-packages',
|
|
'./apis/fixtures/package_verification/packages/zips': '/packages/signed-test-packages',
|
|
};
|
|
const dockerArgs: string[] = Object.entries(volumes).flatMap(([src, dest]) => [
|
|
'-v',
|
|
`${getFullPath(src)}:${dest}`,
|
|
]);
|
|
|
|
const dockerServers = !skipRunningDockerRegistry
|
|
? defineDockerServersConfig({
|
|
registry: {
|
|
enabled: !!registryPort,
|
|
image: fleetPackageRegistryDockerImage,
|
|
portInContainer: 8080,
|
|
port: registryPort,
|
|
args: dockerArgs,
|
|
waitForLogLine: 'package manifests loaded',
|
|
waitForLogLineTimeoutMs: 60 * 2 * 10000, // 2 minutes
|
|
},
|
|
})
|
|
: undefined;
|
|
|
|
if (skipRunningDockerRegistry) {
|
|
const cmd = `docker run ${dockerArgs.join(
|
|
' '
|
|
)} -p ${registryPort}:8080 ${fleetPackageRegistryDockerImage}`;
|
|
log.warning(`Not running docker registry, you can run it with the following command: ${cmd}`);
|
|
}
|
|
|
|
return {
|
|
servers: xPackAPITestsConfig.get('servers'),
|
|
dockerServers,
|
|
services: xPackAPITestsConfig.get('services'),
|
|
esTestCluster: {
|
|
...xPackAPITestsConfig.get('esTestCluster'),
|
|
serverArgs: [...xPackAPITestsConfig.get('esTestCluster.serverArgs'), 'http.host=0.0.0.0'],
|
|
},
|
|
kbnTestServer: {
|
|
...xPackAPITestsConfig.get('kbnTestServer'),
|
|
serverArgs: [
|
|
...xPackAPITestsConfig.get('kbnTestServer.serverArgs'),
|
|
// always install Endpoint package by default when Fleet sets up
|
|
`--xpack.fleet.packages.0.name=endpoint`,
|
|
`--xpack.fleet.packages.0.version=latest`,
|
|
...(registryPort ? [`--xpack.fleet.registryUrl=http://localhost:${registryPort}`] : []),
|
|
`--xpack.fleet.developer.bundledPackageLocation=${BUNDLED_PACKAGE_DIR}`,
|
|
`--xpack.fleet.developer.disableBundledPackagesCache=true`,
|
|
'--xpack.cloudSecurityPosture.enabled=true',
|
|
`--xpack.fleet.developer.maxAgentPoliciesWithInactivityTimeout=10`,
|
|
`--xpack.fleet.packageVerification.gpgKeyPath=${getFullPath(
|
|
'./apis/fixtures/package_verification/signatures/fleet_test_key_public.asc'
|
|
)}`,
|
|
`--xpack.securitySolution.enableExperimental=${JSON.stringify(['endpointRbacEnabled'])}`,
|
|
`--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`,
|
|
`--xpack.fleet.agentless.api.tls.certificate=./config/node.crt`,
|
|
`--xpack.fleet.agentless.api.tls.key=./config/node.key`,
|
|
`--xpack.fleet.agentless.api.tls.ca=./config/ca.crt`,
|
|
`--logging.loggers=${JSON.stringify([
|
|
...getKibanaCliLoggers(xPackAPITestsConfig.get('kbnTestServer.serverArgs')),
|
|
|
|
// Enable debug fleet logs by default
|
|
{
|
|
name: 'plugins.fleet',
|
|
level: 'debug',
|
|
appenders: ['default'],
|
|
},
|
|
])}`,
|
|
],
|
|
},
|
|
};
|
|
}
|