Skip to content

Commit

Permalink
[OSQuery Plugin] Migrate usage og authc.getCurrentUser to coreContext…
Browse files Browse the repository at this point in the history
….security (#187014)

Part of #186574

## Summary

This PR migrates the OSQuery Plugin's route handlers that consume
`authc.getCurrentUser` to use coreContext.security

Background: This PR serves as an example of a plugin migrating away from
depending on the Security plugin, which is a high priority effort for
the last release before 9.0.

### Checklist

Delete any items that are not applicable to this PR.

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
tsullivan authored Jun 28, 2024
1 parent 065ae0e commit 7cf7365
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ export const updateAssetsRoute = (router: IRouter, osqueryContext: OsqueryAppCon
},
},
},
async (context, request, response) => {
const savedObjectsClient = (await context.core).savedObjects.client;
const currentUser = await osqueryContext.security.authc.getCurrentUser(request)?.username;
async (context, _request, response) => {
const coreContext = await context.core;
const savedObjectsClient = coreContext.savedObjects.client;
const currentUser = coreContext.security.authc.getCurrentUser()?.username;

let installation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const createLiveQueryRoute = (router: IRouter, osqueryContext: OsqueryApp
},
async (context, request, response) => {
const [coreStartServices] = await osqueryContext.getStartServices();
const soClient = (await context.core).savedObjects.client;
const coreContext = await context.core;
const soClient = coreContext.savedObjects.client;

const {
osquery: { writeLiveQueries, runSavedQueries },
Expand Down Expand Up @@ -106,7 +107,7 @@ export const createLiveQueryRoute = (router: IRouter, osqueryContext: OsqueryApp
}

try {
const currentUser = await osqueryContext.security.authc.getCurrentUser(request)?.username;
const currentUser = coreContext.security.authc.getCurrentUser()?.username;
const { response: osqueryAction, fleetActionsCount } = await createActionHandler(
osqueryContext,
request.body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const createPackRoute = (router: IRouter, osqueryContext: OsqueryAppConte
const agentPolicyService = osqueryContext.service.getAgentPolicyService();

const packagePolicyService = osqueryContext.service.getPackagePolicyService();
const currentUser = await osqueryContext.security.authc.getCurrentUser(request)?.username;
const currentUser = coreContext.security.authc.getCurrentUser()?.username;

// eslint-disable-next-line @typescript-eslint/naming-convention
const { name, description, queries, enabled, policy_ids, shards = {} } = request.body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const updatePackRoute = (router: IRouter, osqueryContext: OsqueryAppConte
);
const agentPolicyService = osqueryContext.service.getAgentPolicyService();
const packagePolicyService = osqueryContext.service.getPackagePolicyService();
const currentUser = await osqueryContext.security.authc.getCurrentUser(request)?.username;
const currentUser = coreContext.security.authc.getCurrentUser()?.username;

// eslint-disable-next-line @typescript-eslint/naming-convention
const { name, description, queries, enabled, policy_ids, shards = {} } = request.body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const createSavedQueryRoute = (router: IRouter, osqueryContext: OsqueryAp
ecs_mapping,
} = request.body;

const currentUser = await osqueryContext.security.authc.getCurrentUser(request)?.username;
const currentUser = coreContext.security.authc.getCurrentUser()?.username;

const conflictingEntries = await savedObjectsClient.find<SavedQuerySavedObject>({
type: savedQuerySavedObjectType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const updateSavedQueryRoute = (router: IRouter, osqueryContext: OsqueryAp
async (context, request, response) => {
const coreContext = await context.core;
const savedObjectsClient = coreContext.savedObjects.client;
const currentUser = await osqueryContext.security.authc.getCurrentUser(request)?.username;
const currentUser = coreContext.security.authc.getCurrentUser()?.username;

const {
id,
Expand Down

0 comments on commit 7cf7365

Please sign in to comment.