@@ -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,14 @@ 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+
110+ # Default scopes for instance service account
111+ default_scopes = [
112+ "https://www.googleapis.com/auth/devstorage.read_write" ,
113+ "https://www.googleapis.com/auth/logging.write" ,
114+ "https://www.googleapis.com/auth/monitoring.write" ,
115+ ]
116+ self .instance_scopes = instance_scopes or self .config .get ("instance_scopes" , default_scopes )
108117
109118 def create_gcp_config (self ):
110119 subnetwork = f"projects/{ self .network_projectid } /regions/{ self .general_zone } /subnetworks/{ self .network } "
@@ -144,11 +153,7 @@ def create_gcp_config(self):
144153 "serviceAccounts" : [
145154 {
146155 "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- ],
156+ "scopes" : self .instance_scopes ,
152157 }
153158 ],
154159 # Metadata is readable from the instance and allows you to
@@ -516,6 +521,11 @@ class GCPCluster(VMCluster):
516521 service_account: str
517522 Service account that all VMs will run under.
518523 Defaults to the default Compute Engine service account for your GCP project.
524+ instance_scopes: list (optional)
525+ List of GCP OAuth scopes to assign to the service account on instances.
526+ Defaults to ``["https://www.googleapis.com/auth/devstorage.read_write",
527+ "https://www.googleapis.com/auth/logging.write",
528+ "https://www.googleapis.com/auth/monitoring.write"]``.
519529 service_account_credentials: Optional[Dict[str, Any]]
520530 Service account credentials to create the compute engine Vms
521531
@@ -617,6 +627,7 @@ def __init__(
617627 debug = False ,
618628 instance_labels = None ,
619629 service_account = None ,
630+ instance_scopes = None ,
620631 service_account_credentials : Optional [Dict [str , Any ]] = None ,
621632 ** kwargs ,
622633 ):
@@ -717,6 +728,7 @@ def __init__(
717728 ),
718729 "instance_labels" : instance_labels or self .config .get ("instance_labels" ),
719730 "service_account" : service_account or self .config .get ("service_account" ),
731+ "instance_scopes" : instance_scopes or self .config .get ("instance_scopes" ),
720732 }
721733 self .scheduler_options = {** self .options }
722734 self .scheduler_options ["machine_type" ] = self .scheduler_machine_type
0 commit comments