@@ -22,6 +22,7 @@ import (
2222 "fmt"
2323 "os"
2424 "strings"
25+ "time"
2526
2627 "local/test/e2e/utils"
2728
@@ -143,6 +144,34 @@ func (n *GCSFuseCSITestDriver) PrepareTest(ctx context.Context, f *e2eframework.
143144 }
144145 testK8sSA .Create (ctx )
145146
147+ // Grant the required consumer permission on the test project to the active identity.
148+ // This ensures that tests using the `--billing-project` flag (like requester_pays_bucket)
149+ // can successfully authenticate and pass the consumer quota check (403 Forbidden).
150+ member := fmt .Sprintf ("serviceAccount:%v.svc.id.goog[%v/%v]" , n .meta .GetProjectID (), f .Namespace .Name , K8sServiceAccountName )
151+ if ! n .skipGcpSaTest {
152+ member = fmt .Sprintf ("serviceAccount:%v" , testGcpSA .GetEmail ())
153+ }
154+ billingBinding := utils .NewTestGCPProjectIAMPolicyBinding (n .meta .GetProjectID (), member , "roles/serviceusage.serviceUsageConsumer" , "" )
155+ if isBillingTest () {
156+ e2eframework .Logf ("Creating Project IAM Policy Binding for Billing Test (Service Usage Consumer)..." )
157+ billingBinding .Create (ctx )
158+ e2eframework .Logf ("Waiting 5 minutes for Billing IAM policy propagation to prevent 403 flakiness..." )
159+ time .Sleep (5 * time .Minute )
160+ }
161+
162+ // This is required to run the cloud profiler tests. See requirements here:
163+ // https://cloud.google.com/profiler/docs/profiling-go#permissions
164+ profilerAgentBinding := utils .NewTestGCPProjectIAMPolicyBinding (n .meta .GetProjectID (), member , "roles/cloudprofiler.agent" , "" )
165+ profilerUserBinding := utils .NewTestGCPProjectIAMPolicyBinding (n .meta .GetProjectID (), member , "roles/cloudprofiler.user" , "" )
166+
167+ if isProfilerTest () {
168+ e2eframework .Logf ("Creating Project IAM Policy Bindings for Cloud Profiler (Agent and User)..." )
169+ profilerAgentBinding .Create (ctx )
170+ profilerUserBinding .Create (ctx )
171+ e2eframework .Logf ("Waiting 5 minutes for Profiler IAM policy propagation to prevent 403 flakiness..." )
172+ time .Sleep (5 * time .Minute )
173+ }
174+
146175 config := & storageframework.PerTestConfig {
147176 Driver : n ,
148177 Framework : f ,
@@ -161,6 +190,13 @@ func (n *GCSFuseCSITestDriver) PrepareTest(ctx context.Context, f *e2eframework.
161190 n .volumeStore = []* gcsVolume {}
162191
163192 testK8sSA .Cleanup (ctx )
193+ if isProfilerTest () {
194+ profilerUserBinding .Cleanup (ctx )
195+ profilerAgentBinding .Cleanup (ctx )
196+ }
197+ if isBillingTest () {
198+ billingBinding .Cleanup (ctx )
199+ }
164200 if ! n .skipGcpSaTest {
165201 testGcpSA .Cleanup (ctx )
166202 }
@@ -658,3 +694,13 @@ func (n *GCSFuseCSITestDriver) giveDriverAccessToBucketForProfiles(ctx context.C
658694
659695 return nil
660696}
697+
698+ func isProfilerTest () bool {
699+ report := ginkgo .CurrentSpecReport ()
700+ return strings .Contains (report .FullText (), "cloud_profiler" )
701+ }
702+
703+ func isBillingTest () bool {
704+ report := ginkgo .CurrentSpecReport ()
705+ return strings .Contains (report .FullText (), "billing-project" )
706+ }
0 commit comments