Skip to content

Commit d3177a8

Browse files
authored
Pass in initial admin password and remove admin:admin references (opensearch-project#631)
* Update to pass in initial admin password Signed-off-by: Derek Ho <dxho@amazon.com> * Add changelog and logic to distinguish between versions Signed-off-by: Derek Ho <dxho@amazon.com> * fix syntax Signed-off-by: Derek Ho <dxho@amazon.com> * Revert tests Signed-off-by: Derek Ho <dxho@amazon.com> * Add 2.12 to the matrix and fix testing logic Signed-off-by: Derek Ho <dxho@amazon.com> * Fix version logic Signed-off-by: Derek Ho <dxho@amazon.com> * Try to split job into two batches Signed-off-by: Derek Ho <dxho@amazon.com> * Fix lint Signed-off-by: Derek Ho <dxho@amazon.com> * Change name Signed-off-by: Derek Ho <dxho@amazon.com> * Remove period Signed-off-by: Derek Ho <dxho@amazon.com> * Pull password dynamically Signed-off-by: Derek Ho <dxho@amazon.com> * Change to proper env var Signed-off-by: Derek Ho <dxho@amazon.com> * Try passing through Signed-off-by: Derek Ho <dxho@amazon.com> --------- Signed-off-by: Derek Ho <dxho@amazon.com> Signed-off-by: Derek Ho <derek01778@gmail.com>
1 parent a1d27ca commit d3177a8

File tree

10 files changed

+72
-13
lines changed

10 files changed

+72
-13
lines changed

.ci/run-opensearch.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ environment=($(cat <<-END
2727
--env path.repo=/tmp
2828
--env repositories.url.allowed_urls=http://snapshot.test*
2929
--env action.destructive_requires_name=false
30+
--env OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!
3031
END
3132
))
3233

@@ -54,14 +55,23 @@ END
5455
END
5556
))
5657

58+
OPENSEARCH_REQUIRED_VERSION="2.12.0"
59+
# Starting in 2.12.0, security demo configuration script requires an initial admin password
60+
COMPARE_VERSION=`echo $OPENSEARCH_REQUIRED_VERSION $OPENSEARCH_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1`
61+
if [ "$COMPARE_VERSION" != "$OPENSEARCH_REQUIRED_VERSION" ]; then
62+
CREDENTIAL="admin:admin"
63+
else
64+
CREDENTIAL="admin:myStrongPassword123!"
65+
fi
66+
5767
# make sure we detach for all but the last node if DETACH=false (default) so all nodes are started
5868
local_detach="true"
5969
if [[ "$i" == "$((NUMBER_OF_NODES-1))" ]]; then local_detach=$DETACH; fi
6070

6171
set -x
6272
healthcmd="curl -vvv -s --fail http://localhost:9200/_cluster/health || exit 1"
6373
if [[ "$SECURE_INTEGRATION" == "true" ]]; then
64-
healthcmd="curl -vvv -s --insecure -u admin:admin --fail https://localhost:9200/_cluster/health || exit 1"
74+
healthcmd="curl -vvv -s --insecure -u $CREDENTIAL --fail https://localhost:9200/_cluster/health || exit 1"
6575
fi
6676

6777
CLUSTER_TAG=$CLUSTER

.ci/run-repository.sh

+23-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,27 @@ docker build \
3030
echo -e "\033[1m>>>>> Run [opensearch-project/opensearch-py container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
3131

