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

Add EC2 autograder features #2281

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Add EC2 autograder features #2281

wants to merge 14 commits into from

Conversation

evanyeyeye
Copy link
Member

@evanyeyeye evanyeyeye commented Mar 17, 2025

Description

This PR enables the use and configuration of EC2 autograding instances via Autolab.

Documentation will be added in a future PR.

How Has This Been Tested?

  • Verified that requests to Tango properly utilize the EC2 vmms.
  • Verified that configured defaults work correctly.
  • Verified that custom access credentials can be passed to Tango on a per job basis.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have run rubocop and erblint for style check. If you haven't, run overcommit --install && overcommit --sign to use pre-commit hook for linting
  • My change requires a change to the documentation, which is located at Autolab Docs
  • I have updated the documentation accordingly, included in this PR

Copy link
Contributor

coderabbitai bot commented Mar 17, 2025

📝 Walkthrough

Walkthrough

This pull request introduces features to support EC2 SSH configuration for autograders. A new JavaScript file manages access key inputs dynamically, while the autograders controller now accepts additional parameters. The job submission helper method is enhanced with conditional logic for EC2-specific properties. Several new view partials restructure autograder settings into a tabbed interface, and configuration files are updated with a new feature flag. Migrations and schema updates add necessary database fields and adjust various column types and indices.

Changes

