-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Dynamic (inline) groovy scripts that parse JSON do not work with 2.0 #14787
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
Comments
If it is just a property, it does not hurt. Of course, i strongly feel scripts should not be doing any of this. |
As a workaround, I found groovy.json.JsonSlurperClassic class that can be used instead of groovy.json.JsonSlurper without causing any of the errors. |
I've the very same issue with Elastic version 2.2.0. My test script is as simple as that: import groovy.json.JsonSlurper; def jsonSlurper = new JsonSlurper(); def message = jsonSlurper.parseText(_json); When first trying to run the script, I get the SecurityException[access denied ("java.util.PropertyPermission" "groovy.json.internKeys" "read") . I've tried with the following policy but without success: grant { permission java.util.PropertyPermission "groovy.json.internKeys", "read"; permission org.elasticsearch.script.ClassPermission "java.lang.Class"; permission org.elasticsearch.script.ClassPermission "groovy.json.JsonSlurper"; permission org.elasticsearch.script.ClassPermission "groovy.json.internal.*"; permission org.elasticsearch.script.ClassPermission "groovy.json.internal.JsonParserCharArray"; permission org.elasticsearch.script.ClassPermission "org.elasticsearch.common.logging.*"; }; Can anyone please provide an example how to use the JsonSlurper in a Groovy script with Elastic 2.2.0? |
@plebedev correct me if I'm wrong, but it seems like you use a script to update a document and the parameter for the script is JSON encoded as string. If that's the case, you can use a map of maps (i.e. JSON object ) as the value of the parameter which means you don't need to encode the JSON or alternatively you can decode it on your client. Does that make sense? |
@bleskes thanks for your suggestion. |
@fs-chris thanks
Can you elaborate on this - most notably I'm interested in understanding how parsing in your application is different than parsing in the ES process. |
@bleskes thanks for your interest. I'm using Groovy in an update script. So, always parsing in the application would be unecessary overhead in almost all cases. The approach with doing it in the script worked well with previous Elastic releases. |
@fs-chris thanks. I see the discussion on #16808 , most notably @clintongormley 's suggestion:
|
@bleskes, We've migrated to 2.2.1 and we had to change the code to pass JSONObject, so it is not parsed in elastinsearch. Works so far :) Thanks! |
@plebedev cool. Thanks for circling back and letting us know. |
I'm trying to migrate from 1.7 to 2.0 and I can't get my existing dynamic groovy script to work with ES.
First, I added this line to elasticsearch.yml:
script.inline: on
With just this line I'm getting an error when I try to do bulk update with the following script for each update action:
final Script updateScript = new Script("event = new groovy.json.JsonSlurper().parseText(_event);ctx._source.events += event", ScriptType.INLINE, "groovy", ImmutableMap.of("_event", eventJson));
I'm getting the error when I execute the action:
_GroovyScriptExecutionException[failed to run inline script [event = new groovy.json.JsonSlurper().parseText(_event);ctx.source.events += event] using lang [groovy]]; nested: NotSerializableExceptionWrapper[Could not initialize class groovy.json.internal.JsonParserCharArray];
When I add these lines to elasticsearch.yml:
script.engine.groovy.inline.aggs: on
script.engine.groovy.inline.mapping: on
script.engine.groovy.inline.search: on
script.engine.groovy.inline.update: on
script.engine.groovy.inline.plugin: on
and try to execute an update with the same script, I get this error:
_GroovyScriptExecutionException[failed to run inline script [event = new groovy.json.JsonSlurper().parseText(_event);ctx.source.events += event] using lang [groovy]]; nested: NotSerializableExceptionWrapper; nested: SecurityException[access denied ("java.util.PropertyPermission" "groovy.json.internKeys" "read")];
I tried to add
permission java.util.PropertyPermission "groovy.json.internKeys", "read";
to java.policy file but it did not help.
I see
permission java.util.PropertyPermission "*", "read,write";
in org/elasticsearch/bootstrap/security.policy, so it is not clear to me why I'm getting this permission error unless groovy runs with its own security manager that does not
The same script with 1.7 worked.
I have few other scripts for score functions that do not use JSON, and these work fine.
Thanks,
Peter.
The text was updated successfully, but these errors were encountered: