Skip to content

Commit

Permalink
Kibana: WIP: conditionally add agentless index permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
orestisfl committed Dec 11, 2024
1 parent 3683cc2 commit 72913fb
Showing 1 changed file with 28 additions and 8 deletions.
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,15 +183,11 @@ 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 +250,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

0 comments on commit 72913fb

Please sign in to comment.