Skip to content

Commit 831b895

Browse files
[8.19] [Fleet] Remove agent policies revision bump after updating settings (elastic#239977) (elastic#240468)
# Backport This will backport the following commits from `main` to `8.19`: - [[Fleet] Remove agent policies revision bump after updating settings (elastic#239977)](elastic#239977) <!--- Backport version: 10.1.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Nicolas Chaulet","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-22T14:47:47Z","message":"[Fleet] Remove agent policies revision bump after updating settings (elastic#239977)","sha":"f0912d36b342aa7a7b7e8e3084b5b88a888bab55","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport missing","Team:Fleet","backport:version","v9.2.0","v9.3.0","v9.1.6","v8.19.6","v9.0.9"],"title":"[Fleet] Remove agent policies revision bump after updating settings","number":239977,"url":"https://github.com/elastic/kibana/pull/239977","mergeCommit":{"message":"[Fleet] Remove agent policies revision bump after updating settings (elastic#239977)","sha":"f0912d36b342aa7a7b7e8e3084b5b88a888bab55"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","9.0"],"targetPullRequestStates":[{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/240116","number":240116,"state":"OPEN"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/239977","number":239977,"mergeCommit":{"message":"[Fleet] Remove agent policies revision bump after updating settings (elastic#239977)","sha":"f0912d36b342aa7a7b7e8e3084b5b88a888bab55"}},{"branch":"9.1","label":"v9.1.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 88969f2 commit 831b895

File tree

6 files changed

+107
-63
lines changed

6 files changed

+107
-63
lines changed

x-pack/platform/plugins/shared/fleet/server/routes/settings/settings_handler.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
PutSettingsRequestSchema,
1313
PutSpaceSettingsRequestSchema,
1414
} from '../../types';
15-
import { settingsService, agentPolicyService, appContextService } from '../../services';
15+
import { settingsService } from '../../services';
1616
import { getSpaceSettings, saveSpaceSettings } from '../../services/spaces/space_settings';
1717

