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

Merge main changes to Feature-Anywhere branch #4295

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e74ab2d
Fix header icon (#3910) (#3915)
opensearch-trigger-bot[bot] Apr 22, 2023
ef2cb84
Add server side private IP blocking for data source endpoints validat…
kristenTian Apr 24, 2023
a947240
Docs (Jest): Update jest documentation links (#3931)
joshuarrrr Apr 24, 2023
b97a4b5
Revert "[CCI] Replace jquery usage in console plugin with native meth…
joshuarrrr Apr 24, 2023
0e34c3c
[BUG][Dashboard listing] push to history if dashboard otherwise nav (…
kavilla Apr 25, 2023
66aa122
remove jquery console release note for https://github.com/opensearch-…
joshuarrrr Apr 25, 2023
755f16b
[CCI] Update js-yaml to v4.0.5 (#3770)
andreymyssak Apr 25, 2023
ac2ee3a
Update README.md (#3788)
vagimeli Apr 26, 2023
a8ace28
Bump yaml to 2.2.2 (#3947)
manasvinibs Apr 27, 2023
ca0bb8f
Bump `joi` to v14 to avoid the possibility of prototype poisoning in …
AMoo-Miki May 2, 2023
f5a978d
[Doc] Add communication guide (#3837)
joshuarrrr May 3, 2023
5ea0cbe
Temporarily hardcode chromedriver to 112.0.0 to enable all ftr tests …
ananzh May 5, 2023
6e352ff
Fix wording and duplicate code in embeddable example plugin (#3911)
abbyhu2000 May 5, 2023
0188d05
[CI] setup Chrome and utilize binary path (#3997)
kavilla May 11, 2023
8121c9d
[Dashboards listing] fix listing limit (#4021)
kavilla May 15, 2023
0e25f2e
[CCI] Fix EUI/OUI type errors (#3798)
Nicksqain May 15, 2023
87e7951
Fix bottom bar visibility using create portal (#3336) (#3978)
SergeyMyssak May 16, 2023
69b1854
Adds threshold to code coverage changes for project (#4040)
ashwin-pc May 16, 2023
873b7f3
Updates PR template for screenshots and test instructions (#4042)
ashwin-pc May 16, 2023
2c33d57
Replace re2 with RegExp in timeline and add unit tests (#3908)
ananzh May 16, 2023
b04e657
[Console] [CCI] Remove unused ul element and its custom styling. (#3993)
curq May 17, 2023
c5058a3
Add 1.3.10 release note (#4060) (#4063)
opensearch-trigger-bot[bot] May 18, 2023
e737790
[Multiple Datasource] Support Amazon OpenSearch Serverless (#3957)
zhongnansu May 19, 2023
83d7b5b
Remove Sass from `tile_map` plugin (#4110)
BSFishy May 23, 2023
61ea841
Design for New Saved Object Service Interface for Custom Repository (…
bandinib-amzn May 23, 2023
1524784
enhance grouping for context menu options (#3924)
sikhote May 24, 2023
6399a6c
Adding Tao and Zilong to MAINTAINERS (#4137)
zengyan-amazon May 25, 2023
574f119
[MD]Update data-test-subj for functional tests & fix bug in edit flow…
zhongnansu May 25, 2023
1c0ffee
Add support for Node.js >=14.20.1 <19 (#4071)
AMoo-Miki May 26, 2023
ec41f59
Remove timeline application (#3971)
ananzh May 26, 2023
bd7d707
Use `exec` in the CLI shell scripts to prevent new process creation (…
AMoo-Miki May 26, 2023
4978786
chore (lychee): Add company.net to exclusion list (#4171)
joshuarrrr May 30, 2023
20c928f
Bundle Node 14 as a fallback for operating systems that cannot run No…
AMoo-Miki May 30, 2023
821ad73
Refactor authentication description message (#4179)
zhongnansu May 31, 2023
da501e4
[CI] skip checksum verification for cypress tests (#4188)
kavilla May 31, 2023
f017eaa
Adds plugin manifest config to define OpenSearch plugin dependency an…
manasvinibs Jun 1, 2023
efbcb69
[Table Visualization] Remove custom styling for text-align:center in …
curq Jun 1, 2023
bb0c98f
Add new MAINTAINERS to CODEOWNERS file (#4199)
Flyingliuhub Jun 1, 2023
5ffb3d8
Add 2.8.0 release notes (#4204)
kavilla Jun 1, 2023
487cd36
Chore(CHANGELOG): Update with 2.7, 2.8 releases (#3890)
joshuarrrr Jun 2, 2023
5c5de03
[Saved Object Service] Adds Repository Factory Provider (#4149)
bandinib-amzn Jun 5, 2023
cb27336
add category option for context menus (#4144)
sikhote Jun 6, 2023
55b293a
[CCI] Add bluebird replaces for src/plugins/saved_objects (#4026)
Nicksqain Jun 8, 2023
2322c53
Validate and correct change log after 2.8 release (#4275)
zhongnansu Jun 10, 2023
99f7c37
Merge remote-tracking branch 'origin/main' into main-merge
lezzago Jun 15, 2023
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
Prev Previous commit
Next Next commit
Add server side private IP blocking for data source endpoints validat…
…ion (#3912)

Signed-off-by: Kristen Tian <tyarong@amazon.com>
  • Loading branch information
kristenTian authored Apr 24, 2023
commit ef2cb84617793df6bbb1c510d1e3acae448ccb50
3 changes: 3 additions & 0 deletions .lycheeexclude
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ https://opensearch.org/redirect
http://www.opensearch.org/painlessDocs
https://www.hostedgraphite.com/
https://connectionurl.com
http://169.254.169.254/latest/meta-data/

# External urls
https://www.zeek.org/
Expand Down Expand Up @@ -117,3 +118,5 @@ http://www.creedthoughts.gov
https://media-for-the-masses.theacademyofperformingartsandscience.org/
https://yarnpkg.com/latest.msi
https://forum.opensearch.org/
https://facebook.github.io/jest/
https://facebook.github.io/jest/docs/cli.html
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [CVE-2023-25653] Bump node-jose to 2.2.0 ([#3445](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3445))
- [CVE-2023-26486][cve-2023-26487] Bump vega from 5.22.1 to 5.23.0 ([#3533](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3533))
- [CVE-2023-0842] Bump xml2js from 0.4.23 to 0.5.0 ([#3842](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3842))
- [Multi DataSource] Add private IP blocking validation on server side([#3912](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3912))

### 📈 Features/Enhancements

Expand Down
27 changes: 26 additions & 1 deletion config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,30 @@
#data_source.encryption.wrappingKeyNamespace: 'changeme'
#data_source.encryption.wrappingKey: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

#data_source.endpointDeniedIPs: [
# '127.0.0.0/8',
# '::1/128',
# '169.254.0.0/16',
# 'fe80::/10',
# '10.0.0.0/8',
# '172.16.0.0/12',
# '192.168.0.0/16',
# 'fc00::/7',
# '0.0.0.0/8',
# '100.64.0.0/10',
# '192.0.0.0/24',
# '192.0.2.0/24',
# '198.18.0.0/15',
# '192.88.99.0/24',
# '198.51.100.0/24',
# '203.0.113.0/24',
# '224.0.0.0/4',
# '240.0.0.0/4',
# '255.255.255.255/32',
# '::/128',
# '2001:db8::/32',
# 'ff00::/8',
# ]

# Set the value of this setting to false to hide the help menu link to the OpenSearch Dashboards user survey
# opensearchDashboards.survey.url: "https://survey.opensearch.org"
# opensearchDashboards.survey.url: "https://survey.opensearch.org"
1 change: 1 addition & 0 deletions src/plugins/data_source/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: false }),
appender: fileAppenderSchema,
}),
endpointDeniedIPs: schema.maybe(schema.arrayOf(schema.string())),
});

export type DataSourcePluginConfigType = TypeOf<typeof configSchema>;
3 changes: 2 additions & 1 deletion src/plugins/data_source/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class DataSourcePlugin implements Plugin<DataSourcePluginSetup, DataSourc

const dataSourceSavedObjectsClientWrapper = new DataSourceSavedObjectsClientWrapper(
cryptographyServiceSetup,
this.logger.get('data-source-saved-objects-client-wrapper-factory')
this.logger.get('data-source-saved-objects-client-wrapper-factory'),
config.endpointDeniedIPs
);

// Add data source saved objects client wrapper factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ import {
UsernamePasswordTypedContent,
} from '../../common/data_sources';
import { EncryptionContext, CryptographyServiceSetup } from '../cryptography_service';
import { isValidURL } from '../util/endpoint_validator';

/**
* Describes the Credential Saved Objects Client Wrapper class,
* which contains the factory used to create Saved Objects Client Wrapper instances
*/
export class DataSourceSavedObjectsClientWrapper {
constructor(private cryptography: CryptographyServiceSetup, private logger: Logger) {}

/**
* Describes the factory used to create instances of Saved Objects Client Wrappers
* for data source specific operations such as credentials encryption
Expand Down Expand Up @@ -138,14 +137,11 @@ export class DataSourceSavedObjectsClientWrapper {
};
};

private isValidUrl(endpoint: string) {
try {
const url = new URL(endpoint);
return Boolean(url) && (url.protocol === 'http:' || url.protocol === 'https:');
} catch (e) {
return false;
}
}
constructor(
private cryptography: CryptographyServiceSetup,
private logger: Logger,
private endpointBlockedIps?: string[]
) {}

private async validateAndEncryptAttributes<T = unknown>(attributes: T) {
this.validateAttributes(attributes);
Expand Down Expand Up @@ -254,8 +250,10 @@ export class DataSourceSavedObjectsClientWrapper {
);
}

if (!this.isValidUrl(endpoint)) {
throw SavedObjectsErrorHelpers.createBadRequestError('"endpoint" attribute is not valid');
if (!isValidURL(endpoint, this.endpointBlockedIps)) {
throw SavedObjectsErrorHelpers.createBadRequestError(
'"endpoint" attribute is not valid or allowed'
);
}

if (!auth) {
Expand Down
34 changes: 34 additions & 0 deletions src/plugins/data_source/server/util/endpoint_validator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import * as validator from './endpoint_validator';

describe('endpoint_validator', function () {
it('Url1 that should be blocked should return false', function () {
expect(validator.isValidURL('http://127.0.0.1', ['127.0.0.0/8'])).toEqual(false);
});

it('Url2 that is invalid should return false', function () {
expect(validator.isValidURL('www.test.com', [])).toEqual(false);
});

it('Url3 that is invalid should return false', function () {
expect(validator.isValidURL('ftp://www.test.com', [])).toEqual(false);
});

it('Url4 that should be blocked should return false', function () {
expect(
validator.isValidURL('http://169.254.169.254/latest/meta-data/', ['169.254.0.0/16'])
).toEqual(false);
});

it('Url5 that should not be blocked should return true', function () {
expect(validator.isValidURL('https://www.opensearch.org', ['127.0.0.0/8'])).toEqual(true);
});

it('Url6 that should not be blocked should return true when null IPs', function () {
expect(validator.isValidURL('https://www.opensearch.org')).toEqual(true);
});
});
59 changes: 59 additions & 0 deletions src/plugins/data_source/server/util/endpoint_validator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import dns from 'dns-sync';
import IPCIDR from 'ip-cidr';

export function isValidURL(endpoint: string, deniedIPs?: string[]) {
// Check the format of URL, URL has be in the format as
// scheme://server/path/resource otherwise an TypeError
// would be thrown.
let url;
try {
url = new URL(endpoint);
} catch (err) {
return false;
}

if (!(Boolean(url) && (url.protocol === 'http:' || url.protocol === 'https:'))) {
return false;
}

const ip = getIpAddress(url);
if (!ip) {
return false;
}

// IP CIDR check if a specific IP address fall in the
// range of an IP address block
for (const deniedIP of deniedIPs ?? []) {
const cidr = new IPCIDR(deniedIP);
if (cidr.contains(ip)) {
return false;
}
}
return true;
}

/**
* Resolve hostname to IP address
* @param {object} urlObject
* @returns {string} configuredIP
* or null if it cannot be resolve
* According to RFC, all IPv6 IP address needs to be in []
* such as [::1].
* So if we detect a IPv6 address, we remove brackets.
*/
function getIpAddress(urlObject: URL) {
const hostname = urlObject.hostname;
const configuredIP = dns.resolve(hostname);
if (configuredIP) {
return configuredIP;
}
if (hostname.startsWith('[') && hostname.endsWith(']')) {
return hostname.substr(1).slice(0, -1);
}
return null;
}