Skip to content

Ec2 connection/non static ports#7

Merged
iidsample merged 5 commits into
mainfrom
EC2-connection/non-static-ports
Jul 15, 2026
Merged

Ec2 connection/non static ports#7
iidsample merged 5 commits into
mainfrom
EC2-connection/non-static-ports

Conversation

@Saaketh0

@Saaketh0 Saaketh0 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added configurable workflow API ports, including Docker exposure and deployment settings.
    • Added support for explicitly configuring the EC2 SSH private key path.
    • Improved SSH connections to use the configured key securely and consistently.
    • Updated EC2 worker defaults to use t3.micro instances.
  • Documentation

    • Expanded EC2 deployment guidance with updated networking, permissions, setup, cleanup, and troubleshooting instructions.
    • Clarified host reachability and SSH key requirements for distributed deployments.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

EC2 deployment now uses configured SSH private keys without UserData key injection, supports configurable workflow API ports across Docker and runtime paths, updates EC2 defaults and documentation, and adds validation tests for key presence and permissions.

Changes

EC2 deployment flow

Layer / File(s) Summary
Configurable workflow API ports
ventis/templates/config/global_controller.yaml, ventis/controller/utils/agent_specs.py, ventis/stub_generator.py, ventis/cli.py, ventis/controller/cloud_provider_logic/{Local,EC2}/_runtime.py
Workflow API ports are configured, persisted in agent specifications, passed into Docker generation, and used for runtime port mappings.
Validated SSH provisioning and execution
ventis/controller/cloud_provider_logic/EC2/_runtime.py, ventis/controller/global_controller.py
Configured SSH keys are validated and used with restricted SSH options; EC2 provisioning no longer generates keypairs or injects public keys through UserData.
Runtime validation and deployment guidance
tests/test_runtime_ec2.py, ventis/controller/cloud_provider_logic/EC2/README.md, README.md, .gitignore
Tests cover temporary key handling, validation failures, and absent UserData; EC2 setup documentation and ignore rules are updated.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI as cmd_build
  participant Generator as generate_workflow_docker
  participant Specs as write_agent_specs
  participant Runtime as EC2 runtime
  participant AWS as EC2 run_instances
  participant Host as EC2 host
  CLI->>Generator: pass api_port
  Generator->>Generator: generate Dockerfile EXPOSE api_port
  Specs->>Runtime: provide persisted api_port
  Runtime->>Runtime: validate ssh_private_key_path
  Runtime->>AWS: provision without UserData key injection
  Runtime->>Host: transfer image over restricted SSH
Loading

Possibly related PRs

Suggested reviewers: iidsample

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main theme of the changes: EC2 connection handling and making ports configurable.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch EC2-connection/non-static-ports

Comment @coderabbitai help to get the list of available commands.

@coderabbitai
coderabbitai Bot requested a review from iidsample July 15, 2026 22:35
@Saaketh0

Copy link
Copy Markdown
Collaborator Author

This PR changes two things:

  • Allows users to set the port of their workflows to whatever they want in the .yaml file
  • Removes the global controller from creating public/private keys, opting to instead get the keys from the AMI directly.

@iidsample
iidsample merged commit 62803c2 into main Jul 15, 2026
2 of 4 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
ventis/stub_generator.py (1)

461-472: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep the workflow container EXPOSE port at 8080

api_port is the host-side mapping (<api_port>:8080); the container listens on 8080. Exposing api_port here makes the image metadata and docker run -P advertise the wrong port.

Suggested fix
-EXPOSE {api_port}
+EXPOSE 8080
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/stub_generator.py` around lines 461 - 472, Update the Dockerfile
template generated by the stub generator so the workflow container exposes port
8080 instead of interpolating api_port. Keep api_port reserved for the host-side
mapping and preserve the existing other EXPOSE declaration.

Source: MCP tools

ventis/controller/cloud_provider_logic/EC2/_runtime.py (1)

146-182: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Move SSH-key validation inside the try, and decouple terminate_instance() from _aws_clients().
In ventis/controller/cloud_provider_logic/EC2/_runtime.py:146-182,284-296, a bootstrap-time _aws_clients() failure skips cleanup, and the fallback termination path can fail for the same reason. Add a regression test for this failure path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/controller/cloud_provider_logic/EC2/_runtime.py` around lines 146 -
182, The bootstrap flow in bootstrap_instance must catch failures from
_aws_clients() so cleanup still runs; move SSH-key/client validation into its
try block. Update terminate_instance to obtain or receive the required AWS
client independently of _aws_clients(), ensuring fallback termination succeeds
when client initialization fails, and add a regression test covering this
failure path.
🧹 Nitpick comments (3)
ventis/controller/cloud_provider_logic/EC2/README.md (1)

13-14: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Install the controller in a virtual environment.

The documentation says requirements are installed “in env” but then uses --break-system-packages, which explicitly allows pip to modify an externally managed Python installation. Document creating and activating a venv, then run python -m pip install -e . without that flag. (pip.pypa.io)

[details]
Suggested flow:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install -e .

[details]

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/controller/cloud_provider_logic/EC2/README.md` around lines 13 - 14,
Update the installation instructions in the README to explicitly create and
activate a .venv using python3 -m venv and source .venv/bin/activate, then
install the controller with python -m pip install -e . without
--break-system-packages.

Source: MCP tools

ventis/controller/cloud_provider_logic/EC2/_runtime.py (1)

53-67: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant SSH-key re-validation.

_ssh_key_path(cfg) is called in _aws_clients() (Line 66) but its return value is discarded, then recomputed again in _bootstrap_instance (Line 224). Consider having _aws_clients() return the validated path so callers don't re-stat/re-validate the key file on every bootstrap.

Also applies to: 224-224

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/controller/cloud_provider_logic/EC2/_runtime.py` around lines 53 - 67,
Update _aws_clients() to retain and return the validated SSH key path from
_ssh_key_path(cfg), then adjust _bootstrap_instance to consume that returned
path instead of calling _ssh_key_path(cfg) again. Preserve the existing
configuration and client return values while avoiding repeated key-file
validation.
ventis/controller/global_controller.py (1)

508-537: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Reuse the shared SSH key validator ventis/controller/global_controller.py:496-537
This path re-resolves ec2.ssh_private_key_path without _ssh_key_path(), so startup SSH calls can still fall back to a generic ssh failure instead of the same missing/readability/perms check used by EC2 bootstrap. Call the shared helper here, or centralize the resolution in one place.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/controller/global_controller.py` around lines 508 - 537, The remote
execution path in the command-running method bypasses the shared SSH key
validation. Replace its direct ec2.ssh_private_key_path expansion with the
existing _ssh_key_path() helper, preserving the current SSH command construction
while ensuring startup calls use the same missing, readability, and permission
checks as EC2 bootstrap.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Line 78: Update the README deployment guidance link so its anchor text
explicitly identifies the Red Hat SSH key-based access guide instead of using
the generic “here,” while preserving the existing destination URL and
surrounding instructions.

In `@ventis/controller/cloud_provider_logic/EC2/README.md`:
- Line 6: Update the SSH setup documentation in the README to use the correct
authorized-keys filename, changing `~/.ssh/authorizedkeys` to
`~/.ssh/authorized_keys` so the public key is placed where SSH expects it.
- Around line 23-24: Update the EC2 IAM action list in the README to use the
valid plural names ec2:RunInstances and ec2:TerminateInstances, while preserving
ec2:DescribeInstances and ec2:CreateTags.

---

Outside diff comments:
In `@ventis/controller/cloud_provider_logic/EC2/_runtime.py`:
- Around line 146-182: The bootstrap flow in bootstrap_instance must catch
failures from _aws_clients() so cleanup still runs; move SSH-key/client
validation into its try block. Update terminate_instance to obtain or receive
the required AWS client independently of _aws_clients(), ensuring fallback
termination succeeds when client initialization fails, and add a regression test
covering this failure path.

In `@ventis/stub_generator.py`:
- Around line 461-472: Update the Dockerfile template generated by the stub
generator so the workflow container exposes port 8080 instead of interpolating
api_port. Keep api_port reserved for the host-side mapping and preserve the
existing other EXPOSE declaration.

---

Nitpick comments:
In `@ventis/controller/cloud_provider_logic/EC2/_runtime.py`:
- Around line 53-67: Update _aws_clients() to retain and return the validated
SSH key path from _ssh_key_path(cfg), then adjust _bootstrap_instance to consume
that returned path instead of calling _ssh_key_path(cfg) again. Preserve the
existing configuration and client return values while avoiding repeated key-file
validation.

In `@ventis/controller/cloud_provider_logic/EC2/README.md`:
- Around line 13-14: Update the installation instructions in the README to
explicitly create and activate a .venv using python3 -m venv and source
.venv/bin/activate, then install the controller with python -m pip install -e .
without --break-system-packages.

In `@ventis/controller/global_controller.py`:
- Around line 508-537: The remote execution path in the command-running method
bypasses the shared SSH key validation. Replace its direct
ec2.ssh_private_key_path expansion with the existing _ssh_key_path() helper,
preserving the current SSH command construction while ensuring startup calls use
the same missing, readability, and permission checks as EC2 bootstrap.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c0fe69c0-0b4c-4d8e-8810-1908b9b72758

📥 Commits

Reviewing files that changed from the base of the PR and between df0fc70 and efe72ea.

📒 Files selected for processing (11)
  • .gitignore
  • README.md
  • tests/test_runtime_ec2.py
  • ventis/cli.py
  • ventis/controller/cloud_provider_logic/EC2/README.md
  • ventis/controller/cloud_provider_logic/EC2/_runtime.py
  • ventis/controller/cloud_provider_logic/Local/_runtime.py
  • ventis/controller/global_controller.py
  • ventis/controller/utils/agent_specs.py
  • ventis/stub_generator.py
  • ventis/templates/config/global_controller.yaml

Comment thread README.md
```
#### Step 2.1 (Only if performing distributed deployment):
If you are deploying agents and tools to multiple hosts, you need to make sure that the hosts are reachable from the machine where you are running the deploy command. To enable this please ensure that you have passwordless ssh access to the hosts. A guide to enable passwordless ssh access can be found [here](https://www.redhat.com/en/blog/passwordless-ssh).
If you are deploying agents and tools to multiple hosts, make sure the hosts are reachable from the machine where you are running the deploy command and that SSH key-based access is already configured. A guide to set that up can be found [here](https://www.redhat.com/en/blog/passwordless-ssh).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use descriptive link text.

Replace “here” with text identifying the resource, such as “Red Hat’s SSH key-based access guide,” so the link remains understandable in screen-reader and link-list views.

🧰 Tools
🪛 markdownlint-cli2 (0.23.0)

[warning] 78-78: Link text should be descriptive

(MD059, descriptive-link-text)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` at line 78, Update the README deployment guidance link so its
anchor text explicitly identifies the Red Hat SSH key-based access guide instead
of using the generic “here,” while preserving the existing destination URL and
surrounding instructions.

Source: Linters/SAST tools

For local controller
- AMI with the following installed:
- Docker
- Public key in authorizedkeys in ~/.ssh

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use the correct SSH authorized-keys filename.

Line 6 says authorizedkeys; the documented filename is ~/.ssh/authorized_keys. Following this literally leaves the public key unused and prevents SSH setup from working.

🧰 Tools
🪛 LanguageTool

[grammar] ~6-~6: Ensure spelling is correct
Context: ...installed: - Docker - Public key in authorizedkeys in ~/.ssh For global controller - Inst...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/controller/cloud_provider_logic/EC2/README.md` at line 6, Update the
SSH setup documentation in the README to use the correct authorized-keys
filename, changing `~/.ssh/authorizedkeys` to `~/.ssh/authorized_keys` so the
public key is placed where SSH expects it.

Source: Linters/SAST tools

Comment on lines +23 to +24
- IAM Role to attach to global controller instance allowing
- ec2:RunInstance,TerminateInstance,DescribeInstances,CreateTags

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== README excerpt ==\n'
sed -n '18,30p' ventis/controller/cloud_provider_logic/EC2/README.md

printf '\n== Search for related EC2 IAM actions in repo ==\n'
rg -n "RunInstance|RunInstances|TerminateInstance|TerminateInstances|DescribeInstances|CreateTags" ventis/controller/cloud_provider_logic/EC2 -S || true

Repository: CanyonCodeCoreAI/canyoncodecore

Length of output: 821


🌐 Web query:

AWS EC2 IAM policy actions RunInstances TerminateInstances documentation

💡 Result:

In AWS IAM policies, ec2:RunInstances and ec2:TerminateInstances are specific actions used to control the ability to launch and terminate Amazon EC2 instances, respectively [1]. Both actions support resource-level permissions, allowing you to restrict access to specific EC2 instances by specifying their Amazon Resource Name (ARN) in the Resource element of your IAM policy [1][2]. Key details for using these actions in policies: 1. Service Prefix and Format: These actions use the ec2 service prefix [3]. In a JSON policy document, they are specified as ec2:RunInstances and ec2:TerminateInstances [1][4]. 2. Resource-Level Permissions: You can grant access to all instances using a wildcard ("*") or restrict access to specific instances or groups of instances by providing their specific ARNs [1]. For example, a resource ARN for an instance is typically structured as arn:aws:ec2:region:account-id:instance/instance-id [1]. 3. Security Best Practices: Because RunInstances can be used to create resources with broad permissions, it is common to use conditions, such as ec2:ResourceTag or aws:RequestTag, to ensure that only authorized tags are applied during instance creation or to restrict actions to instances that have specific tags [5]. For the most comprehensive and up-to-date list of all EC2 actions, resource types, and condition keys, refer to the official AWS Service Authorization Reference documentation for Amazon EC2 [3][2].

Citations:


Correct the EC2 IAM action names. Use ec2:RunInstances and ec2:TerminateInstances; the singular forms are invalid and will break copied policies with AccessDenied on launch or cleanup.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ventis/controller/cloud_provider_logic/EC2/README.md` around lines 23 - 24,
Update the EC2 IAM action list in the README to use the valid plural names
ec2:RunInstances and ec2:TerminateInstances, while preserving
ec2:DescribeInstances and ec2:CreateTags.

Source: MCP tools

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.

2 participants