1818
export const getSpaceSettingsHandler: FleetRequestHandler = async (context, request, response) => {
@@ -69,12 +69,10 @@ export const putSettingsHandler: FleetRequestHandler<
6969
TypeOf<typeof PutSettingsRequestSchema.body>
7070
> = async (context, request, response) => {
7171
const soClient = (await context.fleet).internalSoClient;
72-
const esClient = (await context.core).elasticsearch.client.asInternalUser;
73-
const user = appContextService.getSecurityCore().authc.getCurrentUser(request) || undefined;
7472

7573
try {
7674
const settings = await settingsService.saveSettings(soClient, request.body);
77-
await agentPolicyService.bumpAllAgentPolicies(esClient, { user });
75+
7876
const body = {
7977
item: settings,
8078
};

x-pack/platform/plugins/shared/fleet/server/types/rest_spec/settings.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,18 @@ export const PutSettingsRequestSchema = {
3232
return 'Protocol and path must be the same for each URL';
3333
}
3434
},
35+
meta: {
36+
deprecated: true,
37+
},
38+
})
39+
),
40+
kibana_ca_sha256: schema.maybe(
41+
schema.string({
42+
meta: {
43+
deprecated: true,
44+
},
3545
})
3646
),
37-
kibana_ca_sha256: schema.maybe(schema.string()),
3847
prerelease_integrations_enabled: schema.maybe(schema.boolean()),
3948
delete_unenrolled_agents: schema.maybe(
4049
schema.object({

x-pack/platform/test/fleet_api_integration/apis/settings/get.ts

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import expect from '@kbn/expect';
9+
import type { CreateAgentPolicyResponse } from '@kbn/fleet-plugin/common';
10+
11+
import type { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
12+
import { skipIfNoDockerRegistry } from '../../helpers';
13+
import { SpaceTestApiClient } from '../space_awareness/api_helper';
14+
15+
export default function (providerContext: FtrProviderContext) {
16+
const { getService } = providerContext;
17+
const supertest = getService('supertest');
18+
const kibanaServer = getService('kibanaServer');
19+
const fleetAndAgents = getService('fleetAndAgents');
20+
const apiClient = new SpaceTestApiClient(supertest);
21+
22+
describe('Global Settings', function () {
23+
skipIfNoDockerRegistry(providerContext);
24+
25+
let agentPolicy: CreateAgentPolicyResponse;
26+
before(async () => {
27+
await kibanaServer.savedObjects.cleanStandardList();
28+
await fleetAndAgents.setup();
29+
30+
agentPolicy = await apiClient.createAgentPolicy();
31+
});
32+
33+
after(async () => {
34+
await kibanaServer.savedObjects.cleanStandardList();
35+
});
36+
37+
it('should respond return settings', async function () {
38+
await apiClient.getSettings();
39+
});
40+
41+
it('should allow to save settings', async function () {
42+
await apiClient.putSettings({
43+
prerelease_integrations_enabled: true,
44+
});
45+
46+
const updatedSettings = await apiClient.getSettings();
47+
expect(updatedSettings.item.prerelease_integrations_enabled).to.be(true);
48+
49+
// it should not bump revision
50+
const updatedAgentPolicy = await apiClient.getAgentPolicy(agentPolicy.item.id);
51+
expect(updatedAgentPolicy.item.revision).to.be(agentPolicy.item.revision);
52+
});
53+
});
54+
}

x-pack/platform/test/fleet_api_integration/apis/settings/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
export default function loadTests({ loadTestFile }) {
99
describe('Settings Endpoints', () => {
10-
loadTestFile(require.resolve('./get'));
1110
loadTestFile(require.resolve('./update'));
11+
loadTestFile(require.resolve('./global_settings'));
1212
loadTestFile(require.resolve('./enrollment'));
1313
loadTestFile(require.resolve('./enrollment_privileges'));
1414
});

x-pack/platform/test/fleet_api_integration/apis/space_awareness/api_helper.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { v4 as uuidV4 } from 'uuid';
9-
import type { Agent } from 'supertest';
9+
import type { Agent, Response } from 'supertest';
1010
import {
1111
CreateAgentPolicyRequest,
1212
CreateAgentPolicyResponse,
@@ -39,6 +39,8 @@ import {
3939
PostFleetServerHostsResponse,
4040
PostOutputRequest,
4141
GetOneOutputResponse,
42+
GetSettingsResponse,
43+
PutSettingsRequest,
4244
} from '@kbn/fleet-plugin/common/types';
4345
import {
4446
GetUninstallTokenResponse,
@@ -47,6 +49,22 @@ import {
4749
import { SimplifiedPackagePolicy } from '@kbn/fleet-plugin/common/services/simplified_package_policy_helper';
4850
import { testUsers } from '../test_users';
4951

52+
function expectStatusCode200(res: Response) {
53+
if (res.statusCode === 200) {
54+
return;
55+
}
56+
57+
if (res.statusCode === 404) {
58+
throw new Error('404 "Not Found"');
59+
} else {
60+
throw new Error(
61+
`${res.statusCode}${res.body?.error ? ` "${res.body?.error}"` : ''}${
62+
res.body?.message ? ` ${res.body?.message}` : ''
63+
}`
64+
);
65+
}
66+
}
67+
5068
export class SpaceTestApiClient {
5169
constructor(
5270
private readonly supertest: Agent,
@@ -375,6 +393,27 @@ export class SpaceTestApiClient {
375393

376394
return res;
377395
}
396+
// Settings
397+
async getSettings(spaceId?: string): Promise<GetSettingsResponse> {
398+
const res = await this.supertest.get(`${this.getBaseUrl(spaceId)}/api/fleet/settings`);
399+
400+
expectStatusCode200(res);
401+
402+
return res.body;
403+
}
404+
async putSettings(
405+
data: PutSettingsRequest['body'],
406+
spaceId?: string
407+
): Promise<GetSettingsResponse> {
408+
const res = await this.supertest
409+
.put(`${this.getBaseUrl(spaceId)}/api/fleet/settings`)
410+
.set('kbn-xsrf', 'xxxx')
411+
.send(data);
412+
413+
expectStatusCode200(res);
414+
415+
return res.body;
416+
}
378417
// Space Settings
379418
async getSpaceSettings(spaceId?: string): Promise<GetSpaceSettingsResponse> {
380419
const { body: res } = await this.supertest

0 commit comments

Comments
 (0)