Skip to content

Commit

Permalink
Ensure default policies after preconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Apr 13, 2021
1 parent 039cfc5 commit 50b682b
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions x-pack/plugins/fleet/server/services/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,10 @@ async function createSetupSideEffects(
soClient: SavedObjectsClientContract,
esClient: ElasticsearchClient
): Promise<SetupStatus> {
const [
installedPackages,
defaultOutput,
{ created: defaultAgentPolicyCreated, policy: defaultAgentPolicy },
{ created: defaultFleetServerPolicyCreated, policy: defaultFleetServerPolicy },
] = await Promise.all([
const [installedPackages, defaultOutput] = await Promise.all([
// packages installed by default
ensureInstalledDefaultPackages(soClient, esClient),
outputService.ensureDefaultOutput(soClient),
agentPolicyService.ensureDefaultAgentPolicy(soClient, esClient),
agentPolicyService.ensureDefaultFleetServerAgentPolicy(soClient, esClient),
updateFleetRoleIfExists(esClient),
settingsService.getSettings(soClient).catch((e: any) => {
if (e.isBoom && e.output.statusCode === 404) {
Expand Down Expand Up @@ -88,6 +81,32 @@ async function createSetupSideEffects(
esClient,
});

const { agentPolicies: policiesOrUndefined, packages: packagesOrUndefined } =
appContextService.getConfig() ?? {};

const policies = policiesOrUndefined ?? [];
const packages = packagesOrUndefined ?? [];

await ensurePreconfiguredPackagesAndPolicies(
soClient,
esClient,
policies,
packages,
defaultOutput
);

// Ensure the predefined default policies AFTER loading preconfigured policies. This allows the kibana config
// to override the default agent policies.

const [
{ created: defaultAgentPolicyCreated, policy: defaultAgentPolicy },
{ created: defaultFleetServerPolicyCreated, policy: defaultFleetServerPolicy },
] = await Promise.all([
agentPolicyService.ensureDefaultAgentPolicy(soClient, esClient),
agentPolicyService.ensureDefaultFleetServerAgentPolicy(soClient, esClient),
]);

// If we just created the default fleet server policy add the fleet server package
if (defaultFleetServerPolicyCreated) {
await addPackageToAgentPolicy(
soClient,
Expand All @@ -98,8 +117,6 @@ async function createSetupSideEffects(
);
}

// If we just created the default fleet server policy add the fleet server package

// If we just created the default policy, ensure default packages are added to it
if (defaultAgentPolicyCreated) {
const agentPolicyWithPackagePolicies = await agentPolicyService.get(
Expand Down Expand Up @@ -153,20 +170,6 @@ async function createSetupSideEffects(

await ensureAgentActionPolicyChangeExists(soClient);

const { agentPolicies: policiesOrUndefined, packages: packagesOrUndefined } =
appContextService.getConfig() ?? {};

const policies = policiesOrUndefined ?? [];
const packages = packagesOrUndefined ?? [];

await ensurePreconfiguredPackagesAndPolicies(
soClient,
esClient,
policies,
packages,
defaultOutput
);

return { isIntialized: true };
}

Expand Down

0 comments on commit 50b682b

Please sign in to comment.