mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-24 23:27:25 -04:00
Add HLRC docs for AuthN and TLS (#51355)
This commit adds examples in our documentation for - An HLRC instance authenticating to an elasticsearch cluster using an elasticsearch token service access token or an API key - An HLRC instance connecting to an elasticsearch cluster that is setup for TLS on the HTTP layer when the CA certificate of the cluster is available either as a PEM file or a keystore - An HLRC instance connecting to an elasticsearch cluster that requires client authentication where the client key and certificate are available in a keystore Co-Authored-By: Lisa Cawley <lcawley@elastic.co>
This commit is contained in:
parent
a57a9a31c3
commit
308f95d9f3
2 changed files with 145 additions and 5 deletions
|
@ -64,21 +64,75 @@ include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-config-disa
|
|||
--------------------------------------------------
|
||||
<1> Disable preemptive authentication
|
||||
|
||||
=== Other authentication methods
|
||||
|
||||
==== Elasticsearch Token Service tokens
|
||||
|
||||
If you want the client to authenticate with an Elasticsearch access token, set the relevant HTTP request header.
|
||||
If the client makes requests on behalf of a single user only, you can set the necessary `Authorization` header as a default header as shown
|
||||
in the following example:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-auth-bearer-token]
|
||||
--------------------------------------------------
|
||||
|
||||
==== Elasticsearch API keys
|
||||
|
||||
If you want the client to authenticate with an Elasticsearch API key, set the relevant HTTP request header.
|
||||
If the client makes requests on behalf of a single user only, you can set the necessary `Authorization` header as a default header as shown
|
||||
in the following example:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-auth-api-key]
|
||||
--------------------------------------------------
|
||||
|
||||
=== Encrypted communication
|
||||
|
||||
Encrypted communication can also be configured through the
|
||||
Encrypted communication using TLS can also be configured through the
|
||||
`HttpClientConfigCallback`. The
|
||||
https://hc.apache.org/httpcomponents-asyncclient-dev/httpasyncclient/apidocs/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.html[`org.apache.http.impl.nio.client.HttpAsyncClientBuilder`]
|
||||
received as an argument exposes multiple methods to configure encrypted
|
||||
communication: `setSSLContext`, `setSSLSessionStrategy` and
|
||||
`setConnectionManager`, in order of precedence from the least important.
|
||||
The following is an example:
|
||||
|
||||
When accessing an Elasticsearch cluster that is setup for TLS on the HTTP layer, the client needs to trust the certificate that
|
||||
Elasticsearch is using.
|
||||
The following is an example of setting up the client to trust the CA that has signed the certificate that Elasticsearch is using, when
|
||||
that CA certificate is available in a PKCS#12 keystore:
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-config-encrypted-communication]
|
||||
--------------------------------------------------
|
||||
|
||||
The following is an example of setting up the client to trust the CA that has signed the certificate that Elasticsearch is using, when
|
||||
that CA certificate is available as a PEM encoded file.
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-config-trust-ca-pem]
|
||||
--------------------------------------------------
|
||||
|
||||
When Elasticsearch is configured to require client TLS authentication, for example when a PKI realm is configured, the client needs to provide
|
||||
a client certificate during the TLS handshake in order to authenticate. The following is an example of setting up the client for TLS
|
||||
authentication with a certificate and a private key that are stored in a PKCS#12 keystore.
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests}/RestClientDocumentation.java[rest-client-config-mutual-tls-authentication]
|
||||
--------------------------------------------------
|
||||
|
||||
If the client certificate and key are not available in a keystore but rather as PEM encoded files, you cannot use them
|
||||
directly to build an SSLContext. You must rely on external libraries to parse the PEM key into a PrivateKey instance. Alternatively, you
|
||||
can use external tools to build a keystore from your PEM files, as shown in the following example:
|
||||
|
||||
```
|
||||
openssl pkcs12 -export -in client.crt -inkey private_key.pem \
|
||||
-name "client" -out client.p12
|
||||
```
|
||||
|
||||
If no explicit configuration is provided, the http://docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/JSSERefGuide.html#CustomizingStores[system default configuration]
|
||||
will be used.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue