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

[Rename] security-oss plugin #146

Merged
merged 2 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/plugins/security_oss/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `securityOss` plugin

`securityOss` is responsible for educating users about Elastic's free security features,
`securityOss` is responsible for educating users about OpenSearch's free security features,
so they can properly protect the data within their clusters.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "securityOss",
"version": "8.0.0",
"kibanaVersion": "kibana",
"opensearchDashboardsVersion": "opensearchDashboards",
"configPath": ["security"],
"ui": true,
"server": true,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/security_oss/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { PluginInitializerContext } from 'kibana/public';
import { PluginInitializerContext } from 'opensearch-dashboards/public';

import { SecurityOssPlugin } from './plugin';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import {
EuiSpacer,
EuiText,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { I18nProvider, FormattedMessage } from '@kbn/i18n/react';
import { MountPoint } from 'kibana/public';
import { i18n } from '@osd/i18n';
import { I18nProvider, FormattedMessage } from '@osd/i18n/react';
import { MountPoint } from 'opensearch-dashboards/public';
import React, { useState } from 'react';
import { render, unmountComponentAtNode } from 'react-dom';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { CoreSetup, CoreStart, MountPoint, Toast } from 'kibana/public';
import { CoreSetup, CoreStart, MountPoint, Toast } from 'opensearch-dashboards/public';

import { BehaviorSubject, combineLatest, from } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators';
Expand Down
62 changes: 31 additions & 31 deletions src/plugins/security_oss/server/check_cluster_data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,34 @@
* under the License.
*/

import { elasticsearchServiceMock, loggingSystemMock } from '../../../core/server/mocks';
import { opensearchServiceMock, loggingSystemMock } from '../../../core/server/mocks';
import { createClusterDataCheck } from './check_cluster_data';

describe('checkClusterForUserData', () => {
it('returns false if no data is found', async () => {
const esClient = elasticsearchServiceMock.createElasticsearchClient();
esClient.cat.indices.mockResolvedValue(
elasticsearchServiceMock.createApiResponse({ body: [] })
const opensearchClient = opensearchServiceMock.createOpenSearchClient();
opensearchClient.cat.indices.mockResolvedValue(
opensearchServiceMock.createApiResponse({ body: [] })
);

const log = loggingSystemMock.createLogger();

const response = await createClusterDataCheck()(esClient, log);
const response = await createClusterDataCheck()(opensearchClient, log);
expect(response).toEqual(false);
expect(esClient.cat.indices).toHaveBeenCalledTimes(1);
expect(opensearchClient.cat.indices).toHaveBeenCalledTimes(1);
});

it('returns false if data only exists in system indices', async () => {
const esClient = elasticsearchServiceMock.createElasticsearchClient();
esClient.cat.indices.mockResolvedValue(
elasticsearchServiceMock.createApiResponse({
const opensearchClient = opensearchServiceMock.createOpenSearchClient();
opensearchClient.cat.indices.mockResolvedValue(
opensearchServiceMock.createApiResponse({
body: [
{
index: '.kibana',
index: '.opensearch-dashboards',
'docs.count': 500,
},
{
index: 'kibana_sample_ecommerce_data',
index: 'opensearch_dashboards_sample_ecommerce_data',
'docs.count': 20,
},
{
Expand All @@ -57,18 +57,18 @@ describe('checkClusterForUserData', () => {

const log = loggingSystemMock.createLogger();

const response = await createClusterDataCheck()(esClient, log);
const response = await createClusterDataCheck()(opensearchClient, log);
expect(response).toEqual(false);
expect(esClient.cat.indices).toHaveBeenCalledTimes(1);
expect(opensearchClient.cat.indices).toHaveBeenCalledTimes(1);
});

it('returns true if data exists in non-system indices', async () => {
const esClient = elasticsearchServiceMock.createElasticsearchClient();
esClient.cat.indices.mockResolvedValue(
elasticsearchServiceMock.createApiResponse({
const opensearchClient = opensearchServiceMock.createOpenSearchClient();
opensearchClient.cat.indices.mockResolvedValue(
opensearchServiceMock.createApiResponse({
body: [
{
index: '.kibana',
index: '.opensearch-dashboards',
'docs.count': 500,
},
{
Expand All @@ -81,31 +81,31 @@ describe('checkClusterForUserData', () => {

const log = loggingSystemMock.createLogger();

const response = await createClusterDataCheck()(esClient, log);
const response = await createClusterDataCheck()(opensearchClient, log);
expect(response).toEqual(true);
});

it('checks each time until the first true response is returned, then stops checking', async () => {
const esClient = elasticsearchServiceMock.createElasticsearchClient();
esClient.cat.indices
const opensearchClient = opensearchServiceMock.createOpenSearchClient();
opensearchClient.cat.indices
.mockResolvedValueOnce(
elasticsearchServiceMock.createApiResponse({
opensearchServiceMock.createApiResponse({
body: [],
})
)
.mockRejectedValueOnce(new Error('something terrible happened'))
.mockResolvedValueOnce(
elasticsearchServiceMock.createApiResponse({
opensearchServiceMock.createApiResponse({
body: [
{
index: '.kibana',
index: '.opensearch-dashboards',
'docs.count': 500,
},
],
})
)
.mockResolvedValueOnce(
elasticsearchServiceMock.createApiResponse({
opensearchServiceMock.createApiResponse({
body: [
{
index: 'some_real_index',
Expand All @@ -119,19 +119,19 @@ describe('checkClusterForUserData', () => {

const doesClusterHaveUserData = createClusterDataCheck();

let response = await doesClusterHaveUserData(esClient, log);
let response = await doesClusterHaveUserData(opensearchClient, log);
expect(response).toEqual(false);

response = await doesClusterHaveUserData(esClient, log);
response = await doesClusterHaveUserData(opensearchClient, log);
expect(response).toEqual(false);

response = await doesClusterHaveUserData(esClient, log);
response = await doesClusterHaveUserData(opensearchClient, log);
expect(response).toEqual(false);

response = await doesClusterHaveUserData(esClient, log);
response = await doesClusterHaveUserData(opensearchClient, log);
expect(response).toEqual(true);

expect(esClient.cat.indices).toHaveBeenCalledTimes(4);
expect(opensearchClient.cat.indices).toHaveBeenCalledTimes(4);
expect(log.warn.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Expand All @@ -140,9 +140,9 @@ describe('checkClusterForUserData', () => {
]
`);

response = await doesClusterHaveUserData(esClient, log);
response = await doesClusterHaveUserData(opensearchClient, log);
expect(response).toEqual(true);
// Same number of calls as above. We should not have to interrogate again.
expect(esClient.cat.indices).toHaveBeenCalledTimes(4);
expect(opensearchClient.cat.indices).toHaveBeenCalledTimes(4);
});
});
8 changes: 4 additions & 4 deletions src/plugins/security_oss/server/check_cluster_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
* under the License.
*/

import { ElasticsearchClient, Logger } from 'kibana/server';
import { OpenSearchClient, Logger } from 'opensearch-dashboards/server';

export const createClusterDataCheck = () => {
let clusterHasUserData = false;

return async function doesClusterHaveUserData(esClient: ElasticsearchClient, log: Logger) {
return async function doesClusterHaveUserData(opensearchClient: OpenSearchClient, log: Logger) {
if (!clusterHasUserData) {
try {
const indices = await esClient.cat.indices<
const indices = await opensearchClient.cat.indices<
Array<{ index: string; ['docs.count']: string }>
>({
format: 'json',
h: ['index', 'docs.count'],
});
clusterHasUserData = indices.body.some((indexCount) => {
const isInternalIndex =
indexCount.index.startsWith('.') || indexCount.index.startsWith('kibana_sample_');
indexCount.index.startsWith('.') || indexCount.index.startsWith('opensearch_dashboards_sample_');

return !isInternalIndex && parseInt(indexCount['docs.count'], 10) > 0;
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/security_oss/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { schema, TypeOf } from '@osd/config-schema';

export type ConfigType = TypeOf<typeof ConfigSchema>;

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/security_oss/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

import { TypeOf } from '@kbn/config-schema';
import { TypeOf } from '@osd/config-schema';

import { PluginConfigDescriptor, PluginInitializerContext } from 'kibana/server';
import { PluginConfigDescriptor, PluginInitializerContext } from 'opensearch-dashboards/server';
import { ConfigSchema } from './config';
import { SecurityOssPlugin } from './plugin';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/security_oss/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { CoreSetup, Logger, Plugin, PluginInitializerContext } from 'kibana/server';
import { CoreSetup, Logger, Plugin, PluginInitializerContext } from 'opensearch-dashboards/server';
import { BehaviorSubject, Observable } from 'rxjs';
import { createClusterDataCheck } from './check_cluster_data';
import { ConfigType } from './config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IRouter, Logger } from 'kibana/server';
import { IRouter, Logger } from 'opensearch-dashboards/server';
import { combineLatest, Observable } from 'rxjs';
import { createClusterDataCheck } from '../check_cluster_data';
import { ConfigType } from '../config';
Expand Down Expand Up @@ -54,7 +54,7 @@ export const setupDisplayInsecureClusterAlertRoute = ({
}

const hasData = await doesClusterHaveUserData(
context.core.elasticsearch.client.asInternalUser,
context.core.opensearch.client.asInternalUser,
log
);
return response.ok({ body: { displayAlert: hasData } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { setupServer } from '../../../../../core/server/test_utils';
import { setupDisplayInsecureClusterAlertRoute } from '../display_insecure_cluster_alert';
import { ConfigType } from '../../config';
import { BehaviorSubject, of } from 'rxjs';
import { UnwrapPromise } from '@kbn/utility-types';
import { UnwrapPromise } from '@osd/utility-types';
import { createClusterDataCheck } from '../../check_cluster_data';
import supertest from 'supertest';

Expand Down