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] Tighten policy permissions, take II #97366

Merged
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
a0cbb98
Add config flag to enable the new permission block
Apr 15, 2021
9272808
Refactor default permission handling
Apr 15, 2021
dadced0
Ensure packages' data_streams contain all metadata
Apr 16, 2021
b6bb88a
Add `permissiosn` key to package data_streams
Apr 16, 2021
61ce8f7
Get permissions from active package policies
Apr 16, 2021
0ba163f
Send default cluster permissions as a separate integration
Apr 16, 2021
3c95ad1
Clarify type naming
Apr 16, 2021
dcc4c47
Add specs
Apr 16, 2021
948aa5f
Add missing property to the mock
May 25, 2021
7ba0cd1
Generate the correct dataset for the custom logs integration
May 31, 2021
1f4deee
Handle APM package
May 31, 2021
cf84bc9
Handle Endpoint integration
May 31, 2021
0d92329
Merge branch 'master' into 64634-policy-permissions-per-package-policy
May 31, 2021
38d01e8
Cleanup code
Jun 1, 2021
2f551c4
Merge branch 'master' into 64634-policy-permissions-per-package-policy
Jun 1, 2021
1d07565
Remove permissions entry for packages with no data_streams
Jun 2, 2021
082b71c
Remove config flag
Jun 2, 2021
c7bff76
Merge branch 'master' into 64634-policy-permissions-per-package-policy
Jun 2, 2021
55383a9
Fix types
Jun 2, 2021
1dc4ad5
Merge branch 'master' into 64634-policy-permissions-per-package-policy
kibanamachine Jun 3, 2021
3d8d2e1
Handle permissions for agent monitoring
Jun 7, 2021
f40569c
Merge branch 'master' into 64634-policy-permissions-per-package-policy
Jun 7, 2021
853023d
Use the right patterns for monitoring
Jun 8, 2021
340999b
Refine typing
Jun 8, 2021
7a237ef
Merge branch 'master' into 64634-policy-permissions-per-package-policy
Jun 8, 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
6 changes: 3 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 @@ -61,9 +61,9 @@ export interface FullAgentPolicyInput {
}

export interface FullAgentPolicyOutputPermissions {
[role: string]: {
cluster: string[];
indices: Array<{
[packagePolicyName: string]: {
cluster?: string[];
indices?: Array<{
names: string[];
privileges: string[];
}>;
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export enum RegistryDataStreamKeys {
ingest_pipeline = 'ingest_pipeline',
elasticsearch = 'elasticsearch',
dataset_is_prefix = 'dataset_is_prefix',
permissions = 'permissions',
}

export interface RegistryDataStream {
Expand All @@ -291,13 +292,19 @@ export interface RegistryDataStream {
[RegistryDataStreamKeys.ingest_pipeline]?: string;
[RegistryDataStreamKeys.elasticsearch]?: RegistryElasticsearch;
[RegistryDataStreamKeys.dataset_is_prefix]?: boolean;
[RegistryDataStreamKeys.permissions]?: RegistryDataStreamPermissions;
}

export interface RegistryElasticsearch {
'index_template.settings'?: object;
'index_template.mappings'?: object;
}

export interface RegistryDataStreamPermissions {
cluster?: string[];
indices?: string[];
}

export type RegistryVarType = 'integer' | 'bool' | 'password' | 'text' | 'yaml' | 'string';
export enum RegistryVarsEntryKeys {
name = 'name',
Expand Down
59 changes: 41 additions & 18 deletions x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ import type {
Output,
} from '../../common';
import { AgentPolicyNameExistsError, HostedAgentPolicyRestrictionRelatedError } from '../errors';
import {
storedPackagePoliciesToAgentPermissions,
DEFAULT_PERMISSIONS,
} from '../services/package_policies_to_agent_permissions';

import { getPackageInfo } from './epm/packages';
import { getAgentsByKuery } from './agents';
Expand Down Expand Up @@ -745,30 +749,49 @@ class AgentPolicyService {
}),
};

const permissions = (await storedPackagePoliciesToAgentPermissions(
soClient,
agentPolicy.package_policies
)) || { _fallback: DEFAULT_PERMISSIONS };

permissions._elastic_agent_checks = {
cluster: DEFAULT_PERMISSIONS.cluster,
};

// TODO fetch this from the elastic agent package
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you file an issue for this and link elastic/integrations#953 as a blocker?

const monitoringOutput = fullAgentPolicy.agent?.monitoring.use_output;
const monitoringNamespace = fullAgentPolicy.agent?.monitoring.namespace;
if (
fullAgentPolicy.agent?.monitoring.enabled &&
monitoringNamespace &&
monitoringOutput &&
fullAgentPolicy.outputs[monitoringOutput]?.type === 'elasticsearch'
) {
const names: string[] = [];
if (fullAgentPolicy.agent.monitoring.logs) {
names.push(`logs-elastic_agent.*-${monitoringNamespace}`);
}
if (fullAgentPolicy.agent.monitoring.metrics) {
names.push(`metrics-elastic_agent.*-${monitoringNamespace}`);
}

permissions._elastic_agent_checks.indices = [
{
names,
privileges: ['auto_configure', 'create_doc'],
},
];
}

// Only add permissions if output.type is "elasticsearch"
fullAgentPolicy.output_permissions = Object.keys(fullAgentPolicy.outputs).reduce<
NonNullable<FullAgentPolicy['output_permissions']>
>((permissions, outputName) => {
>((outputPermissions, outputName) => {
const output = fullAgentPolicy.outputs[outputName];
if (output && output.type === 'elasticsearch') {
permissions[outputName] = {};
permissions[outputName]._fallback = {
cluster: ['monitor'],
indices: [
{
names: [
'logs-*',
'metrics-*',
'traces-*',
'.logs-endpoint.diagnostic.collection-*',
'synthetics-*',
],
privileges: ['auto_configure', 'create_doc'],
},
],
};
outputPermissions[outputName] = permissions;
}
return permissions;
return outputPermissions;
}, {});

// only add settings if not in standalone
Expand Down
8 changes: 2 additions & 6 deletions x-pack/plugins/fleet/server/services/epm/archive/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,24 +224,20 @@ export const getEsPackage = async (
);
const dataStreamManifest = safeLoad(soResDataStreamManifest.attributes.data_utf8);
const {
title: dataStreamTitle,
release,
ingest_pipeline: ingestPipeline,
type,
dataset,
streams: manifestStreams,
...dataStreamManifestProps
} = dataStreamManifest;
const streams = parseAndVerifyStreams(manifestStreams, dataStreamPath);

dataStreams.push({
dataset: dataset || `${pkgName}.${dataStreamPath}`,
title: dataStreamTitle,
release,
package: pkgName,
ingest_pipeline: ingestPipeline || 'default',
path: dataStreamPath,
type,
streams,
...dataStreamManifestProps,
});
})
);
Expand Down
Loading