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] Give permissions to indices with rolling dates #103319

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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 @@ -371,7 +371,7 @@ describe('storedPackagePoliciesToAgentPermissions()', () => {
'test-policy': {
indices: [
{
names: ['logs-osquery_manager.result-test'],
names: ['logs-osquery_manager.result-test*'],
privileges: ['auto_configure', 'create_doc'],
},
],
Expand Down Expand Up @@ -429,6 +429,20 @@ describe('getDataStreamPermissions()', () => {
});
});

it('Appends a wildcard suffix when specified', () => {
const dataStream = {
type: 'logs',
dataset: 'test',
hidden: true,
} as RegistryDataStream;
const permissions = getDataStreamPermissions(dataStream, 'namespace', true);

expect(permissions).toMatchObject({
names: ['.logs-test-namespace*'],
privileges: ['auto_configure', 'create_doc'],
});
});

it('uses custom permissions if they are present in the datastream', () => {
const dataStream = {
type: 'logs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export async function storedPackagePoliciesToAgentPermissions(
}

let dataStreamsForPermissions: DataStreamMeta[];
let wildcardSuffix = false;

switch (pkg.name) {
case 'endpoint':
Expand All @@ -78,6 +79,7 @@ export async function storedPackagePoliciesToAgentPermissions(
// `packagePolicy.inputs`, so we will use _all_ data_streams from
// the package.
dataStreamsForPermissions = pkg.data_streams;
wildcardSuffix = true;
break;

default:
Expand Down Expand Up @@ -121,7 +123,7 @@ export async function storedPackagePoliciesToAgentPermissions(
packagePolicy.name,
{
indices: dataStreamsForPermissions.map((ds) =>
getDataStreamPermissions(ds, packagePolicy.namespace)
getDataStreamPermissions(ds, packagePolicy.namespace, wildcardSuffix)
),
},
];
Expand All @@ -139,7 +141,11 @@ interface DataStreamMeta {
permissions?: RegistryDataStreamPermissions;
}

export function getDataStreamPermissions(dataStream: DataStreamMeta, namespace: string = '*') {
export function getDataStreamPermissions(
dataStream: DataStreamMeta,
namespace: string = '*',
wildcardSuffix: boolean = false
) {
let index = `${dataStream.type}-${dataStream.dataset}`;

if (dataStream.dataset_is_prefix) {
Expand All @@ -152,6 +158,11 @@ export function getDataStreamPermissions(dataStream: DataStreamMeta, namespace:

index += `-${namespace}`;

// Some integrations append a date to the end of the index.
if (wildcardSuffix) {
index += '*';
}

return {
names: [index],
privileges: dataStream.permissions?.indices || ['auto_configure', 'create_doc'],
Expand Down