@@ -66,6 +66,7 @@ def __init__(
6666 preemptible = False ,
6767 instance_labels = None ,
6868 service_account = None ,
69+ instance_scopes = None ,
6970 ** kwargs ,
7071 ):
7172 super ().__init__ (** kwargs )
@@ -105,6 +106,7 @@ def __init__(
105106
106107 self .general_zone = "-" .join (self .zone .split ("-" )[:2 ]) # us-east1-c -> us-east1
107108 self .service_account = service_account or self .config .get ("service_account" )
109+ self .instance_scopes = instance_scopes or self .config .get ("instance_scopes" )
108110
109111 def create_gcp_config (self ):
110112 subnetwork = f"projects/{ self .network_projectid } /regions/{ self .general_zone } /subnetworks/{ self .network } "
@@ -144,11 +146,7 @@ def create_gcp_config(self):
144146 "serviceAccounts" : [
145147 {
146148 "email" : self .service_account ,
147- "scopes" : [
148- "https://www.googleapis.com/auth/devstorage.read_write" ,
149- "https://www.googleapis.com/auth/logging.write" ,
150- "https://www.googleapis.com/auth/monitoring.write" ,
151- ],
149+ "scopes" : self .instance_scopes ,
152150 }
153151 ],
154152 # Metadata is readable from the instance and allows you to
@@ -516,6 +514,11 @@ class GCPCluster(VMCluster):
516514 service_account: str
517515 Service account that all VMs will run under.
518516 Defaults to the default Compute Engine service account for your GCP project.
517+ instance_scopes: list (optional)
518+ List of GCP OAuth scopes to assign to the service account on instances.
519+ Defaults to ``["https://www.googleapis.com/auth/devstorage.read_write",
520+ "https://www.googleapis.com/auth/logging.write",
521+ "https://www.googleapis.com/auth/monitoring.write"]``.
519522 service_account_credentials: Optional[Dict[str, Any]]
520523 Service account credentials to create the compute engine Vms
521524
@@ -617,6 +620,7 @@ def __init__(
617620 debug = False ,
618621 instance_labels = None ,
619622 service_account = None ,
623+ instance_scopes = None ,
620624 service_account_credentials : Optional [Dict [str , Any ]] = None ,
621625 ** kwargs ,
622626 ):
@@ -717,6 +721,7 @@ def __init__(
717721 ),
718722 "instance_labels" : instance_labels or self .config .get ("instance_labels" ),
719723 "service_account" : service_account or self .config .get ("service_account" ),
724+ "instance_scopes" : instance_scopes or self .config .get ("instance_scopes" ),
720725 }
721726 self .scheduler_options = {** self .options }
722727 self .scheduler_options ["machine_type" ] = self .scheduler_machine_type
0 commit comments