diff --git a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.test.ts b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.test.ts index b704aaaba0343..ebe61a3e95392 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.test.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.test.ts @@ -76,7 +76,7 @@ describe('#create', () => { attrNotSoSecret: 'not-so-secret', attrThree: 'three', }; - const options = { id: 'predefined-uuid', overwrite: true }; + const options = { id: 'predefined-uuid', overwrite: true, version: 'some-version' }; const mockedResponse = { id: 'predefined-uuid', type: 'known-type', @@ -117,7 +117,7 @@ describe('#create', () => { attrNotSoSecret: '*not-so-secret*', attrThree: 'three', }, - { id: 'predefined-uuid', overwrite: true } + { id: 'predefined-uuid', overwrite: true, version: 'some-version' } ); }); @@ -328,7 +328,7 @@ describe('#bulkCreate', () => { mockBaseClient.bulkCreate.mockResolvedValue(mockedResponse); const bulkCreateParams = [ - { id: 'predefined-uuid', type: 'known-type', attributes }, + { id: 'predefined-uuid', type: 'known-type', attributes, version: 'some-version' }, { type: 'unknown-type', attributes }, ]; diff --git a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.ts b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.ts index ea4b0ea0a96e6..81acc8de7454c 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.ts @@ -60,7 +60,8 @@ export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientCon // Saved objects with encrypted attributes should have IDs that are hard to guess especially // since IDs are part of the AAD used during encryption, that's why we control them within this // wrapper and don't allow consumers to specify their own IDs directly. - if (options.id && !options.overwrite) { + const canSpecifyID = options.overwrite && options.version; + if (options.id && !canSpecifyID) { throw new Error( 'Predefined IDs are not allowed for saved objects with encrypted attributes.' ); @@ -103,7 +104,8 @@ export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientCon // Saved objects with encrypted attributes should have IDs that are hard to guess especially // since IDs are part of the AAD used during encryption, that's why we control them within this // wrapper and don't allow consumers to specify their own IDs directly. - if (object.id && !options?.overwrite) { + const canSpecifyID = options?.overwrite && object.version; + if (object.id && !canSpecifyID) { throw new Error( 'Predefined IDs are not allowed for saved objects with encrypted attributes.' );