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

Implement SSL Verification #1932

Merged
merged 2 commits into from
Sep 13, 2024
Merged

Implement SSL Verification #1932

merged 2 commits into from
Sep 13, 2024

Conversation

dadoonet
Copy link
Owner

We now support both ssl_verification (default to true) and ca_certificate (default to null).

In order to ingest documents to Elasticsearch over HTTPS based connection, you obviously need to set the URL to https://your-server-address. If your server is using a certificate that has been signed by a Certificate Authority, then you're good to go. For example, that's the case if you are running Elasticsearch from cloud.elastic.co.

But if you are using a self signed certificate, which is the case in development mode, you need to either ignore the ssl check (not recommended) or provide the certificate to the Elasticsearch client.

To bypass the SSL Certificate verification, you can use the ssl_verification option:

name: "test"
elasticsearch:
  api_key: "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw=="
  ssl_verification: false

If you are running Elasticsearch from a Docker container, you can copy the self-signed certificate generated in /usr/share/elasticsearch/config/certs/http_ca.crt to your local machine:

docker cp CONTAINER_NAME:/usr/share/elasticsearch/config/certs/http_ca.crt /path/to/certificate

And then, you can specify this file in the elasticsearch.ca_certificate option:

name: "test"
elasticsearch:
  api_key: "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw=="
  ca_certificate: /path/to/certificate/http_ca.crt

You can also import your certificate into <JAVA_HOME>\lib\security\cacerts.

For example, if you have a root CA chain certificate or Elasticsearch server certificate in DER format (it's a binary format using a .cer extension), you need to:

  1. Logon to server (or client machine) where FSCrawler is running
  2. Run:
keytool -import -alias <alias name> -keystore "<JAVA_HOME>\lib\security\cacerts" -file <Path of Elasticsearch Server certificate or Root certificate>

It will prompt you for the password. Enter the certificate password like changeit.

  1. Make changes to FSCrawler _settings.json file to connect to your Elasticsearch server over HTTPS:
name: "test"
elasticsearch:
  api_key: "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw=="
  nodes:
  - url: "https://localhost:9243"

If you can not find keytool, it probably means that you did not add your JAVA_HOME/bin directory to your path.

Closes #1538.

@dadoonet dadoonet added new For new features or options component:elasticsearch labels Sep 13, 2024
@dadoonet dadoonet added this to the 2.10 milestone Sep 13, 2024
@dadoonet dadoonet self-assigned this Sep 13, 2024
We now support both `ssl_verification` (default to `true`) and `ca_certificate` (default to `null`).

In order to ingest documents to Elasticsearch over HTTPS based connection, you obviously need to set the URL to ``https://your-server-address``. If your server is using a certificate that has been signed by a Certificate Authority, then you're good to go. For example, that's the case if you are running Elasticsearch from cloud.elastic.co.

But if you are using a self signed certificate, which is the case in development mode, you need to either ignore the ssl check (not recommended) or provide the certificate to the Elasticsearch client.

To bypass the SSL Certificate verification, you can use the `ssl_verification` option:

```yaml
name: "test"
elasticsearch:
  api_key: "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw=="
  ssl_verification: false
```

If you are running Elasticsearch from a Docker container, you can copy the self-signed certificate generated in `/usr/share/elasticsearch/config/certs/http_ca.crt` to your local machine:

```sh
docker cp CONTAINER_NAME:/usr/share/elasticsearch/config/certs/http_ca.crt /path/to/certificate
```

And then, you can specify this file in the `elasticsearch.ca_certificate` option:

```yaml
name: "test"
elasticsearch:
  api_key: "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw=="
  ca_certificate: /path/to/certificate/http_ca.crt
```

You can also import your certificate into ``<JAVA_HOME>\lib\security\cacerts``.

For example, if you have a root CA chain certificate or Elasticsearch server certificate in DER format (it's a binary format using a `.cer` extension), you need to:

1. Logon to server (or client machine) where FSCrawler is running
2. Run:

```sh
keytool -import -alias <alias name> -keystore "<JAVA_HOME>\lib\security\cacerts" -file <Path of Elasticsearch Server certificate or Root certificate>
```

It will prompt you for the password. Enter the certificate password like `changeit`.

3. Make changes to FSCrawler `_settings.json` file to connect to your Elasticsearch server over HTTPS:

```yaml
name: "test"
elasticsearch:
  api_key: "VnVhQ2ZHY0JDZGJrUW0tZTVhT3g6dWkybHAyYXhUTm1zeWFrdzl0dk5udw=="
  nodes:
  - url: "https://localhost:9243"
```

If you can not find `keytool`, it probably means that you did not add your `JAVA_HOME/bin` directory to your path.

Closes #1538.
@dadoonet dadoonet merged commit d2338e6 into master Sep 13, 2024
4 of 6 checks passed
@dadoonet dadoonet deleted the ssl-verification branch September 13, 2024 22:17
Copy link

sonarcloud bot commented Sep 13, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:elasticsearch new For new features or options
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement SSL Verification for custom truststore and keystore
1 participant