-
Notifications
You must be signed in to change notification settings - Fork 74
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
Temporary SSH Key files not generated or used in proxmox-iso #301
Comments
I'm going to try just setting the I would also fix it myself/figure out if it really is a bug if I wasn't a noob to Packer. I dug through a TON of code, but couldn't find anything that made me go "AH here it is." |
The only other thing I can think of right now is that maybe it is related to my CD usage for autoinstall instead of HTTP? Perhaps |
When comparing the &awscommon.StepKeyPair{
Debug: b.config.PackerDebug,
Comm: &b.config.RunConfig.Comm,
IsRestricted: b.config.IsChinaCloud(),
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
Tags: b.config.RunTags,
Ctx: b.config.ctx,
}, before they attempt their connection step: &communicator.StepConnect{
Config: &b.config.RunConfig.Comm,
Host: awscommon.SSHHost(ec2conn, b.config.SSHInterface, b.config.Comm.Host()),
SSHPort: awscommon.Port(b.config.SSHInterface, b.config.Comm.Port()),
SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc()
}, The connection step is very very similar to what is in &communicator.StepConnect{
Config: comm,
Host: commHost((*comm).Host()),
SSHConfig: (*comm).SSHConfigFunc(),
}, So it seems like we are missing a key generation step here. It looks like they have their own custom key generation step, but the SSH communicator seems to have type StepSSHKeyGen struct {
CommConf *Config
SSHTemporaryKeyPair
}
// Run executes the Packer build step that generates SSH key pairs.
// The key pairs are added to the ssh config
func (s *StepSSHKeyGen) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packersdk.Ui)
comm := s.CommConf
if comm.SSHPrivateKeyFile != "" {
ui.Say("Using existing SSH private key")
privateKeyBytes, err := comm.ReadSSHPrivateKeyFile()
if err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
comm.SSHPrivateKey = privateKeyBytes
publicKeyBytes, err := sshkey.PublicKeyFromPrivate(privateKeyBytes)
if err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
comm.SSHPublicKey = publicKeyBytes
return multistep.ActionContinue
}
algorithm := s.SSHTemporaryKeyPair.SSHTemporaryKeyPairType
if algorithm == "" {
algorithm = sshkey.RSA.String()
}
a, err := sshkey.AlgorithmString(algorithm)
if err != nil {
err := fmt.Errorf("%w: possible algorithm types are `dsa` | `ecdsa` | `ed25519` | `rsa` ( the default )", err)
state.Put("error", err)
return multistep.ActionHalt
}
ui.Say(fmt.Sprintf("Creating temporary %s SSH key for instance...", strings.ToUpper(a.String())))
pair, err := sshkey.GeneratePair(a, nil, s.SSHTemporaryKeyPairBits)
if err != nil {
err := fmt.Errorf("Error creating temporary SSH key: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
comm.SSHPrivateKey = pair.Private
comm.SSHPublicKey = pair.Public
return multistep.ActionContinue
} |
I think after reading a TON more code I'm starting to understand something; but I have never written Go before, and I've only just touched Packer in the past week. So please be generous with the constructive criticism! |
Overview of the Issue
I am trying to avoid having to hardcode an SSH password or SSH key that will need to be changed/removed later. In the documentation it says:
When not specifying any
communicator
,ssh_username
,ssh_password
, orssh_private_key_file
, it complains about needing anssh_username
(which matches the above statement about SSH being used by default; and the fact that the variable is required by the SSH communicator).After supplying it with
ssh_username
I would expect it to generate a temporary key pair to be given to cloud-init, use those credentials to provision, and then remove them from the system. However, it looks like it tries to authenticate with method "none" and inspecting the server created, the key is not in anyauthorized_keys
files.Reproduction Steps
In my specific instance I was creating an ubuntu-24.04.1 template from the official ISO and passing a CD with the
meta-data
anduser-data
(autoinstall) files (which should include cloud-init options). I'm running Packer in the official Packer docker container with no modifications.I run
init
,validate
, andbuild
in the docker container, and it works as expected until my above issue:meta-data
anduser-data
boot_command
from source to instruct it to use the mounted cidata CDSoftware Versions
Docker Version
Packer Docker Image
Packer Version
proxmox Plugin Version
Proxmox Version
Simplified Packer Buildfile
Removed everything that didn't seem pertinent to how keys should be created/deployed. Can add more detail later if need be.
Log Fragments and crash.log files
The text was updated successfully, but these errors were encountered: