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

Fix sslConfig for multiple datasource to handle when certificateAuthorities is unset #6282

Merged
merged 3 commits into from
Mar 28, 2024
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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BUG][Multiple Datasource] Fix data source filter bug and add tests ([#6152](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6152))
- [BUG][Multiple Datasource] Fix obsolete snapshots for test within data source management plugin ([#6185](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6185))
- [Workspace] Add base path when parse url in http service ([#6233](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6233))
- [Multiple Datasource] Fix sslConfig for multiple datasource to handle when certificateAuthorities is unset ([#6282](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6282))

### 🚞 Infrastructure

Expand Down
29 changes: 28 additions & 1 deletion src/plugins/data_source/server/client/client_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('parseClientOptions', () => {
ssl: {
requestCert: true,
rejectUnauthorized: false,
ca: [],
ca: undefined,
},
})
);
Expand Down Expand Up @@ -109,4 +109,31 @@ describe('parseClientOptions', () => {
})
);
});

test('test ssl config with verification mode set to full with no ca list', () => {
const config = {
enabled: true,
ssl: {
verificationMode: 'full',
},
clientPool: {
size: 5,
},
} as DataSourcePluginConfigType;
mockReadFileSync.mockReset();
mockReadFileSync.mockImplementation((path: string) => `content-of-${path}`);
const parsedConfig = parseClientOptions(config, TEST_DATA_SOURCE_ENDPOINT);
expect(mockReadFileSync).toHaveBeenCalledTimes(0);
mockReadFileSync.mockClear();
expect(parsedConfig).toEqual(
expect.objectContaining({
node: TEST_DATA_SOURCE_ENDPOINT,
ssl: {
requestCert: true,
rejectUnauthorized: true,
ca: undefined,
},
})
);
});
});
2 changes: 1 addition & 1 deletion src/plugins/data_source/server/client/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function parseClientOptions(
config.ssl?.certificateAuthorities
);

sslConfig.ca = certificateAuthorities || [];
sslConfig.ca = certificateAuthorities;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need to fix the interface to make ca as optional I think, at line 16

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should already be covered because DataSourceSSLConfigOptions is a Partial

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, thanks!

}

const clientOptions: ClientOptions = {
Expand Down
28 changes: 27 additions & 1 deletion src/plugins/data_source/server/legacy/client_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('parseClientOptions', () => {
host: TEST_DATA_SOURCE_ENDPOINT,
ssl: {
rejectUnauthorized: false,
ca: [],
ca: undefined,
},
})
);
Expand Down Expand Up @@ -105,4 +105,30 @@ describe('parseClientOptions', () => {
})
);
});

test('test ssl config with verification mode set to full with no ca list', () => {
const config = {
enabled: true,
ssl: {
verificationMode: 'full',
},
clientPool: {
size: 5,
},
} as DataSourcePluginConfigType;
mockReadFileSync.mockReset();
mockReadFileSync.mockImplementation((path: string) => `content-of-${path}`);
const parsedConfig = parseClientOptions(config, TEST_DATA_SOURCE_ENDPOINT);
expect(mockReadFileSync).toHaveBeenCalledTimes(0);
mockReadFileSync.mockClear();
expect(parsedConfig).toEqual(
expect.objectContaining({
host: TEST_DATA_SOURCE_ENDPOINT,
ssl: {
rejectUnauthorized: true,
ca: undefined,
},
})
);
});
});
2 changes: 1 addition & 1 deletion src/plugins/data_source/server/legacy/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function parseClientOptions(
config.ssl?.certificateAuthorities
);

sslConfig.ca = certificateAuthorities || [];
sslConfig.ca = certificateAuthorities;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need to fix the interface to make ca as optional I think, at line 16

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should already be covered because DataSourceSSLConfigOptions is a Partial

}

const configOptions: ConfigOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('readCertificateAuthorities', () => {
expect(mockReadFileSync).toHaveBeenCalledTimes(0);
mockReadFileSync.mockClear();
expect(certificateAuthorities).toEqual({
certificateAuthorities: [],
certificateAuthorities: undefined,
});
});

Expand All @@ -52,7 +52,7 @@ describe('readCertificateAuthorities', () => {
expect(mockReadFileSync).toHaveBeenCalledTimes(0);
mockReadFileSync.mockClear();
expect(certificateAuthorities).toEqual({
certificateAuthorities: [],
certificateAuthorities: undefined,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { readFileSync } from 'fs';
export const readCertificateAuthorities = (
listOfCertificateAuthorities: string | string[] | undefined
) => {
let certificateAuthorities: string[] | undefined = [];
let certificateAuthorities: string[] | undefined;

const addCertificateAuthorities = (ca: string[]) => {
if (ca && ca.length) {
Expand Down
Loading