Skip to content
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

Setting ssh_private_key_file fails with linode error #18

Closed
pingiun opened this issue Jul 20, 2021 · 1 comment · Fixed by #23
Closed

Setting ssh_private_key_file fails with linode error #18

pingiun opened this issue Jul 20, 2021 · 1 comment · Fixed by #23
Labels
bug issues that report a bug

Comments

@pingiun
Copy link

pingiun commented Jul 20, 2021

Overview of the Issue

I tried to set the ssh_private_key_file to make sure I can use the same SSH key after setting up a Linode with NixOS. First I tried using https://www.packer.io/docs/datasources/sshkey, then I tried using my own private key but they both fail.

Build 'linode.example' errored after 838 milliseconds 558 microseconds: Error creating Linode: [400] [authorized_keys] SSH Key 1 key-type must be ssh-dss, ssh-rsa, ecdsa-sha2-nistp, or ssh-ed25519.

Reproduction Steps

Use the linode example config, this still works:

locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }

source "linode" "example" {
  image             = "linode/debian9"
  image_description = "My Private Image"
  image_label       = "private-image-${local.timestamp}"
  instance_label    = "temporary-linode-${local.timestamp}"
  instance_type     = "g6-nanode-1"
  linode_token      = "YOUR API TOKEN"
  region            = "us-east"
  ssh_username      = "root"
}

build {
  sources = ["source.linode.example"]
}

Now add any private key using the ssh_private_key_file option, as stated in the docs. Provisioning now fails.

Plugin and Packer version

Packer v1.7.3

packer-plugin-linode_v1.0.0_x5.0_darwin_amd64

Simplified Packer Buildfile

Reproducable build file
packer {
  required_plugins {
    linode = {
      version = ">= 0.0.1"
      source  = "github.com/hashicorp/linode"
    }
    sshkey = {
      version = ">= 0.1.0"
      source  = "github.com/ivoronin/sshkey"
    }
  }
}

locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }


variable "linode_token" {
  type      = string
  sensitive = true
}

source "linode" "example" {
  image                = "linode/debian9"
  image_description    = "NixOS"
  image_label          = "nixos-${local.timestamp}"
  instance_label       = "packer-build-${local.timestamp}"
  instance_type        = "g6-standard-2"
  linode_token         = var.linode_token
  region               = "us-east"
  ssh_username         = "root"
  ssh_private_key_file = data.sshkey.install.private_key_path
}

data "sshkey" "install" {}

build {
  sources = ["source.linode.example"]
}

Operating system and Environment details

running from MacOS (but via nix), trying to install NixOS with NIXOS_LUSTRATE on a debian 9 base.

Log Fragments and crash.log files

Full logs
2021/07/20 18:03:20 [INFO] Packer version: 1.7.3 [go1.16.6 darwin amd64]
2021/07/20 18:03:20 [TRACE] discovering plugins in /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin
2021/07/20 18:03:20 [TRACE] discovering plugins in /Users/jelle/.packer.d/plugins
2021/07/20 18:03:20 [TRACE] discovering plugins in .
2021/07/20 18:03:20 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2021/07/20 18:03:20 [INFO] PACKER_CONFIG env var set; attempting to open config file: /Users/jelle/.packerconfig
2021/07/20 18:03:20 [WARN] Config file doesn't exist: /Users/jelle/.packerconfig
2021/07/20 18:03:20 [INFO] Setting cache directory: /Users/jelle/dev/projects/peertube-saas/nixos-packer/packer_cache
2021/07/20 18:03:20 [TRACE] init: plugingetter.ListInstallationsOptions{FromFolders:[]string{"/nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer", ".", "/Users/jelle/.packer.d/plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"darwin", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc000086480)}}}}
2021/07/20 18:03:20 [TRACE] listing potential installations for "github.com/hashicorp/linode" that match ">= 0.0.1". plugingetter.ListInstallationsOptions{FromFolders:[]string{"/nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer", ".", "/Users/jelle/.packer.d/plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"darwin", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc000086480)}}}}
2021/07/20 18:03:20 [TRACE] for plugin github.com/hashicorp/linode found 1 matching installation(s)
2021/07/20 18:03:20 [TRACE] listing potential installations for "github.com/ivoronin/sshkey" that match ">= 0.1.0". plugingetter.ListInstallationsOptions{FromFolders:[]string{"/nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer", ".", "/Users/jelle/.packer.d/plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"darwin", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc000086480)}}}}
2021/07/20 18:03:20 [TRACE] for plugin github.com/ivoronin/sshkey found 1 matching installation(s)
2021/07/20 18:03:20 [INFO] (telemetry) Finalizing.
2021/07/20 18:03:20 waiting for all plugin processes to complete...
2021/07/20 18:03:21 [INFO] Packer version: 1.7.3 [go1.16.6 darwin amd64]
2021/07/20 18:03:21 [TRACE] discovering plugins in /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin
2021/07/20 18:03:21 [TRACE] discovering plugins in /Users/jelle/.packer.d/plugins
2021/07/20 18:03:21 [TRACE] discovering plugins in .
2021/07/20 18:03:21 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2021/07/20 18:03:21 [INFO] PACKER_CONFIG env var set; attempting to open config file: /Users/jelle/.packerconfig
2021/07/20 18:03:21 [WARN] Config file doesn't exist: /Users/jelle/.packerconfig
2021/07/20 18:03:21 [INFO] Setting cache directory: /Users/jelle/.cache/packer
2021/07/20 18:03:21 [TRACE] listing potential installations for "github.com/hashicorp/linode" that match ">= 0.0.1". plugingetter.ListInstallationsOptions{FromFolders:[]string{"/nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer", ".", "/Users/jelle/.packer.d/plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"darwin", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc000086600)}}}}
2021/07/20 18:03:21 [TRACE] Found the following "github.com/hashicorp/linode" installations: [{/Users/jelle/.packer.d/plugins/github.com/hashicorp/linode/packer-plugin-linode_v1.0.0_x5.0_darwin_amd64 v1.0.0}]
2021/07/20 18:03:21 [INFO] found external [-packer-default-plugin-name-] builders from linode plugin
2021/07/20 18:03:21 [TRACE] listing potential installations for "github.com/ivoronin/sshkey" that match ">= 0.1.0". plugingetter.ListInstallationsOptions{FromFolders:[]string{"/nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer", ".", "/Users/jelle/.packer.d/plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"darwin", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc000086600)}}}}
2021/07/20 18:03:21 [TRACE] Found the following "github.com/ivoronin/sshkey" installations: [{/Users/jelle/.packer.d/plugins/github.com/ivoronin/sshkey/packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64 v0.1.0}]
2021/07/20 18:03:21 found external [-packer-default-plugin-name-] datasource from sshkey plugin
2021/07/20 18:03:21 [TRACE] validateValue: not active for linode_token, so skipping
2021/07/20 18:03:21 [TRACE] validateValue: not active for nixos_version, so skipping
2021/07/20 18:03:21 [TRACE] Starting external plugin /Users/jelle/.packer.d/plugins/github.com/ivoronin/sshkey/packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64 start datasource -packer-default-plugin-name-
2021/07/20 18:03:21 Starting plugin: /Users/jelle/.packer.d/plugins/github.com/ivoronin/sshkey/packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64 []string{"/Users/jelle/.packer.d/plugins/github.com/ivoronin/sshkey/packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64", "start", "datasource", "-packer-default-plugin-name-"}
2021/07/20 18:03:21 Waiting for RPC address for: /Users/jelle/.packer.d/plugins/github.com/ivoronin/sshkey/packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64
2021/07/20 18:03:21 packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64 plugin: 2021/07/20 18:03:21 Plugin address: unix /tmp/packer-plugin602722078
2021/07/20 18:03:21 packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64 plugin: 2021/07/20 18:03:21 Waiting for connection...
2021/07/20 18:03:21 Received unix RPC address for /Users/jelle/.packer.d/plugins/github.com/ivoronin/sshkey/packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64: addr is /tmp/packer-plugin602722078
2021/07/20 18:03:21 packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64 plugin: 2021/07/20 18:03:21 Serving a plugin connection...
2021/07/20 18:03:21 packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64 plugin: 2021/07/20 18:03:21 [TRACE] starting datasource -packer-default-plugin-name-
2021/07/20 18:03:21 [TRACE] Starting external plugin /Users/jelle/.packer.d/plugins/github.com/hashicorp/linode/packer-plugin-linode_v1.0.0_x5.0_darwin_amd64 start builder -packer-default-plugin-name-
2021/07/20 18:03:21 Starting plugin: /Users/jelle/.packer.d/plugins/github.com/hashicorp/linode/packer-plugin-linode_v1.0.0_x5.0_darwin_amd64 []string{"/Users/jelle/.packer.d/plugins/github.com/hashicorp/linode/packer-plugin-linode_v1.0.0_x5.0_darwin_amd64", "start", "builder", "-packer-default-plugin-name-"}
2021/07/20 18:03:21 Waiting for RPC address for: /Users/jelle/.packer.d/plugins/github.com/hashicorp/linode/packer-plugin-linode_v1.0.0_x5.0_darwin_amd64
2021/07/20 18:03:21 packer-plugin-linode_v1.0.0_x5.0_darwin_amd64 plugin: 2021/07/20 18:03:21 Plugin address: unix /tmp/packer-plugin264359411
2021/07/20 18:03:21 Received unix RPC address for /Users/jelle/.packer.d/plugins/github.com/hashicorp/linode/packer-plugin-linode_v1.0.0_x5.0_darwin_amd64: addr is /tmp/packer-plugin264359411
2021/07/20 18:03:21 packer-plugin-linode_v1.0.0_x5.0_darwin_amd64 plugin: 2021/07/20 18:03:21 Waiting for connection...
2021/07/20 18:03:21 packer-plugin-linode_v1.0.0_x5.0_darwin_amd64 plugin: 2021/07/20 18:03:21 Serving a plugin connection...
2021/07/20 18:03:21 packer-plugin-linode_v1.0.0_x5.0_darwin_amd64 plugin: 2021/07/20 18:03:21 [TRACE] starting builder -packer-default-plugin-name-
2021/07/20 18:03:21 [TRACE] Starting internal plugin packer-provisioner-file
2021/07/20 18:03:21 Starting plugin: /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer []string{"/nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer", "plugin", "packer-provisioner-file"}
2021/07/20 18:03:21 Waiting for RPC address for: /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer
2021/07/20 18:03:21 packer-provisioner-file plugin: [INFO] Packer version: 1.7.3 [go1.16.6 darwin amd64]
2021/07/20 18:03:21 packer-provisioner-file plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2021/07/20 18:03:21 packer-provisioner-file plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /Users/jelle/.packerconfig
2021/07/20 18:03:21 packer-provisioner-file plugin: [WARN] Config file doesn't exist: /Users/jelle/.packerconfig
2021/07/20 18:03:21 packer-provisioner-file plugin: [INFO] Setting cache directory: /Users/jelle/.cache/packer
2021/07/20 18:03:21 packer-provisioner-file plugin: args: []string{"packer-provisioner-file"}
2021/07/20 18:03:21 Received unix RPC address for /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer: addr is /tmp/packer-plugin479551696
2021/07/20 18:03:21 packer-provisioner-file plugin: Plugin address: unix /tmp/packer-plugin479551696
2021/07/20 18:03:21 packer-provisioner-file plugin: Waiting for connection...
2021/07/20 18:03:21 packer-provisioner-file plugin: Serving a plugin connection...
2021/07/20 18:03:21 [TRACE] Starting internal plugin packer-provisioner-shell
2021/07/20 18:03:21 Starting plugin: /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer []string{"/nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer", "plugin", "packer-provisioner-shell"}
2021/07/20 18:03:21 Waiting for RPC address for: /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer
2021/07/20 18:03:22 packer-provisioner-shell plugin: [INFO] Packer version: 1.7.3 [go1.16.6 darwin amd64]
2021/07/20 18:03:22 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2021/07/20 18:03:22 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /Users/jelle/.packerconfig
2021/07/20 18:03:22 packer-provisioner-shell plugin: [WARN] Config file doesn't exist: /Users/jelle/.packerconfig
2021/07/20 18:03:22 packer-provisioner-shell plugin: [INFO] Setting cache directory: /Users/jelle/.cache/packer
2021/07/20 18:03:22 packer-provisioner-shell plugin: args: []string{"packer-provisioner-shell"}
2021/07/20 18:03:22 Received unix RPC address for /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer: addr is /tmp/packer-plugin202666409
2021/07/20 18:03:22 packer-provisioner-shell plugin: Plugin address: unix /tmp/packer-plugin202666409
2021/07/20 18:03:22 packer-provisioner-shell plugin: Waiting for connection...
2021/07/20 18:03:22 packer-provisioner-shell plugin: Serving a plugin connection...
2021/07/20 18:03:22 [TRACE] Starting internal plugin packer-provisioner-shell
2021/07/20 18:03:22 Starting plugin: /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer []string{"/nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer", "plugin", "packer-provisioner-shell"}
2021/07/20 18:03:22 Waiting for RPC address for: /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer
2021/07/20 18:03:22 packer-provisioner-shell plugin: [INFO] Packer version: 1.7.3 [go1.16.6 darwin amd64]
2021/07/20 18:03:22 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2021/07/20 18:03:22 packer-provisioner-shell plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /Users/jelle/.packerconfig
2021/07/20 18:03:22 packer-provisioner-shell plugin: [WARN] Config file doesn't exist: /Users/jelle/.packerconfig
2021/07/20 18:03:22 packer-provisioner-shell plugin: [INFO] Setting cache directory: /Users/jelle/.cache/packer
2021/07/20 18:03:22 packer-provisioner-shell plugin: args: []string{"packer-provisioner-shell"}
2021/07/20 18:03:22 packer-provisioner-shell plugin: Plugin address: unix /tmp/packer-plugin507125290
2021/07/20 18:03:22 packer-provisioner-shell plugin: Waiting for connection...
2021/07/20 18:03:22 Received unix RPC address for /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer: addr is /tmp/packer-plugin507125290
2021/07/20 18:03:22 packer-provisioner-shell plugin: Serving a plugin connection...
2021/07/20 18:03:22 Build debug mode: false
2021/07/20 18:03:22 Force build: false
2021/07/20 18:03:22 On error:
linode.example: output will be in this color.

2021/07/20 18:03:22 Waiting on builds to complete...
2021/07/20 18:03:22 Starting build run: linode.example
2021/07/20 18:03:22 Running builder:
2021/07/20 18:03:22 [INFO] (telemetry) Starting builder
==> linode.example: Running builder ...
==> linode.example: Using existing SSH private key
==> linode.example: Creating Linode...
==> linode.example: Error creating Linode: [400] [authorized_keys] SSH Key 1 key-type must be ssh-dss, ssh-rsa, ecdsa-sha2-nistp, or ssh-ed25519.
2021/07/20 18:03:23 [INFO] (telemetry) ending
==> Wait completed after 840 milliseconds 984 microseconds
2021/07/20 18:03:23 machine readable: error-count []string{"1"}
Build 'linode.example' errored after 838 milliseconds 558 microseconds: Error creating Linode: [400] [authorized_keys] SSH Key 1 key-type must be ssh-dss, ssh-rsa, ecdsa-sha2-nistp, or ssh-ed25519.
==> Some builds didn't complete successfully and had errors:

2021/07/20 18:03:23 machine readable: linode.example,error []string{"Error creating Linode: [400] [authorized_keys] SSH Key 1 key-type must be ssh-dss, ssh-rsa, ecdsa-sha2-nistp, or ssh-ed25519."}
==> Builds finished but no artifacts were created.
==> Wait completed after 840 milliseconds 984 microseconds

==> Some builds didn't complete successfully and had errors:
--> linode.example: Error creating Linode: [400] [authorized_keys] SSH Key 1 key-type must be ssh-dss, ssh-rsa, ecdsa-sha2-nistp, or ssh-ed25519.

2021/07/20 18:03:23 [INFO] (telemetry) Finalizing.
==> Builds finished but no artifacts were created.
2021/07/20 18:03:23 waiting for all plugin processes to complete...
2021/07/20 18:03:23 /Users/jelle/.packer.d/plugins/github.com/ivoronin/sshkey/packer-plugin-sshkey_v0.1.0_x5.0_darwin_amd64: plugin process exited
2021/07/20 18:03:23 /Users/jelle/.packer.d/plugins/github.com/hashicorp/linode/packer-plugin-linode_v1.0.0_x5.0_darwin_amd64: plugin process exited
2021/07/20 18:03:23 /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer: plugin process exited
2021/07/20 18:03:23 /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer: plugin process exited
2021/07/20 18:03:23 /nix/store/qn5pnsn5dchqbsy20ajzjpaqqk9hwzlc-packer-1.7.3/bin/packer: plugin process exited
@LBGarber
Copy link
Contributor

LBGarber commented Aug 27, 2021

Hey there! Just wanted to give a few thoughts on this issue.

I noticed there is an unimplemented/undocumented root_ssh_key option which could be used to specify additional authorized_keys for an instance.

I'm not sure if this would be idiomatic (Packer isn't my area of expertise), but adding an authorized key option along the lines of

AuthorizedKeys []string `mapstructure:"authorized_keys"`
// step_create_linode.go

if pubKey := string(c.Comm.SSHPublicKey); pubKey != "" {
	createOpts.AuthorizedKeys = append(createOpts.AuthorizedKeys, pubKey)
}

createOpts.AuthorizedKeys = append(createOpts.AuthorizedKeys, authorizedKeys...)

could enable this functionality and closely mirror the Linode API.

Alternatively users could manually upload a public key at build time.

I'm not sure if either of these solutions would really solve the underlying issue, but I thought I'd throw them out there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues that report a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants