Skip to content

feat(sshbox): add sshbox to run commands #161

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

Merged
merged 1 commit into from
May 17, 2025
Merged

feat(sshbox): add sshbox to run commands #161

merged 1 commit into from
May 17, 2025

Conversation

mudler
Copy link
Owner

@mudler mudler commented May 17, 2025

This PR adds a specific service "sshbox" that is connected directly to LocalAGI. It is a container running sshd which is set with root/root as default. This can be changed easily by configuring the docker-compose file and tweaking the environment variables as needed.

When LOCALAGI_SSHBOX_URL is set, the ssh action can be picked up without configuration and will give agents automatically access to the sshbox.

@Copilot Copilot AI review requested due to automatic review settings May 17, 2025 21:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR integrates a new service ("sshbox") to allow command execution via an SSH box when LOCALAGI_SSHBOX_URL is provided. Key changes include:

  • Modifying the ShellAction to accept a new sshBoxURL parameter and an optional password.
  • Adjusting the Run method and definition condition to accommodate sshbox usage.
  • Adding configuration constants, environment variables, a new Dockerfile, and a GitHub Actions job for building the sshbox image.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
services/actions/shell.go Updated ShellAction to support sshbox, added parsing for sshBoxURL and handling of an optional password, and switched the action name to "run_command".
services/actions.go Introduced constant for sshbox URL and updated the Shell action construction.
main.go Added new environment variable assignment for sshBoxURL.
docker-compose.yaml Added sshbox service with SSH configuration and environment variable.
README.md Updated documentation to include sshbox configuration instructions.
Dockerfile.sshbox New Dockerfile to build the sshbox container.
.github/workflows/image.yml Added a GitHub Actions job for building the sshbox docker image.
Comments suppressed due to low confidence (1)

services/actions/shell.go:171

  • Avoid using log.Fatalf in library code as it abruptly terminates the application; consider returning an error instead to enable graceful error handling.
key, err := ssh.ParsePrivateKey([]byte(privateKey))

output, err := sshCommand(a.privateKey, result.Command, result.User, result.Host)
password := a.password
if a.sshBoxURL != "" && result.Host == "" && result.User == "" && password == "" {
// sshbox url can be root:root@localhost:2222
Copy link
Preview

Copilot AI May 17, 2025

Choose a reason for hiding this comment

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

Consider validating the format of sshBoxURL (e.g. ensuring it conforms to the expected 'user' or 'user:password@host' pattern) before parsing it, to avoid potential runtime errors.

Suggested change
// sshbox url can be root:root@localhost:2222
// Validate sshBoxURL format (e.g., user or user:password@host)
sshBoxPattern := `^([^:@]+)(:[^:@]+)?@([^:@]+)$`
matched, err := regexp.MatchString(sshBoxPattern, a.sshBoxURL)
if err != nil || !matched {
log.Printf("Invalid sshBoxURL format: %s", a.sshBoxURL)
return types.ActionResult{}, fmt.Errorf("invalid sshBoxURL format")
}
// Parse sshBoxURL

Copilot uses AI. Check for mistakes.

@mudler mudler merged commit 4a0d3a7 into main May 17, 2025
1 check failed
@mudler mudler deleted the feat/sshbox branch May 17, 2025 21:34
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.

1 participant