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

Update Default Password for OS 2.12 #707

Merged
merged 2 commits into from
Feb 26, 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
6 changes: 0 additions & 6 deletions .ci/opensearch/Dockerfile.opensearch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@ ARG opensearch_path=/usr/share/opensearch
ARG opensearch_yml=$opensearch_path/config/opensearch.yml

ARG SECURE_INTEGRATION

Copy link
Member

@DarshitChanpura DarshitChanpura Jan 30, 2024

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?

Copy link
Collaborator Author

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.

HEALTHCHECK --start-period=20s --interval=5s --retries=2 --timeout=1s \
CMD if [ "$SECURE_INTEGRATION" != "true" ]; \
then curl --fail localhost:9200/_cat/health; \
else curl --fail -k https:/localhost:9200/_cat/health -u admin:admin; fi

RUN if [ "$SECURE_INTEGRATION" != "true" ] ; then $opensearch_path/bin/opensearch-plugin remove opensearch-security; fi
12 changes: 1 addition & 11 deletions .ci/opensearch/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@ services:
environment:
- discovery.type=single-node
- bootstrap.memory_lock=true
- SECURE_INTEGRATION=${SECURE_INTEGRATION:-false}
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!
ports:
- '9200:9200'
user: opensearch
autoheal:
restart: always
image: willfarrell/autoheal
environment:
- AUTOHEAL_CONTAINER_LABEL=all
- AUTOHEAL_START_PERIOD=30
- AUTOHEAL_INTERVAL=5
- AUTOHEAL_DEFAULT_STOP_TIMEOUT=30
volumes:
- /var/run/docker.sock:/var/run/docker.sock
5 changes: 3 additions & 2 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- { opensearch_version: 1.3.3 }
- { opensearch_version: 2.0.0 }
- { opensearch_version: 2.0.1 }
env:
OPENSEARCH_VERSION: ${{ matrix.entry.opensearch_version }}
SECURE_INTEGRATION: ${{ matrix.secured }}

steps:
- uses: actions/checkout@v2
Expand All @@ -45,8 +48,6 @@ jobs:
- name: Runs OpenSearch cluster
id: start_opensearch_cluster
run: |
export OPENSEARCH_VERSION=${{ matrix.entry.opensearch_version }}
export SECURE_INTEGRATION=${{ matrix.secured }}
make cluster.clean cluster.opensearch.build cluster.opensearch.start

- name: Use Node.js 16.x
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
paths-ignore:
- '**/*.md'

env:
OPENSEARCH_VERSION: latest

jobs:
helpers-integration-test:
name: Helpers integration test
Expand All @@ -19,6 +22,9 @@ jobs:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x, 18.x]

env:
nhtruong marked this conversation as resolved.
Show resolved Hide resolved
SECURE_INTEGRATION: false

steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -65,6 +71,9 @@ jobs:
matrix:
node-version: [10.x, 12.x, 14.x, 16.x, 18.x]

env:
SECURE_INTEGRATION: true

steps:
- uses: actions/checkout@v2

Expand All @@ -77,7 +86,6 @@ jobs:

- name: Runs OpenSearch secure cluster
run: |
export SECURE_INTEGRATION=true
make cluster.clean cluster.opensearch.build cluster.opensearch.start

- name: Use Node.js ${{ matrix.node-version }}
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Bumps `eslint-plugin-prettier` from 5.1.2 to 5.1.3
- Bumps `@babel/eslint-parser` from 7.23.3 to 7.23.9
### Changed
- Updated integration tests to use strong password in OS 2.12 and up ([#707](https://github.com/opensearch-project/opensearch-js/pull/707))
- Simplified client creation in the guides ([#707](https://github.com/opensearch-project/opensearch-js/pull/707))
### Deprecated
### Removed
- Removed AutoHeal([#707](https://github.com/opensearch-project/opensearch-js/pull/707))
### Fixed
### Security

Expand Down
2 changes: 1 addition & 1 deletion USER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
var host = 'localhost';
var protocol = 'https';
var port = 9200;
var auth = 'admin:admin'; // For testing only. Don't store credentials in code.
var auth = 'admin:strongPassword@999'; // For testing only. Don't store credentials in code.
var ca_certs_path = '/full/path/to/root-ca.pem';

// Optional client certificates if you don't want to use HTTP basic authentication.
Expand Down
5 changes: 3 additions & 2 deletions guides/advanced_index_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Copy link
Member

Choose a reason for hiding this comment

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

why not point to createSecureClient() here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 admin:admin or admin:myStrongPassword123! depending on the OPENSEARCH_VERSION env. Users should not use that function because their password will be different.

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
14 changes: 2 additions & 12 deletions guides/index_lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

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

Should we skip mentioning how to start a cluster here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 => {
Expand Down
9 changes: 1 addition & 8 deletions guides/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ First, create a client instance with the following code to interact with an Open

```javascript
const client = new Client({
ssl: {
rejectUnauthorized: false,
},
node: 'https://localhost:9200',
auth: {
username: 'admin',
password: 'admin',
},
node: 'http://localhost:9200',
});
```

Expand Down
12 changes: 1 addition & 11 deletions guides/msearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,8 @@ OpenSearch's Multi-Search (`msearch`) API allows you to execute multiple search
# Setup

```javascript
const host = "localhost";
const protocol = "https";
const port = 9200;
const auth = "admin:admin";
const ca_certs_path = "/full/path/to/root-ca.pem";
const { Client } = require("@opensearch-project/opensearch");
const fs = require("fs");
const client = new Client({
node: `${protocol}://${auth}@${host}:${port}`,
ssl: {
ca: fs.readFileSync(ca_certs_path),
},
node: 'http://localhost:9200',
});

await client.bulk({
Expand Down
24 changes: 2 additions & 22 deletions guides/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,8 @@ OpenSearch provides a powerful search API that allows you to search for document
# Setup
Let's start by creating an index and adding some documents to it:
```javascript
var host = "localhost";
var protocol = "https";
var port = 9200;
var auth = "admin:admin"; // For testing only. Don't store credentials in code.
var ca_certs_path = "/full/path/to/root-ca.pem";

// Optional client certificates if you don't want to use HTTP basic authentication.
// var client_cert_path = '/full/path/to/client.pem'
// var client_key_path = '/full/path/to/client-key.pem'

// Create a client with SSL/TLS enabled.
var { Client } = require("@opensearch-project/opensearch");
var fs = require("fs");
var client = new Client({
node: protocol + "://" + auth + "@" + host + ":" + port,
ssl: {
ca: fs.readFileSync(ca_certs_path),
// You can turn off certificate verification (rejectUnauthorized: false) if you're using
// self-signed certificates with a hostname mismatch.
// cert: fs.readFileSync(client_cert_path),
// key: fs.readFileSync(client_key_path)
},
const client = new Client({
node: 'http://localhost:9200',
});

await client.indices.create({index: 'movies'});
Expand Down
11 changes: 11 additions & 0 deletions lib/tools.d.ts
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;
21 changes: 21 additions & 0 deletions lib/tools.js
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 };
18 changes: 17 additions & 1 deletion test/integration/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@

'use strict';

const { strongPasswordRequired } = require('../../lib/tools');

function createSecuredClient() {
Copy link
Member

Choose a reason for hiding this comment

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

👏

Copy link
Member

Choose a reason for hiding this comment

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

where would this be used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 test folder.

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) => {
Expand Down Expand Up @@ -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 };
13 changes: 2 additions & 11 deletions test/integration/helpers-secure/http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,9 @@
*/

const { test } = require('tap');
const { Client } = require('../../../');
const { createSecuredClient } = require('../helper');

const client = new Client({
ssl: {
rejectUnauthorized: false,
},
node: 'https://localhost:9200',
auth: {
username: 'admin',
password: 'admin',
},
});
const client = createSecuredClient();
const http = client.http;
const index = 'books';

Expand Down
14 changes: 2 additions & 12 deletions test/integration/helpers-secure/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,10 @@ const { createReadStream } = require('fs');
const { join } = require('path');
const split = require('split2');
const { test, beforeEach, afterEach } = require('tap');

const { Client } = require('../../..');
const { createSecuredClient } = require('../helper');

const INDEX = `test-helpers-${process.pid}`;
const client = new Client({
ssl: {
rejectUnauthorized: false,
},
node: 'https://localhost:9200',
auth: {
username: 'admin',
password: 'admin',
},
});
const client = createSecuredClient();

beforeEach(async () => {
await client.indices.create({ index: INDEX });
Expand Down
13 changes: 2 additions & 11 deletions test/integration/helpers-secure/security.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,9 @@
*/

const { test } = require('tap');
const { Client } = require('../../../');
const { createSecuredClient } = require('../helper');

const client = new Client({
ssl: {
rejectUnauthorized: false,
},
node: 'https://localhost:9200',
auth: {
username: 'admin',
password: 'admin',
},
});
const client = createSecuredClient();
const security = client.security;

test('Security: User', async (t) => {
Expand Down
30 changes: 30 additions & 0 deletions test/unit/tools.test.js
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'));
});
Loading