Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Change agentPolicyUpdateEventHandler to use soClient from appContext when Fleet Policy Change Action's #79341

Merged
Changes from 1 commit
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 @@ -4,11 +4,27 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SavedObjectsClientContract } from 'src/core/server';
import { KibanaRequest, SavedObjectsClientContract } from 'src/core/server';
import { generateEnrollmentAPIKey, deleteEnrollmentApiKeyForAgentPolicyId } from './api_keys';
import { unenrollForAgentPolicyId } from './agents';
import { outputService } from './output';
import { agentPolicyService } from './agent_policy';
import { appContextService } from './app_context';

const fakeRequest = ({
headers: {},
getBasePath: () => '',
path: '/',
route: { settings: {} },
url: {
href: '/',
},
raw: {
req: {
url: '/',
},
},
} as unknown) as KibanaRequest;

export async function agentPolicyUpdateEventHandler(
soClient: SavedObjectsClientContract,
Expand All @@ -17,20 +33,25 @@ export async function agentPolicyUpdateEventHandler(
) {
const adminUser = await outputService.getAdminUser(soClient);
const outputId = await outputService.getDefaultOutputId(soClient);

// If no admin user and no default output fleet is not enabled just skip this hook
if (!adminUser || !outputId) {
return;
}

// `soClient` from ingest `appContextService` is used to create policy change actions
// to ensure encrypted SOs are handled correctly
const internalSoClient = appContextService.getInternalUserSOClient(fakeRequest);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the alternative to this would be to include the encrypted SO plugin in Security_Solution?

@neptunian FYI, is this what would be needed by the error you were seeing? I think it had to do with api key generation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinlog yes, but I don't know much about how that could/would impact the creation of the artifacts as well as the Exceptions List since the current soClient seems to be passed on to those other areas as well as Manifest manger. Really need @madirey (whenever she has some time) to comment on this.

Another alternative might be to use a encryptedSavedObject client only for manifest manager, since I think that is the only one that uses the Ingest policy services. I looked at how Ingest creates their soClient and I think we have what is needed in security solution plugin.start() to create it.


if (action === 'created') {
await generateEnrollmentAPIKey(soClient, {
agentPolicyId,
});
await agentPolicyService.createFleetPolicyChangeAction(soClient, agentPolicyId);
await agentPolicyService.createFleetPolicyChangeAction(internalSoClient, agentPolicyId);
}

if (action === 'updated') {
await agentPolicyService.createFleetPolicyChangeAction(soClient, agentPolicyId);
await agentPolicyService.createFleetPolicyChangeAction(internalSoClient, agentPolicyId);
}

if (action === 'deleted') {
Expand Down