Skip to content

Commit

Permalink
Issue warning about allowed_urls when default value is used (#2534)
Browse files Browse the repository at this point in the history
Co-authored-by: Naman Nandan <[email protected]>
  • Loading branch information
namannandan and Naman Nandan authored Aug 22, 2023
1 parent 58eb2d2 commit 921f423
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.commons.io.IOUtils;
import org.pytorch.serve.servingsdk.snapshot.SnapshotSerializer;
import org.pytorch.serve.snapshot.SnapshotSerializerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class ConfigManager {
Expand Down Expand Up @@ -111,6 +112,9 @@ public final class ConfigManager {
private static final String MODEL_CONFIG = "models";
private static final String VERSION = "version";

// Configuration default values
private static final String DEFAULT_TS_ALLOWED_URLS = "file://.*|http(s)?://.*";

// Variables which are local
public static final String MODEL_METRICS_LOGGER = "MODEL_METRICS";
public static final String MODEL_LOGGER = "MODEL_LOG";
Expand All @@ -136,6 +140,7 @@ public final class ConfigManager {
private String hostName;
private Map<String, Map<String, JsonObject>> modelConfig = new HashMap<>();
private String torchrunLogDir;
private Logger logger = LoggerFactory.getLogger(ConfigManager.class);

private ConfigManager(Arguments args) throws IOException {
prop = new Properties();
Expand Down Expand Up @@ -234,6 +239,13 @@ private ConfigManager(Arguments args) throws IOException {
}

setModelConfig();

// Issue warnining about URLs that can be accessed when loading models
if (prop.getProperty(TS_ALLOWED_URLS, DEFAULT_TS_ALLOWED_URLS) == DEFAULT_TS_ALLOWED_URLS) {
logger.warn(
"Your torchserve instance can access any URL to load models. "
+ "When deploying to production, make sure to limit the set of allowed_urls in config.properties");
}
}

public static String readFile(String path) throws IOException {
Expand Down Expand Up @@ -783,7 +795,7 @@ private static int getAvailableGpu() {
}

public List<String> getAllowedUrls() {
String allowedURL = prop.getProperty(TS_ALLOWED_URLS, "file://.*|http(s)?://.*");
String allowedURL = prop.getProperty(TS_ALLOWED_URLS, DEFAULT_TS_ALLOWED_URLS);
return Arrays.asList(allowedURL.split(","));
}

Expand Down

0 comments on commit 921f423

Please sign in to comment.