3232
mkdir -p junit
33-
docker run \
33+
34+
OPENSEARCH_REQUIRED_VERSION="2.12.0"
35+
# Starting in 2.12.0, security demo configuration script requires an initial admin password
36+
COMPARE_VERSION=`echo $OPENSEARCH_REQUIRED_VERSION $OPENSEARCH_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1`
37+
if [ "$COMPARE_VERSION" != "$OPENSEARCH_REQUIRED_VERSION" ]; then
38+
docker run \
39+
--network=${network_name} \
40+
--env "STACK_VERSION=${STACK_VERSION}" \
41+
--env "OPENSEARCH_URL=${opensearch_url}" \
42+
--env "OPENSEARCH_VERSION=${OPENSEARCH_VERSION}" \
43+
--env "TEST_SUITE=${TEST_SUITE}" \
44+
--env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \
45+
--env "TEST_TYPE=server" \
46+
--env "TEST_PATTERN=${TEST_PATTERN}" \
47+
--env "OPENSEARCH_INITIAL_ADMIN_PASSWORD=admin" \
48+
--name opensearch-py \
49+
--rm \
50+
opensearch-project/opensearch-py \
51+
python setup.py test
52+
else
53+
docker run \
3454
--network=${network_name} \
3555
--env "STACK_VERSION=${STACK_VERSION}" \
3656
--env "OPENSEARCH_URL=${opensearch_url}" \
@@ -39,9 +59,11 @@ docker run \
3959
--env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \
4060
--env "TEST_TYPE=server" \
4161
--env "TEST_PATTERN=${TEST_PATTERN}" \
62+
--env "OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!" \
4263
--name opensearch-py \
4364
--rm \
4465
opensearch-project/opensearch-py \
4566
python setup.py test
67+
fi
4668

4769
unset TEST_PATTERN

.github/workflows/integration.yml

+20-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: Integration Tests
33
on: [push, pull_request]
44

55
jobs:
6-
integration:
7-
name: Integ
6+
integration-pre-212:
7+
name: Integ-pre-212
88
runs-on: ubuntu-latest
99
strategy:
1010
fail-fast: false
@@ -22,3 +22,21 @@ jobs:
2222
uses: actions/checkout@v3
2323
- name: Integ OpenSearch secured=${{ matrix.secured }} version=${{ matrix.opensearch_version }}
2424
run: "./.ci/run-tests ${{ matrix.secured }} ${{ matrix.opensearch_version }}"
25+
26+
integration-post-212:
27+
name: Integ-post-212
28+
runs-on: ubuntu-latest
29+
env:
30+
OPENSEARCH_URL: 'https://admin:myStrongPassword123!@localhost:9200'
31+
OPENSEARCH_INITIAL_ADMIN_PASSWORD: 'myStrongPassword123!'
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
opensearch_version: [ '2.12.0', '2.13.0', '2.14.0' ]
36+
secured: [ "true", "false" ]
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v3
41+
- name: Integ OpenSearch secured=${{ matrix.secured }} version=${{ matrix.opensearch_version }}
42+
run: "./.ci/run-tests ${{ matrix.secured }} ${{ matrix.opensearch_version }}"

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6262
- Enhance generator to update changelog only if generated code differs from existing ([#684](https://github.com/opensearch-project/opensearch-py/pull/684))
6363
- Added guide for configuring ssl_assert_hostname ([#694](https://github.com/opensearch-project/opensearch-py/pull/694))
6464
### Changed
65+
- Pass in initial admin password in setup and remove default `admin` password ([#631](https://github.com/opensearch-project/opensearch-py/pull/631))
6566
- Updated the `get_policy` API in the index_management plugin to allow the policy_id argument as optional ([#633](https://github.com/opensearch-project/opensearch-py/pull/633))
6667
- Updated the `point_in_time.md` guide with examples demonstrating the usage of the new APIs as alternatives to the deprecated ones. ([#661](https://github.com/opensearch-project/opensearch-py/pull/661))
6768
### Deprecated

guides/index_lifecycle.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This guide covers OpenSearch Python Client API actions for Index Lifecycle. You'
1313

1414
## Setup
1515

16-
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`.
16+
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 password>`.
1717

1818
To start the cluster, run the following command:
1919

@@ -28,7 +28,7 @@ Let's create a client instance to access this cluster:
2828
from opensearchpy import OpenSearch
2929

3030
client = OpenSearch(
31-
hosts=['https://admin:admin@localhost:9200'],
31+
hosts=['https://admin:<admin password>@localhost:9200'],
3232
use_ssl=True,
3333
verify_certs=False
3434
)

guides/log_collection.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ docker pull opensearchproject/opensearch:latest
3636
```
3737

3838
```
39-
docker run -d -p 9200:9200 -p 9600:9600 --name opensearch_opensearch_1 -e "discovery.type=single-node" opensearchproject/opensearch:latest
39+
docker run -d -p 9200:9200 -p 9600:9600 --name opensearch_opensearch_1 -e "discovery.type=single-node" -e "OPENSEARCH_INITIAL_ADMIN_PASSWORD=<admin password>" opensearchproject/opensearch:latest
4040
```
4141

4242
## Setup Connection with OpenSearch
4343

4444
Create a client instance:
4545
```python
4646
opensearch_client: Any = OpenSearch(
47-
"https://admin:admin@localhost:9200",
47+
"https://admin:<admin password>@localhost:9200",
4848
use_ssl=True,
4949
verify_certs=False,
5050
ssl_show_warn=False,
51-
http_auth=("admin", "admin"),
51+
http_auth=("admin", "<admin password>"),
5252
)
5353
```
5454

test_opensearchpy/test_async/test_server/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# under the License.
2626

2727

28+
import os
2829
from unittest import IsolatedAsyncioTestCase
2930

3031
from opensearchpy._async.helpers.test import get_test_client
@@ -38,8 +39,9 @@ async def asyncSetUp(
3839
self,
3940
) -> None:
4041
# pylint: disable=invalid-name,missing-function-docstring
42+
password = os.environ.get("OPENSEARCH_INITIAL_ADMIN_PASSWORD", "admin")
4143
self.client = await get_test_client(
42-
verify_certs=False, http_auth=("admin", "admin")
44+
verify_certs=False, http_auth=("admin", password)
4345
)
4446
await add_connection("default", self.client)
4547

test_opensearchpy/test_async/test_server_secured/test_security_plugin.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from __future__ import unicode_literals
1212

13+
import os
1314
from unittest import IsolatedAsyncioTestCase
1415

1516
import pytest
@@ -42,8 +43,9 @@ class TestSecurityPlugin(IsolatedAsyncioTestCase):
4243

4344
async def asyncSetUp(self) -> None:
4445
# pylint: disable=invalid-name, missing-function-docstring
46+
password = os.environ.get("OPENSEARCH_INITIAL_ADMIN_PASSWORD", "admin")
4547
self.client = await get_test_client(
46-
verify_certs=False, http_auth=("admin", "admin")
48+
verify_certs=False, http_auth=("admin", password)
4749
)
4850
await add_connection("default", self.client)
4951

test_opensearchpy/test_server_secured/test_clients.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Modifications Copyright OpenSearch Contributors. See
88
# GitHub history for details.
99

10+
import os
1011
from unittest import TestCase
1112

1213
from opensearchpy import OpenSearch
@@ -15,9 +16,10 @@
1516

1617
class TestSecurity(TestCase):
1718
def test_security(self) -> None:
19+
password = os.environ.get("OPENSEARCH_INITIAL_ADMIN_PASSWORD", "admin")
1820
client = OpenSearch(
1921
OPENSEARCH_URL,
20-
http_auth=("admin", "admin"),
22+
http_auth=("admin", password),
2123
verify_certs=False,
2224
)
2325

test_opensearchpy/test_server_secured/test_security_plugin.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from __future__ import unicode_literals
1212

13+
import os
1314
from unittest import TestCase
1415

1516
from opensearchpy.connection.connections import add_connection
@@ -36,7 +37,8 @@ class TestSecurityPlugin(TestCase):
3637
USER_CONTENT = {"password": "opensearchpy@123", "opendistro_security_roles": []}
3738

3839
def setUp(self) -> None:
39-
self.client = get_test_client(verify_certs=False, http_auth=("admin", "admin"))
40+
password = os.environ.get("OPENSEARCH_INITIAL_ADMIN_PASSWORD", "admin")
41+
self.client = get_test_client(verify_certs=False, http_auth=("admin", password))
4042
add_connection("default", self.client)
4143

4244
def tearDown(self) -> None:

0 commit comments

Comments
 (0)