-
Notifications
You must be signed in to change notification settings - Fork 32
Add tier1 tests for cluster-level RBAC subject types #588
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
Open
RanWurmbrand
wants to merge
2
commits into
migtools:main
Choose a base branch
from
RanWurmbrand:infra/resources-and-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+305
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
e2e-tests/tests/tier1/mta_857_service_account_subject_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "log" | ||
| "path/filepath" | ||
|
|
||
| "github.com/konveyor/crane/e2e-tests/config" | ||
| . "github.com/konveyor/crane/e2e-tests/framework" | ||
| "github.com/konveyor/crane/e2e-tests/utils" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| var _ = Describe("Cluster-level RBAC export", func() { | ||
| It("[MTA-857] Should export CRB with ServiceAccount subject referencing ServiceAccount", Label("tier1"), func() { | ||
| appName := "simple-nginx-nopv" | ||
| namespace := "simple-nginx-nopv" | ||
| serviceName := "my-" + appName | ||
| scenario := NewMigrationScenario( | ||
| appName, | ||
| namespace, | ||
| config.K8sDeployBin, | ||
| config.CraneBin, | ||
| config.SourceContext, | ||
| config.TargetContext, | ||
| ) | ||
| srcApp := scenario.SrcApp | ||
| tgtApp := scenario.TgtApp | ||
| kubectlSrc := scenario.KubectlSrc | ||
| kubectlTgt := scenario.KubectlTgt | ||
| runner := scenario.Crane | ||
| paths, err := NewScenarioPaths("crane-*") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| sa := ServiceAccount{Name: "crane-sa", Namespace: namespace} | ||
| subjectName := sa.Name | ||
| subject := "--serviceaccount=" + namespace + ":" + sa.Name | ||
|
|
||
| cr := ClusterRole{Name: "crane-cr-subject-sa", Verb: "get,list,watch,create,update,delete", Resource: "pods"} | ||
| crb := ClusterRoleBinding{Name: "crane-crb-subject-sa", ClusterRoleName: cr.Name, Subject: subject} | ||
| tgtNamespace := Namespace{Name: namespace} | ||
|
|
||
| exportOpts := ExportOptions{Namespace: srcApp.Namespace, ExportDir: paths.ExportDir} | ||
| transformOpts := TransformOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir} | ||
| applyOpts := ApplyOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir, | ||
| OutputDir: paths.OutputDir} | ||
|
|
||
| DeferCleanup(func() { | ||
| if err := ResourceCleanup([]KubectlRunner{kubectlSrc, kubectlTgt}, []Resource{cr, crb}); err != nil { | ||
| log.Printf("Resources cleanup: %v", err) | ||
| } | ||
| if err := CleanupScenario(paths.TempDir, srcApp, tgtApp); err != nil { | ||
| log.Printf("Scenario cleanup: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| By("Deploying app on source cluster") | ||
| Expect(PrepareSourceApp(srcApp, kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating Creating first Service-account source") | ||
| Expect(sa.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating ClusterRole on source Clusster") | ||
| Expect(cr.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating ClusterRoleBinding with User subject referencing ServiceAccount") | ||
| Expect(crb.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Waiting for source pods and endpoints to drain") | ||
| WaitForSourceQuiesce(kubectlSrc, namespace, "app="+appName, serviceName) | ||
|
|
||
| By("Running crane export, transform, apply") | ||
| Expect(RunCranePipelineWithChecks(runner, exportOpts, transformOpts, applyOpts)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verifying no resources failed to export") | ||
| failuresDir := filepath.Join(paths.ExportDir, "failures", namespace) | ||
| hasFiles, _, err := utils.HasFilesRecursively(failuresDir) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(hasFiles).To(BeFalse()) | ||
|
|
||
| By("Create Namespace On target cluster") | ||
| Expect(tgtNamespace.Create(kubectlTgt)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Dry-run applying output manifests on target") | ||
| Expect(kubectlTgt.ValidateApplyDir(paths.OutputDir)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Applying migrated manifests to target cluster") | ||
| Expect(ApplyOutputToTarget(kubectlTgt, tgtNamespace.Name, paths.OutputDir)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Scaling target deployment and validating app") | ||
| Expect(kubectlTgt.ScaleDeployment(tgtNamespace.Name, appName, 1)).NotTo(HaveOccurred()) | ||
| Eventually(tgtApp.Validate, "2m", "10s").Should(Succeed()) | ||
|
|
||
| By("Verifying ClusterRoleBinding on target references correct ClusterRole and User subject") | ||
| Expect(ValidateClusterRBAC(kubectlTgt, []ExpectedClusterRoleBinding{ | ||
| {ClusterRoleBindingName: crb.Name, ClusterRoleName: crb.ClusterRoleName, SubjectName: subjectName}, | ||
| })).NotTo(HaveOccurred()) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "log" | ||
| "path/filepath" | ||
|
|
||
| "github.com/konveyor/crane/e2e-tests/config" | ||
| . "github.com/konveyor/crane/e2e-tests/framework" | ||
| "github.com/konveyor/crane/e2e-tests/utils" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| var _ = Describe("Cluster-level RBAC export", func() { | ||
| It("[MTA-858] Should export CRB with User subject referencing ServiceAccount", Label("tier1"), func() { | ||
| appName := "simple-nginx-nopv" | ||
| namespace := "simple-nginx-nopv" | ||
| serviceName := "my-" + appName | ||
| scenario := NewMigrationScenario( | ||
| appName, | ||
| namespace, | ||
| config.K8sDeployBin, | ||
| config.CraneBin, | ||
| config.SourceContext, | ||
| config.TargetContext, | ||
| ) | ||
| srcApp := scenario.SrcApp | ||
| tgtApp := scenario.TgtApp | ||
| kubectlSrc := scenario.KubectlSrc | ||
| kubectlTgt := scenario.KubectlTgt | ||
| runner := scenario.Crane | ||
| paths, err := NewScenarioPaths("crane-*") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| sa := ServiceAccount{Name: "crane-sa", Namespace: namespace} | ||
| subjectName := "system:serviceaccount:" + namespace + ":" + sa.Name | ||
| subject := "--user=" + subjectName | ||
|
|
||
| cr := ClusterRole{Name: "crane-cr-subject-user", Verb: "get,list,watch,create,update,delete", Resource: "pods"} | ||
| crb := ClusterRoleBinding{Name: "crane-crb-subject-user", ClusterRoleName: cr.Name, Subject: subject} | ||
| tgtNamespace := Namespace{Name: namespace} | ||
|
|
||
| exportOpts := ExportOptions{Namespace: srcApp.Namespace, ExportDir: paths.ExportDir} | ||
| transformOpts := TransformOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir} | ||
| applyOpts := ApplyOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir, | ||
| OutputDir: paths.OutputDir} | ||
|
|
||
| DeferCleanup(func() { | ||
| if err := ResourceCleanup([]KubectlRunner{kubectlSrc, kubectlTgt}, []Resource{cr, crb}); err != nil { | ||
| log.Printf("Resources cleanup: %v", err) | ||
| } | ||
| if err := CleanupScenario(paths.TempDir, srcApp, tgtApp); err != nil { | ||
| log.Printf("Scenario cleanup: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| By("Deploying app on source cluster") | ||
| Expect(PrepareSourceApp(srcApp, kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating Creating first Service-account source") | ||
| Expect(sa.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating ClusterRole on source Clusster") | ||
| Expect(cr.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating ClusterRoleBinding with User subject referencing ServiceAccount") | ||
| Expect(crb.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Waiting for source pods and endpoints to drain") | ||
| WaitForSourceQuiesce(kubectlSrc, namespace, "app="+appName, serviceName) | ||
|
|
||
| By("Running crane export, transform, apply") | ||
| Expect(RunCranePipelineWithChecks(runner, exportOpts, transformOpts, applyOpts)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verifying no resources failed to export") | ||
| failuresDir := filepath.Join(paths.ExportDir, "failures", namespace) | ||
| hasFiles, _, err := utils.HasFilesRecursively(failuresDir) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(hasFiles).To(BeFalse()) | ||
|
|
||
| By("Create Namespace On target cluster") | ||
| Expect(tgtNamespace.Create(kubectlTgt)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Dry-run applying output manifests on target") | ||
| Expect(kubectlTgt.ValidateApplyDir(paths.OutputDir)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Applying migrated manifests to target cluster") | ||
| Expect(ApplyOutputToTarget(kubectlTgt, tgtNamespace.Name, paths.OutputDir)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Scaling target deployment and validating app") | ||
| Expect(kubectlTgt.ScaleDeployment(tgtNamespace.Name, appName, 1)).NotTo(HaveOccurred()) | ||
| Eventually(tgtApp.Validate, "2m", "10s").Should(Succeed()) | ||
|
|
||
| By("Verifying ClusterRoleBinding on target references correct ClusterRole and User subject") | ||
| Expect(ValidateClusterRBAC(kubectlTgt, []ExpectedClusterRoleBinding{ | ||
| {ClusterRoleBindingName: crb.Name, ClusterRoleName: crb.ClusterRoleName, SubjectName: subjectName}, | ||
| })).NotTo(HaveOccurred()) | ||
|
RanWurmbrand marked this conversation as resolved.
|
||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "log" | ||
| "path/filepath" | ||
|
|
||
| "github.com/konveyor/crane/e2e-tests/config" | ||
| . "github.com/konveyor/crane/e2e-tests/framework" | ||
| "github.com/konveyor/crane/e2e-tests/utils" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| ) | ||
|
|
||
| var _ = Describe("Cluster-level RBAC export", func() { | ||
| It("[MTA-859] Should export CRB with Group subject referencing namespace ServiceAccounts", Label("tier1"), func() { | ||
| appName := "simple-nginx-nopv" | ||
| namespace := "simple-nginx-nopv" | ||
| serviceName := "my-" + appName | ||
|
|
||
| scenario := NewMigrationScenario( | ||
| appName, | ||
| namespace, | ||
| config.K8sDeployBin, | ||
| config.CraneBin, | ||
| config.SourceContext, | ||
| config.TargetContext, | ||
| ) | ||
| srcApp := scenario.SrcApp | ||
| tgtApp := scenario.TgtApp | ||
| kubectlSrc := scenario.KubectlSrc | ||
| kubectlTgt := scenario.KubectlTgt | ||
| runner := scenario.Crane | ||
| paths, err := NewScenarioPaths("crane-ca4c-*") | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| sa := ServiceAccount{Name: "crane-sa", Namespace: namespace} | ||
| subjectName := "system:serviceaccounts:" + namespace | ||
| subject := "--group=" + subjectName | ||
|
|
||
| cr := ClusterRole{Name: "crane-cr-subject-group", Verb: "get,list,watch,create,update,delete", Resource: "pods"} | ||
| crb := ClusterRoleBinding{Name: "crane-crb-subject-group", ClusterRoleName: cr.Name, Subject: subject} | ||
| tgtNamespace := Namespace{Name: namespace} | ||
|
|
||
| exportOpts := ExportOptions{Namespace: srcApp.Namespace, ExportDir: paths.ExportDir} | ||
| transformOpts := TransformOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir} | ||
| applyOpts := ApplyOptions{ExportDir: paths.ExportDir, TransformDir: paths.TransformDir, | ||
| OutputDir: paths.OutputDir} | ||
|
|
||
| DeferCleanup(func() { | ||
| if err := ResourceCleanup([]KubectlRunner{kubectlSrc, kubectlTgt}, []Resource{cr, crb}); err != nil { | ||
| log.Printf("Resources cleanup: %v", err) | ||
| } | ||
| if err := CleanupScenario(paths.TempDir, srcApp, tgtApp); err != nil { | ||
| log.Printf("Scenario cleanup: %v", err) | ||
| } | ||
| }) | ||
|
|
||
| By("Deploying app with ServiceAccount on source cluster") | ||
| Expect(PrepareSourceApp(srcApp, kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating Creating first Service-account source") | ||
| Expect(sa.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating ClusterRole with pod read permissions") | ||
| Expect(cr.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Creating ClusterRoleBinding with Group subject for namespace ServiceAccounts") | ||
| Expect(crb.Create(kubectlSrc)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Waiting for source pods and endpoints to drain") | ||
| WaitForSourceQuiesce(kubectlSrc, namespace, "app="+appName, serviceName) | ||
|
|
||
| By("Running crane export, transform, apply") | ||
| Expect(RunCranePipelineWithChecks(runner, exportOpts, transformOpts, applyOpts)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Verifying no resources failed to export") | ||
| failuresDir := filepath.Join(paths.ExportDir, "failures", namespace) | ||
| hasFiles, _, err := utils.HasFilesRecursively(failuresDir) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(hasFiles).To(BeFalse()) | ||
|
|
||
| By("Create Namespace On target cluster") | ||
| Expect(tgtNamespace.Create(kubectlTgt)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Dry-run applying output manifests on target") | ||
| Expect(kubectlTgt.ValidateApplyDir(paths.OutputDir)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Applying migrated manifests to target cluster") | ||
| Expect(ApplyOutputToTarget(kubectlTgt, namespace, paths.OutputDir)).NotTo(HaveOccurred()) | ||
|
|
||
| By("Scaling target deployment and validating app") | ||
| Expect(kubectlTgt.ScaleDeployment(tgtNamespace.Name, appName, 1)).NotTo(HaveOccurred()) | ||
| Eventually(tgtApp.Validate, "2m", "10s").Should(Succeed()) | ||
|
|
||
| By("Verifying ClusterRoleBinding on target references correct ClusterRole and Group subject") | ||
| Expect(ValidateClusterRBAC(kubectlTgt, []ExpectedClusterRoleBinding{ | ||
| {ClusterRoleBindingName: crb.Name, ClusterRoleName: crb.ClusterRoleName, SubjectName: subjectName}, | ||
| })).NotTo(HaveOccurred()) | ||
|
RanWurmbrand marked this conversation as resolved.
|
||
| }) | ||
|
|
||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.