@@ -15,7 +15,6 @@ import (
1515 . "github.com/onsi/ginkgo/v2"
1616 . "github.com/onsi/gomega"
1717 . "github.com/onsi/gomega/gstruct"
18- "github.com/stretchr/testify/assert"
1918 "github.com/stretchr/testify/require"
2019 appsv1 "k8s.io/api/apps/v1"
2120 authorizationv1 "k8s.io/api/authorization/v1"
@@ -1887,6 +1886,7 @@ var _ = Describe("Install Plan", func() {
18871886
18881887 By (`If the CSV is succeeded, we successfully rolled out the RBAC changes` )
18891888 })
1889+
18901890 It ("AttenuatePermissions" , func () {
18911891
18921892 defer func () {
@@ -2017,7 +2017,33 @@ var _ = Describe("Install Plan", func() {
20172017 _ , err = fetchCSV (crc , generatedNamespace .GetName (), mainCSV .GetName (), csvSucceededChecker )
20182018 require .NoError (GinkgoT (), err )
20192019
2020- By (`Update CatalogSource with a new CSV with more permissions` )
2020+ By ("Wait for ServiceAccount to have access" )
2021+ err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
2022+ res , err := c .KubernetesInterface ().AuthorizationV1 ().SubjectAccessReviews ().Create (context .Background (), & authorizationv1.SubjectAccessReview {
2023+ Spec : authorizationv1.SubjectAccessReviewSpec {
2024+ User : "system:serviceaccount:" + generatedNamespace .GetName () + ":" + serviceAccountName ,
2025+ ResourceAttributes : & authorizationv1.ResourceAttributes {
2026+ Group : "cluster.com" ,
2027+ Version : "v1alpha1" ,
2028+ Resource : crdPlural ,
2029+ Verb : rbac .VerbAll ,
2030+ },
2031+ },
2032+ }, metav1.CreateOptions {})
2033+ if err != nil {
2034+ return false , err
2035+ }
2036+ if res == nil {
2037+ return false , nil
2038+ }
2039+ GinkgoT ().Log ("checking serviceaccount for permission" )
2040+
2041+ By ("should be allowed" )
2042+ return res .Status .Allowed , nil
2043+ })
2044+ Expect (err ).NotTo (HaveOccurred ())
2045+
2046+ By (`Update CatalogSource with a new CSV with fewer permissions` )
20212047 updatedPermissions := []operatorsv1alpha1.StrategyDeploymentPermissions {
20222048 {
20232049 ServiceAccountName : serviceAccountName ,
@@ -2043,9 +2069,6 @@ var _ = Describe("Install Plan", func() {
20432069 },
20442070 }
20452071
2046- oldSecrets , err := c .KubernetesInterface ().CoreV1 ().Secrets (generatedNamespace .GetName ()).List (context .Background (), metav1.ListOptions {})
2047- require .NoError (GinkgoT (), err , "error listing secrets" )
2048-
20492072 By (`Create the catalog sources` )
20502073 updatedNamedStrategy := newNginxInstallStrategy (genName ("dep-" ), updatedPermissions , updatedClusterPermissions )
20512074 updatedCSV := newCSV (mainPackageStable + "-next" , generatedNamespace .GetName (), mainCSV .GetName (), semver .MustParse ("0.2.0" ), []apiextensionsv1.CustomResourceDefinition {mainCRD }, nil , & updatedNamedStrategy )
@@ -2077,15 +2100,6 @@ var _ = Describe("Install Plan", func() {
20772100 _ , err = fetchCSV (crc , generatedNamespace .GetName (), updatedCSV .GetName (), csvSucceededChecker )
20782101 require .NoError (GinkgoT (), err )
20792102
2080- newSecrets , err := c .KubernetesInterface ().CoreV1 ().Secrets (generatedNamespace .GetName ()).List (context .Background (), metav1.ListOptions {})
2081- require .NoError (GinkgoT (), err , "error listing secrets" )
2082-
2083- By (`Assert that the number of secrets is not increased from updating service account as part of the install plan,` )
2084- assert .EqualValues (GinkgoT (), len (oldSecrets .Items ), len (newSecrets .Items ))
2085-
2086- By (`And that the secret list is indeed updated.` )
2087- assert .Equal (GinkgoT (), oldSecrets .Items , newSecrets .Items )
2088-
20892103 By (`Wait for ServiceAccount to not have access anymore` )
20902104 err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
20912105 res , err := c .KubernetesInterface ().AuthorizationV1 ().SubjectAccessReviews ().Create (context .Background (), & authorizationv1.SubjectAccessReview {
0 commit comments