Skip to content
Open
Show file tree
Hide file tree
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
41 changes: 41 additions & 0 deletions app/assets/javascripts/autograder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
;(function() {
$(document).ready(function () {
function access_key_callback() {
const checked = $(this).prop('checked');
const $access_key_field = $('#autograder_access_key');
const $access_key_id_field = $('#autograder_access_key_id');
$access_key_field.prop('disabled', !checked);
$access_key_id_field.prop('disabled', !checked);
if (!checked) {
$access_key_field.val('', checked);
$access_key_id_field.val('', checked);
}
}

$('#autograder_use_access_key').on('change', access_key_callback);
access_key_callback.call($('#autograder_use_access_key'));

function initializeEC2Dropdown() {
if ($.fn.tooltip) {
$('.browser-default[data-tooltip]').tooltip({
enterDelay: 300,
exitDelay: 200,
position: 'top'
});
}

$('#autograder_instance_type option').hover(
function() { $(this).addClass('highlighted-option'); },
function() { $(this).removeClass('highlighted-option'); }
);

$('#autograder_instance_type').on('change.ec2-instance', function() {
const selectedInstance = $(this).val();
console.log('Selected EC2 instance type:', selectedInstance);
});
}

// Initialize the EC2 dropdown functionality
initializeEC2Dropdown();
});
})();
6 changes: 5 additions & 1 deletion app/controllers/autograders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def create
a.autograde_timeout = 180
a.autograde_image = "autograding_image"
a.release_score = true
a.access_key_id = ""
a.access_key = ""
a.instance_type = "t2.micro"
end
if @autograder.save
flash[:success] = "Autograder created."
Expand Down Expand Up @@ -112,7 +115,8 @@ def set_autograder
end

def autograder_params
params[:autograder].permit(:autograde_timeout, :autograde_image, :release_score)
params[:autograder].permit(:autograde_timeout, :autograde_image, :release_score, :access_key,
:access_key_id, :instance_type)
Comment on lines +118 to +119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Ensure proper validation for EC2 parameters

The controller now correctly permits the new EC2 parameters. However, consider adding validation for the instance type and secure handling of AWS credentials.


🏁 Script executed:

#!/bin/bash
# Check if there's validation for instance type and access keys in the autograder model

# Look for validation in the autograder model
echo "Checking for validations in the Autograder model:"
rg -A 5 "validates.*instance_type" app/models/
rg -A 5 "validates.*access_key" app/models/

# Check if there's any encryption for the AWS credentials
echo "Checking for potential credential encryption:"
rg -A 5 "encrypt.*access_key" app/models/

Length of output: 348


Action Required: Enforce Validations on EC2 Parameters & Secure AWS Credentials

The controller now permits the new EC2 parameters, but our search in the Autograder model did not reveal any validations for instance_type or any encryption for AWS credentials. Please ensure that:

  • The model includes proper validations for instance_type (e.g., checking that it matches a set of allowed values).
  • AWS credentials such as access_key (and potentially access_key_id) are processed securely (e.g., through encryption or another secure handling mechanism).

end

def assessment_params
Expand Down
16 changes: 15 additions & 1 deletion app/helpers/assessment_autograde_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,21 @@ 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}
if Rails.configuration.x.ec2_ssh.present?
job_properties["ec2Vmms"] = true
if @autograde_prop.use_access_key?
job_properties["accessKey"] = @autograde_prop.access_key
job_properties["accessKeyId"] = @autograde_prop.access_key_id
else
job_properties["accessKey"] = ""
job_properties["accessKeyId"] = ""
end
job_properties["instanceType"] = @autograde_prop.instance_type
end

job_properties = job_properties.to_json