File(s) Change Summary
app/assets/javascripts/autograder.js New JS file with a self-invoking function that toggles the enabled state and value of access key input fields based on the checkbox state.
app/controllers/autograders_controller.rb Updated the create method and permitted parameters to include access_key, access_key_id, and instance_type.
app/helpers/assessment_autograde_core.rb Modified tango_add_job method to conditionally add EC2 job properties (e.g., ec2Vmms, accessKey, accessKeyId, instanceType) based on configuration and autograde properties.
app/views/autograders/_basic_settings.html.erb,
app/views/autograders/_ec2_settings.html.erb,
app/views/autograders/_form.html.erb
New and restructured view templates: added basic and EC2 settings partials and refactored the form into a tabbed interface for autograder configuration.
config/environments/development.rb,
config/environments/production.rb.template
Added feature flag config.x.ec2_ssh (set to true in development and false in production).
db/migrate/20241205233214_add_ec2_ssh_fields_to_autograders.rb,
db/migrate/20241211042124_add_use_access_key_to_autograder.rb,
db/schema.rb
New migrations add columns (instance_type, access_key, access_key_id, use_access_key) to the autograders table; schema updates include data type modifications, new indices, and additional foreign keys.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant D as Document (DOM)
  participant JS as AutoGrader.js
  participant CB as Checkbox (#autograder_use_access_key)
  participant IF as Input Fields (#autograder_access_key & #autograder_access_key_id)

  U->>D: Load page
  D->>JS: Document ready event
  JS->>CB: Read checkbox state
  JS->>IF: Toggle enabled state (clear values if unchecked)
  U->>CB: Change checkbox state
  CB-->>JS: Emit change event
  JS->>IF: Update input fields accordingly
Loading
sequenceDiagram
  participant A as AssessmentAutogradeCore
  participant C as Configuration (Rails.config.x.ec2_ssh)
  participant P as AutogradeProp
  participant T as TangoClient

  A->>C: Check if ec2_ssh is enabled
  alt EC2 enabled
      A->>P: Evaluate use_access_key?
      alt use_access_key true
          A->>A: Set accessKey and accessKeyId from properties
      else use_access_key false
          A->>A: Set accessKey and accessKeyId to empty strings
      end
      A->>A: Set ec2Vmms to true and assign instanceType from property
  end
  A->>T: Convert job_properties to JSON and submit job
Loading

Possibly related PRs

  • Autograder improvements #2209: The changes in the main PR, specifically the introduction of JavaScript functions for managing access key fields and EC2 instance types, are related to the modifications in the retrieved PR that enhance the autograder UI, including file upload indicators and settings for network access, as they both aim to improve the functionality and user experience of the autograder system.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (3)
db/migrate/20241205233214_add_ec2_ssh_fields_to_autograders.rb (1)

1-7:

❓ Verification inconclusive

Consider encryption for sensitive AWS credentials.

The migration adds string columns for AWS credentials (access_key and access_key_id). Consider using encryption or a secure credentials management strategy to avoid storing sensitive AWS credentials in plaintext.

Consider using Rails' built-in encryption capabilities or a gem like attr_encrypted:

-    add_column :autograders, :access_key, :string, default: ""
-    add_column :autograders, :access_key_id, :string, default: ""
+    add_column :autograders, :encrypted_access_key, :string, default: ""
+    add_column :autograders, :encrypted_access_key_iv, :string, default: ""
+    add_column :autograders, :encrypted_access_key_id, :string, default: ""
+    add_column :autograders, :encrypted_access_key_id_iv, :string, default: ""

With model changes:

class Autograder < ApplicationRecord
  attr_encrypted :access_key, key: Rails.application.credentials.secret_key_base[0..31]
  attr_encrypted :access_key_id, key: Rails.application.credentials.secret_key_base[0..31]
end

Let's check if similar sensitive data is encrypted elsewhere in the codebase:


🏁 Script executed:

#!/bin/bash
# Search for encryption patterns in models
echo "Searching for encryption patterns in models..."
rg -l "attr_encrypted" --type ruby app/models/
rg -l "encrypted_" --type ruby app/models/

Length of output: 192


Encryption for AWS Credentials: Manual Verification Required

After searching for encryption usage in the models (using patterns like "attr_encrypted" and "encrypted_"), no evidence was found that AWS credentials are currently secured. This suggests the migration is adding plaintext credentials. It’s recommended to update the migration and the related model as follows:

  • Migration Update: Replace the plaintext columns with encrypted counterparts:

    -    add_column :autograders, :access_key, :string, default: ""
    -    add_column :autograders, :access_key_id, :string, default: ""
    +    add_column :autograders, :encrypted_access_key, :string, default: ""
    +    add_column :autograders, :encrypted_access_key_iv, :string, default: ""
    +    add_column :autograders, :encrypted_access_key_id, :string, default: ""
    +    add_column :autograders, :encrypted_access_key_id_iv, :string, default: ""
  • Model Update: Incorporate encryption using Rails’ built-in capabilities or a gem like attr_encrypted:

    class Autograder < ApplicationRecord
      attr_encrypted :access_key, key: Rails.application.credentials.secret_key_base[0..31]
      attr_encrypted :access_key_id, key: Rails.application.credentials.secret_key_base[0..31]
    end

Please manually verify that no other parts of the codebase secure similar sensitive data before proceeding.

app/views/autograders/_ec2_settings.html.erb (1)

15-17: Fix typo in confirmation message

There's a typo in the delete confirmation message.

 <%= 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?" } %>
+            data: { confirm: "Are you sure you want to delete the Autograder for this assessment?" } %>
app/views/autograders/_basic_settings.html.erb (1)

26-28: Confirm deletion text contains a typo.

There's a typo in the delete confirmation message.

- data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>
+ data: { confirm: "Are you sure you want to delete the Autograder for this assessment?" } %>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7992e9a and 259f0f2.

📒 Files selected for processing (11)
  • app/assets/javascripts/autograder.js (1 hunks)
  • app/controllers/autograders_controller.rb (2 hunks)
  • app/helpers/assessment_autograde_core.rb (1 hunks)
  • app/views/autograders/_basic_settings.html.erb (1 hunks)
  • app/views/autograders/_ec2_settings.html.erb (1 hunks)
  • app/views/autograders/_form.html.erb (1 hunks)
  • config/environments/development.rb (1 hunks)
  • config/environments/production.rb.template (1 hunks)
  • db/migrate/20241205233214_add_ec2_ssh_fields_to_autograders.rb (1 hunks)
  • db/migrate/20241211042124_add_use_access_key_to_autograder.rb (1 hunks)
  • db/schema.rb (10 hunks)
🧰 Additional context used
🪛 RuboCop (1.73)
db/schema.rb

[convention] 14-15: Extra empty line detected at block body beginning.

(Layout/EmptyLinesAroundBlockBody)

🪛 GitHub Actions: Ruby on Rails CI
db/schema.rb

[error] 443-443: ActiveRecord::MismatchedForeignKey: Column blob_id on table active_storage_attachments does not match column id on active_storage_blobs, which has type bigint. To resolve this issue, change the type of the blob_id column on active_storage_attachments to be :bigint.

🔇 Additional comments (16)
db/migrate/20241211042124_add_use_access_key_to_autograder.rb (1)

1-5: LGTM! Migration is well structured.

The migration adds a boolean column with an appropriate default value of false, which is good for backward compatibility.

config/environments/development.rb (1)

77-78: Feature flag looks good.

The EC2 autograder feature flag follows the established pattern in the file and is well positioned with other feature flags.

app/assets/javascripts/autograder.js (1)

15-17: Good practice with immediate initialization.

Good approach to call the callback immediately after binding to ensure the initial state of the fields is correct based on the checkbox.

config/environments/production.rb.template (1)

91-93: Feature flag addition looks good

The new feature flag config.x.ec2_ssh is added for controlling the EC2 autograder functionality. The flag follows the existing pattern of feature flags in the codebase and is set to false by default, which is appropriate for a template file.

app/views/autograders/_ec2_settings.html.erb (1)

1-3: JavaScript inclusion looks good

The JavaScript inclusion for the autograder functionality is appropriately placed in the content_for block for javascripts.

app/controllers/autograders_controller.rb (1)

19-21: Initialize EC2-specific properties correctly

Good addition of EC2-specific properties with sensible defaults. The "t2.micro" choice for the default instance type is appropriate as it's in the AWS free tier.

app/views/autograders/_form.html.erb (2)

1-17: Tabbed interface implementation looks good

The implementation of a tabbed interface for the autograder settings is a nice UI improvement. The conditional rendering of the EC2 tab based on the feature flag is properly implemented.


19-34: Form structure and partial rendering is well organized

The form structure with partials for different setting categories is well organized and follows good separation of concerns principles.

app/views/autograders/_basic_settings.html.erb (3)

1-4: Good VM image input implementation with helpful context links.

The text field for VM image includes contextual help with links to view existing VM images and optionally upload Docker images. This improves user experience by providing direct access to related functionality.


6-10: Well-constrained timeout input with appropriate help text.

The number field for timeout has appropriate min/max constraints (10-900 seconds) with clear help text explaining the limits. The release scores checkbox includes a helpful recommendation.


12-18: Clear file upload interface with existing file indication.

The file upload implementation correctly indicates when files already exist and will be overridden. The help block about file renaming helps set appropriate user expectations.

app/helpers/assessment_autograde_core.rb (2)

182-182: Job properties serialization moved after EC2 properties are added.

The job_properties are correctly converted to JSON after all properties have been added, including the EC2-specific ones.


169-181:

✅ Verification successful

Well-implemented conditional logic for EC2 configuration.

The implementation correctly checks for the presence of the EC2 SSH configuration flag before adding EC2-specific properties to the job. The conditional handling of access credentials based on the use_access_key? method is a good practice, providing empty strings as fallbacks when custom credentials aren't used.


🏁 Script executed:

#!/bin/bash
# Description: Verify that the EC2 configuration is correctly set in the application configuration

# Check if EC2 SSH configuration is present in the application's configuration files
echo "Checking for EC2 SSH configuration..."
grep -r "config.x.ec2_ssh" --include="*.rb" config/

# Check for any related EC2 configuration in the application
echo "Checking for any other EC2-related configurations..."
grep -r "ec2" --include="*.rb" --include="*.yml" config/

Length of output: 611


EC2 Configuration Condition Verified

The conditional logic in app/helpers/assessment_autograde_core.rb is correctly implemented. Verification of the configuration (with config.x.ec2_ssh set in config/environments/development.rb) confirms that EC2-specific properties are only added when expected. The handling of access keys—using values from @autograde_prop when available and falling back to empty strings otherwise—is appropriate.

db/schema.rb (3)

152-155: New autograders table fields for EC2 support.

The schema includes new fields in the autograders table to support EC2 configuration:

  • instance_type: For specifying the EC2 instance type
  • access_key and access_key_id: For AWS authentication
  • use_access_key: Boolean flag to determine whether custom keys should be used

These fields align well with the EC2 feature implementation in the controller code.


13-13: Schema version updated.

The schema version has been updated to reflect the new migrations that add EC2 support.


445-448: New foreign key constraints added.

The schema adds foreign key constraints for GitHub integrations and OAuth-related tables, improving database integrity.

Comment on lines 1 to 18
;(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'));
});
})();
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix val() method usage and consider additional validation.

The JavaScript function properly manages the state of the input fields based on the checkbox, but there's an issue with the val() method usage.

  1. The val() method doesn't take a second argument. Fix lines 10-11:
-                $access_key_field.val('', checked);
-                $access_key_id_field.val('', checked);
+                $access_key_field.val('');
+                $access_key_id_field.val('');
  1. Consider adding validation for the AWS credentials format when enabled to provide immediate feedback to users.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
;(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() {
$(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('');
$access_key_id_field.val('');
}
}
$('#autograder_use_access_key').on('change', access_key_callback);
access_key_callback.call($('#autograder_use_access_key'));
});
})();

Comment on lines +118 to +119
params[:autograder].permit(:autograde_timeout, :autograde_image, :release_score, :access_key,
:access_key_id, :instance_type)
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).

@KesterTan KesterTan self-requested a review March 17, 2025 20:48
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
db/schema.rb (1)

13-451: 🛠️ Refactor suggestion

Consider encrypting sensitive AWS credentials

While the schema changes look good, AWS access keys are sensitive credentials that should be encrypted when stored in the database. Consider using Rails' built-in encryption capabilities or a gem like attr_encrypted to protect these values.

You could implement encryption for these fields by:

  1. Adding encrypted_attribute columns instead of plaintext
  2. Using Rails' Active Record Encryption (for Rails 7+) or a gem like attr_encrypted
  3. Ensuring the keys are properly rotated and secured

