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

[MD]Support md global configuration and cm plugin level configuration on osd.yml #18

Merged
merged 8 commits into from
Jul 22, 2022
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
1 change: 0 additions & 1 deletion config/credential_management.yml

This file was deleted.

12 changes: 12 additions & 0 deletions config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,15 @@
# Set the value of this setting to false to suppress search usage telemetry
# for reducing the load of OpenSearch cluster.
# data.search.usageTelemetry.enabled: false

# Set the value of this setting to true to enable all multipleDataSource
# related features including:
# 1. credential management for managing the credential of each OpenSearch cluster.
# 2. data source management for managing the connection endpoint of each OpenSearch cluster.
# opensearchDashboards.multipleDataSource.enabled: false

# Set the value of this setting to custermize crypto materials config to
# use encryption / decryption within credential management plugin
# credential_management.keyName: "keyName"
# credential_management.keyNamespace: "keyNamespace"
# credential_management.materialPath: "path/to/your/crypto_material"
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"osd:bootstrap": "node scripts/build_ts_refs && node scripts/register_git_hook",
"spec_to_console": "node scripts/spec_to_console",
"pkg-version": "./dev-tools/get-version.sh"
"pkg-version": "./dev-tools/get-version.sh",
"generate-crypto-materials": "node scripts/crypto_materials_generator"
},
"repository": {
"type": "git",
Expand Down
17 changes: 17 additions & 0 deletions scripts/crypto_materials_generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

require('../src/setup_node_env');

var args = require('yargs').argv;
var generateCryptoMaterials = require('../src/plugins/credential_management/server/crypto/crypto_cli');

generateCryptoMaterials(args.path, args.keyName, args.keyNamespace);
3 changes: 3 additions & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export function pluginInitializerContextConfigMock<T>(config: T) {
index: '.opensearch_dashboards_tests',
autocompleteTerminateAfter: duration(100000),
autocompleteTimeout: duration(1000),
multipleDataSource: {
enabled: false,
},
},
opensearch: {
shardTimeout: duration('30s'),
Expand Down
3 changes: 3 additions & 0 deletions src/core/server/opensearch_dashboards_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export const config = {
defaultValue: '',
}),
}),
multipleDataSource: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
}),
deprecations,
};
4 changes: 2 additions & 2 deletions src/core/server/opensearch_data/client/data_source_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Logger } from '../../logging';
import { OpenSearchClient, OpenSearchClientConfig } from '../../opensearch/client';
import { SavedObjectsClientContract } from '../../saved_objects/types';
// @ts-ignore
import { CryptoCli } from '../../../../../src/plugins/credential_management/server/crypto/cli/crypto_cli';
import { CryptographySingleton } from '../../../../../src/plugins/credential_management/server/crypto/singleton/cryptography_singleton';