begin
response = TangoClient.addjob("#{course.name}-#{assessment.name}", job_properties)
rescue TangoClient::TangoException => e
Expand Down
36 changes: 36 additions & 0 deletions app/views/autograders/_basic_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<%= f.text_field :autograde_image, display_name: "VM Image",
help_text: "VM image for autograding (e.g. <kbd>rhel.img</kbd>). #{link_to 'Click here', tango_status_course_jobs_path} to view the list of VM images and pools currently being used".html_safe +
(Rails.configuration.x.docker_image_upload_enabled.presence ? ", or #{link_to 'click here', course_dockers_path} to upload a new docker image.".html_safe : "."),
required: true, maxlength: 64 %>

<%= f.number_field :autograde_timeout, display_name: "Timeout",
help_text: "Timeout for autograding jobs (secs). Must be between 10s and 900s, inclusive.", min: 10, max: 900 %>
<%= f.check_box :release_score,
display_name: "Release Scores?",
help_text: "Check to release autograded scores to students immediately after autograding (strongly recommended)." %>

<% help_tar_text = "Tar file exists, upload a file to override." %>
<% help_makefile_text = "Makefile exists, upload a file to override." %>
<%= f.file_field :makefile, label_text: "Autograder Makefile", action: :upload, file_exists_text: help_makefile_text, class: "form-file-field", file_exists: @makefile_exists %>
<%= f.file_field :tar, label_text: "Autograder Tar", action: :upload, file_exists_text: help_tar_text, class: "form-file-field", file_exists: @tar_exists %>
<p class="help-block">
Both of the above files will be renamed upon upload.
</p>

<%= f.fields_for :assessment, @assessment do |af| %>
<%= af.check_box :disable_network, help_text: "Disable network access for autograding containers." %>
<% end %>

<%= f.submit "Save Settings" %>

<%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment),
method: :delete, class: "btn danger",
data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>

<% unless @makefile_exists.nil? %>
<%= link_to "Download Makefile", download_file_course_assessment_autograder_path(file_path: @makefile_exists, file_key: 'makefile'), class: "btn" %>
<% end %>

<% unless @tar_exists.nil? %>
<%= link_to "Download Tar", download_file_course_assessment_autograder_path(file_path: @tar_exists, file_key: 'tar'), class: "btn" %>
<% end %>
84 changes: 84 additions & 0 deletions app/views/autograders/_ec2_settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<% content_for :javascripts do %>
<%= javascript_include_tag "autograder" %>
<% end %>

<h4>EC2 Settings</h4>
<%= f.check_box :use_access_key,
display_name: "Enable Access Key",
help_text: "(Optional) Use your own provided access key to authenticate to different EC2 instances than the default one on Tango" %>
<%= f.text_field :access_key, display_name: "Access Key" %>
<%= f.text_field :access_key_id, display_name: "Access Key ID" %>

<%
# Group EC2 instance options by category for better organization
ec2_instance_options = [
# General Purpose - T2 (burstable)
['T2 - General Purpose (Burstable)', [
['t2.nano - 1 vCPU, 0.5 GiB RAM (minimal, lowest cost)', 't2.nano'],
['t2.micro - 1 vCPU, 1 GiB RAM (lowest cost, suitable for small jobs)', 't2.micro'],
['t2.small - 1 vCPU, 2 GiB RAM (low cost, better for memory-intensive tasks)', 't2.small'],
['t2.medium - 2 vCPU, 4 GiB RAM (balanced, good for most autograding tasks)', 't2.medium'],
['t2.large - 2 vCPU, 8 GiB RAM (better for memory-heavy workloads)', 't2.large'],
['t2.xlarge - 4 vCPU, 16 GiB RAM (good for parallel processing)', 't2.xlarge'],
['t2.2xlarge - 8 vCPU, 32 GiB RAM (high performance, burstable)', 't2.2xlarge']
]],
# General Purpose - T3 (newer generation)
['T3 - General Purpose (Newer Generation)', [
['t3.micro - 2 vCPU, 1 GiB RAM (better performance than t2.micro)', 't3.micro'],
['t3.small - 2 vCPU, 2 GiB RAM (improved over t2.small)', 't3.small'],
['t3.medium - 2 vCPU, 4 GiB RAM (better CPU performance than t2)', 't3.medium'],
['t3.large - 2 vCPU, 8 GiB RAM (improved networking)', 't3.large']
]],
# Compute Optimized
['C - Compute Optimized', [
['c5.large - 2 vCPU, 4 GiB RAM (compute-optimized, faster CPU)', 'c5.large'],
['c5.xlarge - 4 vCPU, 8 GiB RAM (high compute performance)', 'c5.xlarge'],
['c5.2xlarge - 8 vCPU, 16 GiB RAM (very high compute performance)', 'c5.2xlarge']
]],
# Memory Optimized
['R - Memory Optimized', [
['r5.large - 2 vCPU, 16 GiB RAM (memory-optimized, for large datasets)', 'r5.large'],
['r5.xlarge - 4 vCPU, 32 GiB RAM (high memory capacity)', 'r5.xlarge'],
['r5.2xlarge - 8 vCPU, 64 GiB RAM (very high memory capacity)', 'r5.2xlarge']
]]
]
%>

<div style="margin-bottom: 5px;"><strong>EC2 Instance Type</strong></div>

<%= f.select :instance_type,
grouped_options_for_select(ec2_instance_options, @autograder.instance_type),
{ include_blank: false, label: "EC2 Instance Type" },
{ class: 'browser-default',
data: { tooltip: "Select an EC2 instance type based on your autograding needs. Larger instances cost more but run faster." },
display_name: "EC2 Instance Type" } %>
<div class="help-text">
Choose an instance type based on your autograding requirements:
<ul class="browser-default" style="margin-top: 5px; margin-left: 15px;">
<li><strong>T2 instances</strong>: Burstable performance instances, good for varying workloads
<ul>
<li><strong>t2.micro</strong>: Default, lowest cost, suitable for simple autograding</li>
<li><strong>t2.medium/large</strong>: Better for more complex tests with moderate requirements</li>
</ul>
</li>
<li><strong>T3 instances</strong>: Newer generation with better baseline performance than T2</li>
<li><strong>C5 (Compute-optimized)</strong>: Best for CPU-bound tasks like compilation, testing algorithms</li>
<li><strong>R5 (Memory-optimized)</strong>: Best for memory-intensive operations with large datasets</li>
</ul>
<div class="recommendation-box" style="background-color: #f5f5f5; padding: 10px; border-left: 4px solid #2196F3; margin-top: 10px;">
<strong>Recommendations:</strong>
<ul class="browser-default" style="margin-top: 5px; margin-left: 15px;">
<li>Start with <strong>t2.micro</strong> for basic assignments with minimal resource requirements</li>
<li>Use <strong>t2.medium</strong> or <strong>t3.medium</strong> for most standard programming assignments</li>
<li>Choose <strong>c5.xlarge</strong> for computationally intensive tasks (e.g., compiler projects)</li>
<li>Select <strong>r5.large</strong> for memory-intensive workloads (e.g., large datasets, ML)</li>
</ul>
</div>
<small>Note: Larger instances incur higher AWS costs. <a href='https://aws.amazon.com/ec2/pricing/on-demand/' target='_blank'>View EC2 pricing</a></small>
</div>

<%= f.submit "Save Settings" %>

<%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment),
method: :delete, class: "btn danger",
data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>
72 changes: 33 additions & 39 deletions app/views/autograders/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
<%= form_for @autograder, url: course_assessment_autograder_path(@course, @assessment, @autograder),
builder: FormBuilderWithDateTimeInput,
html: { multipart: true } do |f| %>
<%= f.text_field :autograde_image, display_name: "VM Image",
help_text: "VM image for autograding (e.g. <kbd>rhel.img</kbd>). #{link_to 'Click here', tango_status_course_jobs_path} to view the list of VM images and pools currently being used".html_safe +
(Rails.configuration.x.docker_image_upload_enabled.presence ? ", or #{link_to 'click here', course_dockers_path} to upload a new docker image.".html_safe : "."),
required: true, maxlength: 64 %>
<div class="row">
<div class="col s12">
<ul id="tabs" class="tabs tabs-fixed-width">
<% list = ["basic"] %>
<% if Rails.configuration.x.ec2_ssh.presence %>
<% list.append("ec2") %>
<% end %>
<% list.each do |tab_name| %>
<%= if tab_name == params[:active_tab]
tag.li(link_to(tab_name.titleize, "#tab_#{tab_name}"), class: "active tab")
else
tag.li(link_to(tab_name.titleize, "#tab_#{tab_name}"), class: :tab)
end %>
<% end %>
</ul>
</div>
</div>

