From 2f3cb86455332336548b53a38e563fe2903c54bf Mon Sep 17 00:00:00 2001 From: Clinton Wolfe Date: Fri, 10 Jul 2020 15:29:00 -0400 Subject: [PATCH 1/2] Add filter on product code to ensure centos 6 and 7 come from official source Signed-off-by: Clinton Wolfe --- .../driver/aws/standard_platform/centos.rb | 15 +++++++++++++++ spec/kitchen/driver/aws/image_selection_spec.rb | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/lib/kitchen/driver/aws/standard_platform/centos.rb b/lib/kitchen/driver/aws/standard_platform/centos.rb index 9a116d3b..fbe05777 100644 --- a/lib/kitchen/driver/aws/standard_platform/centos.rb +++ b/lib/kitchen/driver/aws/standard_platform/centos.rb @@ -23,6 +23,13 @@ class StandardPlatform class Centos < StandardPlatform StandardPlatform.platforms["centos"] = self + PRODUCT_CODES = { + "6" => "6x5jmcajty9edm3f211pqjfn2", + "7" => "aw0evgkw8e5c1q413zgy5pjce", + # It appears that v8 is not published to the + # AWS marketplace and hence does not have a product code + }.freeze + # default username for this platform's ami # @return [String] def username @@ -38,6 +45,14 @@ def image_search "owner-alias" => "aws-marketplace", "name" => ["CentOS Linux #{version}*", "CentOS-#{version}*-GA-*"], } + # Additionally filter on product code if known for major version to + # avoid non-official AMIs + # https://github.com/test-kitchen/kitchen-ec2/issues/456 + if version + PRODUCT_CODES.keys.each do |major_version| + search["product-code"] = PRODUCT_CODES[major_version] if version.start_with?(major_version) + end + end search["architecture"] = architecture if architecture search end diff --git a/spec/kitchen/driver/aws/image_selection_spec.rb b/spec/kitchen/driver/aws/image_selection_spec.rb index 6a3b4f2a..0fa93a51 100644 --- a/spec/kitchen/driver/aws/image_selection_spec.rb +++ b/spec/kitchen/driver/aws/image_selection_spec.rb @@ -85,14 +85,17 @@ def new_instance(platform_name: "blarghle") "centos-7" => [ { name: "owner-alias", values: %w{aws-marketplace} }, { name: "name", values: ["CentOS Linux 7*", "CentOS-7*-GA-*"] }, + { name: "product-code", values: ["aw0evgkw8e5c1q413zgy5pjce"] }, ], "centos-6" => [ { name: "owner-alias", values: %w{aws-marketplace} }, { name: "name", values: ["CentOS Linux 6*", "CentOS-6*-GA-*"] }, + { name: "product-code", values: ["6x5jmcajty9edm3f211pqjfn2"] }, ], "centos-6.3" => [ { name: "owner-alias", values: %w{aws-marketplace} }, { name: "name", values: ["CentOS Linux 6.3*", "CentOS-6.3*-GA-*"] }, + { name: "product-code", values: ["6x5jmcajty9edm3f211pqjfn2"] }, ], "centos-x86_64" => [ { name: "owner-alias", values: %w{aws-marketplace} }, @@ -102,11 +105,13 @@ def new_instance(platform_name: "blarghle") "centos-6.3-x86_64" => [ { name: "owner-alias", values: %w{aws-marketplace} }, { name: "name", values: ["CentOS Linux 6.3*", "CentOS-6.3*-GA-*"] }, + { name: "product-code", values: ["6x5jmcajty9edm3f211pqjfn2"] }, { name: "architecture", values: %w{x86_64} }, ], "centos-7-x86_64" => [ { name: "owner-alias", values: %w{aws-marketplace} }, { name: "name", values: ["CentOS Linux 7*", "CentOS-7*-GA-*"] }, + { name: "product-code", values: ["aw0evgkw8e5c1q413zgy5pjce"] }, { name: "architecture", values: %w{x86_64} }, ], From a98cb1c7f554fb40d33c4ebc0e5b3e204af55a2d Mon Sep 17 00:00:00 2001 From: Clinton Wolfe Date: Fri, 10 Jul 2020 16:19:52 -0400 Subject: [PATCH 2/2] Update to properly search for centos 8 Signed-off-by: Clinton Wolfe --- .../driver/aws/standard_platform/centos.rb | 20 +++++++++++++------ .../driver/aws/image_selection_spec.rb | 12 +++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/kitchen/driver/aws/standard_platform/centos.rb b/lib/kitchen/driver/aws/standard_platform/centos.rb index fbe05777..97025b0a 100644 --- a/lib/kitchen/driver/aws/standard_platform/centos.rb +++ b/lib/kitchen/driver/aws/standard_platform/centos.rb @@ -23,6 +23,7 @@ class StandardPlatform class Centos < StandardPlatform StandardPlatform.platforms["centos"] = self + CENTOS_OWNER_ID = "125523088429".freeze PRODUCT_CODES = { "6" => "6x5jmcajty9edm3f211pqjfn2", "7" => "aw0evgkw8e5c1q413zgy5pjce", @@ -41,14 +42,21 @@ def username end def image_search + # Version 8+ are published directly, not to the AWS marketplace. Use OWNER ID. search = { - "owner-alias" => "aws-marketplace", - "name" => ["CentOS Linux #{version}*", "CentOS-#{version}*-GA-*"], + "owner-id" => CENTOS_OWNER_ID, + "name" => ["CentOS #{version}*", "CentOS-#{version}*-GA-*"], } - # Additionally filter on product code if known for major version to - # avoid non-official AMIs - # https://github.com/test-kitchen/kitchen-ec2/issues/456 - if version + + if version && version.split(".").first.to_i < 8 + # Versions <8 are published to the AWS marketplace and use a different naming convention + search = { + "owner-alias" => "aws-marketplace", + "name" => ["CentOS Linux #{version}*", "CentOS-#{version}*-GA-*"], + } + # For versions published to aws-marketplace, additionally filter on product code to + # avoid non-official AMIs. Can't use CentOS owner ID here, as the owner ID is that of aws marketplace. + # https://github.com/test-kitchen/kitchen-ec2/issues/456 PRODUCT_CODES.keys.each do |major_version| search["product-code"] = PRODUCT_CODES[major_version] if version.start_with?(major_version) end diff --git a/spec/kitchen/driver/aws/image_selection_spec.rb b/spec/kitchen/driver/aws/image_selection_spec.rb index 0fa93a51..60c04a88 100644 --- a/spec/kitchen/driver/aws/image_selection_spec.rb +++ b/spec/kitchen/driver/aws/image_selection_spec.rb @@ -79,8 +79,12 @@ def new_instance(platform_name: "blarghle") ], "centos" => [ - { name: "owner-alias", values: %w{aws-marketplace} }, - { name: "name", values: ["CentOS Linux *", "CentOS-*-GA-*"] }, + { name: "owner-id", values: %w{125523088429} }, + { name: "name", values: ["CentOS *", "CentOS-*-GA-*"] }, + ], + "centos-8" => [ + { name: "owner-id", values: %w{125523088429} }, + { name: "name", values: ["CentOS 8*", "CentOS-8*-GA-*"] }, ], "centos-7" => [ { name: "owner-alias", values: %w{aws-marketplace} }, @@ -98,8 +102,8 @@ def new_instance(platform_name: "blarghle") { name: "product-code", values: ["6x5jmcajty9edm3f211pqjfn2"] }, ], "centos-x86_64" => [ - { name: "owner-alias", values: %w{aws-marketplace} }, - { name: "name", values: ["CentOS Linux *", "CentOS-*-GA-*"] }, + { name: "owner-id", values: %w{125523088429} }, + { name: "name", values: ["CentOS *", "CentOS-*-GA-*"] }, { name: "architecture", values: %w{x86_64} }, ], "centos-6.3-x86_64" => [