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

Add Groovy as a scripting language, add groovy sandboxing #6233

Merged
merged 1 commit into from Jun 20, 2014

Conversation

dakrone
Copy link
Member

@dakrone dakrone commented May 19, 2014

Sandboxes the groovy scripting language with multiple configurable
whitelists:

script.groovy.sandbox.receiver_whitelist: comma-separated list of string
classes for objects that may have methods invoked.
script.groovy.sandbox.package_whitelist: comma-separated list of
packages under which new objects may be constructed.
script.groovy.sandbox.class_whitelist comma-separated list of classes
that are allowed to be constructed.

As well as a method blacklist:

script.groovy.sandbox.method_blacklist: comma-separated list of
methods that are never allowed to be invoked, regardless of target
object.

The sandbox can be entirely disabled by setting:

script.groovy.sandbox.enabled: false

@@ -6,28 +6,30 @@ expressions. For example, scripts can be used to return "script fields"
as part of a search request, or can be used to evaluate a custom score
for a query and so on.

The scripting module uses by default http://mvel.codehaus.org/[mvel] as
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should really have a section that says that we added this in 1.3 and where to find the docs for the prev. version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I added the "coming in 1.3.0" part, but not sure where to link for older documentation since 1.2 hasn't been released yet. Once it's released I'll add a commit to point to the older documentation.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs are built for branches, ie 1.x, master, not for released versions. So you should use a deprecated tag for mvel eg deprecated[1.3.0,Replace by groovy as the default scripting language, see old docs here <>]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dakrone can you address clintons comments?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a commit to rearrange and (hopefully) clarify the mvel deprecation.

@s1monw
Copy link
Contributor

s1monw commented May 19, 2014

oh man this looks awesome!

"java.lang.Double", "[D", "[[D", "[[[D",
"java.lang.Long", "[J", "[[J", "[[[J",
"java.lang.Short", "[S", "[[S", "[[[S",
"java.lang.Char", "[C", "[[C", "[[[C",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be java.lang.Character?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, good catch, fixed.

@dakrone
Copy link
Member Author

dakrone commented Jun 3, 2014

Added a number of commits to address the feedback, @s1monw can you take another look?

