Skip to content

Commit

Permalink
Properly handle space ids with dashes in them
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallmain committed Aug 4, 2021
1 parent 0214b61 commit 498f9c4
Showing 1 changed file with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,10 @@ export const createDetectionIndex = async (
// for BOTH the index AND alias name. However, through 7.14 admins only needed permissions for .siem-signals (the index)
// and not .alerts-security.alerts (the alias). From the security solution perspective, all .siem-signals-<space id>-*
// indices should have an alias to .alerts-security.alerts-<space id> so it's safe to add those aliases as the internal user.
await context.core.elasticsearch.client.asInternalUser.indices.putAlias({
index: `${index}-*`,
name: aadIndexAliasName,
body: {
is_write_index: false,
},
await addIndexAliases({
esClient: context.core.elasticsearch.client.asInternalUser,
index,
aadIndexAliasName,
});
const indexVersion = await getIndexVersion(esClient, index);
if (isOutdated({ current: indexVersion, target: SIGNALS_TEMPLATE_VERSION })) {
Expand Down Expand Up @@ -182,3 +180,27 @@ const addFieldAliasesToIndices = async ({
} as estypes.IndicesPutMappingRequest);
}
};

const addIndexAliases = async ({
esClient,
index,
aadIndexAliasName,
}: {
esClient: ElasticsearchClient;
index: string;
aadIndexAliasName: string;
}) => {
const { body: indices } = await esClient.indices.getAlias({ name: index });
const aliasActions = {
actions: Object.keys(indices).map((concreteIndexName) => {
return {
add: {
index: concreteIndexName,
alias: aadIndexAliasName,
is_write_index: false,
},
};
}),
};
await esClient.indices.updateAliases({ body: aliasActions });
};

0 comments on commit 498f9c4

Please sign in to comment.