Skip to content

Commit

Permalink
Update Beats tutorials for security on by default (elastic#120388)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover authored and TinLe committed Dec 22, 2021
1 parent 622df6c commit 17dcd15
Show file tree
Hide file tree
Showing 121 changed files with 1,726 additions and 1,508 deletions.
3 changes: 2 additions & 1 deletion src/plugins/home/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export interface HomeServerPluginSetupDependencies {
}

export class HomeServerPlugin implements Plugin<HomeServerPluginSetup, HomeServerPluginStart> {
private readonly tutorialsRegistry = new TutorialsRegistry();
private readonly tutorialsRegistry;
private readonly sampleDataRegistry: SampleDataRegistry;
private customIntegrations?: CustomIntegrationsPluginSetup;

constructor(private readonly initContext: PluginInitializerContext) {
this.sampleDataRegistry = new SampleDataRegistry(this.initContext);
this.tutorialsRegistry = new TutorialsRegistry(this.initContext);
}

public setup(core: CoreSetup, plugins: HomeServerPluginSetupDependencies): HomeServerPluginSetup {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum TutorialsCategory {
export type Platform = 'WINDOWS' | 'OSX' | 'DEB' | 'RPM';

export interface TutorialContext {
kibanaBranch: string;
[key: string]: unknown;
}
export type TutorialProvider = (context: TutorialContext) => TutorialSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const validTutorialProvider = VALID_TUTORIAL;

describe('TutorialsRegistry', () => {
let mockCoreSetup: MockedKeys<CoreSetup>;
let mockInitContext: ReturnType<typeof coreMock.createPluginInitializerContext>;
let testProvider: TutorialProvider;
let testScopedTutorialContextFactory: ScopedTutorialContextFactory;
let mockCustomIntegrationsPluginSetup: jest.Mocked<CustomIntegrationsPluginSetup>;
Expand All @@ -80,6 +81,7 @@ describe('TutorialsRegistry', () => {
describe('GET /api/kibana/home/tutorials', () => {
beforeEach(() => {
mockCoreSetup = coreMock.createSetup();
mockInitContext = coreMock.createPluginInitializerContext();
});

test('has a router that retrieves registered tutorials', () => {
Expand All @@ -90,21 +92,30 @@ describe('TutorialsRegistry', () => {

describe('setup', () => {
test('exposes proper contract', () => {
const setup = new TutorialsRegistry().setup(mockCoreSetup, mockCustomIntegrationsPluginSetup);
const setup = new TutorialsRegistry(mockInitContext).setup(
mockCoreSetup,
mockCustomIntegrationsPluginSetup
);
expect(setup).toHaveProperty('registerTutorial');
expect(setup).toHaveProperty('addScopedTutorialContextFactory');
});

test('registerTutorial throws when registering a tutorial with an invalid schema', () => {
const setup = new TutorialsRegistry().setup(mockCoreSetup, mockCustomIntegrationsPluginSetup);
const setup = new TutorialsRegistry(mockInitContext).setup(
mockCoreSetup,
mockCustomIntegrationsPluginSetup
);
testProvider = ({}) => invalidTutorialProvider;
expect(() => setup.registerTutorial(testProvider)).toThrowErrorMatchingInlineSnapshot(
`"Unable to register tutorial spec because its invalid. Error: [name]: is not allowed to be empty"`
);
});

test('registerTutorial registers a tutorial with a valid schema', () => {
const setup = new TutorialsRegistry().setup(mockCoreSetup, mockCustomIntegrationsPluginSetup);
const setup = new TutorialsRegistry(mockInitContext).setup(
mockCoreSetup,
mockCustomIntegrationsPluginSetup
);
testProvider = ({}) => validTutorialProvider;
expect(() => setup.registerTutorial(testProvider)).not.toThrowError();
expect(mockCustomIntegrationsPluginSetup.registerCustomIntegration.mock.calls).toEqual([
Expand All @@ -129,7 +140,10 @@ describe('TutorialsRegistry', () => {
});

test('addScopedTutorialContextFactory throws when given a scopedTutorialContextFactory that is not a function', () => {
const setup = new TutorialsRegistry().setup(mockCoreSetup, mockCustomIntegrationsPluginSetup);
const setup = new TutorialsRegistry(mockInitContext).setup(
mockCoreSetup,
mockCustomIntegrationsPluginSetup
);
const testItem = {} as TutorialProvider;
expect(() =>
setup.addScopedTutorialContextFactory(testItem)
Expand All @@ -139,7 +153,10 @@ describe('TutorialsRegistry', () => {
});

test('addScopedTutorialContextFactory adds a scopedTutorialContextFactory when given a function', () => {
const setup = new TutorialsRegistry().setup(mockCoreSetup, mockCustomIntegrationsPluginSetup);
const setup = new TutorialsRegistry(mockInitContext).setup(
mockCoreSetup,
mockCustomIntegrationsPluginSetup
);
testScopedTutorialContextFactory = ({}) => 'string';
expect(() =>
setup.addScopedTutorialContextFactory(testScopedTutorialContextFactory)
Expand All @@ -149,7 +166,7 @@ describe('TutorialsRegistry', () => {

describe('start', () => {
test('exposes proper contract', () => {
const start = new TutorialsRegistry().start(
const start = new TutorialsRegistry(mockInitContext).start(
coreMock.createStart(),
mockCustomIntegrationsPluginSetup
);
Expand Down
15 changes: 11 additions & 4 deletions src/plugins/home/server/services/tutorials/tutorials_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
* Side Public License, v 1.
*/

import { CoreSetup, CoreStart } from 'src/core/server';
import { CoreSetup, CoreStart, PluginInitializerContext } from 'src/core/server';
import {
TutorialProvider,
TutorialContextFactory,
ScopedTutorialContextFactory,
TutorialContext,
} from './lib/tutorials_registry_types';
import { TutorialSchema, tutorialSchema } from './lib/tutorial_schema';
import { builtInTutorials } from '../../tutorials/register';
Expand Down Expand Up @@ -71,12 +72,14 @@ export class TutorialsRegistry {
private tutorialProviders: TutorialProvider[] = []; // pre-register all the tutorials we know we want in here
private readonly scopedTutorialContextFactories: TutorialContextFactory[] = [];

constructor(private readonly initContext: PluginInitializerContext) {}

public setup(core: CoreSetup, customIntegrations?: CustomIntegrationsPluginSetup) {
const router = core.http.createRouter();
router.get(
{ path: '/api/kibana/home/tutorials', validate: false },
async (context, req, res) => {
const initialContext = {};
const initialContext = this.baseTutorialContext;
const scopedContext = this.scopedTutorialContextFactories.reduce(
(accumulatedContext, contextFactory) => {
return { ...accumulatedContext, ...contextFactory(req) };
Expand All @@ -92,7 +95,7 @@ export class TutorialsRegistry {
);
return {
registerTutorial: (specProvider: TutorialProvider) => {
const emptyContext = {};
const emptyContext = this.baseTutorialContext;
let tutorial: TutorialSchema;
try {
tutorial = tutorialSchema.validate(specProvider(emptyContext));
Expand Down Expand Up @@ -132,12 +135,16 @@ export class TutorialsRegistry {

if (customIntegrations) {
builtInTutorials.forEach((provider) => {
const tutorial = provider({});
const tutorial = provider(this.baseTutorialContext);
registerBeatsTutorialsWithCustomIntegrations(core, customIntegrations, tutorial);
});
}
return {};
}

private get baseTutorialContext(): TutorialContext {
return { kibanaBranch: this.initContext.env.packageInfo.branch };
}
}

/** @public */
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/activemq_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function activemqLogsSpecProvider(context: TutorialContext): TutorialSche
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/activemq_logs/screenshot.png',
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['web'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/activemq_metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export function activemqMetricsSpecProvider(context: TutorialContext): TutorialS
},
completionTimeMinutes: 10,
onPrem: onPremInstructions(moduleName, context),
elasticCloud: cloudInstructions(moduleName),
onPremElasticCloud: onPremCloudInstructions(moduleName),
elasticCloud: cloudInstructions(moduleName, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, context),

integrationBrowserCategories: ['web'],
};
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/aerospike_metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export function aerospikeMetricsSpecProvider(context: TutorialContext): Tutorial
},
completionTimeMinutes: 10,
onPrem: onPremInstructions(moduleName, context),
elasticCloud: cloudInstructions(moduleName),
onPremElasticCloud: onPremCloudInstructions(moduleName),
elasticCloud: cloudInstructions(moduleName, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, context),
integrationBrowserCategories: ['web'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/apache_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function apacheLogsSpecProvider(context: TutorialContext): TutorialSchema
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/apache_logs/screenshot.png',
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['web'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/apache_metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function apacheMetricsSpecProvider(context: TutorialContext): TutorialSch
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/apache_metrics/screenshot.png',
onPrem: onPremInstructions(moduleName, context),
elasticCloud: cloudInstructions(moduleName),
onPremElasticCloud: onPremCloudInstructions(moduleName),
elasticCloud: cloudInstructions(moduleName, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, context),
integrationBrowserCategories: ['web'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/auditbeat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ processes, users, logins, sockets information, file accesses, and more. \
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/auditbeat/screenshot.png',
onPrem: onPremInstructions(platforms, context),
elasticCloud: cloudInstructions(platforms),
onPremElasticCloud: onPremCloudInstructions(platforms),
elasticCloud: cloudInstructions(platforms, context),
onPremElasticCloud: onPremCloudInstructions(platforms, context),
integrationBrowserCategories: ['web'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/auditd_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function auditdLogsSpecProvider(context: TutorialContext): TutorialSchema
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/auditd_logs/screenshot.png',
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['os_system'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/aws_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function awsLogsSpecProvider(context: TutorialContext): TutorialSchema {
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/aws_logs/screenshot.png',
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['aws', 'cloud', 'datastore', 'security', 'network'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/aws_metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function awsMetricsSpecProvider(context: TutorialContext): TutorialSchema
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/aws_metrics/screenshot.png',
onPrem: onPremInstructions(moduleName, context),
elasticCloud: cloudInstructions(moduleName),
onPremElasticCloud: onPremCloudInstructions(moduleName),
elasticCloud: cloudInstructions(moduleName, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, context),
integrationBrowserCategories: ['aws', 'cloud', 'datastore', 'security', 'network'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/azure_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function azureLogsSpecProvider(context: TutorialContext): TutorialSchema
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/azure_logs/screenshot.png',
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['azure', 'cloud', 'network', 'security'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/azure_metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function azureMetricsSpecProvider(context: TutorialContext): TutorialSche
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/azure_metrics/screenshot.png',
onPrem: onPremInstructions(moduleName, context),
elasticCloud: cloudInstructions(moduleName),
onPremElasticCloud: onPremCloudInstructions(moduleName),
elasticCloud: cloudInstructions(moduleName, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, context),
integrationBrowserCategories: ['azure', 'cloud', 'network', 'security'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/barracuda_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export function barracudaLogsSpecProvider(context: TutorialContext): TutorialSch
},
completionTimeMinutes: 10,
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['network', 'security'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/bluecoat_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export function bluecoatLogsSpecProvider(context: TutorialContext): TutorialSche
},
completionTimeMinutes: 10,
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['network', 'security'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/cef_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export function cefLogsSpecProvider(context: TutorialContext): TutorialSchema {
},
completionTimeMinutes: 10,
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['network', 'security'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/ceph_metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export function cephMetricsSpecProvider(context: TutorialContext): TutorialSchem
},
completionTimeMinutes: 10,
onPrem: onPremInstructions(moduleName, context),
elasticCloud: cloudInstructions(moduleName),
onPremElasticCloud: onPremCloudInstructions(moduleName),
elasticCloud: cloudInstructions(moduleName, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, context),
integrationBrowserCategories: ['network', 'security'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/checkpoint_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export function checkpointLogsSpecProvider(context: TutorialContext): TutorialSc
},
completionTimeMinutes: 10,
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['security'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/cisco_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function ciscoLogsSpecProvider(context: TutorialContext): TutorialSchema
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/cisco_logs/screenshot.png',
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['network', 'security'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/cloudwatch_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export function cloudwatchLogsSpecProvider(context: TutorialContext): TutorialSc
},
completionTimeMinutes: 10,
onPrem: onPremInstructions([], context),
elasticCloud: cloudInstructions(),
onPremElasticCloud: onPremCloudInstructions(),
elasticCloud: cloudInstructions(context),
onPremElasticCloud: onPremCloudInstructions(context),
integrationBrowserCategories: ['aws', 'cloud', 'datastore', 'security', 'network'],
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export function cockroachdbMetricsSpecProvider(context: TutorialContext): Tutori
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/cockroachdb_metrics/screenshot.png',
onPrem: onPremInstructions(moduleName, context),
elasticCloud: cloudInstructions(moduleName),
onPremElasticCloud: onPremCloudInstructions(moduleName),
elasticCloud: cloudInstructions(moduleName, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, context),
integrationBrowserCategories: ['security', 'network', 'web'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/consul_metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function consulMetricsSpecProvider(context: TutorialContext): TutorialSch
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/consul_metrics/screenshot.png',
onPrem: onPremInstructions(moduleName, context),
elasticCloud: cloudInstructions(moduleName),
onPremElasticCloud: onPremCloudInstructions(moduleName),
elasticCloud: cloudInstructions(moduleName, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, context),
integrationBrowserCategories: ['security', 'network', 'web'],
};
}
4 changes: 2 additions & 2 deletions src/plugins/home/server/tutorials/coredns_logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function corednsLogsSpecProvider(context: TutorialContext): TutorialSchem
completionTimeMinutes: 10,
previewImagePath: '/plugins/home/assets/coredns_logs/screenshot.png',
onPrem: onPremInstructions(moduleName, platforms, context),
elasticCloud: cloudInstructions(moduleName, platforms),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms),
elasticCloud: cloudInstructions(moduleName, platforms, context),
onPremElasticCloud: onPremCloudInstructions(moduleName, platforms, context),
integrationBrowserCategories: ['security', 'network', 'web'],
};
}
Loading

0 comments on commit 17dcd15

Please sign in to comment.