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

Remove references to the default credentials of admin:admin #449

Merged
merged 10 commits into from
Mar 12, 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
16 changes: 14 additions & 2 deletions .ci/opensearch/Dockerfile.opensearch
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
ARG OPENSEARCH_VERSION
FROM opensearchproject/opensearch:${OPENSEARCH_VERSION}

ARG OPENSEARCH_VERSION
ARG opensearch_path=/usr/share/opensearch
ARG SECURE_INTEGRATION
ENV SECURE_INTEGRATION=$SECURE_INTEGRATION

RUN if [ "$SECURE_INTEGRATION" != "true" ] ; then $opensearch_path/bin/opensearch-plugin remove opensearch-security; fi
# Starting in 2.12.0 security demo requires an initial admin password, which is set as myStrongPassword123!
# https://apple.stackexchange.com/a/123408/11374
RUN if [ "$SECURE_INTEGRATION" != "true" ] ; then \
$opensearch_path/bin/opensearch-plugin remove opensearch-security; \
else \
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }; \
if [ $(version $OPENSEARCH_VERSION) -ge $(version "2.12.0") ] || [ $OPENSEARCH_VERSION == "latest" ]; then \
echo user admin:myStrongPassword123! > curl.conf ; \
else \
echo user admin:admin > curl.conf ; \
fi\
fi

HEALTHCHECK --start-period=20s --interval=30s \
CMD curl -sf -retry 5 --max-time 5 --retry-delay 5 --retry-max-time 30 \
$(if $SECURE_INTEGRATION; then echo "-u admin:admin -k https://"; fi)"localhost:9200" \
$(if $SECURE_INTEGRATION; then echo "-K curl.conf -k https://"; fi)"localhost:9200" \
|| bash -c 'kill -s 15 -1 && (sleep 10; kill -s 9 -1)'
1 change: 1 addition & 0 deletions .ci/opensearch/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
- discovery.type=single-node
- bootstrap.memory_lock=true
- path.repo=/usr/share/opensearch/mnt
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123!
ports:
- "9200:9200"
user: opensearch
1 change: 1 addition & 0 deletions .github/workflows/test-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- { opensearch_version: 2.9.0 }
- { opensearch_version: 2.10.0 }
- { opensearch_version: 2.11.0 }
- { opensearch_version: 2.12.0 }
steps:
- uses: actions/checkout@v3
with: { fetch-depth: 1 }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ jobs:
run: |
make cluster.clean cluster.build cluster.start
for attempt in `seq 25`; do sleep 5; \
if curl -s -ku admin:admin https://localhost:9200; \
if curl -s -ku admin:myStrongPassword123! https://localhost:9200; \
then echo '=====> ready'; break; fi; if [ $attempt == 25 ]; then exit 1; fi; echo '=====> waiting...'; done
- run: make test-integ-secure
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Bumps `github.com/aws/aws-sdk-go-v2/config` from 1.25.11 to 1.27.0
### Added
- Added new struct fields introduced by opensearch 2.12 ([#482](https://github.com/opensearch-project/opensearch-go/pull/482))
- Adds initial admin password environment variable and CI changes to support 2.12.0 release ([#449](https://github.com/opensearch-project/opensearch-go/pull/449))
### Changed
- Changed field opensearch_version of type NodesInfoPlugin to json.RawMessage as opensearch 3.0.0 uses an array instead of string ([#482](https://github.com/opensearch-project/opensearch-go/pull/482))
### Deprecated
Expand Down
4 changes: 2 additions & 2 deletions guides/index_lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This guide covers OpenSearch Golang Client API actions for Index Lifecycle. You'

## 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`.
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 >`.

To start the cluster, run the following command:

Expand Down Expand Up @@ -46,7 +46,7 @@ func example() error {
},
Addresses: []string{"https://localhost:9200"},
Username: "admin", // For testing only. Don't store credentials in code.
Password: "admin",
Password: "< admin password >",
},
},
)
Expand Down
41 changes: 21 additions & 20 deletions opensearch_secure_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package opensearch_test
import (
"context"
"crypto/tls"
"errors"
"log"
"net/http"
"testing"
Expand All @@ -37,29 +38,29 @@ import (
)

func getSecuredClient() (*opensearchapi.Client, error) {
return opensearchapi.NewClient(
opensearchapi.Config{
Client: opensearch.Config{
Username: "admin",
Password: "admin",
Addresses: []string{"https://localhost:9200"},
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
errs := make([]error, 0)
for _, password := range []string{"admin", "myStrongPassword123!"} {
client, _ := opensearchapi.NewClient(
opensearchapi.Config{
Client: opensearch.Config{
Username: "admin",
Password: password,
Addresses: []string{"https://localhost:9200"},
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
},
},
},
)
}

type clusterVersion struct {
Number string `json:"number"`
BuildFlavor string `json:"build_flavor"`
Distribution string `json:"distribution"`
}
)
_, err := client.Info(nil, nil)
if err != nil {
errs = append(errs, err)
continue
}
return client, nil
}
return nil, errors.Join(errs...)

type Info struct {
Version clusterVersion `json:"version"`
Tagline string `json:"tagline"`
}

func TestSecuredClientAPI(t *testing.T) {
Expand Down
Loading