Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.15] [Fleet] Missing policy filter in Fleet Server check to enable secrets (#187935) #188089

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ describe('checkFleetServerVersionsForSecretsStorage', () => {
version
);
expect(result).toBe(true);
expect(mockedGetAgentsByKuery).toHaveBeenCalledWith(
esClientMock,
soClientMock,
expect.objectContaining({
kuery: 'policy_id:("1" or "2")',
})
);
});
});

Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/fleet/server/services/fleet_server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,19 @@ export async function checkFleetServerVersionsForSecretsStorage(
hasMore = false;
}
}
if (policyIds.size === 0) {
return false;
}

const kuery = `policy_id:(${Array.from(policyIds)
.map((id) => `"${id}"`)
.join(' or ')})`;

const managedAgentPolicies = await agentPolicyService.getAllManagedAgentPolicies(soClient);
const fleetServerAgents = await getAgentsByKuery(esClient, soClient, {
showInactive: true,
perPage: SO_SEARCH_LIMIT,
kuery,
});

if (fleetServerAgents.agents.length === 0) {
Expand Down
5 changes: 5 additions & 0 deletions x-pack/test/fleet_api_integration/apis/policy_secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,8 @@ export default function (providerContext: FtrProviderContext) {
it('should not store secrets if fleet server does not meet minimum version', async () => {
const { fleetServerAgentPolicy } = await createFleetServerAgentPolicy();
await createFleetServerAgent(fleetServerAgentPolicy.id, 'server_1', '7.0.0');
const { fleetServerAgentPolicy: fleetServerPolicy2 } = await createFleetServerAgentPolicy(); // extra policy to verify `or` condition
await createFleetServerAgent(fleetServerPolicy2.id, 'server_1', '8.12.0');

await callFleetSetup();

Expand All @@ -865,7 +867,10 @@ export default function (providerContext: FtrProviderContext) {
});

it('should not store secrets if there are no fleet servers', async () => {
await createFleetServerAgentPolicy();
const agentPolicy = await createAgentPolicy();
// agent with new version shouldn't make storage secrets enabled
await createFleetServerAgent(agentPolicy.id, 'server_2', '8.12.0');
const packagePolicyWithSecrets = await createPackagePolicyWithSecrets(agentPolicy.id);

// secret should be in plain text i.e not a secret refrerence
Expand Down
Loading