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

[Fleet] Allow to preconfigure alternative ES outputs (on the same cluster) #111002

Merged
merged 25 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e0bfc4f
[Fleet] Allow to preconfigure multiple ES outputs
nchaulet Sep 2, 2021
0a8ad75
Support multiple output permissions
nchaulet Sep 2, 2021
6fcfb80
Add is_preconfigured flag
nchaulet Sep 3, 2021
57f8fb3
Merge branch 'master' of github.com:elastic/kibana into feature-outpu…
nchaulet Sep 7, 2021
6f97c02
Add fleet_server.service_token to output
nchaulet Sep 7, 2021
e1a1efd
More tests and refacto
nchaulet Sep 8, 2021
2bd4a36
Fix default hosts
nchaulet Sep 8, 2021
255aeaa
Clean preconfigured output
nchaulet Sep 8, 2021
0ed4842
Fix doc
nchaulet Sep 9, 2021
5e75149
Encrypt fleet_server in output saved object
nchaulet Sep 10, 2021
30c46c6
Merge branch 'master' of github.com:elastic/kibana into feature-outpu…
nchaulet Sep 10, 2021
9dfe244
Merge branch 'master' into feature-outputs-preconfigure
kibanamachine Sep 15, 2021
a711b08
[Fleet] Remove support for external ES and only support one output pe…
nchaulet Sep 16, 2021
9a2eb8c
Remove saved object output property .fleet_server
nchaulet Sep 16, 2021
7755da8
Fix tests
nchaulet Sep 16, 2021
021d641
Merge branch 'master' of github.com:elastic/kibana into feature-outpu…
nchaulet Sep 20, 2021
52b57e1
Update after codereview
nchaulet Sep 20, 2021
28f7946
Merge branch 'master' of github.com:elastic/kibana into feature-outpu…
nchaulet Sep 20, 2021
d014dc8
Update after codereview
nchaulet Sep 20, 2021
c48dbb8
fix unhandled promise and default output id
nchaulet Sep 20, 2021
bf9a7e3
Merge branch 'master' of github.com:elastic/kibana into feature-outpu…
nchaulet Sep 20, 2021
6e9364f
Fix lint errors
nchaulet Sep 20, 2021
aef2a44
Update tests
nchaulet Sep 20, 2021
8548b80
Bump policies when preconfigred output are updated
nchaulet Sep 21, 2021
5fb80b3
Add basic unit test for bumpAllAgentPolciesForOutput
nchaulet Sep 21, 2021
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
16 changes: 16 additions & 0 deletions docs/settings/fleet-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Optional properties are:
be changed by updating the {kib} config.
`is_default`:: If `true`, this policy is the default agent policy.
`is_default_fleet_server`:: If `true`, this policy is the default {fleet-server} agent policy.
`data_output_id`:: ID of the output to send data (Need to be identical to `monitoring_output_id`)
`monitoring_output_id`:: ID of the output to send monitoring data. (Need to be identical to `data_output_id`)
`package_policies`:: List of integration policies to add to this policy.
`name`::: (required) Name of the integration policy.
`package`::: (required) Integration that this policy configures
Expand All @@ -96,6 +98,20 @@ Optional properties are:
integration. Follows the same schema as integration inputs, with the
exception that any object in `vars` can be passed `frozen: true` in order to
prevent that specific `var` from being edited by the user.

| `xpack.fleet.outputs`
| List of ouputs that are configured when the {fleet} app starts.
Required properties are:

`id`:: Unique ID for this output. The ID should be a string.
`name`:: Output name.
`type`:: Type of Output. Currently we only support "elasticsearch".
`hosts`:: Array that contains the list of host for that output.
`config`:: Extra config for that output.

Optional properties are:

`is_default`:: If `true`, this output is the default output.
|===

Example configuration:
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/common/constants/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export const outputType = {
Elasticsearch: 'elasticsearch',
} as const;

export const DEFAULT_OUTPUT_ID = 'default';

export const DEFAULT_OUTPUT: NewOutput = {
name: 'default',
name: DEFAULT_OUTPUT_ID,
is_default: true,
type: outputType.Elasticsearch,
hosts: [''],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import type { PackagePolicy, FullAgentPolicyInput, FullAgentPolicyInputStream }
import { DEFAULT_OUTPUT } from '../constants';

export const storedPackagePoliciesToAgentInputs = (
packagePolicies: PackagePolicy[]
packagePolicies: PackagePolicy[],
outputId: string = DEFAULT_OUTPUT.name
): FullAgentPolicyInput[] => {
const fullInputs: FullAgentPolicyInput[] = [];

Expand All @@ -32,7 +33,7 @@ export const storedPackagePoliciesToAgentInputs = (
data_stream: {
namespace: packagePolicy.namespace || 'default',
},
use_output: DEFAULT_OUTPUT.name,
use_output: outputId,
...(input.compiled_input || {}),
...(input.streams.length
? {
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
export * from './models';
export * from './rest_spec';

import type { PreconfiguredAgentPolicy, PreconfiguredPackage } from './models/preconfiguration';
import type {
PreconfiguredAgentPolicy,
PreconfiguredPackage,
PreconfiguredOutput,
} from './models/preconfiguration';

export interface FleetConfigType {
enabled: boolean;
Expand All @@ -26,6 +30,7 @@ export interface FleetConfigType {
};
agentPolicies?: PreconfiguredAgentPolicy[];
packages?: PreconfiguredPackage[];
outputs?: PreconfiguredOutput[];
agentIdVerificationEnabled?: boolean;
}

Expand Down
10 changes: 7 additions & 3 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface NewAgentPolicy {
monitoring_enabled?: MonitoringType;
unenroll_timeout?: number;
is_preconfigured?: boolean;
data_output_id?: string;
monitoring_output_id?: string;
}

export interface AgentPolicy extends NewAgentPolicy {
Expand Down Expand Up @@ -71,12 +73,14 @@ export interface FullAgentPolicyOutputPermissions {
};
}

export type FullAgentPolicyOutput = Pick<Output, 'type' | 'hosts' | 'ca_sha256' | 'api_key'> & {
[key: string]: any;
};

export interface FullAgentPolicy {
id: string;
outputs: {
[key: string]: Pick<Output, 'type' | 'hosts' | 'ca_sha256' | 'api_key'> & {
[key: string]: any;
};
[key: string]: FullAgentPolicyOutput;
};
output_permissions?: {
[output: string]: FullAgentPolicyOutputPermissions;
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/fleet/common/types/models/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export interface NewOutput {
hosts?: string[];
ca_sha256?: string;
api_key?: string;
config?: Record<string, any>;
config_yaml?: string;
is_preconfigured?: boolean;
}

export type OutputSOAttributes = NewOutput;
export type OutputSOAttributes = NewOutput & {
output_id?: string;
};

export type Output = NewOutput & {
id: string;
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/fleet/common/types/models/preconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
NewPackagePolicyInput,
} from './package_policy';
import type { NewAgentPolicy } from './agent_policy';
import type { Output } from './output';

export type InputsOverride = Partial<NewPackagePolicyInput> & {
vars?: Array<NewPackagePolicyInput['vars'] & { name: string }>;
Expand All @@ -29,3 +30,7 @@ export interface PreconfiguredAgentPolicy extends Omit<NewAgentPolicy, 'namespac
}

export type PreconfiguredPackage = Omit<PackagePolicyPackage, 'title'>;

export interface PreconfiguredOutput extends Omit<Output, 'config_yaml'> {
config?: Record<string, unknown>;
}
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/server/errors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export function isESClientError(error: unknown): error is ResponseError {
return error instanceof ResponseError;
}

export const isElasticsearchVersionConflictError = (error: Error): boolean => {
export function isElasticsearchVersionConflictError(error: Error): boolean {
return isESClientError(error) && error.meta.statusCode === 409;
};
}
7 changes: 6 additions & 1 deletion x-pack/plugins/fleet/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { schema } from '@kbn/config-schema';
import type { TypeOf } from '@kbn/config-schema';
import type { PluginConfigDescriptor, PluginInitializerContext } from 'src/core/server';

import { PreconfiguredPackagesSchema, PreconfiguredAgentPoliciesSchema } from './types';
import {
PreconfiguredPackagesSchema,
PreconfiguredAgentPoliciesSchema,
PreconfiguredOutputsSchema,
} from './types';

import { FleetPlugin } from './plugin';

Expand Down Expand Up @@ -113,6 +117,7 @@ export const config: PluginConfigDescriptor = {
}),
packages: PreconfiguredPackagesSchema,
agentPolicies: PreconfiguredAgentPoliciesSchema,
outputs: PreconfiguredOutputsSchema,
agentIdVerificationEnabled: schema.boolean({ defaultValue: true }),
}),
};
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ const getSavedObjectTypes = (
revision: { type: 'integer' },
monitoring_enabled: { type: 'keyword', index: false },
is_preconfigured: { type: 'keyword' },
data_output_id: { type: 'keyword' },
monitoring_output_id: { type: 'keyword' },
Comment on lines +159 to +160
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to index these?

Copy link
Member Author

@nchaulet nchaulet Sep 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could make sense to allow user to search for a policy that use an output.

},
},
migrations: {
Expand Down Expand Up @@ -196,13 +198,15 @@ const getSavedObjectTypes = (
},
mappings: {
properties: {
output_id: { type: 'keyword', index: false },
name: { type: 'keyword' },
type: { type: 'keyword' },
is_default: { type: 'boolean' },
hosts: { type: 'keyword' },
ca_sha256: { type: 'keyword', index: false },
config: { type: 'flattened' },
config_yaml: { type: 'text' },
is_preconfigured: { type: 'boolean', index: false },
},
},
migrations: {
Expand Down
Loading