trampgeek / jobeinabox

The dockerfile and doc for building the Docker image JobeInABox
MIT License
12 stars 29 forks source link

Submission problem in container environment #12

Closed vanniand closed 2 years ago

vanniand commented 2 years ago

Hi, I installed a containerized version of moodle provided by bitnami (moodle 4.0.3 + mysql containers). I added to this environment jobeinabox container. I get a problem when try to check my code by coderunner plugin. Here some details: the file /bitnami/moodle/question/type/coderunner/classes/jobesandbox.php run on moodle container shows this message: http://172.19.0.1:4000/jobe/index.php/restapi/runs/ headers: array ( 0 => 'User-Agent: CodeRunner', 1 => 'Content-Type: application/json; charset=utf-8', 2 => 'Accept-Charset: utf-8', 3 => 'Accept: application/json', 4 => 'X-CodeRunner-Job-Id: 1b20e7eb', ) resource: 'runs' body: '{"run_spec":{"language_id":"python3","sourcecode":"def sqr(n):\r\n return n\n\n__student_answer = \"\"\"def sqr(n):\r\n return n\"\"\"\n\nSEPARATOR = \"#ab@17943918#@#\"\n\nprint(sqr(-5))\nprint(SEPARATOR)\nprint(sqr(-7))\n","sourcefilename":"tester__.python3","input":"\n","file_list":[],"parameters":[]}}' URL http://172.19.0.1:4000/jobe/index.php/restapi/runs/ response: 'The URL is blocked.'

As you can see the response is 'The URL is blocked. But if I run the testsubmit.py script on the same moodle container: all seems OK

root@4fc0375b2cd4:/# python3 testsubmit.py Supported languages: /jobe/index.php/restapi/languages {'Content-type': 'application/json; charset=utf-8', 'Accept': 'application/json', 'X-API-KEY': '2AAA7A5415B4A9B394B54BF1D2E9D'} None c: 9.4.0 cpp: 9.4.0 java: 16.0.1 nodejs: 10.19.0 octave: 5.2.0 pascal: 3.0.4 php: 7.4.3 python3: 3.8.10

/jobe/index.php/restapi/runs/ {'Content-type': 'application/json; charset=utf-8', 'Accept': 'application/json', 'X-API-KEY': '2AAA7A5415B4A9B394B54BF1D2E9D'} {"run_spec": {"language_id": "python3", "sourcecode": "print(\"Hello world!\")\n", "sourcefilename": "test.py"}} Valid Python3 OK /jobe/index.php/restapi/runs/ {'Content-type': 'application/json; charset=utf-8', 'Accept': 'application/json', 'X-API-KEY': '2AAA7A5415B4A9B394B54BF1D2E9D'} {"run_spec": {"language_id": "python3", "sourcecode": "print(input())\nprint(input())\n", "input": "Line1\nLine2\n", "sourcefilename": "test.py"}} Python3 with stdin OK

here the conf of my docker environment: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ede7964e517a localhost/jobe "/usr/sbin/apache2ct…" 22 hours ago Up 57 minutes (healthy) 0.0.0.0:4000->80/tcp, :::4000->80/tcp jobe 4fc0375b2cd4 moodle_moodle "/opt/bitnami/script…" 25 hours ago Up 57 minutes 0.0.0.0:80->8080/tcp, :::80->8080/tcp, 0.0.0.0:443->8443/tcp, :::443->8443/tcp moodle 73e3ee3b6057 bitnami/mariadb:10.6 "/opt/bitnami/script…" 25 hours ago Up 57 minutes 3306/tcp mysql

many thxs

Andrea

trampgeek commented 2 years ago

I haven't seen this message but it looks like it might be like the problem described here: https://moodle.org/mod/forum/discuss.php?d=436087

Try temporarily deleting all entries in Site administration > General > HTTP Security > Curl Blocked Hosts List ?

vanniand commented 2 years ago

Thnx for the answer. I tried to remove all hosts in curl hostlist but it did non work. Maybe the funcion protected function check_securityhelper_blocklist(string $url): ?string { in /moodle/lib/filelib.php blocks url due to a other plugin settings and not only for global settings

I modified the function in question/type/coderunner/classes/jobesandbox.php as follows. So it works private function http_request($resource, $method, $body=null) { list($url, $headers) = $this->get_jobe_connection_info($resource);

$settings['ignoresecurity']=true;
    $curl = new curl($settings);
trampgeek commented 2 years ago

Thanks for the information. Good to know you've found a solution. It's not one I'd want to lock into the code as it might open other security holes, but the information might be of interest to others trying to run a system with a configuration like yours. Thanks for posting.