Skip to content

Commit 5c31959

Browse files
committed
Fix username and password
1 parent d22311c commit 5c31959

File tree

5 files changed

+17
-26
lines changed

5 files changed

+17
-26
lines changed

internal/stack/_static/docker-compose-stack.yml renamed to internal/stack/_static/docker-compose-stack.yml.tmpl

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
{{ $username := fact "username" }}
2+
{{ $password := fact "password" }}
13
version: '2.3'
24
services:
35
elasticsearch:
46
image: "${ELASTICSEARCH_IMAGE_REF}"
57
healthcheck:
6-
test: "curl -s --cacert /usr/share/elasticsearch/config/certs/ca-cert.pem -f -u elastic:changeme https://127.0.0.1:9200/_cat/health | cut -f4 -d' ' | grep -E '(green|yellow)'"
8+
test: "curl -s --cacert /usr/share/elasticsearch/config/certs/ca-cert.pem -f -u {{ $username }}:{{ $password }} https://127.0.0.1:9200/_cat/health | cut -f4 -d' ' | grep -E '(green|yellow)'"
79
retries: 300
810
interval: 1s
911
environment:
1012
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
11-
- "ELASTIC_PASSWORD=changeme"
13+
- "ELASTIC_PASSWORD={{ $password }}"
1214
volumes:
1315
- "./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
1416
- "./certs/elasticsearch:/usr/share/elasticsearch/config/certs"

internal/stack/_static/kibana.yml.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ elasticsearch.hosts: [ "https://elasticsearch:9200" ]
1010
elasticsearch.ssl.certificateAuthorities: "/usr/share/kibana/config/certs/ca-cert.pem"
1111

1212
{{ if semverLessThan $version "8.0.0" }}
13-
elasticsearch.username: elastic
14-
elasticsearch.password: changeme
13+
elasticsearch.username: {{ fact "username" }}
14+
elasticsearch.password: {{ fact "password" }}
1515

1616
xpack.monitoring.ui.container.elasticsearch.enabled: true
1717
xpack.fleet.enabled: true

internal/stack/_static/kibana_healthcheck.sh renamed to internal/stack/_static/kibana_healthcheck.sh.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
set -e
44

55
curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f https://localhost:5601/login | grep kbn-injected-metadata 2>&1 >/dev/null
6-
curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f -u elastic:changeme "https://elasticsearch:9200/_cat/indices/.security-*?h=health" | grep -v red
6+
curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f -u {{ fact "username" }}:{{ fact "password" }} "https://elasticsearch:9200/_cat/indices/.security-*?h=health" | grep -v red

internal/stack/initconfig.go

+2-19
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ package stack
66

77
import (
88
"fmt"
9-
"os"
109

1110
"github.com/pkg/errors"
12-
"gopkg.in/yaml.v3"
1311

1412
"github.com/elastic/elastic-package/internal/compose"
1513
"github.com/elastic/elastic-package/internal/install"
@@ -25,21 +23,6 @@ type InitConfig struct {
2523
}
2624

2725
func StackInitConfig(elasticStackProfile *profile.Profile) (*InitConfig, error) {
28-
// Read Elasticsearch username and password from Kibana configuration file.
29-
body, err := os.ReadFile(elasticStackProfile.Path(profileStackPath, KibanaConfigFile))
30-
if err != nil {
31-
return nil, errors.Wrap(err, "error reading Kibana config file")
32-
}
33-
34-
var kibanaCfg struct {
35-
ElasticsearchUsername string `yaml:"elasticsearch.username"`
36-
ElasticsearchPassword string `yaml:"elasticsearch.password"`
37-
}
38-
err = yaml.Unmarshal(body, &kibanaCfg)
39-
if err != nil {
40-
return nil, errors.Wrap(err, "unmarshalling Kibana configuration failed")
41-
}
42-
4326
// Read Elasticsearch and Kibana hostnames from Elastic Stack Docker Compose configuration file.
4427
p, err := compose.NewProject(DockerComposeProjectName, elasticStackProfile.Path(profileStackPath, SnapshotFile))
4528
if err != nil {
@@ -72,8 +55,8 @@ func StackInitConfig(elasticStackProfile *profile.Profile) (*InitConfig, error)
7255

7356
return &InitConfig{
7457
ElasticsearchHostPort: esHostPort,
75-
ElasticsearchUsername: kibanaCfg.ElasticsearchUsername,
76-
ElasticsearchPassword: kibanaCfg.ElasticsearchPassword,
58+
ElasticsearchUsername: elasticsearchUsername,
59+
ElasticsearchPassword: elasticsearchPassword,
7760
KibanaHostPort: kibHostPort,
7861
CACertificatePath: caCert,
7962
}, nil

internal/stack/resources.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ const (
4444
ElasticAgentEnvFile = "elastic-agent.env"
4545

4646
profileStackPath = "stack"
47+
48+
elasticsearchUsername = "elastic"
49+
elasticsearchPassword = "changeme"
4750
)
4851

4952
var (
@@ -58,7 +61,7 @@ var (
5861
},
5962
&resource.File{
6063
Path: SnapshotFile,
61-
Content: staticSource.File("_static/docker-compose-stack.yml"),
64+
Content: staticSource.Template("_static/docker-compose-stack.yml.tmpl"),
6265
},
6366
&resource.File{
6467
Path: ElasticsearchConfigFile,
@@ -89,7 +92,7 @@ var (
8992
},
9093
&resource.File{
9194
Path: KibanaHealthcheckFile,
92-
Content: staticSource.File("_static/kibana_healthcheck.sh"),
95+
Content: staticSource.Template("_static/kibana_healthcheck.sh.tmpl"),
9396
},
9497
&resource.File{
9598
Path: PackageRegistryConfigFile,
@@ -111,6 +114,9 @@ func applyResources(profile *profile.Profile, stackVersion string) error {
111114
"elasticsearch_version": stackVersion,
112115
"kibana_version": stackVersion,
113116
"agent_version": stackVersion,
117+
118+
"username": elasticsearchUsername,
119+
"password": elasticsearchPassword,
114120
})
115121

116122
os.MkdirAll(stackDir, 0755)

0 commit comments

Comments
 (0)