Skip to content

Commit 5a22f57

Browse files
authored
Merge pull request #49 from marklogic/feature/CLD-568
CLD-568: Use Random Password for Admin
2 parents bd0464e + 2b81bcd commit 5a22f57

File tree

6 files changed

+85
-25
lines changed

6 files changed

+85
-25
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# MarkLogic Kubernetes Helm Chart
22

3+
- [MarkLogic Kubernetes Helm Chart](#marklogic-kubernetes-helm-chart)
34
- [Introduction](#introduction)
45
- [Prerequisites](#prerequisites)
56
- [Set Up the Required Tools](#set-up-the-required-tools)
@@ -17,6 +18,11 @@
1718
- [Configuration Options](#configuration-options)
1819
- [--values](#--values)
1920
- [--set](#--set)
21+
- [Setting MarkLogic admin password](#setting-marklogic-admin-password)
22+
- [Log Collection](#log-collection)
23+
- [Adding and Removing Hosts from Clusters](#adding-and-removing-hosts-from-clusters)
24+
- [Adding Hosts](#adding-hosts)
25+
- [Removing Hosts](#removing-hosts)
2026
- [Access the MarkLogic Server](#access-the-marklogic-server)
2127
- [Service](#service)
2228
- [Get the ClusterIP Service Name](#get-the-clusterip-service-name)
@@ -221,6 +227,22 @@ helm install my-release marklogic/marklogic --version=1.0.0-ea1 \
221227

222228
We recommend that you use the `values.yaml` file for configuring your installation.
223229

230+
### Setting MarkLogic admin password
231+
232+
If the password does not provided when installing the MarkLogic Chart, a randomly generated aphanumeric value will be set for MarkLogic admin password. This value is stored in Kuberenetes secrets.
233+
User can also set a custom password by setting auth.adminPassword value during installation.
234+
To retrieve the randomly generated admin password, use the following commands:
235+
236+
1. List the secrets for MarkLogic deployment:
237+
```
238+
kubectl get secrets
239+
```
240+
Identify the name of the secret.
241+
242+
2. Save the secret name from step 1 and get the admin password using the following script:
243+
```
244+
kubectl get secret SECRET_NAME -o jsonpath='{.data.marklogic-password}' | base64 --decode
245+
```
224246
### Log Collection
225247

226248
To enable log collection for all Marklogic logs set logCollection.enabled to true. Set each option in logCollection.files to true of false depending on if you want to track each type of Marklogic log file.

charts/templates/secret.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
{{- $adminPassword := (default (randAlphaNum 10) .Values.auth.adminPassword) | b64enc | quote }}
2+
{{- $secret := (lookup "v1" "Secret" .Release.Namespace (printf "%s-admin" (include "marklogic.fullname" .))) }}
3+
{{- if $secret }}
4+
{{- $adminPassword = index $secret.data "password" }}
5+
{{- end }}
6+
17
apiVersion: v1
28
kind: Secret
39
metadata:
4-
name: {{ include "marklogic.fullname" . }}
10+
name: {{ include "marklogic.fullname" . }}-admin
511
namespace: {{ .Release.Namespace }}
612
labels:
713
{{- include "marklogic.labels" . | nindent 4 }}
814
type: kubernetes.io/basic-auth
9-
stringData:
10-
username: {{ .Values.auth.adminUsername}}
11-
password: {{ .Values.auth.adminPassword}}
15+
data:
16+
password: {{ $adminPassword }}
17+
username: {{ .Values.auth.adminUsername | b64enc | quote }}
18+

charts/templates/statefulset.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ spec:
7272
- name: MARKLOGIC_ADMIN_USERNAME
7373
valueFrom:
7474
secretKeyRef:
75-
name: {{ include "marklogic.fullname" . }}
75+
name: {{ include "marklogic.fullname" . }}-admin
7676
key: username
7777
- name: MARKLOGIC_ADMIN_PASSWORD
7878
valueFrom:
7979
secretKeyRef:
80-
name: {{ include "marklogic.fullname" . }}
80+
name: {{ include "marklogic.fullname" . }}-admin
8181
key: password
8282
- name: POD_NAME
8383
valueFrom:
@@ -100,13 +100,13 @@ spec:
100100
env:
101101
- name: MARKLOGIC_ADMIN_USERNAME
102102
valueFrom:
103-
secretKeyRef:
104-
name: {{ include "marklogic.fullname" . }}
105-
key: username
103+
secretKeyRef:
104+
name: {{ include "marklogic.fullname" . }}-admin
105+
key: username
106106
- name: MARKLOGIC_ADMIN_PASSWORD
107107
valueFrom:
108108
secretKeyRef:
109-
name: {{ include "marklogic.fullname" . }}
109+
name: {{ include "marklogic.fullname" . }}-admin
110110
key: password
111111
- name: MARKLOGIC_GROUP
112112
value: {{ .Values.group.name }}

charts/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fullnameOverride: ""
5050
# Configure Marklogic Admin Username and Password
5151
auth:
5252
adminUsername: admin
53-
adminPassword: admin
53+
adminPassword: ""
5454

5555
# Configure Affinity property for scheduling pods to nodes
5656
# ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity

test/e2e/install_test.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1616
"github.com/gruntwork-io/terratest/modules/k8s"
1717
"github.com/gruntwork-io/terratest/modules/random"
18+
"github.com/stretchr/testify/assert"
1819
"github.com/tidwall/gjson"
1920
digestAuth "github.com/xinsnake/go-http-digest-auth-client"
2021
)
@@ -27,8 +28,6 @@ func TestHelmInstall(t *testing.T) {
2728
}
2829
imageRepo, repoPres := os.LookupEnv("dockerRepository")
2930
imageTag, tagPres := os.LookupEnv("dockerVersion")
30-
username := "admin"
31-
password := "admin"
3231
var resp *http.Response
3332
var body []byte
3433
var err error
@@ -52,8 +51,6 @@ func TestHelmInstall(t *testing.T) {
5251
"replicaCount": "2",
5352
"image.repository": imageRepo,
5453
"image.tag": imageTag,
55-
"auth.adminUsername": username,
56-
"auth.adminPassword": password,
5754
"logCollection.enabled": "false",
5855
},
5956
}
@@ -72,16 +69,15 @@ func TestHelmInstall(t *testing.T) {
7269
podName := releaseName + "-marklogic-0"
7370
// wait until the pod is in Ready status
7471
k8s.WaitUntilPodAvailable(t, kubectlOptions, podName, 10, 15*time.Second)
75-
tunnel := k8s.NewTunnel(
76-
kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
77-
defer tunnel.Close()
78-
tunnel.ForwardPort(t)
79-
endpoint := fmt.Sprintf("http://%s", tunnel.Endpoint())
80-
t.Logf(`Endpoint: %s`, endpoint)
72+
tunnel7997 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 7997, 7997)
73+
defer tunnel7997.Close()
74+
tunnel7997.ForwardPort(t)
75+
endpoint7997 := fmt.Sprintf("http://%s", tunnel7997.Endpoint())
8176

77+
// verify if 7997 health check endpoint returns 200
8278
http_helper.HttpGetWithRetryWithCustomValidation(
8379
t,
84-
endpoint,
80+
endpoint7997,
8581
&tlsConfig,
8682
10,
8783
15*time.Second,
@@ -90,12 +86,34 @@ func TestHelmInstall(t *testing.T) {
9086
},
9187
)
9288

93-
tunnel8002 := k8s.NewTunnel(
94-
kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
89+
t.Log("====Testing Generated Random Password====")
90+
secretName := releaseName + "-marklogic-admin"
91+
secret := k8s.GetSecret(t, kubectlOptions, secretName)
92+
passwordArr := secret.Data["password"]
93+
password := string(passwordArr[:])
94+
// the generated random password should have length of 10
95+
assert.Equal(t, 10, len(password))
96+
usernameArr := secret.Data["username"]
97+
username := string(usernameArr[:])
98+
expectedUsername := "admin"
99+
// the username from secret expected to be "admin"
100+
assert.Equal(t, expectedUsername, username)
101+
102+
tunnel8002 := k8s.NewTunnel(kubectlOptions, k8s.ResourceTypePod, podName, 8002, 8002)
95103
defer tunnel8002.Close()
96104
tunnel8002.ForwardPort(t)
105+
endpointManage := fmt.Sprintf("http://%s/manage/v2", tunnel8002.Endpoint())
106+
107+
request := digestAuth.NewRequest(username, password, "GET", endpointManage, "")
108+
response, err := request.Execute()
109+
if err != nil {
110+
t.Fatalf(err.Error())
111+
}
112+
defer response.Body.Close()
113+
// the generated password should be able to access the manage endpoint
114+
assert.Equal(t, 200, response.StatusCode)
97115

98-
// Verify no groups beyond enode were created/modified
116+
t.Log("====Verify no groups beyond enode were created/modified====")
99117
groupStatusEndpoint := fmt.Sprintf("http://%s/manage/v2/groups?format=json", tunnel8002.Endpoint())
100118
groupStatus := digestAuth.NewRequest(username, password, "GET", groupStatusEndpoint, "")
101119
t.Logf(`groupStatusEndpoint: %s`, groupStatusEndpoint)

test/e2e/upgrade_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
http_helper "github.com/gruntwork-io/terratest/modules/http-helper"
1414
"github.com/gruntwork-io/terratest/modules/k8s"
1515
"github.com/gruntwork-io/terratest/modules/random"
16+
"github.com/stretchr/testify/assert"
1617
)
1718

1819
func TestHelmUpgrade(t *testing.T) {
@@ -56,6 +57,12 @@ func TestHelmUpgrade(t *testing.T) {
5657
releaseName := "test-upgrade"
5758
helm.Install(t, options, helmChartPath, releaseName)
5859

60+
// save the generated password from first installation
61+
secretName := releaseName + "-marklogic-admin"
62+
secret := k8s.GetSecret(t, kubectlOptions, secretName)
63+
passwordArr := secret.Data["password"]
64+
passwordAfterInstall := string(passwordArr[:])
65+
5966
newOptions := &helm.Options{
6067
KubectlOptions: kubectlOptions,
6168
SetValues: map[string]string{
@@ -92,4 +99,10 @@ func TestHelmUpgrade(t *testing.T) {
9299
return statusCode == 200
93100
},
94101
)
102+
103+
t.Log("====Test password in secret should not change after upgrade====")
104+
secret = k8s.GetSecret(t, kubectlOptions, secretName)
105+
passwordArr = secret.Data["password"]
106+
passwordAfterUpgrade := string(passwordArr[:])
107+
assert.Equal(t, passwordAfterUpgrade, passwordAfterInstall)
95108
}

0 commit comments

Comments
 (0)