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

Issue warning about allowed_urls when default value is used #2534

Merged
merged 1 commit into from
Aug 22, 2023
Merged
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
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
Loading