/**
* TODO: update doc
Expand Down Expand Up @@ -125,7 +125,7 @@ export class DataSourceClient implements ICustomDataSourceClient {
const credentialObj = credential!.attributes as any;
const { user_name: username, password: encryptedPassword } = credentialObj.credential_material;

const password = await CryptoCli.getInstance().decrypt(
const password = await CryptographySingleton.getInstance().decrypt(
Buffer.from(encryptedPassword, 'base64')
);
return { username, password };
Expand Down
7 changes: 6 additions & 1 deletion src/core/server/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,12 @@ export interface Plugin<

export const SharedGlobalConfigKeys = {
// We can add more if really needed
opensearchDashboards: ['index', 'autocompleteTerminateAfter', 'autocompleteTimeout'] as const,
opensearchDashboards: [
'index',
'autocompleteTerminateAfter',
'autocompleteTimeout',
'multipleDataSource',
] as const,
opensearch: ['shardTimeout', 'requestTimeout', 'pingTimeout'] as const,
path: ['data'] as const,
savedObjects: ['maxImportPayloadBytes'] as const,
Expand Down
3 changes: 3 additions & 0 deletions src/legacy/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ export default () =>
faviconUrl: Joi.any().default('/'),
applicationTitle: Joi.any().default(''),
}),
multipleDataSource: Joi.object({
enabled: Joi.boolean().default(false),
}),
}).default(),

savedObjects: HANDLED_IN_NEW_PLATFORM,
Expand Down
28 changes: 23 additions & 5 deletions src/plugins/credential_management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,34 @@ See the [OpenSearch Dashboards contributing
guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/master/CONTRIBUTING.md) for instructions
setting up your development environment.

## Configuration

## Build and Run crypto_materials_generator
1. To enable this feature, override config/opensearch_dashboards.yml

```
npm install @types/yargs
npm install -g ts-node typescript '@types/node'
opensearchDashboards.multipleDataSource.enabled: true
```

2. To setup path for crypto material, override config/opensearch_dashboards.yml

```
credential_management.materialPath: "path/to/your/crypto_material"
```

## Generate your own crypto material via crypto_materials_generator script

```
cd <root dir>
yarn generate-crypto-materials --path='path/to/your/crypto_material' --keyName='aes-name' --keyNamespace='aes-namespace'

// Expected Output

% yarn generate-crypto-materials --path='data/crypto_material' --keyName='aes-name' --keyNamespace='aes-namespace'

yarn run v1.22.19
$ node scripts/crypto_materials_generator --path=data/crypto_material --keyName=aes-name --keyNamespace=aes-namespace
Crypto materials generated!
✨ Done in 2.06s.

ts-node src/plugins/credential_management/server/crypto/crypto_materials_generator.ts --keyName='aes-name' --keyNamespace='aes-namespace'
```


26 changes: 26 additions & 0 deletions src/plugins/credential_management/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

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

export const configSchema = schema.object({
keyName: schema.string({
defaultValue: 'keyName',
}),
keyNamespace: schema.string({
defaultValue: 'keyNamespace',
}),
materialPath: schema.string({
defaultValue: 'data/crypto_material',
}),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"id": "credentialManagement",
"version": "1.0.0",
"opensearchDashboardsVersion": "opensearchDashboards",
"configPath": ["credential_management"],
"server": true,
"ui": true,
"requiredPlugins": ["management", "data", "navigation", "urlForwarding"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { HttpSetup } from '../../../../core/public';
import { CredentialCreationConfig, CredentialCreationManager } from './creation';


interface SetupDependencies {
httpClient: HttpSetup;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Any modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
import { CryptoCli } from '../crypto';
import { CryptographySingleton } from '../crypto';
import { Credential } from '../../common';

const USERNAME_PASSWORD_TYPE: Credential.USERNAME_PASSWORD_TYPE = 'username_password_credential';
Expand All @@ -20,7 +20,7 @@ export async function encryptionHandler(
usernamePasswordCredentialMaterials: Record<string, string> | undefined,
awsIamCredentialMaterials: Record<string, string> | undefined
) {
const cryptoCli = CryptoCli.getInstance();
const cryptoCli = CryptographySingleton.getInstance();
if (credentialType === USERNAME_PASSWORD_TYPE && usernamePasswordCredentialMaterials) {
const { user_name, password } = usernamePasswordCredentialMaterials;
return {
Expand Down
97 changes: 0 additions & 97 deletions src/plugins/credential_management/server/crypto/cli/crypto_cli.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@
* GitHub history for details.
*/

import { CryptoCli } from './cli';

const args = require('yargs').argv;

CryptoCli.generateCryptoMaterials(args.keyName, args.keyNamespace);
export { generateCryptoMaterials } from './singleton';
3 changes: 2 additions & 1 deletion src/plugins/credential_management/server/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
* GitHub history for details.
*/

export { CryptoCli } from './cli/index';
export { CryptographySingleton } from './singleton/cryptography_singleton';
export { generateCryptoMaterials } from './crypto_cli';
Loading