@@ -285,6 +285,15 @@ class GKEStartPodOperator(KubernetesPodOperator):
285285 :param gcp_conn_id: The google cloud connection id to use. This allows for
286286 users to specify a service account.
287287 :type gcp_conn_id: str
288+ :param impersonation_chain: Optional service account to impersonate using short-term
289+ credentials, or list of accounts required to get the access_token
290+ of the last account in the list, which will be impersonated in the request.
291+ If set as a string, the account must grant the originating account
292+ the Service Account Token Creator IAM role.
293+ If set as a sequence, the identities from the list must grant
294+ Service Account Token Creator IAM role to the directly preceding identity, with first
295+ account from the list granting this role to the originating account (templated).
296+ :type impersonation_chain: Union[str, Sequence[str]]
288297 """
289298
290299 template_fields = {'project_id' , 'location' , 'cluster_name' } | set (KubernetesPodOperator .template_fields )
@@ -297,6 +306,7 @@ def __init__(
297306 use_internal_ip : bool = False ,
298307 project_id : Optional [str ] = None ,
299308 gcp_conn_id : str = 'google_cloud_default' ,
309+ impersonation_chain : Optional [Union [str , Sequence [str ]]] = None ,
300310 ** kwargs ,
301311 ) -> None :
302312 super ().__init__ (** kwargs )
@@ -305,6 +315,7 @@ def __init__(
305315 self .cluster_name = cluster_name
306316 self .gcp_conn_id = gcp_conn_id
307317 self .use_internal_ip = use_internal_ip
318+ self .impersonation_chain = impersonation_chain
308319
309320 if self .gcp_conn_id is None :
310321 raise AirflowException (
@@ -350,6 +361,22 @@ def execute(self, context) -> Optional[str]:
350361 "--project" ,
351362 self .project_id ,
352363 ]
364+ if self .impersonation_chain :
365+ if isinstance (self .impersonation_chain , str ):
366+ impersonation_account = self .impersonation_chain
367+ elif len (self .impersonation_chain ) == 1 :
368+ impersonation_account = self .impersonation_chain [:- 1 ]
369+ else :
370+ raise AirflowException (
371+ "Chained list of accounts is not supported, please specify only one service account"
372+ )
373+
374+ cmd .extend (
375+ [
376+ '--impersonate-service-account' ,
377+ impersonation_account ,
378+ ]
379+ )
353380 if self .use_internal_ip :
354381 cmd .append ('--internal-ip' )
355382 execute_in_subprocess (cmd )
0 commit comments