增强安全性

This commit is contained in:
virusdefender 2016-10-10 00:00:54 +08:00
parent 822b8e879e
commit a363c0f7a7
4 changed files with 40 additions and 25 deletions

View File

@ -14,10 +14,8 @@ RUN pip install psutil gunicorn web.py requests
RUN mkdir -p /judger_run /test_case /log /code RUN mkdir -p /judger_run /test_case /log /code
COPY deploy/java_policy /etc COPY deploy/java_policy /etc
RUN chmod -R 777 /judger_run RUN chmod -R 777 /judger_run
RUN mkdir -p /spj/exe /spj/src
RUN chown -R nobody:nogroup /spj
RUN pip install futures psutil gunicorn web.py RUN pip install futures psutil gunicorn web.py
HEALTHCHECK --interval=5s --retries=3 CMD python /code/service.py HEALTHCHECK --interval=5s --retries=3 CMD python /code/service.py
WORKDIR /code WORKDIR /code
EXPOSE 8080 EXPOSE 8080
CMD gunicorn --workers 4 --threads 4 --error-logfile /log/gunicorn.log --bind 0.0.0.0:8080 server:wsgiapp CMD chown -R nobody:nogroup /spj; gunicorn --workers 4 --threads 4 --error-logfile /log/gunicorn.log --bind 0.0.0.0:8080 server:wsgiapp

View File

@ -6,7 +6,8 @@ import json
import requests import requests
from languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, c_lang_spj_compile, py2_lang_config from languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, \
c_lang_spj_compile, py2_lang_config
class JudgeServerClientError(Exception): class JudgeServerClientError(Exception):
@ -30,14 +31,17 @@ class JudgeServerClient(object):
def ping(self): def ping(self):
return self._request(self.server_base_url + "/ping") return self._request(self.server_base_url + "/ping")
def judge(self, src, language_config, max_cpu_time, max_memory, test_case_id, spj_version=None, spj_config=None): def judge(self, src, language_config, max_cpu_time, max_memory, test_case_id, spj_version=None, spj_config=None,
spj_compile_config=None, spj_src=None):
data = {"language_config": language_config, data = {"language_config": language_config,
"src": src, "src": src,
"max_cpu_time": max_cpu_time, "max_cpu_time": max_cpu_time,
"max_memory": max_memory, "max_memory": max_memory,
"test_case_id": test_case_id, "test_case_id": test_case_id,
"spj_version": spj_version, "spj_version": spj_version,
"spj_config": spj_config} "spj_config": spj_config,
"spj_compile_config": spj_compile_config,
"spj_src": spj_src}
return self._request(self.server_base_url + "/judge", data=data) return self._request(self.server_base_url + "/judge", data=data)
def compile_spj(self, src, spj_version, spj_compile_config, test_case_id): def compile_spj(self, src, spj_version, spj_compile_config, test_case_id):
@ -96,14 +100,12 @@ if __name__ == "__main__":
s1 = s.split(" ") s1 = s.split(" ")
print int(s1[0]) + int(s1[1])""" print int(s1[0]) + int(s1[1])"""
js_src = "console.log(3)"
client = JudgeServerClient(token="token", server_base_url="http://123.57.151.42:12358") client = JudgeServerClient(token="token", server_base_url="http://123.57.151.42:12358")
print client.ping(), "\n\n" print client.ping(), "\n\n"
print client.judge(src=py2_src, language_config=py2_lang_config, print client.compile_spj(src=c_spj_src, spj_version="2", spj_compile_config=c_lang_spj_compile,
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
test_case_id="normal"), "\n\n"
print client.compile_spj(src=c_spj_src, spj_version="1", spj_compile_config=c_lang_spj_compile,
test_case_id="spj"), "\n\n" test_case_id="spj"), "\n\n"
print client.judge(src=c_src, language_config=c_lang_config, print client.judge(src=c_src, language_config=c_lang_config,
@ -121,4 +123,9 @@ print int(s1[0]) + int(s1[1])"""
print client.judge(src=c_src, language_config=c_lang_config, print client.judge(src=c_src, language_config=c_lang_config,
max_cpu_time=1000, max_memory=1024 * 1024 * 128, max_cpu_time=1000, max_memory=1024 * 1024 * 128,
test_case_id="spj", test_case_id="spj",
spj_version="1", spj_config=c_lang_spj_config), "\n\n" spj_version="3", spj_config=c_lang_spj_config,
spj_compile_config=c_lang_spj_compile, spj_src=c_spj_src), "\n\n"
print client.judge(src=py2_src, language_config=py2_lang_config,
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
test_case_id="normal"), "\n\n"

View File

@ -15,5 +15,5 @@ LOW_PRIVILEDGE_UID = pwd.getpwnam("nobody").pw_uid
LOW_PRIVILEDGE_GID = grp.getgrnam("nogroup").gr_gid LOW_PRIVILEDGE_GID = grp.getgrnam("nogroup").gr_gid
TEST_CASE_DIR = "/test_case" TEST_CASE_DIR = "/test_case"
SPJ_SRC_DIR = "/spj/src" SPJ_SRC_DIR = "/spj"
SPJ_EXE_DIR = "/spj/exe" SPJ_EXE_DIR = "/spj"

View File

@ -1,11 +1,21 @@
judge_server: version: "2"
image: judge_server services:
cpu_quota: 90000 judge_server:
volumes: image: judge_server
- /data/JudgeServer/test/test_case:/test_case cpu_quota: 90000
- /data/log:/log read_only: true
- /data/JudgeServer:/code:ro tmpfs:
environment: - /tmp
- judger_token=PLEASE_REPLACE_TO_SECRET_TOKEN - /judger_run
ports: - /spj
- "0.0.0.0:11235:8080" volumes:
- /data/JudgeServer/tests/test_case:/test_case:ro
- /data/log:/log
- /data/JudgeServer:/code:ro
environment:
- judger_token=token
- service_discovery_url=https://virusdefender.net/service.php
- service_url=http://1.2.3.4:12345
- judger_debug=1
ports:
- "0.0.0.0:12358:8080"