Skip to content

Commit

Permalink
Fix username and password
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Dec 1, 2022
1 parent d22311c commit 5c31959
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{{ $username := fact "username" }}
{{ $password := fact "password" }}
version: '2.3'
services:
elasticsearch:
image: "${ELASTICSEARCH_IMAGE_REF}"
healthcheck:
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)'"
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)'"
retries: 300
interval: 1s
environment:
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
- "ELASTIC_PASSWORD=changeme"
- "ELASTIC_PASSWORD={{ $password }}"
volumes:
- "./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
- "./certs/elasticsearch:/usr/share/elasticsearch/config/certs"
Expand Down
4 changes: 2 additions & 2 deletions internal/stack/_static/kibana.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ elasticsearch.hosts: [ "https://elasticsearch:9200" ]
elasticsearch.ssl.certificateAuthorities: "/usr/share/kibana/config/certs/ca-cert.pem"

{{ if semverLessThan $version "8.0.0" }}
elasticsearch.username: elastic
elasticsearch.password: changeme
elasticsearch.username: {{ fact "username" }}
elasticsearch.password: {{ fact "password" }}

xpack.monitoring.ui.container.elasticsearch.enabled: true
xpack.fleet.enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -e

curl -s --cacert /usr/share/kibana/config/certs/ca-cert.pem -f https://localhost:5601/login | grep kbn-injected-metadata 2>&1 >/dev/null
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
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
21 changes: 2 additions & 19 deletions internal/stack/initconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ package stack

import (
"fmt"
"os"

"github.com/pkg/errors"
"gopkg.in/yaml.v3"

"github.com/elastic/elastic-package/internal/compose"
"github.com/elastic/elastic-package/internal/install"
Expand All @@ -25,21 +23,6 @@ type InitConfig struct {
}

func StackInitConfig(elasticStackProfile *profile.Profile) (*InitConfig, error) {
// Read Elasticsearch username and password from Kibana configuration file.
body, err := os.ReadFile(elasticStackProfile.Path(profileStackPath, KibanaConfigFile))
if err != nil {
return nil, errors.Wrap(err, "error reading Kibana config file")
}

var kibanaCfg struct {
ElasticsearchUsername string `yaml:"elasticsearch.username"`
ElasticsearchPassword string `yaml:"elasticsearch.password"`
}
err = yaml.Unmarshal(body, &kibanaCfg)
if err != nil {
return nil, errors.Wrap(err, "unmarshalling Kibana configuration failed")
}

// Read Elasticsearch and Kibana hostnames from Elastic Stack Docker Compose configuration file.
p, err := compose.NewProject(DockerComposeProjectName, elasticStackProfile.Path(profileStackPath, SnapshotFile))
if err != nil {
Expand Down Expand Up @@ -72,8 +55,8 @@ func StackInitConfig(elasticStackProfile *profile.Profile) (*InitConfig, error)

return &InitConfig{
ElasticsearchHostPort: esHostPort,
ElasticsearchUsername: kibanaCfg.ElasticsearchUsername,
ElasticsearchPassword: kibanaCfg.ElasticsearchPassword,
ElasticsearchUsername: elasticsearchUsername,
ElasticsearchPassword: elasticsearchPassword,
KibanaHostPort: kibHostPort,
CACertificatePath: caCert,
}, nil
Expand Down
10 changes: 8 additions & 2 deletions internal/stack/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const (
ElasticAgentEnvFile = "elastic-agent.env"

profileStackPath = "stack"

elasticsearchUsername = "elastic"
elasticsearchPassword = "changeme"
)

var (
Expand All @@ -58,7 +61,7 @@ var (
},
&resource.File{
Path: SnapshotFile,
Content: staticSource.File("_static/docker-compose-stack.yml"),
Content: staticSource.Template("_static/docker-compose-stack.yml.tmpl"),
},
&resource.File{
Path: ElasticsearchConfigFile,
Expand Down Expand Up @@ -89,7 +92,7 @@ var (
},
&resource.File{
Path: KibanaHealthcheckFile,
Content: staticSource.File("_static/kibana_healthcheck.sh"),
Content: staticSource.Template("_static/kibana_healthcheck.sh.tmpl"),
},
&resource.File{
Path: PackageRegistryConfigFile,
Expand All @@ -111,6 +114,9 @@ func applyResources(profile *profile.Profile, stackVersion string) error {
"elasticsearch_version": stackVersion,
"kibana_version": stackVersion,
"agent_version": stackVersion,

"username": elasticsearchUsername,
"password": elasticsearchPassword,
})

os.MkdirAll(stackDir, 0755)
Expand Down

0 comments on commit 5c31959

Please sign in to comment.