<%= f.number_field :autograde_timeout, display_name: "Timeout",
help_text: "Timeout for autograding jobs (secs). Must be between 10s and 900s, inclusive.", min: 10, max: 900 %>
<%= f.check_box :release_score,
display_name: "Release Scores?",
help_text: "Check to release autograded scores to students immediately after autograding (strongly recommended)." %>

<% help_tar_text = "Tar file exists, upload a file to override." %>
<% help_makefile_text = "Makefile exists, upload a file to override." %>
<%= f.file_field :makefile, label_text: "Autograder Makefile", action: :upload, file_exists_text: help_makefile_text, class: "form-file-field", file_exists: @makefile_exists %>
<%= f.file_field :tar, label_text: "Autograder Tar", action: :upload, file_exists_text: help_tar_text, class: "form-file-field", file_exists: @tar_exists %>
<p class="help-block">
Both of the above files will be renamed upon upload.
</p>

<%= f.fields_for :assessment, @assessment do |af| %>
<%= af.check_box :disable_network, help_text: "Disable network access for autograding containers." %>
<% end %>

<%= f.submit "Save Settings" %>

<%= link_to "Delete Autograder", course_assessment_autograder_path(@course, @assessment),
method: :delete, class: "btn danger",
data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>

<% unless @makefile_exists.nil? %>
<%= link_to "Download Makefile", download_file_course_assessment_autograder_path(file_path: @makefile_exists, file_key: 'makefile'), class: "btn" %>
<% end %>

<% unless @tar_exists.nil? %>
<%= link_to "Download Tar", download_file_course_assessment_autograder_path(file_path: @tar_exists, file_key: 'tar'), class: "btn" %>
<% end %>
<% end %>
<div class="row">
<div class="col s12">
<%= form_for @autograder, url: course_assessment_autograder_path(@course, @assessment, @autograder),
builder: FormBuilderWithDateTimeInput,
html: { multipart: true } do |f| %>
<div id="tab_basic">
<%= render "basic_settings", f: %>
</div>
<% if Rails.configuration.x.ec2_ssh.presence %>
<div id="tab_ec2">
<%= render "ec2_settings", f: %>
</div>
<% end %>
<% end %>
</div>
</div>
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
# Feature flag for docker image upload
config.x.docker_image_upload_enabled = true

# Feature flag for EC2 autograder
config.x.ec2_ssh = true

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

Expand Down
3 changes: 3 additions & 0 deletions config/environments/production.rb.template
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Autolab3::Application.configure do
# Feature flag for docker image upload
config.x.docker_image_upload_enabled = false

# Feature flag for EC2 autograder
config.x.ec2_ssh = false

# ID for Heap Analytics
config.x.analytics_id = nil

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddEc2SshFieldsToAutograders < ActiveRecord::Migration[6.1]
def change
add_column :autograders, :instance_type, :string, default: ""
add_column :autograders, :access_key, :string, default: ""
add_column :autograders, :access_key_id, :string, default: ""
end
end
5 changes: 5 additions & 0 deletions db/migrate/20241211042124_add_use_access_key_to_autograder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUseAccessKeyToAutograder < ActiveRecord::Migration[6.1]
def change
add_column :autograders, :use_access_key, :boolean, default: false
end
end
Loading