title: How to implement SSL with Self Signed Certificates on Spring Boot against Elasticsearch deployed at Openshift (a cloud-based Kubernetes)
body: <p>Does anyone know how to use SSL on Spring Boot application to connect with ElasticSearch which is deployed at Openshift in the form of https? I have a config.java in my Spring Boot application like the following:</p>
  <pre><code>@Configuration
  @EnableElasticsearchRepositories(basePackages = &quot;com.siolbca.repository&quot;)
  @ComponentScan(basePackages = &quot;com.siolbca.services&quot;)
  public class Config {
      @Bean
      public RestHighLevelClient client() {
          ClientConfiguration clientConfiguration 
              = ClientConfiguration.builder()
                  .connectedTo(&quot;elasticsearch-siol-es-http.siolbca-dev.svc.cluster.local&quot;)
                  .usingSsl()
                  .withBasicAuth(&quot;elastic&quot;,&quot;G0D1g6TurJ79pcxr1065pU0U&quot;)
                  .build();
  
          return RestClients.create(clientConfiguration).rest();
      }
  
      @Bean
      public ElasticsearchOperations elasticsearchTemplate() {
          return new ElasticsearchRestTemplate(client());
      }
  }
  </code></pre>
  <p>However, when I run it with Postman to run elasticsearch, an error appears like this:</p>
  <pre><code>javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  </code></pre>
  <p>I've seen some tutorials on the internet that say it's a certificate issue but I can't get a clue how to implement it in my code because I'm a beginner to Java &amp; Spring Boot.
  <a href="https://stackoverflow.com/questions/47334476/using-elasticsearch-java-rest-api-with-self-signed-certificates">using-elasticsearch-java-rest-api-with-self-signed-certificates</a>
  <a href="https://stackoverflow.com/questions/56598798/how-to-connect-spring-boot-2-1-with-elasticsearch-6-6-with-cluster-node-https">how-to-connect-spring-boot-2-1-with-elasticsearch-6-6-with-cluster-node-https</a></p>
  <p>And here’s my configuration for elasticsearch.yml:</p>
  <pre><code>cluster:
    name: elasticsearch-siol
    routing:
      allocation:
        awareness:
          attributes: k8s_node_name
  discovery:
    seed_providers: file
  http:
    publish_host: ${POD_NAME}.${HEADLESS_SERVICE_NAME}.${NAMESPACE}.svc
  network:
    host: &quot;0&quot;
    publish_host: ${POD_IP}
  node:
    attr:
      attr_name: attr_value
      k8s_node_name: ${NODE_NAME}
    name: ${POD_NAME}
    roles:
    - master
    - data
    store:
      allow_mmap: false
  path:
    data: /usr/share/elasticsearch/data
    logs: /usr/share/elasticsearch/logs
  xpack:
    license:
      upload:
        types:
        - trial
        - enterprise
    security:
      authc:
        realms:
          file:
            file1:
              order: -100
          native:
            native1:
              order: -99
        reserved_realm:
          enabled: &quot;false&quot;
      enabled: &quot;true&quot;
      http:
        ssl:
          certificate: /usr/share/elasticsearch/config/http-certs/tls.crt
          certificate_authorities: /usr/share/elasticsearch/config/http-certs/ca.crt
          enabled: true
          key: /usr/share/elasticsearch/config/http-certs/tls.key
      transport:
        ssl:
          certificate: /usr/share/elasticsearch/config/node-transport-cert/transport.tls.crt
          certificate_authorities:
          - /usr/share/elasticsearch/config/transport-certs/ca.crt
          - /usr/share/elasticsearch/config/transport-remote-certs/ca.crt
          enabled: &quot;true&quot;
          key: /usr/share/elasticsearch/config/node-transport-cert/transport.tls.key
          verification_mode: certificate
  </code></pre>
  <p>Does anyone know how to use the provided certificate in my Spring Boot application? Thank you.</p>