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

Iris: Fix an error related to Iris settings when tutors navigate to course management #9725

Merged

Conversation

alexjoham
Copy link
Member

@alexjoham alexjoham commented Nov 10, 2024

Checklist

General

  • I tested all changes and their related features with all corresponding user types on a test server.
  • This is a small issue that I tested locally and was confirmed by another developer on a test server.
  • I chose a title conforming to the naming conventions for pull requests.

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I added pre-authorization annotations according to the guidelines and checked the course groups for all new REST Calls (security).
  • I documented the Java code using JavaDoc style.

Changes affecting Programming Exercises

  • High priority: I tested all changes and their related features with all corresponding user types on a test server configured with the integrated lifecycle setup (LocalVC and LocalCI).
  • I tested all changes and their related features with all corresponding user types on a test server configured with Gitlab and Jenkins.

Motivation and Context

The changes were needed to fix Issue#7797. The bug was that every time a tutor opened the setting, a not allowed error was displayed.

Description

The problem was that the Iris Settings permission was checked for Tutors, but the permission to check the settings was only allowed for accounts with at least editors. This has been fixed by adding the correct permission.

Steps for Testing

Prerequisites:

  • 1 Tutor
  • 1 Programming Exercise with Iris enabled
  1. Log in to Artemis
  2. Navigate to Course Administration
  3. Check if a error message is displayed in the UI

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Exam Mode Test

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

  • New Features

    • Updated access roles for retrieving course and exercise settings, now requiring a tutor role for specific endpoints.
  • Bug Fixes

    • Enhanced security by refining authorization checks for accessing raw settings.

@alexjoham alexjoham requested a review from a team as a code owner November 10, 2024 12:30
@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) iris Pull requests that affect the corresponding module labels Nov 10, 2024
@alexjoham alexjoham linked an issue Nov 10, 2024 that may be closed by this pull request
Copy link

coderabbitai bot commented Nov 10, 2024

Walkthrough

The changes in this pull request involve modifications to the IrisSettingsResource class, specifically updating security annotations for two GET endpoints. The getRawCourseSettings method now requires the @EnforceAtLeastTutorInCourse annotation, while the getRawExerciseSettings method has been updated to use @EnforceAtLeastTutorInExercise. These changes adjust the role requirements for accessing raw iris settings, impacting authorization checks. Additionally, the relevant import statements have been updated accordingly.

Changes

File Path Change Summary
src/main/java/de/tum/cit/aet/artemis/iris/web/IrisSettingsResource.java Updated security annotations for getRawCourseSettings and getRawExerciseSettings methods to enforce tutor roles instead of editor roles. Adjusted import statements accordingly.

Possibly related PRs

Suggested labels

ready to merge, maintainer-approved, core

Suggested reviewers

  • JohannesWt
  • SimonEntholzer
  • az108
  • iyannsch
  • pzdr7
  • raffifasaro

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 pmd
src/main/java/de/tum/cit/aet/artemis/iris/web/IrisSettingsResource.java

The following rules are missing or misspelled in your ruleset file category/vm/bestpractices.xml: BooleanInstantiation, DontImportJavaLang, DuplicateImports, EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptyStatementNotInLoop, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, EmptyWhileStmt, ExcessiveClassLength, ExcessiveMethodLength, ImportFromSamePackage, MissingBreakInSwitch, SimplifyBooleanAssertion. Please check your ruleset configuration.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8d1a353 and c3ad35f.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/iris/web/IrisSettingsResource.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/de/tum/cit/aet/artemis/iris/web/IrisSettingsResource.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 resolve resolve all the CodeRabbit review comments.
  • @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 or @coderabbitai title anywhere in the PR title to generate the title automatically.

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

@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 and nitpick comments (3)
src/main/java/de/tum/cit/aet/artemis/iris/web/IrisSettingsResource.java (3)

Line range hint 92-98: Remove redundant authorization check.

There's a logical inconsistency in the authorization checks:

  1. The @EnforceAtLeastTutorInExercise annotation already ensures the user has at least TUTOR role
  2. The subsequent checkHasAtLeastRoleForExerciseElseThrow(Role.STUDENT, ...) check is redundant since tutors inherently have higher privileges than students

Apply this diff to remove the redundant check:

    @EnforceAtLeastTutorInExercise
    public ResponseEntity<IrisSettings> getRawExerciseSettings(@PathVariable Long exerciseId) {
        var exercise = exerciseRepository.findByIdElseThrow(exerciseId);
-       var user = userRepository.getUserWithGroupsAndAuthorities();
-       authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.STUDENT, exercise, user);

        var combinedIrisSettings = irisSettingsService.getRawIrisSettingsFor(exercise);
        return ResponseEntity.ok(combinedIrisSettings);
    }

Line range hint 78-98: Consider implementing a consistent settings access model.

The current changes create an architectural inconsistency in how settings are exposed:

  1. getCourseSettings and getExerciseSettings implement reduced views for non-editors
  2. The raw settings endpoints now expose full settings to tutors without any filtering

Consider implementing a consistent approach:

  1. Create a service method that returns filtered raw settings based on user role
  2. Apply this filtering consistently across all settings endpoints
  3. Document the security model clearly, specifying which roles can access what level of settings detail

Would you like me to propose a detailed design for implementing role-based settings filtering?


Based on the gathered information, I can now provide a final response:

Security concern: Raw settings contain sensitive authentication tokens and API configurations

The raw settings contain sensitive data that should not be exposed to tutors:

  1. Authentication tokens for Pyris integration (authenticationToken in settings)
  2. API secrets and credentials for service communication
  3. Configuration that determines system security boundaries

The existing endpoint getCourseSettings already implements proper security filtering for non-editors by using getReduced parameter. The raw settings endpoint should maintain the same security level as it exposes unfiltered configuration.

Recommendation: Keep @EnforceAtLeastEditorInCourse for the raw settings endpoint to align with the existing security model where only editors and above can access sensitive configuration.

🔗 Analysis chain

Line range hint 78-83: Verify security implications of exposing raw course settings to tutors.

While this change aligns with the PR's objective to fix tutor permissions, exposing raw course settings to tutors requires careful consideration:

  1. The method provides unrestricted access to raw settings, unlike getCourseSettings which has logic to show reduced settings to non-editors.
  2. Consider whether tutors should see the complete raw settings or if a filtered view would be more appropriate.

Let me gather more information about the security implications by checking how the raw settings are used and what sensitive data they might contain.


Let me gather more information about the IrisSettings class and its usage to understand what sensitive data it might contain.


Let me gather one final piece of information about the authentication tokens and sensitive configuration in the settings.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing security checks or filtering for raw settings access
rg -A 5 "getRawIrisSettingsFor.*course" 

# Look for any existing tutor-specific handling in the codebase
ast-grep --pattern 'class $_ {
  $$$
  @EnforceAtLeastTutorInCourse
  $$$
}'

Length of output: 3466


Script:

#!/bin/bash
# Check the IrisCourseSettings class to understand what data it contains
rg -l "class IrisCourseSettings"
rg -A 20 "class IrisCourseSettings"

# Check if there's any filtering/security logic in getCourseSettings
rg -A 10 "getCourseSettings.*course" 

# Check if there are any other endpoints with similar security annotations
ast-grep --pattern '@EnforceAtLeastTutorInCourse
    $$$
    public $_ get$_($$$) {
        $$$
    }'

Length of output: 295415


Script:

#!/bin/bash
# Check IrisSettings class and its fields
rg -A 10 "class IrisSettings" 

# Check if there are any other endpoints that expose raw settings
rg -A 5 "getRawIrisSettingsFor"

# Check if there are any security-sensitive fields in the settings
rg -A 5 "class IrisCourseSettings|class IrisExerciseSettings|class IrisChatSettings|class IrisLectureIngestionSettings|class IrisCompetencyGenerationSettings"

Length of output: 24418


Script:

#!/bin/bash
# Check for sensitive fields in IrisSettings and related classes
rg -A 5 "authenticationToken|apiKey|secret|password|credential|token" src/main/java/de/tum/cit/aet/artemis/iris/

# Check if there's any filtering logic in the service
rg -A 10 "getCombinedIrisSettingsFor" src/main/java/de/tum/cit/aet/artemis/iris/service/settings/

Length of output: 41740

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bf2fbbd and 8d1a353.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/iris/web/IrisSettingsResource.java (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/iris/web/IrisSettingsResource.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

🔇 Additional comments (1)
src/main/java/de/tum/cit/aet/artemis/iris/web/IrisSettingsResource.java (1)

20-20: LGTM: Import statements are correctly added.

The new security annotation imports align with the PR's objective to adjust tutor permissions.

Also applies to: 23-23

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 10, 2024
Copy link
Member

@Hialus Hialus left a comment

Choose a reason for hiding this comment

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

I noticed one small thing in getRawExerciseSettings.
Apart from that the code is good.

Copy link
Contributor

@iyannsch iyannsch left a comment

Choose a reason for hiding this comment

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

Code LGTM

Copy link
Member

@Hialus Hialus left a comment

Choose a reason for hiding this comment

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

Code looks good now. 👍🏻

@bassner bassner changed the title Iris: Fix Course Management View Permission Bug as Tutor User Iris: Fix an error related to Iris settings when tutors navigate to course management Nov 12, 2024
@bassner bassner added this to the 7.7.1 milestone Nov 12, 2024
@bassner bassner merged commit 7876792 into develop Nov 12, 2024
51 of 55 checks passed
@bassner bassner deleted the bugfix/iris/fix-course-management-view-permission-bug-as-tutor branch November 12, 2024 13:20
@coderabbitai coderabbitai bot mentioned this pull request Nov 12, 2024
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iris Pull requests that affect the corresponding module server Pull requests that update Java code. (Added Automatically!)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Course Management View Permission Bug as Tutor User
5 participants