Skip to content

Commit e3ec1ac

Browse files
authored
Add support for credential configuation file auth to Google Secrets Manager secrets backend (#31597)
1 parent e3d4e56 commit e3ec1ac

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

airflow/providers/google/cloud/secrets/secret_manager.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class CloudSecretManagerBackend(BaseSecretsBackend, LoggingMixin):
7272
:param gcp_key_path: Path to Google Cloud Service Account key file (JSON). Mutually exclusive with
7373
gcp_keyfile_dict. use default credentials in the current environment if not provided.
7474
:param gcp_keyfile_dict: Dictionary of keyfile parameters. Mutually exclusive with gcp_key_path.
75+
:param gcp_credential_config_file: File path to or content of a GCP credential configuration file.
7576
:param gcp_scopes: Comma-separated string containing OAuth2 scopes
7677
:param project_id: Project ID to read the secrets from. If not passed, the project ID from credentials
7778
will be used.
@@ -85,6 +86,7 @@ def __init__(
8586
config_prefix: str = "airflow-config",
8687
gcp_keyfile_dict: dict | None = None,
8788
gcp_key_path: str | None = None,
89+
gcp_credential_config_file: dict[str, str] | str | None = None,
8890
gcp_scopes: str | None = None,
8991
project_id: str | None = None,
9092
sep: str = "-",
@@ -103,13 +105,16 @@ def __init__(
103105
)
104106
try:
105107
self.credentials, self.project_id = get_credentials_and_project_id(
106-
keyfile_dict=gcp_keyfile_dict, key_path=gcp_key_path, scopes=gcp_scopes
108+
keyfile_dict=gcp_keyfile_dict,
109+
key_path=gcp_key_path,
110+
credential_config_file=gcp_credential_config_file,
111+
scopes=gcp_scopes,
107112
)
108113
except (DefaultCredentialsError, FileNotFoundError):
109114
log.exception(
110115
"Unable to load credentials for GCP Secret Manager. "
111-
"Make sure that the keyfile path, dictionary, or GOOGLE_APPLICATION_CREDENTIALS "
112-
"environment variable is correct and properly configured."
116+
"Make sure that the keyfile path or dictionary, credential configuration file, "
117+
"or GOOGLE_APPLICATION_CREDENTIALS environment variable is correct and properly configured."
113118
)
114119

115120
# In case project id provided

docs/apache-airflow-providers-google/secrets-backends/google-cloud-secret-manager-backend.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ the following parameters:
7373
* ``variables_prefix``: Specifies the prefix of the secret to read to get Variables. Default: ``"airflow-variables"``
7474
* ``gcp_key_path``: Path to Google Cloud Service Account Key file (JSON).
7575
* ``gcp_keyfile_dict``: Dictionary of keyfile parameters.
76+
* ``gcp_credential_config_file``: File path to or content of a GCP credential configuration file.
7677
* ``gcp_scopes``: Comma-separated string containing OAuth2 scopes.
7778
* ``sep``: Separator used to concatenate connections_prefix and conn_id. Default: ``"-"``
7879
* ``project_id``: Project ID to read the secrets from. If not passed, the project ID from credentials will be used.
@@ -95,6 +96,8 @@ You can configure the credentials in three ways:
9596
* By default, Application Default Credentials (ADC) is used obtain credentials.
9697
* ``gcp_key_path`` option in ``backend_kwargs`` option - allows you to configure authorizations with a service account stored in local file.
9798
* ``gcp_keyfile_dict`` option in ``backend_kwargs`` option - allows you to configure authorizations with a service account stored in Airflow configuration.
99+
* ``gcp_credential_config_file`` option in ``backend_kwargs`` option - allows you to configure authentication with a credential configuration file.
100+
A credential configuration file is a configuration file that typically contains non-sensitive metadata to instruct the ``google-auth`` library on how to retrieve external subject tokens and exchange them for service account access tokens.
98101

99102
.. note::
100103

0 commit comments

Comments
 (0)