Skip to content

Commit

Permalink
[Response Ops][Alerting] Add managed: true to meta for alerting API k…
Browse files Browse the repository at this point in the history
…eys (elastic#179770)

Resolves elastic#179163

## Summary

This PR adds `managed:true` to the meta field when creating API keys a
rule.


### To verify

- Create a rule
- Go to the [API key
page](http://localhost:5601/app/management/security/api_keys/) and
verify that the managed tag is visible in the ui
- Use dev tools and refresh the page to inspect the api_key request,
verify that `metadata: { managed: true }`
  • Loading branch information
doakalexi authored Apr 2, 2024
1 parent ad99ea8 commit e43dd0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion x-pack/plugins/alerting/server/rules_client_factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,19 @@ test('createAPIKey() returns an API key when security is enabled', async () => {
id: 'abc',
name: '',
});
const createAPIKeyResult = await constructorCall.createAPIKey();
const createAPIKeyResult = await constructorCall.createAPIKey('test');
expect(createAPIKeyResult).toEqual({
apiKeysEnabled: true,
result: { api_key: '123', id: 'abc', name: '' },
});
expect(securityPluginStart.authc.apiKeys.grantAsInternalUser).toHaveBeenCalledWith(
expect.any(Object),
{
metadata: { managed: true },
name: 'test',
role_descriptors: {},
}
);
});

test('createAPIKey() throws when security plugin createAPIKey throws an error', async () => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/rules_client_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class RulesClientFactory {
// privileges
const createAPIKeyResult = await securityPluginStart.authc.apiKeys.grantAsInternalUser(
request,
{ name, role_descriptors: {} }
{ name, role_descriptors: {}, metadata: { managed: true } }
);
if (!createAPIKeyResult) {
return { apiKeysEnabled: false };
Expand Down

0 comments on commit e43dd0e

Please sign in to comment.