@@ -74,7 +74,7 @@ public ScriptService(Settings settings, Environment env, Set<ScriptEngineService
TimeValue cacheExpire = componentSettings.getAsTime("cache.expire", null);
logger.debug("using script cache with max_size [{}], expire [{}]", cacheMaxSize, cacheExpire);

this.defaultLang = componentSettings.get("default_lang", "mvel");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any chance we can make this a constant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will make everything a constant that can be for this.

@@ -951,7 +951,7 @@ public void script_Score() {
SearchResponse response = client().prepareSearch("idx").setTypes("type")
.setQuery(functionScoreQuery(matchAllQuery()).add(ScoreFunctionBuilders.scriptFunction("doc['" + SINGLE_VALUED_FIELD_NAME + "'].value")))
.addAggregation(terms("terms")
.script("ceil(_doc.score/3)")
.script("ceil(_doc.score()/3)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mabye we can use _score here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into this, _score doesn't work for either Groovy or Mvel (probably due to this being in an aggregation?). If this is something we want to support I think we should open a separate issue for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see makes sense!

@s1monw
Copy link
Contributor

s1monw commented Jun 12, 2014

did another review.... looks pretty close... left some commetns

@s1monw s1monw removed the review label Jun 12, 2014
/**
* Float encapsulation that allows updating the value with public member access
*/
public class UpdateableFloat extends Number {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should make this class package private and final? Can you also put in the comment where this is used and for what reason just be a little more verbose.... we might also just put it as a inner class?

@dakrone
Copy link
Member Author

dakrone commented Jun 16, 2014

@s1monw updated this PR with all of the changes you recommended :)

@dakrone dakrone added the review label Jun 17, 2014
@s1monw
Copy link
Contributor

s1monw commented Jun 18, 2014

this actually LGTM maybe @kimchy want's to take a look?
good job!

@kimchy
Copy link
Member

kimchy commented Jun 18, 2014

@dakrone this looks great!, a few comments:

  • I would add a 3 value setting to dynamic script enable now, true, false, and sandbox.

For 2.0:

  • I would remove mvel completely
  • Default to sandbox in dynamic script setting, and groovy as the lang.

For 1.3:

  • I would suggest also removing mvel completely, aside from security, its just buggy, if we decide to, then its the same changes as 2.0, including properly documenting how to install the mvel plugin and setting mvel as the lang by default, and properly mark it as a breaking change.
  • If there is resistance from removing mvel, then keep mvel around and keep it as the default lang, next to groovy being an option. Default dynamic script should still be sandbox.

@dakrone
Copy link
Member Author

dakrone commented Jun 18, 2014

@kimchy Sounds good, I updated the documentation and completely removed mvel as well. I also added the 3-value setting for dynamic scripting.

@s1monw
Copy link
Contributor

s1monw commented Jun 18, 2014

so this means that upgrading to 1.3 from any prev version means you need to install the mvel plugin on the upgrade and pass mvel as a param in the request to opt in to this language? I think we really need to invest into an upgrade guide here!

@s1monw s1monw removed the review label Jun 18, 2014
@dakrone
Copy link
Member Author

dakrone commented Jun 19, 2014

@s1monw yes, the mvel plugin will have to be installed and the script.default_lang: mvel option would have to be added to continue using mvel as the default.

For an upgrade guide, do we want to add the two settings to the release notes? It will also be on the scripting blog post to come out after this is merged as well.

@dakrone dakrone changed the title Add Groovy as a scripting language, change default from mvel -> groovy Add Groovy as a scripting language, add groovy sandboxing Jun 20, 2014
@dakrone dakrone removed the breaking label Jun 20, 2014
Sandboxes the groovy scripting language with multiple configurable
whitelists:

`script.groovy.sandbox.receiver_whitelist`: comma-separated list of string
classes for objects that may have methods invoked.
`script.groovy.sandbox.package_whitelist`: comma-separated list of
packages under which new objects may be constructed.
`script.groovy.sandbox.class_whitelist` comma-separated list of classes
that are allowed to be constructed.

As well as a method blacklist:

`script.groovy.sandbox.method_blacklist`: comma-separated list of
methods that are never allowed to be invoked, regardless of target
object.

The sandbox can be entirely disabled by setting:

`script.groovy.sandbox.enabled: false`
@dakrone dakrone merged commit c70f6d0 into elastic:master Jun 20, 2014
@clintongormley clintongormley changed the title Add Groovy as a scripting language, add groovy sandboxing Scripting: Add Groovy as a scripting language, add groovy sandboxing Jul 16, 2014
dadoonet added a commit to elastic/elasticsearch-river-couchdb that referenced this pull request Jul 18, 2014
As for elasticsearch 1.3.0, `groovy` is the new default scripting language.

Related to: elastic/elasticsearch#6233

Closes #61.
(cherry picked from commit 170a2cd)
dadoonet added a commit to elastic/elasticsearch-river-couchdb that referenced this pull request Jul 18, 2014
As for elasticsearch 1.3.0, `groovy` is the new default scripting language.

Related to: elastic/elasticsearch#6233

Closes #61.
(cherry picked from commit 170a2cd)
dadoonet added a commit to elastic/elasticsearch-river-couchdb that referenced this pull request Jul 18, 2014
As for elasticsearch 1.3.0, `groovy` is the new default scripting language.

Related to: elastic/elasticsearch#6233

Closes #61.
@dakrone dakrone deleted the feature/add-groovy-scripting branch September 9, 2014 13:47
@clintongormley clintongormley added the :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache label Jun 6, 2015
@clintongormley clintongormley changed the title Scripting: Add Groovy as a scripting language, add groovy sandboxing Add Groovy as a scripting language, add groovy sandboxing Jun 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants