Skip to content
Open
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 @@ -19,7 +19,7 @@ export const up = async (next) => {
if (element) {
const eventFiles = groupFiles.map((f) => storeFileConverter(SYSTEM_USER, f));
const source = 'ctx._source.x_opencti_files = params.files;';
return elUpdate(element._index, element.internal_id, {
return elUpdate(context, element._index, element.internal_id, {
script: { source, lang: 'painless', params: { files: eventFiles } },
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const up = async (next) => {
if (element) {
const eventFiles = groupFiles.map((f) => storeFileConverter(SYSTEM_USER, f));
const source = 'ctx._source.x_opencti_files = params.files;';
return elUpdate(element._index, element.internal_id, {
return elUpdate(context, element._index, element.internal_id, {
script: { source, lang: 'painless', params: { files: eventFiles } },
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const up = async (next) => {
params[key] = Array.isArray(data[key]) ? data[key].flat() : data[key];
}
}
await elUpdate(data._index, mergedId, {
await elUpdate(context, data._index, mergedId, {
script: {
source: 'for (key in ctx._source.keySet()) { '
+ "if (key.startsWith('rel_')) { "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const up = async (next) => {
const authorIdToKeep = currentAuthorsIds[currentAuthorsIds.length - 1];
// 1. Update the denormalized refs of the current entity
const updateCreatedByWithUniqueIdSource = "ctx._source['rel_created-by.internal_id'] = [params.authorIdToKeep]";
await elUpdate(currentEntityWithMultipleAuthors._index, currentEntityWithMultipleAuthors._id, {
await elUpdate(context, currentEntityWithMultipleAuthors._index, currentEntityWithMultipleAuthors._id, {
script: { source: updateCreatedByWithUniqueIdSource, lang: 'painless', params: { authorIdToKeep } },
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export const up = async (next) => {
};
const newTokensList = [...currentTokens, newToken];
const source = "ctx._source.api_tokens = params.api_tokens; ctx._source.remove('api_token');";
await elUpdate(user._index, user.internal_id, {
await elUpdate(context, user._index, user.internal_id, {
script: { source, lang: 'painless', params: { api_tokens: newTokensList } },
});
} else {
// Ensure old api_token attribute cleanup
const source = "ctx._source.remove('api_token');";
await elUpdate(user._index, user.internal_id, { script: { source, lang: 'painless' } });
await elUpdate(context, user._index, user.internal_id, { script: { source, lang: 'painless' } });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export const up = async (next) => {
// ------ Update description of SETTINGS_SETPARAMETERS
const setParametersCapability = await elLoadById(context, SYSTEM_USER, 'capability--d6dd23a1-4f95-58f1-aa06-a9ed4e3ff33b');
const setParametersCapabilityPatch = { description: 'Manage parameters' };
await elReplace(setParametersCapability._index, setParametersCapability.internal_id, { doc: setParametersCapabilityPatch });
await elReplace(context, setParametersCapability._index, setParametersCapability.internal_id, { doc: setParametersCapabilityPatch });
// ------ Update description of SETTINGS_SUPPORT
const setSupportCapability = await elLoadById(context, SYSTEM_USER, 'capability--b91b5483-5d6d-59a2-9ee1-a39ca7ebaab7');
const setSupportCapabilityPatch = { description: 'Access to support data' };
await elReplace(setSupportCapability._index, setSupportCapability.internal_id, { doc: setSupportCapabilityPatch });
await elReplace(context, setSupportCapability._index, setSupportCapability.internal_id, { doc: setSupportCapabilityPatch });

logMigration.info(`${message} > done`);
next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const up = async (next) => {
let currentProcessing = 0;
const groupsOfOperations = R.splitEvery(MAX_BULK_OPERATIONS, bulkOperations);
const concurrentUpdate = async (bulk) => {
await elBulk({ refresh: true, timeout: BULK_TIMEOUT, body: bulk });
await elBulk(context, { refresh: true, timeout: BULK_TIMEOUT, body: bulk });
currentProcessing += bulk.length;
logApp.info(`[OPENCTI] Rewriting Note standard ids: ${currentProcessing} / ${bulkOperations.length}`);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const up = async (next) => {
const groupsOfOperations = R.splitEvery(MAX_BULK_OPERATIONS, bulkOperations);
const concurrentUpdate = async (bulk) => {
if (bulk.length > 0) {
await elBulk({ refresh: true, timeout: BULK_TIMEOUT, body: bulk });
await elBulk(context, { refresh: true, timeout: BULK_TIMEOUT, body: bulk });
currentProcessing += bulk.length / 2;
logApp.info(`[OPENCTI] Migrating decay rule filters: ${currentProcessing} / ${bulkOperations.length / 2}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const up = async (next) => {
let currentProcessing = 0;
const groupsOfOperations = R.splitEvery(MAX_BULK_OPERATIONS, bulkOperations);
const concurrentUpdate = async (bulk) => {
await elBulk({ refresh: true, timeout: BULK_TIMEOUT, body: bulk });
await elBulk(context, { refresh: true, timeout: BULK_TIMEOUT, body: bulk });
currentProcessing += bulk.length;
logApp.info(`${message} > bulk rewrote Software standard ids: ${currentProcessing} / ${bulkOperations.length}`);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import { elUpdate } from '../database/engine';

const message = '[MIGRATION] Encrypt credentials at rest for ingestions and synchronizers';

const encryptIngestionFieldIfNeeded = async (entity, fieldName) => {
const encryptIngestionFieldIfNeeded = async (context, entity, fieldName) => {
const value = entity[fieldName];
if (!value) return;
if (await isIngestionCredentialEncrypted(value)) return;
const encrypted = await encryptIngestionCredential(value);
await elUpdate(entity._index, entity.internal_id, { doc: { [fieldName]: encrypted } });
await elUpdate(context, entity._index, entity.internal_id, { doc: { [fieldName]: encrypted } });
};

const encryptSynchronizerFieldIfNeeded = async (entity, fieldName) => {
const encryptSynchronizerFieldIfNeeded = async (context, entity, fieldName) => {
const value = entity[fieldName];
if (!value) return;
if (await isSynchronizerCredentialEncrypted(value)) return;
const encrypted = await encryptSynchronizerCredential(value);
await elUpdate(entity._index, entity.internal_id, { doc: { [fieldName]: encrypted } });
await elUpdate(context, entity._index, entity.internal_id, { doc: { [fieldName]: encrypted } });
};

export const up = async (next) => {
Expand All @@ -33,28 +33,28 @@ export const up = async (next) => {
const csvIngestions = await fullEntitiesOrRelationsList(context, SYSTEM_USER, [ENTITY_TYPE_INGESTION_CSV]);
logMigration.info(`${message} > found ${csvIngestions.length} CSV ingestions`);
for (let i = 0; i < csvIngestions.length; i += 1) {
await encryptIngestionFieldIfNeeded(csvIngestions[i], 'authentication_value');
await encryptIngestionFieldIfNeeded(context, csvIngestions[i], 'authentication_value');
}

// -- IngestionJson --
const jsonIngestions = await fullEntitiesOrRelationsList(context, SYSTEM_USER, [ENTITY_TYPE_INGESTION_JSON]);
logMigration.info(`${message} > found ${jsonIngestions.length} JSON ingestions`);
for (let i = 0; i < jsonIngestions.length; i += 1) {
await encryptIngestionFieldIfNeeded(jsonIngestions[i], 'authentication_value');
await encryptIngestionFieldIfNeeded(context, jsonIngestions[i], 'authentication_value');
}

// -- IngestionTaxii --
const taxiiIngestions = await fullEntitiesOrRelationsList(context, SYSTEM_USER, [ENTITY_TYPE_INGESTION_TAXII]);
logMigration.info(`${message} > found ${taxiiIngestions.length} TAXII ingestions`);
for (let i = 0; i < taxiiIngestions.length; i += 1) {
await encryptIngestionFieldIfNeeded(taxiiIngestions[i], 'authentication_value');
await encryptIngestionFieldIfNeeded(context, taxiiIngestions[i], 'authentication_value');
}

// -- Synchronizer --
const synchronizers = await fullEntitiesOrRelationsList(context, SYSTEM_USER, [ENTITY_TYPE_SYNC]);
logMigration.info(`${message} > found ${synchronizers.length} synchronizers`);
for (let i = 0; i < synchronizers.length; i += 1) {
await encryptSynchronizerFieldIfNeeded(synchronizers[i], 'token');
await encryptSynchronizerFieldIfNeeded(context, synchronizers[i], 'token');
}

logMigration.info(`${message} > done`);
Expand Down
Loading