[Logstash Plugin] Migrate authc.getCurrentUser usage to coreContext.security (#187180)

Part of https://github.com/elastic/kibana/issues/186574

## Summary

This PR migrates the Logstash Plugin's route handler for saving a
pipeline, which consumes `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

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tim Sullivan 2024-07-03 10:39:37 -07:00 committed by GitHub
parent 0a0bb1498e
commit 482f2a9503
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 18 deletions

View file

@ -8,12 +8,10 @@
import { CoreSetup, CoreStart, Logger, Plugin, PluginInitializerContext } from '@kbn/core/server';
import { LicensingPluginSetup } from '@kbn/licensing-plugin/server';
import { PluginSetupContract as FeaturesPluginSetup } from '@kbn/features-plugin/server';
import { SecurityPluginSetup } from '@kbn/security-plugin/server';
import { registerRoutes } from './routes';
interface SetupDeps {
licensing: LicensingPluginSetup;
security?: SecurityPluginSetup;
features: FeaturesPluginSetup;
}
@ -27,7 +25,7 @@ export class LogstashPlugin implements Plugin {
setup(core: CoreSetup, deps: SetupDeps) {
this.logger.debug('Setting up Logstash plugin');
registerRoutes(core.http.createRouter(), deps.security);
registerRoutes(core.http.createRouter());
deps.features.registerElasticsearchFeature({
id: 'pipelines',

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { SecurityPluginSetup } from '@kbn/security-plugin/server';
import type { LogstashPluginRouter } from '../types';
import { registerClusterLoadRoute } from './cluster';
import {
@ -15,12 +14,12 @@ import {
} from './pipeline';
import { registerPipelinesListRoute, registerPipelinesDeleteRoute } from './pipelines';
export function registerRoutes(router: LogstashPluginRouter, security?: SecurityPluginSetup) {
export function registerRoutes(router: LogstashPluginRouter) {
registerClusterLoadRoute(router);
registerPipelineDeleteRoute(router);
registerPipelineLoadRoute(router);
registerPipelineSaveRoute(router, security);
registerPipelineSaveRoute(router);
registerPipelinesListRoute(router);
registerPipelinesDeleteRoute(router);

View file

@ -9,15 +9,11 @@ import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { wrapRouteWithLicenseCheck } from '@kbn/licensing-plugin/server';
import { SecurityPluginSetup } from '@kbn/security-plugin/server';
import { Pipeline } from '../../models/pipeline';
import { checkLicense } from '../../lib/check_license';
import type { LogstashPluginRouter } from '../../types';
export function registerPipelineSaveRoute(
router: LogstashPluginRouter,
security?: SecurityPluginSetup
) {
export function registerPipelineSaveRoute(router: LogstashPluginRouter) {
router.put(
{
path: '/api/logstash/pipeline/{id}',
@ -39,14 +35,12 @@ export function registerPipelineSaveRoute(
wrapRouteWithLicenseCheck(
checkLicense,
router.handleLegacyErrors(async (context, request, response) => {
const coreContext = await context.core;
try {
let username: string | undefined;
if (security) {
const user = await security.authc.getCurrentUser(request);
username = user?.username;
}
const user = coreContext.security.authc.getCurrentUser();
const username = user?.username;
const { client } = (await context.core).elasticsearch;
const { client } = coreContext.elasticsearch;
const pipeline = Pipeline.fromDownstreamJSON(request.body, request.params.id, username);
await client.asCurrentUser.logstash.putPipeline({

View file

@ -16,7 +16,6 @@
"@kbn/features-plugin",
"@kbn/licensing-plugin",
"@kbn/security-plugin",
"@kbn/i18n",
"@kbn/i18n-react",
"@kbn/test-jest-helpers",