Skip to content

Add SSH public key option to VM create command #539

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 4 commits into from
Apr 30, 2025

Conversation

devin-ai-integration[bot]
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Apr 29, 2025

Add SSH public key option to VM create command

This PR adds a new optional argument --ssh-public-key to the vm create command that allows specifying SSH public keys to be added to the VM. The feature:

  • Allows specifying multiple public keys by using the flag multiple times
  • Validates that the provided files contain valid SSH public keys
  • Base64 encodes the public keys for JSON-safe transmission with newlines
  • Passes the public keys to the API for provisioning

Example usage:

# Create a VM with an SSH public key
replicated vm create --distribution ubuntu --version 20.04 --ssh-public-key ~/.ssh/id_rsa.pub

# Create a VM with multiple SSH public keys
replicated vm create --distribution ubuntu --version 20.04 --ssh-public-key ~/.ssh/id_rsa.pub --ssh-public-key ~/.ssh/id_ed25519.pub

Changes:

  • Added createVMPublicKeys field to runnerArgs struct
  • Added PublicKeys field to CreateVMOpts and CreateVMRequest structs
  • Added --ssh-public-key flag to the VM create command
  • Created utility function to read and validate SSH public keys
  • Added base64 encoding of public keys for JSON-safe transmission

Link to Devin run: https://app.devin.ai/sessions/067166b1cc674933a94c4969c014b8bc
Requested by: [email protected]

Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

pkg/util/ssh.go Outdated
return "", fmt.Errorf("public key file is empty: %s", path)
}

_, _, _, _, err = ssh.ParseAuthorizedKey([]byte(keyContent))
Copy link
Member

Choose a reason for hiding this comment

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

This will parse successfully if the email has an injection string for bash: https://go.dev/play/p/MnNRcTbx_cf

@marccampbell marccampbell merged commit 4e2766d into main Apr 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants