diff --git a/x-pack/plugins/alerting/server/saved_objects/index.ts b/x-pack/plugins/alerting/server/saved_objects/index.ts index 8e76f28ff7fb8..8f11020ee6285 100644 --- a/x-pack/plugins/alerting/server/saved_objects/index.ts +++ b/x-pack/plugins/alerting/server/saved_objects/index.ts @@ -217,6 +217,11 @@ export function setupSavedObjects( // Encrypted attributes encryptedSavedObjects.registerType({ type: RULE_SAVED_OBJECT_TYPE, + /** + * We disable enforcing random SO IDs for the rule SO + * to allow users creating rules with a predefined ID. + */ + enforceRandomId: false, attributesToEncrypt: new Set(RuleAttributesToEncrypt), attributesToIncludeInAAD: new Set(RuleAttributesIncludedInAAD), }); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts index 57d41424186b3..5a6385a3895d2 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/group1/create.ts @@ -395,20 +395,18 @@ export default function createAlertTests({ getService }: FtrProviderContext) { }); }); - it('should not allow providing simple custom ids (non uuid)', async () => { - const customId = '1'; + it('should create a rule with a predefined non random ID', async () => { + const ruleId = 'my_id'; + const response = await supertest - .post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule/${customId}`) + .post(`${getUrlPrefix(Spaces.space1.id)}/api/alerting/rule/${ruleId}`) .set('kbn-xsrf', 'foo') - .send(getTestRuleData()); + .send(getTestRuleData()) + .expect(200); - expect(response.status).to.eql(400); - expect(response.body).to.eql({ - statusCode: 400, - error: 'Bad Request', - message: - 'Predefined IDs are not allowed for saved objects with encrypted attributes unless the ID is a UUID.: Bad Request', - }); + objectRemover.add(Spaces.space1.id, response.body.id, 'rule', 'alerting'); + + expect(response.body.id).to.eql(ruleId); }); it('should return 409 when document with id already exists', async () => {