diff --git a/app/helpers/assessment_autograde_core.rb b/app/helpers/assessment_autograde_core.rb index 41c100ac8..b5e1b3d4c 100644 --- a/app/helpers/assessment_autograde_core.rb +++ b/app/helpers/assessment_autograde_core.rb @@ -166,9 +166,13 @@ def tango_add_job(course, assessment, upload_file_list, callback_url, job_name, "timeout" => @autograde_prop.autograde_timeout, "callback_url" => callback_url, "jobName" => job_name, - "disable_network" => assessment.disable_network }.to_json + "disable_network" => assessment.disable_network + } + unless assessment.allowed_outgoing_ips.nil? || assessment.allowed_outgoing_ips.empty? + job_properties["allowed_outgoing_ips"] = assessment.allowed_outgoing_ips.split(/\s*,\s*/) + end begin - response = TangoClient.addjob("#{course.name}-#{assessment.name}", job_properties) + response = TangoClient.addjob("#{course.name}-#{assessment.name}", job_properties.to_json) rescue TangoClient::TangoException => e COURSE_LOGGER.log("Error while adding job to the queue: #{e.message}") raise AutogradeError.new("Error while adding job to the queue", :tango_add_job, e.message) diff --git a/app/views/assessments/_edit_advanced.html.erb b/app/views/assessments/_edit_advanced.html.erb index 5c8afc026..5195e4ac8 100644 --- a/app/views/assessments/_edit_advanced.html.erb +++ b/app/views/assessments/_edit_advanced.html.erb @@ -23,6 +23,8 @@ <% end %> <%= f.check_box :disable_network, help_text: "Disable network access for autograding containers." %> +<%= f.text_field :allowed_outgoing_ips, + help_text: "Specify allowed outgoing IPs for autograding containers (comma separated). If left empty, all outgoing connections are allowed." %> <%= f.check_box :allow_unofficial, help_text: "Allow unofficial submission. Unless you know what you're doing, leave this unchecked." %> <%= f.check_box :embedded_quiz, diff --git a/db/migrate/20240401200408_add_allowed_outgoing_ips_to_assessment.rb b/db/migrate/20240401200408_add_allowed_outgoing_ips_to_assessment.rb new file mode 100644 index 000000000..6cac7abfe --- /dev/null +++ b/db/migrate/20240401200408_add_allowed_outgoing_ips_to_assessment.rb @@ -0,0 +1,5 @@ +class AddAllowedOutgoingIPsToAssessment < ActiveRecord::Migration[6.1] + def change + add_column :assessments, :allowed_outgoing_ips, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 67e37a270..68326ea0a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_03_16_162826) do +ActiveRecord::Schema.define(version: 2024_04_01_200408) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -119,6 +119,7 @@ t.boolean "allow_student_assign_group", default: true t.boolean "is_positive_grading", default: false t.boolean "disable_network", default: false + t.string "allowed_outgoing_ips" end create_table "attachments", force: :cascade do |t|