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

Integrated code lifecycle: Unify ssh usage config condition for build agents #10293

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

Conversation

jfr2102
Copy link
Contributor

@jfr2102 jfr2102 commented Feb 8, 2025

Checklist

General

Server

Motivation and Context

While trying to find right configuration values I found the current behaviour of config artemis.version-control.build-agent-use-ssh quite confusing.
artemis.version-control.build-agent-use-ssh actually only controls wether a keypair will be generated at the startup of an buildagent and what the getPublicKeyAsString() method returns (this result is stored in the hazelcast map where core nodes can read it).

However, the actual condition wether the build agent will configure ssh in the BuildJobGitService currently depends on the useSsh() method in the parent AbstractGitService which returns true if the 2 configuration values ssh-host-key-path and ssh-template-clone-url are present.

Currently configuringbuild-agent-use-ssh: false but ssh-host-key-path and ssh-template-clone-url being present will not create a keypair, and not push the public key into the hazelcast store, but still try configure ssh on the build agent.

If keys get manually generated in the configured ssh-template-clone-url and this build-agent-use-ssh is supposed to just prevent the creation of a new key then build-agent-use-ssh:false would also prevent public key being put into hazelcast (because getPublicKeyAsString() returns null then.) Which seems weird.

Description

I suggest to override useSsh() in BuildJobGitService to check on configuration build-agent-use-ssh to be consistent with the conditions for generating the keypair and throwing a RuntimeException if build-agent-use-ssh:true but no ssh-template-clone-url is set

Steps for Testing

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

Summary by CodeRabbit

  • New Features
    • Introduced a configurable option that allows builds to optionally use SSH-based authentication.
  • Bug Fixes
    • Enhanced error checks to ensure all necessary SSH configuration details are provided, preventing misconfigurations during build operations.

@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) buildagent Pull requests that affect the corresponding module labels Feb 8, 2025
@jfr2102 jfr2102 changed the title use ssh in BuildJobGitService if build-agent-use-ssh: true Integrated Code Lifecycle: use ssh in BuildJobGitService if build-agent-use-ssh: true Feb 8, 2025
@jfr2102 jfr2102 changed the title Integrated Code Lifecycle: use ssh in BuildJobGitService if build-agent-use-ssh: true Integrated code lifecycle: use ssh in BuildJobGitService if build-agent-use-ssh: true Feb 8, 2025
@jfr2102 jfr2102 changed the title Integrated code lifecycle: use ssh in BuildJobGitService if build-agent-use-ssh: true Integrated code lifecycle: Unify ssh config for build agents Feb 8, 2025
@jfr2102 jfr2102 changed the title Integrated code lifecycle: Unify ssh config for build agents Integrated code lifecycle: Unify ssh config for build agents Feb 8, 2025
@jfr2102 jfr2102 changed the title Integrated code lifecycle: Unify ssh config for build agents Integrated code lifecycle: Unify ssh usage condition for build agents Feb 14, 2025
@jfr2102 jfr2102 changed the title Integrated code lifecycle: Unify ssh usage condition for build agents Integrated code lifecycle: Unify ssh usage config condition for build agents Feb 14, 2025
@helios-aet helios-aet bot temporarily deployed to artemis-test6.artemis.cit.tum.de February 16, 2025 17:32 Inactive
@jfr2102 jfr2102 marked this pull request as ready for review February 17, 2025 20:57
@jfr2102 jfr2102 requested a review from a team as a code owner February 17, 2025 20:57
Copy link

coderabbitai bot commented Feb 17, 2025

Walkthrough

This pull request updates the BuildJobGitService by introducing a new boolean field useSshForBuildAgent, which is initialized from a configuration property. The method useSsh() now returns the value of this field, impacting the authentication mechanism. The init() method has been enhanced to validate that the sshUrlTemplate is set when SSH is enabled, throwing a RuntimeException otherwise. Additionally, the getGitUri() method has been modified to utilize the new SSH configuration, ensuring the authentication flow reflects the updated settings.

Changes

File Change Summary
.../BuildJobGitService.java - Added the boolean field useSshForBuildAgent initialized from configuration
- Overridden useSsh() to return the new field's value
- Updated init() to check sshUrlTemplate when SSH is enabled
- Modified getGitUri() to use the updated SSH configuration

Sequence Diagram(s)

sequenceDiagram
    participant UA as User/Application
    participant CFG as Configuration Provider
    participant GS as BuildJobGitService

    UA->>GS: Initialize build job
    GS->>CFG: Retrieve setting for SSH usage (useSshForBuildAgent)
    CFG-->>GS: Return SSH configuration value
    alt SSH enabled
        GS->>GS: Call init() and validate sshUrlTemplate
        GS-->>UA: Throw RuntimeException if sshUrlTemplate is missing
    else
        GS->>GS: Proceed without SSH
    end
    UA->>GS: Request Git URI via getGitUri()
    GS->>GS: Call overridden useSsh() method
    GS-->>UA: Return appropriate Git URI based on SSH configuration
Loading

Possibly related PRs

Suggested labels

config-change, feature, programming, ready for review

Suggested reviewers

  • BBesrour
  • JohannesStoehr
  • Hialus
  • SimonEntholzer
  • krusche
✨ 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.

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 (1)
src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobGitService.java (1)

78-80: Consider using a more specific exception type.

While the validation logic is correct, consider using a more specific exception type like IllegalStateException instead of RuntimeException to better indicate the nature of the configuration error.

-                throw new RuntimeException("No SSH url template was set but should use SSH for build agent authentication.");
+                throw new IllegalStateException("No SSH url template was set but should use SSH for build agent authentication.");
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b80e594 and ccdde07.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobGitService.java (2 hunks)
🧰 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/buildagent/service/BuildJobGitService.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
src/main/java/de/tum/cit/aet/artemis/buildagent/service/BuildJobGitService.java (3)

48-49: LGTM!

The field declaration follows Java naming conventions and correctly uses constructor injection with a default value of false for backward compatibility.


53-65: LGTM!

The method is well-documented and correctly implements the override to use the configuration value, aligning with the PR objectives.


104-104: LGTM!

The implementation correctly uses the overridden useSsh() method to determine the URI type, maintaining consistency with the new SSH configuration.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 17, 2025
BBesrour
BBesrour previously approved these changes Feb 18, 2025
Copy link
Member

@BBesrour BBesrour 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, would be great if you could add it in the template application.properties with a descriptive comment

az108
az108 previously approved these changes Feb 18, 2025
Copy link
Contributor

@az108 az108 left a comment

Choose a reason for hiding this comment

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

Code 👍

@jfr2102 jfr2102 dismissed stale reviews from BBesrour and coderabbitai[bot] via dd9f329 February 18, 2025 10:20
@github-actions github-actions bot added the config-change Pull requests that change the config in a way that they require a deployment via Ansible. label Feb 18, 2025
@jfr2102
Copy link
Contributor Author

jfr2102 commented Feb 18, 2025

code lgtm, would be great if you could add it in the template application.properties with a descriptive comment

Thanks good idea, I added it in application-localvc.yml with a small comment. Does it make sense to you like this?

@jfr2102 jfr2102 requested review from BBesrour and az108 February 18, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buildagent Pull requests that affect the corresponding module config-change Pull requests that change the config in a way that they require a deployment via Ansible. ready for review server Pull requests that update Java code. (Added Automatically!)
Projects
Status: Work In Progress
Development

Successfully merging this pull request may close these issues.

3 participants