-
Notifications
You must be signed in to change notification settings - Fork 123
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
Update Default Password for OS 2.12 #707
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,11 @@ In this guide, we will look at some advanced index actions that are not covered | |
Let's create a client instance, and an index named `movies`: | ||
```javascript | ||
const { Client } = require('@opensearch-project/opensearch'); | ||
|
||
const client = new Client({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not point to createSecureClient() here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beecause that's a helper function for our test suites only. The function creates a client using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh I see. ty for explanation!! |
||
node: 'https://admin:admin@localhost:9200', | ||
ssl: { rejectUnauthorized: false } | ||
node: 'http://localhost:9200', | ||
}); | ||
|
||
client.indices.create({index: 'movies'}) | ||
``` | ||
## API Actions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,23 +3,13 @@ This guide covers OpenSearch JavaScript Client API actions for Index Lifecycle. | |
|
||
## Setup | ||
|
||
In this guide, we will need an OpenSearch cluster with more than one node. Let's use the sample [docker-compose.yml](https://opensearch.org/samples/docker-compose.yml) to start a cluster with two nodes. The cluster's API will be available at `localhost:9200` with basic authentication enabled with default username and password of `admin:admin`. | ||
|
||
To start the cluster, run the following command: | ||
|
||
```bash | ||
cd /path/to/docker-compose.yml | ||
docker-compose up -d | ||
``` | ||
|
||
Let's create a client instance to access this cluster: | ||
Let's create a client instance to access an OpenSearch cluster: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we skip mentioning how to start a cluster here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should. These guides should focus on OpenSearch features, not how to setup a cluster. We can have another guide to cover how to set up a cluster, but that's already covered in the Readme and especially the OpenSearch website itself. |
||
|
||
```javascript | ||
const { Client } = require('@opensearch-project/opensearch'); | ||
|
||
const client = new Client({ | ||
node: 'https://admin:admin@localhost:9200', | ||
ssl: { rejectUnauthorized: false } | ||
node: 'http://localhost:9200', | ||
}); | ||
|
||
client.info().then(response => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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. | ||
* | ||
*/ | ||
|
||
export function strongPasswordRequired(os_version?: string): boolean; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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. | ||
* | ||
*/ | ||
|
||
function strongPasswordRequired(os_version = process.env.OPENSEARCH_VERSION) { | ||
// OpenSearch 2.12.X and later require strong passwords | ||
if (os_version === undefined) | ||
throw new Error('OPENSEARCH_VERSION environment variable is not set'); | ||
if (os_version === 'latest') return true; | ||
const [major, minor] = os_version.split('.'); | ||
if (parseInt(major) > 2) return true; | ||
return major === '2' && (minor === 'x' || parseInt(minor) >= 12); | ||
} | ||
|
||
module.exports = { strongPasswordRequired }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,22 @@ | |
|
||
'use strict'; | ||
|
||
const { strongPasswordRequired } = require('../../lib/tools'); | ||
|
||
function createSecuredClient() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where would this be used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is meant to be used in integration tests only. It's a helper function inside |
||
const { Client } = require('../../'); | ||
return new Client({ | ||
ssl: { | ||
rejectUnauthorized: false, | ||
}, | ||
node: 'https://localhost:9200', | ||
auth: { | ||
username: 'admin', | ||
password: strongPasswordRequired() ? 'myStrongPassword123!' : 'admin', | ||
}, | ||
}); | ||
} | ||
|
||
function runInParallel(client, operation, options, clientOptions) { | ||
if (options.length === 0) return Promise.resolve(); | ||
const operations = options.map((opts) => { | ||
|
@@ -62,4 +78,4 @@ function to(promise) { | |
|
||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
|
||
module.exports = { runInParallel, delve, to, sleep }; | ||
module.exports = { runInParallel, delve, to, sleep, createSecuredClient }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { test } = require('tap'); | ||
const { strongPasswordRequired } = require('../../lib/tools'); | ||
|
||
test('strongPasswordRequired', (t) => { | ||
t.plan(9); | ||
|
||
t.throws(() => strongPasswordRequired()); | ||
|
||
t.ok(strongPasswordRequired('latest')); | ||
t.ok(strongPasswordRequired('3.0')); | ||
t.ok(strongPasswordRequired('2.12.x')); | ||
t.ok(strongPasswordRequired('2.12.0')); | ||
|
||
t.notOk(strongPasswordRequired('2.11')); | ||
t.notOk(strongPasswordRequired('2.11.x')); | ||
t.notOk(strongPasswordRequired('1.13.0')); | ||
t.notOk(strongPasswordRequired('1.x')); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to replace this health-check with something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added to this repo to solve a flaky spec issue myself when I first started. No other client repo has this. From what I've observed so far, it doesn't really help. If it happens again, I'm better equiped to find a better solution. This also adds complexity to the CI workflows esp now that HEALTHCHECK has to be aware of the OS version.