github-advanced-security[bot] commented on code in PR #39834:
URL: https://github.com/apache/beam/pull/39834#discussion_r3826455651


##########
sdks/python/apache_beam/yaml/integration_tests.py:
##########
@@ -508,6 +514,113 @@
       raise err
 
 
[email protected]
+def temp_postgres_database_with_secret_manager(
+    project=None, prefix='yaml_jdbc_sm_it_'):
+  """Context manager to provide a temporary PostgreSQL database authenticated
+  via GCP Secret Manager for testing.
+
+  This function utilizes the 'testcontainers' library to spin up a
+  PostgreSQL instance within a Docker container, creates a predefined 
'tmp_table',
+  registers the database container password in GCP Secret Manager, and yields
+  a dictionary containing the JDBC connection URL, username, secret 
specification,
+  and secret manager identifier.
+
+  The Docker container, database instance, and GCP secret are automatically
+  managed and torn down when the context manager exits.
+
+  Args:
+      project (str): Google Cloud Project ID. If not provided, reads from
+        the GOOGLE_CLOUD_PROJECT environment variable or defaults to
+        'apache-beam-testing'.
+      prefix (str): Prefix to use for the temporary GCP secret name.
+
+  Yields:
+      dict: A dictionary containing connection and secret details:
+            {
+                'URL': 'jdbc:postgresql://<host>:<port>/<dbname>',
+                'USERNAME': '<username>',
+                'PASSWORD_SPEC': '{"name": "<secret_id>", "project": 
"<project_id>"}',
+                'SECRET_MANAGER': 'googlecloudsecretmanager',
+            }
+  """
+  if secretmanager is None:
+    raise RuntimeError("google-cloud-secret-manager is not installed.")
+
+  project_id = project or os.environ.get(
+      'GOOGLE_CLOUD_PROJECT', 'apache-beam-testing')
+  secret_client = secretmanager.SecretManagerServiceClient()
+
+  default_port = 5432
+  with PostgresContainer(port=default_port) as postgres_container:
+    secret_postfix = (
+        datetime.now(timezone.utc).strftime('%m%d_%H%M%S') + '_' +
+        uuid.uuid4().hex[:6])
+    secret_id = f'{prefix}{secret_postfix}'
+    project_path = f'projects/{project_id}'
+    secret_path = f'{project_path}/secrets/{secret_id}'
+
+    _LOGGER.info("Creating GCP secret %s in project %s", secret_id, project_id)

Review Comment:
   ## CodeQL / Clear-text logging of sensitive information
   
   This expression logs [sensitive data (secret)](1) as clear text.
   This expression logs [sensitive data (secret)](2) as clear text.
   
   [Show more 
details](https://github.com/apache/beam/security/code-scanning/1919)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to