You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add security on by default documentation
* Fix id collision in connecting section
* Update .doc/connecting.asciidoc
Co-authored-by: István Zoltán Szabó <[email protected]>
* Update .doc/connecting.asciidoc
Co-authored-by: István Zoltán Szabó <[email protected]>
* Update .doc/connecting.asciidoc
Co-authored-by: István Zoltán Szabó <[email protected]>
Co-authored-by: István Zoltán Szabó <[email protected]>
@@ -6,15 +6,186 @@ This page contains the information you need to connect and use the Client with
6
6
7
7
**On this page**
8
8
9
-
* <<auth-reference, Authentication options>>
9
+
* Connecting
10
+
** <<connecting-to-elastic-cloud, Connecting to Elastic Cloud>>
11
+
** <<connecting-to-self-managed, Connecting to a self-managed cluster>>
12
+
** <<verifying-with-ca, Verifying HTTPS with CA certificates>>
13
+
** <<verifying-with-fingerprint, Verifying HTTPS with certificate fingerprint>>
14
+
** <<connecting-without-security, Connecting without security enabled>>
15
+
** <<connecting-multiple-nodes, Connecting to multiple nodes>>
16
+
* <<auth-reference, Authentication>>
17
+
** <<auth-basic, Basic Authentication>>
18
+
** <<auth-token, HTTP Bearer authentication>>
19
+
* <<compatibility-mode, Compatibility mode>>
10
20
* <<client-usage, Using the client>>
21
+
* <<connecting-faas, Using the Client in a Function-as-a-Service Environment>>
22
+
23
+
[discrete]
24
+
[[connecting-to-elastic-cloud]]
25
+
==== Connecting to Elastic Cloud
26
+
27
+
If you are using https://www.elastic.co/cloud[Elastic Cloud], the client offers
28
+
an easy way to connect to it. You must pass the Cloud ID that you can find in
29
+
the cloud console and the corresponding API key.
30
+
31
+
[source,go]
32
+
------------------------------------
33
+
cfg := elasticsearch.Config{
34
+
CloudID: "CLOUD_ID",
35
+
APIKey: "API_KEY"
36
+
}
37
+
es, err := elasticsearch.NewClient(cfg)
38
+
------------------------------------
39
+
IMPORTANT: you need to copy and store the `API key` in a secure place since you will not be able to view it again in Elastic Cloud.
40
+
41
+
[discrete]
42
+
[[connecting-to-self-managed]]
43
+
==== Connecting to a self-managed cluster
44
+
45
+
Starting from version 8.0, {es} offers security by default with authentication and TLS enabled.
46
+
47
+
To connect to the {es} cluster you need to configure the client to use the generated CA certificate. If you’re just getting started with {es} we recommend reading the documentation on configuring and starting {es} to ensure your cluster is running as expected.
48
+
49
+
When you start {es} for the first time you’ll see a distinct block like the one below in the output from {es} (you may have to scroll up if it’s been a while):
Note down the `elastic` user password and HTTP CA fingerprint for the next sections. In the examples below they will be stored in the variables `ELASTIC_PASSWORD` and `CERT_FINGERPRINT` respectively.
64
+
65
+
Depending on the circumstances there are two options for verifying the HTTPS connection, either verifying with the CA certificate itself or via the HTTP CA certificate fingerprint.
66
+
67
+
[discrete]
68
+
[[verifying-with-ca]]
69
+
==== Verifying HTTPS with CA certificates
70
+
71
+
The generated root CA certificate can be found in the `certs` directory in your {es} config location (`$ES_CONF_PATH/certs/http_ca.crt`). If you're running {es} in Docker there is https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html[additional documentation for retrieving the CA certificate].
72
+
73
+
Once you have the `http_ca.crt` file somewhere accessible pass the content of the file to the client via `CACert`:
This method of verifying the HTTPS connection takes advantage of the certificate fingerprint value noted down earlier. Take this SHA256 fingerprint value and pass it to the Go {es} client via `ca_fingerprint`:
95
+
96
+
[source,go]
97
+
------------------------------------
98
+
cfg := elasticsearch.Config{
99
+
Addresses: []string{
100
+
"https://localhost:9200",
101
+
},
102
+
Username: "elastic",
103
+
Password: ELASTIC_PASSWORD
104
+
CertificateFingerprint: CERT_FINGERPRINT
105
+
}
106
+
es, err := elasticsearch.NewClient(cfg)
107
+
------------------------------------
108
+
109
+
The certificate fingerprint can be calculated using openssl x509 with the certificate file:
If you don't have access to the generated CA file from {es} you can use the following script to output the root CA fingerprint of the {es} instance with `openssl s_client`:
117
+
118
+
[source,sh]
119
+
----
120
+
# Replace the values of 'localhost' and '9200' to the
121
+
# corresponding host and port values for the cluster.
0 commit comments