From c82cbdacad3f60ffa46904d3e8dc32222c1c6204 Mon Sep 17 00:00:00 2001 From: Derek Nola Date: Tue, 6 Feb 2024 16:30:21 -0800 Subject: [PATCH] [E2E] Secrets Encryption test (#5234) * Add e2e for secrets encryption Signed-off-by: Derek Nola * Cleanup vagrant files Signed-off-by: Derek Nola * Add support for the classic secrets-encyrption rotate workflow Signed-off-by: Derek Nola --------- Signed-off-by: Derek Nola --- tests/e2e/dualstack/Vagrantfile | 5 +- tests/e2e/mixedos/Vagrantfile | 5 +- tests/e2e/resource_files/secrets.yaml | 49 ++++ tests/e2e/secretsencryption/Vagrantfile | 83 +++++++ .../secretsencryption_test.go | 145 +++++++++++ tests/e2e/secretsencryption_old/Vagrantfile | 83 +++++++ .../secretsencryption_test.go | 235 ++++++++++++++++++ tests/e2e/splitserver/Vagrantfile | 4 +- tests/e2e/upgradecluster/Vagrantfile | 5 +- tests/e2e/validatecluster/Vagrantfile | 5 +- 10 files changed, 600 insertions(+), 19 deletions(-) create mode 100644 tests/e2e/resource_files/secrets.yaml create mode 100644 tests/e2e/secretsencryption/Vagrantfile create mode 100644 tests/e2e/secretsencryption/secretsencryption_test.go create mode 100644 tests/e2e/secretsencryption_old/Vagrantfile create mode 100644 tests/e2e/secretsencryption_old/secretsencryption_test.go diff --git a/tests/e2e/dualstack/Vagrantfile b/tests/e2e/dualstack/Vagrantfile index b356c1d83f..67ae2298a5 100644 --- a/tests/e2e/dualstack/Vagrantfile +++ b/tests/e2e/dualstack/Vagrantfile @@ -104,10 +104,7 @@ Vagrant.configure("2") do |config| NODE_BOXES = NODE_BOXES.split(" ", -1) end - # Must iterate on the index, vagrant does not understand iterating - # over the node roles themselves - NODE_ROLES.length.times do |i| - name = NODE_ROLES[i] + NODE_ROLES.each_with_index do |name, i| config.vm.define name do |node| roles = name.split("-", -1) role_num = roles.pop.to_i diff --git a/tests/e2e/mixedos/Vagrantfile b/tests/e2e/mixedos/Vagrantfile index 12398f2f08..bd176ef0fc 100644 --- a/tests/e2e/mixedos/Vagrantfile +++ b/tests/e2e/mixedos/Vagrantfile @@ -135,10 +135,7 @@ Vagrant.configure("2") do |config| NODE_BOXES = NODE_BOXES.split(" ", -1) end - # Must iterate on the index, vagrant does not understand iterating - # over the node roles themselves - NODE_ROLES.length.times do |i| - name = NODE_ROLES[i] + NODE_ROLES.each_with_index do |name, i| config.vm.define name do |node| role_num = name.split("-", -1).pop.to_i provision(node.vm, name, role_num, i) diff --git a/tests/e2e/resource_files/secrets.yaml b/tests/e2e/resource_files/secrets.yaml new file mode 100644 index 0000000000..3f8d060685 --- /dev/null +++ b/tests/e2e/resource_files/secrets.yaml @@ -0,0 +1,49 @@ +apiVersion: v1 +kind: Secret +metadata: + name: e2e-secret1 +type: Opaque +stringData: + config.yaml: | + key: "hello" + val: "world" +--- +apiVersion: v1 +kind: Secret +metadata: + name: e2e-secret2 +type: Opaque +stringData: + config.yaml: | + key: "good" + val: "day" +--- +apiVersion: v1 +kind: Secret +metadata: + name: e2e-secret3 +type: Opaque +stringData: + config.yaml: | + key: "top-secret" + val: "information" +--- +apiVersion: v1 +kind: Secret +metadata: + name: e2e-secret4 +type: Opaque +stringData: + config.yaml: | + key: "lock" + val: "key" +--- +apiVersion: v1 +kind: Secret +metadata: + name: e2e-secret5 +type: Opaque +stringData: + config.yaml: | + key: "last" + val: "call" \ No newline at end of file diff --git a/tests/e2e/secretsencryption/Vagrantfile b/tests/e2e/secretsencryption/Vagrantfile new file mode 100644 index 0000000000..f0f7e749d1 --- /dev/null +++ b/tests/e2e/secretsencryption/Vagrantfile @@ -0,0 +1,83 @@ +ENV['VAGRANT_NO_PARALLEL'] = 'no' +NODE_ROLES = (ENV['E2E_NODE_ROLES'] || ["server-0", "server-1", "server-2"]) +NODE_BOXES = (ENV['E2E_NODE_BOXES'] || ['generic/ubuntu2204', 'generic/ubuntu2204', 'generic/ubuntu2204']) +GITHUB_BRANCH = (ENV['E2E_GITHUB_BRANCH'] || "master") +RELEASE_VERSION = (ENV['E2E_RELEASE_VERSION'] || "") +NODE_CPUS = (ENV['E2E_NODE_CPUS'] || 2).to_i +NODE_MEMORY = (ENV['E2E_NODE_MEMORY'] || 3072).to_i +REGISTRY = (ENV['E2E_REGISTRY'] || "") +# Virtualbox >= 6.1.28 require `/etc/vbox/network.conf` for expanded private networks, +# see https://www.virtualbox.org/manual/ch06.html#network_hostonly +NETWORK_PREFIX = "10.10.10" + +def provision(vm, roles, role_num, node_num) + vm.box = NODE_BOXES[node_num] + vm.hostname = "#{roles[0]}-#{role_num}" + # An expanded netmask is required to allow VM<-->VM communication, virtualbox defaults to /32 + node_ip = "#{NETWORK_PREFIX}.#{100+node_num}" + vm.network "private_network", ip: node_ip, netmask: "255.255.255.0" + + scripts_location = Dir.exists?("./scripts") ? "./scripts" : "../scripts" + vagrant_defaults = File.exists?("./vagrantdefaults.rb") ? "./vagrantdefaults.rb" : "../vagrantdefaults.rb" + load vagrant_defaults + + defaultOSConfigure(vm) + install_type = getInstallType(vm, RELEASE_VERSION, GITHUB_BRANCH) + + vm.provision "shell", inline: "ping -c 2 rke2.io" + + if !REGISTRY.empty? + vm.provision "Set private registry", type: "shell", path: scripts_location + "/registry.sh", args: [ "#{NETWORK_PREFIX}.1" ] + end + + if roles.include?("server") && role_num == 0 + vm.provision :rke2, run: 'once' do |rke2| + rke2.env = %W[INSTALL_RKE2_TYPE=server #{install_type}] + rke2.config = <<~YAML + write-kubeconfig-mode: '0644' + node-external-ip: #{NETWORK_PREFIX}.100 + node-ip: #{NETWORK_PREFIX}.100 + token: vagrant-rke2 + YAML + end + elsif roles.include?("server") && role_num != 0 + vm.provision :rke2, run: 'once' do |rke2| + rke2.env = %W[INSTALL_RKE2_TYPE=server #{install_type}] + rke2.config = <<~YAML + write-kubeconfig-mode: '0644' + node-external-ip: #{node_ip} + node-ip: #{node_ip} + server: https://#{NETWORK_PREFIX}.100:9345 + token: vagrant-rke2 + YAML + end + end +end + +Vagrant.configure("2") do |config| + config.vagrant.plugins = ["vagrant-rke2", "vagrant-reload"] + # Default provider is libvirt, virtualbox is only provided as a backup + config.vm.provider "libvirt" do |v| + v.cpus = NODE_CPUS + v.memory = NODE_MEMORY + end + config.vm.provider "virtualbox" do |v| + v.cpus = NODE_CPUS + v.memory = NODE_MEMORY + end + + if NODE_ROLES.kind_of?(String) + NODE_ROLES = NODE_ROLES.split(" ", -1) + end + if NODE_BOXES.kind_of?(String) + NODE_BOXES = NODE_BOXES.split(" ", -1) + end + + NODE_ROLES.each_with_index do |name, i| + config.vm.define name do |node| + roles = name.split("-", -1) + role_num = roles.pop.to_i + provision(node.vm, roles, role_num, i) + end + end +end diff --git a/tests/e2e/secretsencryption/secretsencryption_test.go b/tests/e2e/secretsencryption/secretsencryption_test.go new file mode 100644 index 0000000000..1ef6168b46 --- /dev/null +++ b/tests/e2e/secretsencryption/secretsencryption_test.go @@ -0,0 +1,145 @@ +package secretsencryption + +import ( + "flag" + "fmt" + "os" + "strings" + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/rancher/rke2/tests/e2e" +) + +// This test is desigened for the new secrets-encrypt rotate-keys command, +// Added in v1.28.0+rke2r1 + +// Valid nodeOS: generic/ubuntu2204, opensuse/Leap-15.3.x86_64 +var nodeOS = flag.String("nodeOS", "generic/ubuntu2204", "VM operating system") +var serverCount = flag.Int("serverCount", 3, "number of server nodes") +var ci = flag.Bool("ci", false, "running on CI") + +// Environment Variables Info: +// E2E_RELEASE_VERSION=v1.23.1+rke2r1 or nil for latest commit from master + +func Test_E2ESecretsEncryption(t *testing.T) { + RegisterFailHandler(Fail) + flag.Parse() + suiteConfig, reporterConfig := GinkgoConfiguration() + RunSpecs(t, "Secrets Encryption Test Suite", suiteConfig, reporterConfig) +} + +var ( + kubeConfigFile string + serverNodeNames []string +) + +var _ = ReportAfterEach(e2e.GenReport) + +var _ = Describe("Verify Secrets Encryption Rotation", Ordered, func() { + Context("Secrets Keys are rotated:", func() { + It("Starts up with no issues", func() { + var err error + serverNodeNames, _, err = e2e.CreateCluster(*nodeOS, *serverCount, 0) + Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err)) + fmt.Println("CLUSTER CONFIG") + fmt.Println("OS:", *nodeOS) + fmt.Println("Server Nodes:", serverNodeNames) + kubeConfigFile, err = e2e.GenKubeConfigFile(serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred()) + }) + + It("Checks node and pod status", func() { + fmt.Printf("\nFetching node status\n") + Eventually(func(g Gomega) { + nodes, err := e2e.ParseNodes(kubeConfigFile, false) + g.Expect(err).NotTo(HaveOccurred()) + for _, node := range nodes { + g.Expect(node.Status).Should(Equal("Ready")) + } + }, "620s", "5s").Should(Succeed()) + _, _ = e2e.ParseNodes(kubeConfigFile, true) + + fmt.Printf("\nFetching pods status\n") + Eventually(func(g Gomega) { + pods, err := e2e.ParsePods(kubeConfigFile, false) + g.Expect(err).NotTo(HaveOccurred()) + for _, pod := range pods { + if strings.Contains(pod.Name, "helm-install") { + g.Expect(pod.Status).Should(Equal("Completed"), pod.Name) + } else { + g.Expect(pod.Status).Should(Equal("Running"), pod.Name) + } + } + }, "620s", "5s").Should(Succeed()) + _, _ = e2e.ParsePods(kubeConfigFile, true) + }) + + It("Deploys several secrets", func() { + _, err := e2e.DeployWorkload("secrets.yaml", kubeConfigFile) + Expect(err).NotTo(HaveOccurred(), "Secrets not deployed") + }) + + It("Verifies encryption start stage", func() { + cmd := "sudo rke2 secrets-encrypt status" + for _, nodeName := range serverNodeNames { + res, err := e2e.RunCmdOnNode(cmd, nodeName) + Expect(err).NotTo(HaveOccurred()) + Expect(res).Should(ContainSubstring("Encryption Status: Enabled")) + Expect(res).Should(ContainSubstring("Current Rotation Stage: start")) + Expect(res).Should(ContainSubstring("Server Encryption Hashes: All hashes match")) + } + }) + + It("Rotates the Secrets-Encryption Keys", func() { + cmd := "sudo rke2 secrets-encrypt rotate-keys" + res, err := e2e.RunCmdOnNode(cmd, serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred(), res) + for i, nodeName := range serverNodeNames { + Eventually(func(g Gomega) { + cmd := "sudo rke2 secrets-encrypt status" + res, err := e2e.RunCmdOnNode(cmd, nodeName) + g.Expect(err).NotTo(HaveOccurred(), res) + g.Expect(res).Should(ContainSubstring("Server Encryption Hashes: hash does not match")) + if i == 0 { + g.Expect(res).Should(ContainSubstring("Current Rotation Stage: reencrypt_finished")) + } else { + g.Expect(res).Should(ContainSubstring("Current Rotation Stage: start")) + } + }, "420s", "2s").Should(Succeed()) + } + }) + + It("Restarts RKE2 servers", func() { + Expect(e2e.RestartCluster(serverNodeNames)).To(Succeed(), e2e.GetVagrantLog(nil)) + }) + + It("Verifies reencryption_finished stage", func() { + cmd := "sudo rke2 secrets-encrypt status" + for _, nodeName := range serverNodeNames { + Eventually(func(g Gomega) { + res, err := e2e.RunCmdOnNode(cmd, nodeName) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(res).Should(ContainSubstring("Encryption Status: Enabled")) + g.Expect(res).Should(ContainSubstring("Current Rotation Stage: reencrypt_finished")) + g.Expect(res).Should(ContainSubstring("Server Encryption Hashes: All hashes match")) + }, "420s", "2s").Should(Succeed()) + } + }) + }) +}) + +var failed bool +var _ = AfterEach(func() { + failed = failed || CurrentSpecReport().Failed() +}) + +var _ = AfterSuite(func() { + if failed && !*ci { + fmt.Println("FAILED!") + } else { + Expect(e2e.DestroyCluster()).To(Succeed()) + Expect(os.Remove(kubeConfigFile)).To(Succeed()) + } +}) diff --git a/tests/e2e/secretsencryption_old/Vagrantfile b/tests/e2e/secretsencryption_old/Vagrantfile new file mode 100644 index 0000000000..f0f7e749d1 --- /dev/null +++ b/tests/e2e/secretsencryption_old/Vagrantfile @@ -0,0 +1,83 @@ +ENV['VAGRANT_NO_PARALLEL'] = 'no' +NODE_ROLES = (ENV['E2E_NODE_ROLES'] || ["server-0", "server-1", "server-2"]) +NODE_BOXES = (ENV['E2E_NODE_BOXES'] || ['generic/ubuntu2204', 'generic/ubuntu2204', 'generic/ubuntu2204']) +GITHUB_BRANCH = (ENV['E2E_GITHUB_BRANCH'] || "master") +RELEASE_VERSION = (ENV['E2E_RELEASE_VERSION'] || "") +NODE_CPUS = (ENV['E2E_NODE_CPUS'] || 2).to_i +NODE_MEMORY = (ENV['E2E_NODE_MEMORY'] || 3072).to_i +REGISTRY = (ENV['E2E_REGISTRY'] || "") +# Virtualbox >= 6.1.28 require `/etc/vbox/network.conf` for expanded private networks, +# see https://www.virtualbox.org/manual/ch06.html#network_hostonly +NETWORK_PREFIX = "10.10.10" + +def provision(vm, roles, role_num, node_num) + vm.box = NODE_BOXES[node_num] + vm.hostname = "#{roles[0]}-#{role_num}" + # An expanded netmask is required to allow VM<-->VM communication, virtualbox defaults to /32 + node_ip = "#{NETWORK_PREFIX}.#{100+node_num}" + vm.network "private_network", ip: node_ip, netmask: "255.255.255.0" + + scripts_location = Dir.exists?("./scripts") ? "./scripts" : "../scripts" + vagrant_defaults = File.exists?("./vagrantdefaults.rb") ? "./vagrantdefaults.rb" : "../vagrantdefaults.rb" + load vagrant_defaults + + defaultOSConfigure(vm) + install_type = getInstallType(vm, RELEASE_VERSION, GITHUB_BRANCH) + + vm.provision "shell", inline: "ping -c 2 rke2.io" + + if !REGISTRY.empty? + vm.provision "Set private registry", type: "shell", path: scripts_location + "/registry.sh", args: [ "#{NETWORK_PREFIX}.1" ] + end + + if roles.include?("server") && role_num == 0 + vm.provision :rke2, run: 'once' do |rke2| + rke2.env = %W[INSTALL_RKE2_TYPE=server #{install_type}] + rke2.config = <<~YAML + write-kubeconfig-mode: '0644' + node-external-ip: #{NETWORK_PREFIX}.100 + node-ip: #{NETWORK_PREFIX}.100 + token: vagrant-rke2 + YAML + end + elsif roles.include?("server") && role_num != 0 + vm.provision :rke2, run: 'once' do |rke2| + rke2.env = %W[INSTALL_RKE2_TYPE=server #{install_type}] + rke2.config = <<~YAML + write-kubeconfig-mode: '0644' + node-external-ip: #{node_ip} + node-ip: #{node_ip} + server: https://#{NETWORK_PREFIX}.100:9345 + token: vagrant-rke2 + YAML + end + end +end + +Vagrant.configure("2") do |config| + config.vagrant.plugins = ["vagrant-rke2", "vagrant-reload"] + # Default provider is libvirt, virtualbox is only provided as a backup + config.vm.provider "libvirt" do |v| + v.cpus = NODE_CPUS + v.memory = NODE_MEMORY + end + config.vm.provider "virtualbox" do |v| + v.cpus = NODE_CPUS + v.memory = NODE_MEMORY + end + + if NODE_ROLES.kind_of?(String) + NODE_ROLES = NODE_ROLES.split(" ", -1) + end + if NODE_BOXES.kind_of?(String) + NODE_BOXES = NODE_BOXES.split(" ", -1) + end + + NODE_ROLES.each_with_index do |name, i| + config.vm.define name do |node| + roles = name.split("-", -1) + role_num = roles.pop.to_i + provision(node.vm, roles, role_num, i) + end + end +end diff --git a/tests/e2e/secretsencryption_old/secretsencryption_test.go b/tests/e2e/secretsencryption_old/secretsencryption_test.go new file mode 100644 index 0000000000..6e67e05f30 --- /dev/null +++ b/tests/e2e/secretsencryption_old/secretsencryption_test.go @@ -0,0 +1,235 @@ +package secretsencryption + +import ( + "flag" + "fmt" + "os" + "strings" + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/rancher/rke2/tests/e2e" +) + +// Valid nodeOS: generic/ubuntu2204, opensuse/Leap-15.3.x86_64 +var nodeOS = flag.String("nodeOS", "generic/ubuntu2204", "VM operating system") +var serverCount = flag.Int("serverCount", 3, "number of server nodes") +var ci = flag.Bool("ci", false, "running on CI") + +// Environment Variables Info: +// E2E_RELEASE_VERSION=v1.23.1+rke2r1 or nil for latest commit from master + +func Test_E2ESecretsEncryptionOld(t *testing.T) { + RegisterFailHandler(Fail) + flag.Parse() + suiteConfig, reporterConfig := GinkgoConfiguration() + RunSpecs(t, "Secrets Encryption Test Suite", suiteConfig, reporterConfig) +} + +var ( + kubeConfigFile string + serverNodeNames []string +) + +var _ = ReportAfterEach(e2e.GenReport) + +var _ = Describe("Verify Secrets Encryption Rotation", Ordered, func() { + Context("Secrets Keys are rotated:", func() { + It("Starts up with no issues", func() { + var err error + serverNodeNames, _, err = e2e.CreateCluster(*nodeOS, *serverCount, 0) + Expect(err).NotTo(HaveOccurred(), e2e.GetVagrantLog(err)) + fmt.Println("CLUSTER CONFIG") + fmt.Println("OS:", *nodeOS) + fmt.Println("Server Nodes:", serverNodeNames) + kubeConfigFile, err = e2e.GenKubeConfigFile(serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred()) + }) + + It("Checks node and pod status", func() { + fmt.Printf("\nFetching node status\n") + Eventually(func(g Gomega) { + nodes, err := e2e.ParseNodes(kubeConfigFile, false) + g.Expect(err).NotTo(HaveOccurred()) + for _, node := range nodes { + g.Expect(node.Status).Should(Equal("Ready")) + } + }, "620s", "5s").Should(Succeed()) + _, _ = e2e.ParseNodes(kubeConfigFile, true) + + fmt.Printf("\nFetching pods status\n") + Eventually(func(g Gomega) { + pods, err := e2e.ParsePods(kubeConfigFile, false) + g.Expect(err).NotTo(HaveOccurred()) + for _, pod := range pods { + if strings.Contains(pod.Name, "helm-install") { + g.Expect(pod.Status).Should(Equal("Completed"), pod.Name) + } else { + g.Expect(pod.Status).Should(Equal("Running"), pod.Name) + } + } + }, "620s", "5s").Should(Succeed()) + _, _ = e2e.ParsePods(kubeConfigFile, true) + }) + + It("Deploys several secrets", func() { + _, err := e2e.DeployWorkload("secrets.yaml", kubeConfigFile) + Expect(err).NotTo(HaveOccurred(), "Secrets not deployed") + }) + + It("Verifies encryption start stage", func() { + cmd := "sudo rke2 secrets-encrypt status" + for _, nodeName := range serverNodeNames { + res, err := e2e.RunCmdOnNode(cmd, nodeName) + Expect(err).NotTo(HaveOccurred()) + Expect(res).Should(ContainSubstring("Encryption Status: Enabled")) + Expect(res).Should(ContainSubstring("Current Rotation Stage: start")) + Expect(res).Should(ContainSubstring("Server Encryption Hashes: All hashes match")) + } + }) + + It("Prepares for Secrets-Encryption Rotation", func() { + cmd := "sudo rke2 secrets-encrypt prepare" + res, err := e2e.RunCmdOnNode(cmd, serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred(), res) + for i, nodeName := range serverNodeNames { + cmd := "sudo rke2 secrets-encrypt status" + res, err := e2e.RunCmdOnNode(cmd, nodeName) + Expect(err).NotTo(HaveOccurred(), res) + Expect(res).Should(ContainSubstring("Server Encryption Hashes: hash does not match")) + if i == 0 { + Expect(res).Should(ContainSubstring("Current Rotation Stage: prepare")) + } else { + Expect(res).Should(ContainSubstring("Current Rotation Stage: start")) + } + } + }) + + It("Restarts RKE2 servers", func() { + Expect(e2e.RestartCluster(serverNodeNames)).To(Succeed(), e2e.GetVagrantLog(nil)) + }) + + It("Checks node and pod status", func() { + Eventually(func(g Gomega) { + nodes, err := e2e.ParseNodes(kubeConfigFile, false) + g.Expect(err).NotTo(HaveOccurred()) + for _, node := range nodes { + g.Expect(node.Status).Should(Equal("Ready")) + } + }, "420s", "5s").Should(Succeed()) + + Eventually(func(g Gomega) { + pods, err := e2e.ParsePods(kubeConfigFile, false) + g.Expect(err).NotTo(HaveOccurred()) + for _, pod := range pods { + if strings.Contains(pod.Name, "helm-install") { + g.Expect(pod.Status).Should(Equal("Completed"), pod.Name) + } else { + g.Expect(pod.Status).Should(Equal("Running"), pod.Name) + } + } + }, "420s", "5s").Should(Succeed()) + _, _ = e2e.ParseNodes(kubeConfigFile, true) + }) + + It("Verifies encryption prepare stage", func() { + cmd := "sudo rke2 secrets-encrypt status" + for _, nodeName := range serverNodeNames { + Eventually(func(g Gomega) { + res, err := e2e.RunCmdOnNode(cmd, nodeName) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(res).Should(ContainSubstring("Encryption Status: Enabled")) + g.Expect(res).Should(ContainSubstring("Current Rotation Stage: prepare")) + g.Expect(res).Should(ContainSubstring("Server Encryption Hashes: All hashes match")) + }, "420s", "2s").Should(Succeed()) + } + }) + + It("Rotates the Secrets-Encryption Keys", func() { + cmd := "sudo rke2 secrets-encrypt rotate" + res, err := e2e.RunCmdOnNode(cmd, serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred(), res) + for i, nodeName := range serverNodeNames { + Eventually(func(g Gomega) { + cmd := "sudo rke2 secrets-encrypt status" + res, err := e2e.RunCmdOnNode(cmd, nodeName) + g.Expect(err).NotTo(HaveOccurred(), res) + g.Expect(res).Should(ContainSubstring("Server Encryption Hashes: hash does not match")) + if i == 0 { + g.Expect(res).Should(ContainSubstring("Current Rotation Stage: rotate")) + } else { + g.Expect(res).Should(ContainSubstring("Current Rotation Stage: prepare")) + } + }, "420s", "2s").Should(Succeed()) + } + }) + + It("Restarts RKE2 servers", func() { + Expect(e2e.RestartCluster(serverNodeNames)).To(Succeed(), e2e.GetVagrantLog(nil)) + }) + + It("Verifies encryption rotate stage", func() { + cmd := "sudo rke2 secrets-encrypt status" + for _, nodeName := range serverNodeNames { + Eventually(func(g Gomega) { + res, err := e2e.RunCmdOnNode(cmd, nodeName) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(res).Should(ContainSubstring("Encryption Status: Enabled")) + g.Expect(res).Should(ContainSubstring("Current Rotation Stage: rotate")) + g.Expect(res).Should(ContainSubstring("Server Encryption Hashes: All hashes match")) + }, "420s", "2s").Should(Succeed()) + } + }) + + It("Reencrypts the Secrets-Encryption Keys", func() { + cmd := "sudo rke2 secrets-encrypt reencrypt" + res, err := e2e.RunCmdOnNode(cmd, serverNodeNames[0]) + Expect(err).NotTo(HaveOccurred(), res) + + cmd = "sudo rke2 secrets-encrypt status" + Eventually(func() (string, error) { + return e2e.RunCmdOnNode(cmd, serverNodeNames[0]) + }, "240s", "10s").Should(ContainSubstring("Current Rotation Stage: reencrypt_finished")) + + for _, nodeName := range serverNodeNames[1:] { + res, err := e2e.RunCmdOnNode(cmd, nodeName) + Expect(err).NotTo(HaveOccurred(), res) + Expect(res).Should(ContainSubstring("Server Encryption Hashes: hash does not match")) + Expect(res).Should(ContainSubstring("Current Rotation Stage: rotate")) + } + }) + + It("Restarts RKE2 Servers", func() { + Expect(e2e.RestartCluster(serverNodeNames)).To(Succeed(), e2e.GetVagrantLog(nil)) + }) + + It("Verifies Encryption Reencrypt Stage", func() { + cmd := "sudo rke2 secrets-encrypt status" + for _, nodeName := range serverNodeNames { + Eventually(func(g Gomega) { + res, err := e2e.RunCmdOnNode(cmd, nodeName) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(res).Should(ContainSubstring("Encryption Status: Enabled")) + g.Expect(res).Should(ContainSubstring("Current Rotation Stage: reencrypt_finished")) + g.Expect(res).Should(ContainSubstring("Server Encryption Hashes: All hashes match")) + }, "420s", "5s").Should(Succeed()) + } + }) + }) + +}) + +var failed bool +var _ = AfterEach(func() { + failed = failed || CurrentSpecReport().Failed() +}) + +var _ = AfterSuite(func() { + if failed && !*ci { + fmt.Println("FAILED!") + } else { + Expect(e2e.DestroyCluster()).To(Succeed()) + Expect(os.Remove(kubeConfigFile)).To(Succeed()) + } +}) diff --git a/tests/e2e/splitserver/Vagrantfile b/tests/e2e/splitserver/Vagrantfile index 46d03e6422..647615382a 100644 --- a/tests/e2e/splitserver/Vagrantfile +++ b/tests/e2e/splitserver/Vagrantfile @@ -113,9 +113,7 @@ Vagrant.configure("2") do |config| NODE_BOXES = NODE_BOXES.split(" ", -1) end - # Must iterate on the index, vagrant does not understand iterating - # over the node roles themselves - NODE_ROLES.length.times do |i| + NODE_ROLES.each_with_index do |name, i| name = NODE_ROLES[i] role_num = name.split("-", -1).pop.to_i config.vm.define name do |node| diff --git a/tests/e2e/upgradecluster/Vagrantfile b/tests/e2e/upgradecluster/Vagrantfile index bba9e847c3..a4d3489236 100644 --- a/tests/e2e/upgradecluster/Vagrantfile +++ b/tests/e2e/upgradecluster/Vagrantfile @@ -100,10 +100,7 @@ Vagrant.configure("2") do |config| NODE_BOXES = NODE_BOXES.split(" ", -1) end - # Must iterate on the index, vagrant does not understand iterating - # over the node roles themselves - NODE_ROLES.length.times do |i| - name = NODE_ROLES[i] + NODE_ROLES.each_with_index do |name, i| config.vm.define name do |node| roles = name.split("-", -1) role_num = roles.pop.to_i diff --git a/tests/e2e/validatecluster/Vagrantfile b/tests/e2e/validatecluster/Vagrantfile index ab481028d0..7227728c8b 100644 --- a/tests/e2e/validatecluster/Vagrantfile +++ b/tests/e2e/validatecluster/Vagrantfile @@ -94,10 +94,7 @@ Vagrant.configure("2") do |config| NODE_BOXES = NODE_BOXES.split(" ", -1) end - # Must iterate on the index, vagrant does not understand iterating - # over the node roles themselves - NODE_ROLES.length.times do |i| - name = NODE_ROLES[i] + NODE_ROLES.each_with_index do |name, i| config.vm.define name do |node| roles = name.split("-", -1) role_num = roles.pop.to_i