This would significantly improve the security posture of your application when handling AWS credentials.

🧰 Tools
🪛 RuboCop (1.73)

[convention] 14-15: Extra empty line detected at block body beginning.

(Layout/EmptyLinesAroundBlockBody)

♻️ Duplicate comments (1)
app/assets/javascripts/autograder.js (1)

10-11: ⚠️ Potential issue

Fix val() method usage

The jQuery val() method doesn't accept a second argument. It should be called without the second parameter.

- $access_key_field.val('', checked);
- $access_key_id_field.val('', checked);
+ $access_key_field.val('');
+ $access_key_id_field.val('');
🧹 Nitpick comments (6)
app/views/autograders/_ec2_settings.html.erb (4)

25-25: Remove trailing whitespace

There is trailing whitespace at the end of this line.

-    
+
🧰 Tools
🪛 GitHub Actions: Ruby on Rails CI

[warning] 25-25: Extra whitespace detected at end of line.


33-33: Remove trailing whitespace

There is trailing whitespace at the end of this line.

-    
+
🧰 Tools
🪛 GitHub Actions: Ruby on Rails CI

[warning] 33-33: Extra whitespace detected at end of line.


40-40: Remove trailing whitespace

There is trailing whitespace at the end of this line.

-    
+
🧰 Tools
🪛 GitHub Actions: Ruby on Rails CI

[warning] 40-40: Extra whitespace detected at end of line.


1-87: Add trailing newline at the end of the file

Files should end with a newline character.

            method: :delete, class: "btn danger",
            data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>
+
🧰 Tools
🪛 GitHub Actions: Ruby on Rails CI

[warning] 25-25: Extra whitespace detected at end of line.


[warning] 33-33: Extra whitespace detected at end of line.


[warning] 40-40: Extra whitespace detected at end of line.


[warning] 87-87: Missing a trailing newline at the end of the file.

app/assets/javascripts/autograder.js (1)

32-35: Remove console.log in production code

Console logs should be removed from production code. They may expose sensitive information and have no value in a production environment.

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

14-15: Remove extra empty line

There's an extra empty line at the beginning of the block body that should be removed according to RuboCop.

 ActiveRecord::Schema.define(version: 2024_12_11_042124) do

-
   create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
🧰 Tools
🪛 RuboCop (1.73)

[convention] 14-15: Extra empty line detected at block body beginning.

(Layout/EmptyLinesAroundBlockBody)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 259f0f2 and b240eaf.

📒 Files selected for processing (3)
  • app/assets/javascripts/autograder.js (1 hunks)
  • app/views/autograders/_ec2_settings.html.erb (1 hunks)
  • db/schema.rb (23 hunks)
🧰 Additional context used
🪛 GitHub Actions: Ruby on Rails CI
app/views/autograders/_ec2_settings.html.erb

[warning] 25-25: Extra whitespace detected at end of line.


[warning] 33-33: Extra whitespace detected at end of line.


[warning] 40-40: Extra whitespace detected at end of line.


[warning] 87-87: Missing a trailing newline at the end of the file.

🪛 RuboCop (1.73)
db/schema.rb

[convention] 14-15: Extra empty line detected at block body beginning.

(Layout/EmptyLinesAroundBlockBody)

🔇 Additional comments (5)
app/views/autograders/_ec2_settings.html.erb (2)

9-10: Sensitive credentials should use password fields

The AWS access key fields contain sensitive credentials that should be masked when displayed.

-<%= f.text_field :access_key, display_name: "Access Key" %>
-<%= f.text_field :access_key_id, display_name: "Access Key ID" %>
+<%= f.password_field :access_key, display_name: "Access Key" %>
+<%= f.password_field :access_key_id, display_name: "Access Key ID" %>

12-81: Well-structured and informative EC2 instance selection

The EC2 instance options are well-organized by category with detailed descriptions, making it easy for users to understand the tradeoffs between different instance types. The recommendation box is particularly helpful for guiding users to choose appropriate instances for their specific use cases.

🧰 Tools
🪛 GitHub Actions: Ruby on Rails CI

[warning] 25-25: Extra whitespace detected at end of line.


[warning] 33-33: Extra whitespace detected at end of line.


[warning] 40-40: Extra whitespace detected at end of line.

app/assets/javascripts/autograder.js (2)

3-16: Good implementation of access key field toggling

The access key callback function properly disables/enables the access key fields based on the checkbox state, which matches the UI requirement for optional access key input.


18-30: Well-implemented tooltip and hover functionality

The initialization of tooltips and hover effects for the EC2 dropdown enhances the user experience by providing visual feedback.

db/schema.rb (1)

152-155: Well-structured database fields for EC2 configuration

The new fields added to the autograders table properly support the EC2 autograder features:

  • instance_type for storing the selected EC2 instance type
  • access_key and access_key_id for custom AWS credentials
  • use_access_key flag to toggle custom credentials

These fields align well with the UI elements in the EC2 settings form and have appropriate default values.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (6)
app/views/autograders/_ec2_settings.html.erb (6)

9-10: Implement conditional display of access key fields

