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

Programming exercises: Add logging of failed authorization attempts to the VCS access log #10369

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

SimonEntholzer
Copy link
Contributor

@SimonEntholzer SimonEntholzer commented Feb 20, 2025

Checklist

General

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 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).

Motivation and Context

At the moment the VCS access log, logs only fully successful interactions, and interactions failing at the authentication step already.
When pushing/pulling fails at the authorization, Artemis writes no VCS access log, in the case of HTTPS not even a server log.

Description

  • add VCS access log entry when authorization fails for SSH and

Steps for Testing

  1. Create a programming exercise
  2. participate with a student (clone and push)
  3. As the instructor, set the due date of the exercise to the current time
  4. Try to push to the repository with the student account (this should fail) Via SSH and HTTPS
  5. Check the access log as the instructor

Testserver States

You can manage test servers using Helios. Check environment statuses in the environment list. To deploy to a test server, go to the CI/CD page, find your PR or branch, and trigger the deployment.

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Screenshots

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a new authentication constant to represent missing authentication headers.
    • Introduced a method for logging failed access attempts to enhance tracking of permission issues.
    • Added a method to retrieve the latest commit hash from a repository.
  • Bug Fixes

    • Enhanced error handling for repository access, providing clearer feedback when permissions are denied.
    • Improved logging for failed access attempts, ensuring better tracking of access issues.

@SimonEntholzer SimonEntholzer requested a review from a team as a code owner February 20, 2025 08:08
@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) programming Pull requests that affect the corresponding module labels Feb 20, 2025
Copy link

coderabbitai bot commented Feb 20, 2025

Walkthrough

This pull request introduces modifications across authentication and version control access handling. The changes extend the enumeration of authentication mechanisms by adding a new constant NONE, which represents a scenario where the authentication header is missing. Additionally, the service managing local version control now includes enhanced error handling with try-catch blocks, improved logging for failed access attempts, and a centralized method for commit hash retrieval. A related service updates its error handling to log failed access on exceptions, ensuring more detailed tracking of authorization issues.

Changes

File(s) Change Summary
src/.../AuthenticationMechanism.java Added a new enum constant: NONE to represent a missing authentication header.
src/.../LocalVCServletService.java Enhanced error handling via try-catch blocks, improved logging with saveFailedAccessVcsAccessLog, and introduced methods for commit hash retrieval and authentication mechanism resolution. Updated documentation for authorizeUser.
src/.../SshGitLocationResolverService.java Added a call to saveFailedAccessVcsAccessLog for logging failed access attempts on LocalVCForbiddenException.
src/.../AuthenticationContext.java Introduced a new sealed interface AuthenticationContext with records Session and Request to standardize IP address retrieval.

Suggested labels

bugfix, tests, documentation

Suggested reviewers

  • HawKhiem
  • BBesrour
  • az108
  • JohannesStoehr
  • krusche
  • N0W0RK
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 20, 2025
Copy link
Contributor

@ole-ve ole-ve left a comment

Choose a reason for hiding this comment

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

code seems fine, see my inline comments.

just as a pointer: some server tests are currently failing as no exception seem to be thrown anymore. also, coverage is mildly violated 🙃

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 23, 2025
Copy link
Contributor

@ole-ve ole-ve left a comment

Choose a reason for hiding this comment

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

also tested on TS6, works fine.

Code + Manual test

ole-ve
ole-ve previously approved these changes Feb 23, 2025
coolchock
coolchock previously approved these changes Feb 23, 2025
Copy link
Contributor

@coolchock coolchock left a comment

Choose a reason for hiding this comment

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

code + manual test, LGTM

cremertim
cremertim previously approved these changes Feb 25, 2025
Copy link
Contributor

@cremertim cremertim 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

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 25, 2025
ole-ve
ole-ve previously approved these changes Feb 25, 2025
Copy link
Contributor

@ole-ve ole-ve left a comment

Choose a reason for hiding this comment

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

re-approve after re-throwing exception instead of throwing a new one

Copy link
Contributor

@magaupp magaupp left a comment

Choose a reason for hiding this comment

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

Some suggestions

Copy link
Contributor

@magaupp magaupp left a comment

Choose a reason for hiding this comment

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

Thanks for the change. Code looks good 👍

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

🧹 Nitpick comments (3)
src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/AuthenticationContext.java (3)

7-26: Add JavaDoc documentation to improve code maintainability.

The new AuthenticationContext interface design is clean and follows good principles, but would benefit from proper documentation explaining:

  1. The purpose of this interface
  2. How it relates to logging failed authorization attempts
  3. When to use each implementation

Add documentation like:

/**
 * Provides a common interface for accessing authentication context information
 * from different sources (SSH sessions and HTTP requests).
 * Used primarily for logging failed authorization attempts to the VCS access log.
 */
public sealed interface AuthenticationContext {

    /**
     * Implementation for SSH-based authentication.
     */
    record Session(ServerSession session) implements AuthenticationContext {
        // ...
    }

    /**
     * Implementation for HTTP-based authentication.
     */
    record Request(HttpServletRequest request) implements AuthenticationContext {
        // ...
    }

    /**
     * Returns the IP address of the client.
     * @return the IP address as a string
     */
    String getIpAddress();
}

12-14: Consider adding null checks for defensive programming.

The implementation assumes that session will never be null. If there's a possibility of null values, consider adding defensive checks.

@Override
public String getIpAddress() {
-    return session.getClientAddress().toString();
+    return session != null && session.getClientAddress() != null 
+           ? session.getClientAddress().toString() 
+           : "unknown";
}

20-22: Consider adding null checks for defensive programming.

Similar to the Session implementation, consider adding checks for null request.

@Override
public String getIpAddress() {
-    return request.getRemoteAddr();
+    return request != null ? request.getRemoteAddr() : "unknown";
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1c58f6 and f659e98.

📒 Files selected for processing (4)
  • src/main/java/de/tum/cit/aet/artemis/programming/domain/AuthenticationMechanism.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/AuthenticationContext.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java (5 hunks)
  • src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/SshGitLocationResolverService.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/java/de/tum/cit/aet/artemis/programming/domain/AuthenticationMechanism.java
  • src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/SshGitLocationResolverService.java
  • src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java
🧰 Additional context used
📓 Path-based instructions (1)
`src/main/java/**/*.java`: naming:CamelCase; principles:{sin...

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

  • src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/AuthenticationContext.java
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: client-style
  • GitHub Check: client-tests
  • GitHub Check: server-tests
  • GitHub Check: server-style
  • GitHub Check: Analyse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
programming Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!)
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

5 participants