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

Elasticsearch disable CA retrieval when ssl is disabled #2475

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
15 changes: 15 additions & 0 deletions modules/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ func configureAddress(ctx context.Context, c *ElasticsearchContainer) (string, e
// The certificate is only available since version 8, and will be located in a well-known location.
func configureCertificate(settings *Options, req *testcontainers.GenericContainerRequest) error {
if isAtLeastVersion(req.Image, 8) {
// These configuration keys explicitly disable CA generation.
// If any are set we skip the file retrieval.
configKeys := []string{
"xpack.security.enabled",
"xpack.security.http.ssl.enabled",
"xpack.security.transport.ssl.enabled",
}
for _, configKey := range configKeys {
if value, ok := req.Env[configKey]; ok {
if value == "false" {
return nil
}
}
}

// The container needs a post ready hook to copy the certificate from the container to the host.
// This certificate is only available since version 8
req.LifecycleHooks[0].PostReadies = append(req.LifecycleHooks[0].PostReadies,
Expand Down
45 changes: 45 additions & 0 deletions modules/elasticsearch/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,51 @@ func TestElasticsearch(t *testing.T) {
}
}

func TestElasticsearch8WithoutSSL(t *testing.T) {
tests := []struct {
name string
configKey string
}{
{
name: "security disabled",
configKey: "xpack.security.enabled",
},
{
name: "transport ssl disabled",
configKey: "xpack.security.transport.ssl.enabled",
},
{
name: "http ssl disabled",
configKey: "xpack.security.http.ssl.enabled",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ctx := context.Background()
container, err := elasticsearch.RunContainer(
ctx,
testcontainers.WithImage(baseImage8),
testcontainers.WithEnv(map[string]string{
test.configKey: "false",
}))
if err != nil {
t.Fatal(err)
}

t.Cleanup(func() {
if err := container.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err)
}
})

if len(container.Settings.CACert) > 0 {
t.Fatal("expected CA cert to be empty")
}
})
}

}

func TestElasticsearch8WithoutCredentials(t *testing.T) {
ctx := context.Background()

Expand Down
Loading