The access key fields should be conditionally shown based on the "Enable Access Key" checkbox status to improve usability. These fields should be disabled or hidden when the checkbox is unchecked.

You could add an id to the checkbox and control the visibility with JavaScript:

<%= f.check_box :use_access_key,
                display_name: "Enable Access Key",
+               id: "use_access_key_checkbox",
                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" %>
+<%= f.text_field :access_key, display_name: "Access Key", id: "access_key_field", disabled: [email protected]_access_key %>
+<%= f.text_field :access_key_id, display_name: "Access Key ID", id: "access_key_id_field", disabled: [email protected]_access_key %>

Then in your autograder.js file:

document.addEventListener('DOMContentLoaded', function() {
  const checkbox = document.getElementById('use_access_key_checkbox');
  const keyField = document.getElementById('access_key_field');
  const keyIdField = document.getElementById('access_key_id_field');
  
  function updateFieldState() {
    const isEnabled = checkbox.checked;
    keyField.disabled = !isEnabled;
    keyIdField.disabled = !isEnabled;
  }
  
  checkbox.addEventListener('change', updateFieldState);
  updateFieldState(); // Initial state
});

14-44: Consider moving EC2 instance options to a helper method

The large array of EC2 instance options makes this template harder to read and maintain. Consider moving this configuration to a helper method or a constant in a separate file.

You could create a helper method in app/helpers/autograders_helper.rb:

def ec2_instance_options
  [
    ['T2 - General Purpose (Burstable)', [
      ['t2.nano - 1 vCPU, 0.5 GiB RAM (minimal, lowest cost)', 't2.nano'],
      # ... rest of the options
    ]],
    # ... other categories
  ]
end

Then in your template:

<%= f.select :instance_type,
             grouped_options_for_select(ec2_instance_options, @autograder.instance_type),
             # ... rest of the code
%>

50-50: Add fallback for @autograder.instance_type

If @autograder is nil or doesn't have an instance_type attribute set, this could cause errors. Add a fallback value.

-grouped_options_for_select(ec2_instance_options, @autograder.instance_type),
+grouped_options_for_select(ec2_instance_options, @autograder&.instance_type || 't2.micro'),

84-84: Fix typo in confirmation message

There's a typo in the word "assesssment" (extra 's').

-            data: { confirm: "Are you sure you want to delete the Autograder for this assesssment?" } %>
+            data: { confirm: "Are you sure you want to delete the Autograder for this assessment?" } %>

80-84: Consider separating save and delete actions

Placing the delete button immediately after the save button could lead to accidental deletions. Consider adding more visual separation or moving the delete button to a different location.

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

+<div style="margin-top: 20px; border-top: 1px solid #ddd; padding-top: 15px;">
+  <h5>Danger Zone</h5>
 <%= 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 assessment?" } %>
+</div>

77-77: Consider adding more comprehensive pricing information

The note about pricing is helpful, but more detailed information about cost implications would be valuable.

Consider adding more specific pricing information or warnings:

-  <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>
+  <small>Note: Larger instances incur higher AWS costs. For example, a t2.2xlarge can cost up to 8x more than a t2.micro. Check <a href='https://aws.amazon.com/ec2/pricing/on-demand/' target='_blank'>EC2 pricing</a> before selecting larger instances for your assignments.</small>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b240eaf and 5a93401.

📒 Files selected for processing (1)
  • app/views/autograders/_ec2_settings.html.erb (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
app/views/autograders/_ec2_settings.html.erb (1)

9-10: Use password fields for AWS credentials

AWS access keys and IDs are sensitive credentials that should be masked in the UI. Use password_field instead of text_field to prevent exposure.

-<%= f.text_field :access_key, display_name: "Access Key" %>
-<%= f.text_field :access_key_id, display_name: "Access Key ID" %>
+<%= f.password_field :access_key, display_name: "Access Key" %>
+<%= f.password_field :access_key_id, display_name: "Access Key ID" %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants