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] Add data tags to agent policy APIs #183563

Merged
merged 28 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
15749db
feature(179915): updated saved objects and index mapping to add globa…
kaanyalti May 14, 2024
45a31b5
feature(179915): updated agent policy models
kaanyalti May 15, 2024
8046938
feature(179915): updated package policy to input conversion to includ…
kaanyalti May 15, 2024
ddf5bc1
feature(179915): updated agent_policy and agent_policy_create_request…
kaanyalti May 16, 2024
9a6efd2
feature(179915): bundled open api spec and validated
kaanyalti May 17, 2024
6c31ece
feature(179915): added custom validation for agent policy request bod…
kaanyalti May 17, 2024
58aab2c
feature(179915): formatted global_data_tags_exclude constans
kaanyalti May 17, 2024
50df4ff
feature(179915): updated excluded inputs, updated validation error me…
kaanyalti May 17, 2024
39115b9
feature(179915): update storedPackagePolicyToAgentInputs to add add_f…
kaanyalti May 17, 2024
9cc6d30
feature(179915): updated input validation
kaanyalti May 17, 2024
57c79db
feature(179915): added global_data_tags to copy policy endpoint
kaanyalti May 17, 2024
58206b8
feature(179915): updated mappings
kaanyalti May 20, 2024
b33b44c
feature(179915): added unit tests
kaanyalti May 20, 2024
a63fd01
feature(179915): updated unit tests
kaanyalti May 20, 2024
f33303a
feature(179915): added integration tests
kaanyalti May 22, 2024
7821821
feature(179915): updated integration tests
kaanyalti May 23, 2024
67f0bfe
feature(179914): remove unnecessary comment
kaanyalti May 23, 2024
127ec26
feature(179915): removed only from tests
kaanyalti May 23, 2024
69541ad
feature(179915): moved excluded input strings
kaanyalti May 24, 2024
57c090a
feature(179915): added unit tests for global data tag input validatio…
kaanyalti May 24, 2024
f5dbdd1
feature(179915): replaced nested data type with flattened for global_…
kaanyalti May 24, 2024
c77b4b1
feature(179915): removed validation tests from integration tests, rem…
kaanyalti May 24, 2024
fcbffa5
feature(179915): added comments
kaanyalti May 24, 2024
3c2cd1d
feature(179915): udpate imports
kaanyalti May 24, 2024
a781dbd
feature(179915): updated integration test equal assertions
kaanyalti May 25, 2024
7c101f0
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine May 24, 2024
42adabd
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine May 24, 2024
93b384a
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine May 24, 2024
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 @@ -500,6 +500,7 @@
"description",
"download_source_id",
"fleet_server_host_id",
"global_data_tags",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added by kibanamachine

"inactivity_timeout",
"is_default",
"is_default_fleet_server",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,10 @@
"fleet_server_host_id": {
"type": "keyword"
},
"global_data_tags": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added by kibanamachine

"index": false,
"type": "flattened"
},
"inactivity_timeout": {
"type": "integer"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"infra-custom-dashboards": "1a5994f2e05bb8a1609825ddbf5012f77c5c67f3",
"infrastructure-monitoring-log-view": "5f86709d3c27aed7a8379153b08ee5d3d90d77f5",
"infrastructure-ui-source": "113182d6895764378dfe7fa9fa027244f3a457c4",
"ingest-agent-policies": "803dc27e106440c41e8f3c3d8ee8bbb0821bcde2",
"ingest-agent-policies": "90625b4a5ded9d4867358fcccc14a57c0454fcee",
"ingest-download-sources": "279a68147e62e4d8858c09ad1cf03bd5551ce58d",
"ingest-outputs": "daafff49255ab700e07491376fe89f04fc998b91",
"ingest-package-policies": "44c682a6bf23993c665f0a60a427f3c120a0a10d",
Expand Down
32 changes: 32 additions & 0 deletions x-pack/plugins/fleet/common/constants/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@ export const FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE = 'kspm';
export const FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE = 'cspm';
export const FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE = 'vuln_mgmt';
export const FLEET_CLOUD_DEFEND_PACKAGE = 'cloud_defend';
export const FLEET_PF_HOST_AGENT_PACKAGE = 'pf-host-agent';
export const FLEET_PF_ELASTIC_SYMBOLIZER_PACKAGE = 'pf-elastic-symbolizer';
export const FLEET_PF_ELASTIC_COLLECTOR_PACKAGE = 'pf-elastic-collector';
export const FLEET_CLOUD_BEAT_PACKAGE = 'cloudbeat';
export const FLEET_CLOUD_BEAT_CIS_K8S_PACKAGE = `${FLEET_CLOUD_BEAT_PACKAGE}/cis_k8s`;
export const FLEET_CLOUD_BEAT_CIS_EKS_PACKAGE = `${FLEET_CLOUD_BEAT_PACKAGE}/cis_eks`;
export const FLEET_CLOUD_BEAT_CIS_AWS_PACKAGE = `${FLEET_CLOUD_BEAT_PACKAGE}/cis_aws`;
export const FLEET_CLOUD_BEAT_CIS_GCP_PACKAGE = `${FLEET_CLOUD_BEAT_PACKAGE}/cis_gcp`;
export const FLEET_CLOUD_BEAT_CIS_AZURE_PACKAGE = `${FLEET_CLOUD_BEAT_PACKAGE}/cis_azure`;
export const FLEET_CLOUD_BEAT_VULN_MGMT_AWS_PACKAGE = `${FLEET_CLOUD_BEAT_PACKAGE}/vuln_mgmt_aws`;

export const GLOBAL_DATA_TAG_EXCLUDED_INPUTS = new Set<string>([
FLEET_APM_PACKAGE,
FLEET_PF_HOST_AGENT_PACKAGE,
FLEET_PF_ELASTIC_SYMBOLIZER_PACKAGE,
FLEET_PF_ELASTIC_COLLECTOR_PACKAGE,
/* The package names and input types are not the same. For example package
* name for fleet server is "fleet_server" whereas the input type is "fleet-server".
* This is the same case for cloud defend. That's why we are replacing the
* underscores with dashes for the two of them. Global data tag functionality
* relies on input types.
*/
FLEET_SERVER_PACKAGE.replace(/_/g, '-'),
FLEET_CLOUD_DEFEND_PACKAGE.replace(/_/g, '-'),
FLEET_CLOUD_BEAT_PACKAGE,
FLEET_CLOUD_BEAT_CIS_K8S_PACKAGE,
FLEET_CLOUD_BEAT_CIS_EKS_PACKAGE,
FLEET_CLOUD_BEAT_CIS_AWS_PACKAGE,
FLEET_CLOUD_BEAT_CIS_GCP_PACKAGE,
FLEET_CLOUD_BEAT_CIS_AZURE_PACKAGE,
FLEET_CLOUD_BEAT_VULN_MGMT_AWS_PACKAGE,
]);

export const PACKAGE_TEMPLATE_SUFFIX = '@package';
export const USER_SETTINGS_TEMPLATE_SUFFIX = '@custom';
Expand Down
34 changes: 34 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -7660,6 +7660,23 @@
"supports_agentless": {
"type": "boolean",
"description": "Indicates whether the agent policy supports agentless integrations. Only allowed in a serverless environment."
},
"global_data_tags": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "string"
},
{
"type": "number"
}
]
},
"description": "User defined data tags that are added to all of the inputs. The values can be strings or numbers."
}
}
},
"required": [
Expand Down Expand Up @@ -7741,6 +7758,23 @@
"force": {
"type": "boolean",
"description": "Force agent policy creation even if packages are not verified."
},
"global_data_tags": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "string"
},
{
"type": "number"
}
]
},
"description": "User defined data tags that are added to all of the inputs. The values can be strings or numbers."
}
}
},
"required": [
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4933,6 +4933,17 @@ components:
description: >-
Indicates whether the agent policy supports agentless integrations.
Only allowed in a serverless environment.
global_data_tags:
type: array
items:
type: object
additionalProperties:
oneOf:
- type: string
- type: number
description: >-
User defined data tags that are added to all of the inputs. The
values can be strings or numbers.
required:
- id
- status
Expand Down Expand Up @@ -4990,6 +5001,17 @@ components:
force:
type: boolean
description: Force agent policy creation even if packages are not verified.
global_data_tags:
type: array
items:
type: object
additionalProperties:
oneOf:
- type: string
- type: number
description: >-
User defined data tags that are added to all of the inputs. The
values can be strings or numbers.
required:
- name
- namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ properties:
supports_agentless:
type: boolean
description: Indicates whether the agent policy supports agentless integrations. Only allowed in a serverless environment.
global_data_tags:
type: array
items:
type: object
additionalProperties:
oneOf:
- type: string
- type: number
description: User defined data tags that are added to all of the inputs. The values can be strings or numbers.
required:
- id
- status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ properties:
force:
type: boolean
description: Force agent policy creation even if packages are not verified.
global_data_tags:
type: array
items:
type: object
additionalProperties:
oneOf:
- type: string
- type: number
description: User defined data tags that are added to all of the inputs. The values can be strings or numbers.
required:
- name
- namespace
16 changes: 16 additions & 0 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export interface NewAgentPolicy {
advanced_settings?: { [key: string]: any } | null;
keep_monitoring_alive?: boolean | null;
supports_agentless?: boolean | null;
global_data_tags?: GlobalDataTag[];
}

export interface GlobalDataTag {
name: string;
value: string | number;
}

// SO definition for this type is declared in server/types/interfaces
Expand Down Expand Up @@ -80,9 +86,19 @@ export interface FullAgentPolicyInput {
[key: string]: unknown;
};
streams?: FullAgentPolicyInputStream[];
processors?: FullAgentPolicyAddFields[];
[key: string]: any;
}

export interface FullAgentPolicyAddFields {
add_fields: {
target: string;
fields: {
[key: string]: string | number;
kaanyalti marked this conversation as resolved.
Show resolved Hide resolved
};
};
}

export type FullAgentPolicyOutputPermissions = Record<string, SecurityRoleDescriptor>;

export type FullAgentPolicyOutput = Pick<Output, 'type' | 'hosts' | 'ca_sha256'> & {
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const getSavedObjectTypes = (
keep_monitoring_alive: { type: 'boolean' },
advanced_settings: { type: 'flattened', index: false },
supports_agentless: { type: 'boolean' },
global_data_tags: { type: 'flattened', index: false },
},
},
migrations: {
Expand Down Expand Up @@ -197,6 +198,16 @@ export const getSavedObjectTypes = (
},
],
},
'3': {
changes: [
{
type: 'mappings_addition',
addedMappings: {
global_data_tags: { type: 'flattened', index: false },
},
},
],
},
},
},
[OUTPUT_SAVED_OBJECT_TYPE]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export async function getFullAgentPolicy(
agentPolicy.package_policies as PackagePolicy[],
packageInfoCache,
getOutputIdForAgentPolicy(dataOutput),
agentPolicy.namespace
agentPolicy.namespace,
agentPolicy.global_data_tags
);
const features = (agentPolicy.agent_features || []).reduce((acc, { name, ...featureConfig }) => {
acc[name] = featureConfig;
Expand Down
Loading
Loading