Add ability to get private keys or use existing key pairs when provisioning on EC2
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1333604
Description of problem:
After configuring AWS EC2 as a compute resource and provisioning a virtual machine, the user cannot SSH onto the virtual machine because foreman has generated an SSH key pair itself used to provision the machine.
The user should be able to view and download these keys through the Foreman web gui (as a minimum).
They should also be able to use existing pairs already configured in AWS or should be given the option to generate their own.
This entails a potential security risk as it is not obvious if a keypair is generated per virtual machine OR per compute resource.
Here is the work around to get the key to SSH to the machine:
1) Run the command hammer compute-resources list
2) Take note of the compute-resource (can vary depending on how many you have or have had, the number increments even after they have been deleted).
3) Now run su to the postgres user, CD to tmp and run the following command:
echo 'select secret from key_pairs where compute_resource_id = <Compute Resource ID>;' | psql -d foreman -t | sed -e 's/^[ \t]*//'| sed 's/+$//' | sed "s/[[:blank:]]*$//" > /tmp/<Key Pair Name>.pem
- Where the Compute Resource ID and Key Pair Name have been replaced.
- You can verify the integrity of key using this command: openssl rsa -in <Key Pair Name>
If the key is not displayed, or it asks you for a pass phrase, there is an issue with the key.
4) You should have a pem file which can now be used to log into your EC2 machine. Depending on your AMI, try the following command:
ssh -i <Key Pair Name>.pem ec2-user@<EC2 VM Hostname or IP>
For regular RHEL AMI, the initial user is ec2-user, it may be different depending on the AMI used.
Steps to Reproduce:
1. Setup AWS Compute Resource and users, provision a VM.
2. > Try to connect to the machine via SSH, not possible without key.
3. Run work around to get key, but it should be easier!
Key pairs are not visible to user unless they run database queries.
User should be able to get their key pair easily.
#1 Updated by Ondřej Pražák over 3 years ago
- Subject changed from AWS Compute Resource Enhancement: Add ability to get private keys or use existing key pairs when provisioning on EC2 to AWS Compute Resource Enhancement: Add ability to get private keys or use existing key pairs when provisioning on EC2
- Target version set to 115
#3 Updated by Dominic Cleal over 3 years ago
- Subject changed from AWS Compute Resource Enhancement: Add ability to get private keys or use existing key pairs when provisioning on EC2 to Add ability to get private keys or use existing key pairs when provisioning on EC2
- Description updated (diff)
Very hard to read with code formatting!