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

Document how to connect with authentication #154

Open
tacman opened this issue Mar 8, 2023 · 1 comment
Open

Document how to connect with authentication #154

tacman opened this issue Mar 8, 2023 · 1 comment

Comments

@tacman
Copy link
Contributor

tacman commented Mar 8, 2023

I've installed the docker version of OpenSearch, which appears to require authentication.

https://opensearch.org/docs/1.2/#docker-quickstart

So this works as expected:

curl -XGET --insecure -u 'admin:admin' 'https://localhost:9200'

I've followed the instruction at https://github.com/jolicode/elastically#configuration-1 to configure the bundle (though I wish it had a recipe to add the bundle and such), but the sample code fails with an error 52, I assume because it's not authenticated

How do I configure authentication in the .env file? I tried this, but it doesn't work.

# .env
ELASTICSEARCH_HOST=https://admin:admin@localhost:9200

I've also tried tweaking the .yaml

# config/packages/elastically.yaml
elastically:
  connections:
    default:
      client:
        host:                '%env(ELASTICSEARCH_HOST)%'
        username: admin
        password: admin

This is probably related to #112

@Korbeil
Copy link
Member

Korbeil commented Mar 8, 2023

Hey @tacman and thanks for your feedback !

Since elastically is based upon ruflin/elastica library, we do support the same configuration schemes.
For a username/password authentication, you can use the same as Elastica: ruflin/Elastica#1030

Sadly, in your case, I do not see them implementing this in the DSN configuration section. So will you have to declare the configuration in separate env vars, here is an example:

ENV:

ELASTICSEARCH_HOST=https://admin:admin@localhost:9200
ELASTICSEARCH_USERNAME=admin
ELASTICSEARCH_PASSWORD=admin

YAML;

elastically:
  connections:
    default:
      client:
        host: %env(ELASTICSEARCH_HOST)%
        username: %env(ELASTICSEARCH_USERNAME)%
        password: %env(ELASTICSEARCH_PASSWORD)%

Also, if you are using the https://github.com/jolicode/elastically/blob/master/src/Transport/HttpClientTransport.php transport we provide, we do not support this configuration keys. You will have to add authentication headers in your declared Symfony HttpClient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants