diff --git a/builder/ebs/builder_acc_test.go b/builder/ebs/builder_acc_test.go index d462ede01..1b002018b 100644 --- a/builder/ebs/builder_acc_test.go +++ b/builder/ebs/builder_acc_test.go @@ -489,7 +489,7 @@ func TestAccBuilder_EbsRunTagsJSON(t *testing.T) { acctest.TestPlugin(t, testcase) } -//go:embed test-fixtures/rsa_ssh_keypair.pkr.hcl +//go:embed test-fixtures/ssh-keys/rsa_ssh_keypair.pkr.hcl var testSSHKeyPairRSA string func TestAccBuilder_EbsKeyPair_rsa(t *testing.T) { @@ -526,7 +526,7 @@ func TestAccBuilder_EbsKeyPair_rsa(t *testing.T) { acctest.TestPlugin(t, testcase) } -//go:embed test-fixtures/ed25519_ssh_keypair.pkr.hcl +//go:embed test-fixtures/ssh-keys/ed25519_ssh_keypair.pkr.hcl var testSSHKeyPairED25519 string func TestAccBuilder_EbsKeyPair_ed25519(t *testing.T) { @@ -563,6 +563,42 @@ func TestAccBuilder_EbsKeyPair_ed25519(t *testing.T) { acctest.TestPlugin(t, testcase) } +//go:embed test-fixtures/ssh-keys/rsa_sha2_only_server.pkr.hcl +var testRSASHA2OnlyServer string + +func TestAccBuilder_EbsKeyPair_rsaSHA2OnlyServer(t *testing.T) { + testcase := &acctest.PluginTestCase{ + Name: "amazon-ebs_rsa_sha2_srv_test", + Template: testRSASHA2OnlyServer, + Check: func(buildCommand *exec.Cmd, logfile string) error { + if buildCommand.ProcessState.ExitCode() != 0 { + return fmt.Errorf("Bad exit code. Logfile: %s", logfile) + } + logs, err := os.Open(logfile) + if err != nil { + return fmt.Errorf("Unable find %s", logfile) + } + defer logs.Close() + + logsBytes, err := ioutil.ReadAll(logs) + if err != nil { + return fmt.Errorf("Unable to read %s", logfile) + } + logsString := string(logsBytes) + + re := regexp.MustCompile(`amazon-ebs.basic-example:\s+Successful login`) + matched := re.FindString(logsString) + + if matched == "" { + return fmt.Errorf("unable to success string from %q", logfile) + } + + return nil + }, + } + acctest.TestPlugin(t, testcase) +} + func testEC2Conn() (*ec2.EC2, error) { access := &common.AccessConfig{RawRegion: "us-east-1"} session, err := access.Session() diff --git a/builder/ebs/test-fixtures/ed25519_ssh_keypair.pkr.hcl b/builder/ebs/test-fixtures/ssh-keys/ed25519_ssh_keypair.pkr.hcl similarity index 100% rename from builder/ebs/test-fixtures/ed25519_ssh_keypair.pkr.hcl rename to builder/ebs/test-fixtures/ssh-keys/ed25519_ssh_keypair.pkr.hcl diff --git a/builder/ebs/test-fixtures/ssh-keys/rsa_sha2_only_server.pkr.hcl b/builder/ebs/test-fixtures/ssh-keys/rsa_sha2_only_server.pkr.hcl new file mode 100644 index 000000000..58a2a715b --- /dev/null +++ b/builder/ebs/test-fixtures/ssh-keys/rsa_sha2_only_server.pkr.hcl @@ -0,0 +1,40 @@ +/* +OpenSSH migrated the ssh-rsa key type, which historically used the ssh-rsa +signature algorithm based on SHA-1, to the new rsa-sha2-256 and rsa-sha2-512 signature algorithms. + +Golang issues: https://github.com/golang/go/issues/49952 + +See plugin issue: https://github.com/hashicorp/packer-plugin-amazon/issues/213 +*/ + +data "amazon-ami" "autogenerated_1" { + filters = { + name = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" + root-device-type = "ebs" + virtualization-type = "hvm" + } + most_recent = true + owners = ["099720109477"] + region = "us-east-1" +} + +locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") } + +source "amazon-ebs" "basic-example" { + ami_description = "Ubuntu 22.04 GoldenImage" + ami_name = "ubuntu-22.04-${local.timestamp}" + instance_type = "t3.micro" + region = "us-east-1" + source_ami = "${data.amazon-ami.autogenerated_1.id}" + ssh_username = "ubuntu" + skip_create_ami = true +} + +build { + sources = ["source.amazon-ebs.basic-example"] + + provisioner "shell" { + inline = ["echo Successful login"] + } + +} diff --git a/builder/ebs/test-fixtures/rsa_ssh_keypair.pkr.hcl b/builder/ebs/test-fixtures/ssh-keys/rsa_ssh_keypair.pkr.hcl similarity index 100% rename from builder/ebs/test-fixtures/rsa_ssh_keypair.pkr.hcl rename to builder/ebs/test-fixtures/ssh-keys/rsa_ssh_keypair.pkr.hcl diff --git a/go.mod b/go.mod index 061cc634d..68382f61b 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,8 @@ require ( github.com/hashicorp/aws-sdk-go-base v0.7.1 github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/go-multierror v1.1.1 - github.com/hashicorp/hcl/v2 v2.11.1 - github.com/hashicorp/packer-plugin-sdk v0.2.11 + github.com/hashicorp/hcl/v2 v2.12.0 + github.com/hashicorp/packer-plugin-sdk v0.2.12 github.com/hashicorp/vault/api v1.1.1 github.com/mitchellh/mapstructure v1.4.1 github.com/stretchr/testify v1.7.0 @@ -41,7 +41,7 @@ require ( github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-getter/gcs/v2 v2.0.0-20200604122502-a6995fa1edad // indirect github.com/hashicorp/go-getter/s3/v2 v2.0.0-20200604122502-a6995fa1edad // indirect - github.com/hashicorp/go-getter/v2 v2.0.0 // indirect + github.com/hashicorp/go-getter/v2 v2.0.2 // indirect github.com/hashicorp/go-hclog v0.16.2 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-retryablehttp v0.7.0 // indirect @@ -76,7 +76,7 @@ require ( github.com/ugorji/go/codec v1.2.6 // indirect github.com/ulikunitz/xz v0.5.10 // indirect go.opencensus.io v0.23.0 // indirect - golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect + golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect diff --git a/go.sum b/go.sum index 16144164c..f20ba3455 100644 --- a/go.sum +++ b/go.sum @@ -294,8 +294,8 @@ github.com/hashicorp/go-getter/gcs/v2 v2.0.0-20200604122502-a6995fa1edad/go.mod github.com/hashicorp/go-getter/s3/v2 v2.0.0-20200604122502-a6995fa1edad h1:hwk5mQRwVvZc/f+So1kHbOhW/f7P2fEcCr2D5pSk9sI= github.com/hashicorp/go-getter/s3/v2 v2.0.0-20200604122502-a6995fa1edad/go.mod h1:kcB6Mv+0wzYXbQjTAeD/Pb85145WcFk2EElpe02fuoE= github.com/hashicorp/go-getter/v2 v2.0.0-20200511090339-3107ec4af37a/go.mod h1:QJ+LwRM91JBKBLyHoKBrcmi49i9Tu/ItpgTNXWSnpGM= -github.com/hashicorp/go-getter/v2 v2.0.0 h1:wamdcQazMBZK6VwUo3HAOWLkcOJBWBoXPKfmf7/S17w= -github.com/hashicorp/go-getter/v2 v2.0.0/go.mod h1:w65fE5glbccYjndAuj1kA5lnVBGZYEaH0e5qA1kpIks= +github.com/hashicorp/go-getter/v2 v2.0.2 h1:HzjjbWeXm/FQVJONiBUAGYAi/RMCeC7i7ZzARSD9u7A= +github.com/hashicorp/go-getter/v2 v2.0.2/go.mod h1:w65fE5glbccYjndAuj1kA5lnVBGZYEaH0e5qA1kpIks= github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= @@ -345,14 +345,14 @@ github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+l github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/hcl/v2 v2.11.1 h1:yTyWcXcm9XB0TEkyU/JCRU6rYy4K+mgLtzn2wlrJbcc= -github.com/hashicorp/hcl/v2 v2.11.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= +github.com/hashicorp/hcl/v2 v2.12.0 h1:PsYxySWpMD4KPaoJLnsHwtK5Qptvj/4Q6s0t4sUxZf4= +github.com/hashicorp/hcl/v2 v2.12.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC7AO2g= github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= -github.com/hashicorp/packer-plugin-sdk v0.2.11 h1:FsL2oOfLJmXC9F6W9eMFe0eUi3+ggFuqkLGX41fyPE0= -github.com/hashicorp/packer-plugin-sdk v0.2.11/go.mod h1:DI8REf9TEIcVkYPErI/nedo6zS2h81ze7sKuc/mIlTE= +github.com/hashicorp/packer-plugin-sdk v0.2.12 h1:YYvNPPayNFfr8L7hR2QkC2s/PE93oOCCnEFwFavjKiM= +github.com/hashicorp/packer-plugin-sdk v0.2.12/go.mod h1:/smseyg0inyxWv1B+XWppPU0FJz2hwIzFOM172U3i0Y= github.com/hashicorp/serf v0.9.5 h1:EBWvyu9tcRszt3Bxp3KNssBMP1KuHWyO51lz9+786iM= github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/hashicorp/vault/api v1.0.5-0.20200519221902-385fac77e20f/go.mod h1:euTFbi2YJgwcju3imEt919lhJKF68nN1cQPq3aA+kBE= @@ -582,8 +582,8 @@ golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc= +golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -668,7 +668,7 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210825183410-e898025ed96a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM= golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=