diff --git a/airflow/providers/google/cloud/utils/credentials_provider.py b/airflow/providers/google/cloud/utils/credentials_provider.py index ac1cfb42a31abf..258a0f37ff8936 100644 --- a/airflow/providers/google/cloud/utils/credentials_provider.py +++ b/airflow/providers/google/cloud/utils/credentials_provider.py @@ -29,8 +29,9 @@ import google.auth import google.auth.credentials import google.oauth2.service_account -from google.auth import impersonated_credentials +from google.auth import compute_engine, impersonated_credentials from google.auth.environment_vars import CREDENTIALS, LEGACY_PROJECT, PROJECT +from google.auth.transport import _http_client from airflow.exceptions import AirflowException from airflow.providers.google.cloud._internal_client.secret_manager_client import _SecretManagerClient @@ -248,6 +249,9 @@ def get_credentials_and_project(self) -> Tuple[google.auth.credentials.Credentia project_id = _get_project_id_from_service_account_email(self.target_principal) + if isinstance(credentials, compute_engine.Credentials): + credentials.refresh(_http_client.Request()) + return credentials, project_id def _get_credentials_using_keyfile_dict(self):