Search code examples
javaelasticsearch-pluginelasticsearchelasticsearch-shield

Disabling shield for intergration tests


I have an app that connects to an elastic search node on another server via the Transport client using the JAVA API. The node has shield security enabled, so I use maven to fetch the shield jar. My app runs fine. However, now I'm trying to set up integration tests for the build process of my app. Thus instead of trying the Transport client, I try to run a local node to run my tests against. However, the local node complaints about the following issues.

  1. The license is only valid for 30 days. The documentation describes perfectly well on how to do this using all kinds of tooling, but it doesn't tell how to update the license via the JAVA API.
  2. I get an org.elasticsearch.shield.authz.AuthorizationException: action [indices:data/write/index] is unauthorized for user [__es_system_user]. This happens because my node doesn't configure any users. Again the documentation describes perfectly well how add users to a node, but doesn't explain on how to accomplish this using the JAVA API.

This I'm wondering whether it's possible to just disable shield for integration tests. I tried the following, but it didn't work. Any help is appreciated.

nodeBuilder().local(true).settings(ImmutableSettings.builder()
    .put("shield.enabled", false)).build()

Solution

  • What version of Elasticsearch and Shield are you using? shield.enabled works for me; I just did the following in a simple maven project with ES 1.5.2 and Shield 1.2.0

    final Node node = NodeBuilder.nodeBuilder()
                .settings(ImmutableSettings.builder().put("shield.enabled", false))
                .local(true).node();
    Client client = node.client();
    ClusterHealthResponse response = client.admin().cluster().prepareHealth().get();
    System.out.println(response.toString());
    

    No errors about licensing when doing this. If you still have some errors can you add them to your original post?