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

Internal: Add versionless alias for rest client codebase in policy files #26521

Merged
merged 5 commits into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions core/src/main/java/org/elasticsearch/bootstrap/Security.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

package org.elasticsearch.bootstrap;

import org.elasticsearch.Build;
import org.elasticsearch.SecureSM;
import org.elasticsearch.Version;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.network.NetworkModule;
Expand All @@ -43,10 +45,12 @@
import java.security.Permissions;
import java.security.Policy;
import java.security.URIParameter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -191,27 +195,39 @@ static Map<String,Policy> getPluginPermissions(Environment environment) throws I
@SuppressForbidden(reason = "accesses fully qualified URLs to configure security")
static Policy readPolicy(URL policyFile, Set<URL> codebases) {
try {
List<String> propertiesSet = new ArrayList<>();
try {
// set codebase properties
for (URL url : codebases) {
String shortName = PathUtils.get(url.toURI()).getFileName().toString();
if (shortName.endsWith(".jar") == false) {
continue; // tests :(
}
String previous = System.setProperty("codebase." + shortName, url.toString());
String property = "codebase." + shortName;
if (shortName.startsWith("elasticsearch-rest-client")) {
// The rest client is currently the only example where we have an elasticsearch built artifact
// which needs special permissions in policy files when used. This temporary solution is to
// pass in an extra system property that omits the -version.jar suffix the other properties have.
// That allows the snapshots to reference snapshot builds of the client, and release builds to
// referenced release builds of the client, all with the same grant statements.
final String esVersion = Version.CURRENT + (Build.CURRENT.isSnapshot() ? "-SNAPSHOT" : "");
final int index = property.indexOf("-" + esVersion + ".jar");
assert index >= 0;
String restClientAlias = property.substring(0, index);
propertiesSet.add(restClientAlias);
System.setProperty(restClientAlias, url.toString());
}
propertiesSet.add(property);
String previous = System.setProperty(property, url.toString());
if (previous != null) {
throw new IllegalStateException("codebase property already set: " + shortName + "->" + previous);
}
}
return Policy.getInstance("JavaPolicy", new URIParameter(policyFile.toURI()));
} finally {
// clear codebase properties
for (URL url : codebases) {
String shortName = PathUtils.get(url.toURI()).getFileName().toString();
if (shortName.endsWith(".jar") == false) {
continue; // tests :(
}
System.clearProperty("codebase." + shortName);
for (String property : propertiesSet) {
System.clearProperty(property);
}
}
} catch (NoSuchAlgorithmException | URISyntaxException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ grant codeBase "${codebase.mocksocket-1.2.jar}" {
permission java.net.SocketPermission "*", "accept,connect";
};

grant codeBase "${codebase.elasticsearch-rest-client-7.0.0-alpha1-SNAPSHOT.jar}" {
grant codeBase "${codebase.elasticsearch-rest-client}" {
// rest makes socket connections for rest tests
permission java.net.SocketPermission "*", "connect";
// rest client uses system properties which gets the default proxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ grant {
permission java.net.SocketPermission "*", "connect";
};

grant codeBase "${codebase.elasticsearch-rest-client-7.0.0-alpha1-SNAPSHOT.jar}" {
grant codeBase "${codebase.elasticsearch-rest-client}" {
// rest client uses system properties which gets the default proxy
permission java.net.NetPermission "getProxySelector";
};
Expand Down