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

Conditionally add agentless index permissions #203810

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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 @@ -52,6 +52,16 @@ export const ELASTIC_CONNECTORS_INDEX_PERMISSIONS = [
'view_index_metadata',
];

export const AGENTLESS_INDEX_PERMISSIONS = [
'read',
'write',
'monitor',
'create_index',
'auto_configure',
'maintenance',
'view_index_metadata',
];

export function storedPackagePoliciesToAgentPermissions(
packageInfoCache: Map<string, PackageInfo>,
agentPolicyNamespace: string,
Expand Down Expand Up @@ -173,13 +183,10 @@ export function storedPackagePoliciesToAgentPermissions(
}
// namespace is either the package policy's or the agent policy one
const namespace = packagePolicy?.namespace || agentPolicyNamespace;
return [
packagePolicy.id,
{
indices: dataStreamsForPermissions.map((ds) => getDataStreamPrivileges(ds, namespace)),
...clusterRoleDescriptor,
},
];
return maybeAddAgentlessPermissions(packagePolicy, {
indices: dataStreamsForPermissions.map((ds) => getDataStreamPrivileges(ds, namespace)),
...clusterRoleDescriptor,
});
});

return Object.fromEntries(permissionEntries);
Expand Down Expand Up @@ -244,6 +251,20 @@ function universalProfilingPermissions(packagePolicyId: string): [string, Securi
];
}

function maybeAddAgentlessPermissions(
packagePolicy: PackagePolicy,
existing: SecurityRoleDescriptor
): [string, SecurityRoleDescriptor] {
if (!packagePolicy.supports_agentless) {
return [packagePolicy.id, existing];
}
existing.indices!.push({
names: ['agentless-*'],
privileges: AGENTLESS_INDEX_PERMISSIONS,
});
return [packagePolicy.id, existing];
}

function apmPermissions(packagePolicyId: string): [string, SecurityRoleDescriptor] {
return [
packagePolicyId,
Expand Down