Skip to content

fix(bigquery-jdbc): restrict auto-created LargeResultDataset ACLs to creator and enforce 1h minimum TTL - #15332

Open
keshavdandeva wants to merge 1 commit into
jdbc/large-results-2-statement-concurrencyfrom
jdbc/large-results-3-dataset-acls
Open

keshavdandeva wants to merge 1 commit into
jdbc/large-results-2-statement-concurrencyfrom
jdbc/large-results-3-dataset-acls

Conversation

@keshavdandeva

@keshavdandeva keshavdandeva commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

b/584840569

Summary of Changes

  1. Extracted LargeResultDestinations (LargeResultDestinations.java, BigQueryConnection.java, BigQueryStatement.java):
    • Moved LargeResultDataset provisioning out of BigQueryStatement into a dedicated package-private collaborator LargeResultDestinations owned by BigQueryConnection (keeping BigQueryStatement focused on JDBC statement lifecycle; PR 3 touches only 26 lines in BigQueryStatement.java).
  2. Creator-only ACLs on auto-created LargeResultDataset (b/584840569):
    • Service accounts / impersonated service accounts: Resolves the owner email (BigQueryConnection.resolveOwnerEmail()) and sets creator-only OWNER ACL atomically on datasets.insert (zero extra RPCs, no window of project-wide special-group exposure).
    • Non-service-account credentials (e.g., user OAuth / WIF): Strips BigQuery's default special groups (projectOwners, projectWriters, projectReaders) via datasets.patch before any query job writes to the dataset; fails closed and rolls back the empty dataset (wrapping both BigQueryJdbcException and unexpected RuntimeException) if a creator OWNER entry cannot be verified or the patch fails.
    • 409 Conflict race handling: On 409 Conflict, reloads the dataset; for non-service-account credentials, verifies the dataset does not retain default project-wide special groups without mutating ACLs on a dataset another actor may have created.
  3. 1-hour minimum defaultTableLifetime clamp:
    • Clamps auto-created dataset defaultTableLifetime to BigQuery's 1-hour minimum (3600000 ms) with a LOG.warning(...) when LargeResultsDatasetExpirationTime is below 1 hour, preventing BigQuery 400 rejections on auto-create.
  4. Docs & Tests (USER_GUIDE.md, BigQueryConnectionTest, BigQueryStatementTest, ITStatementTest):
    • Documents creator-only ACL behavior and pre-creation guidance for shared/multi-process non-SA deployments; adds unit tests and updates ITStatementTest.

Decisions Taken & Open Review Points

  • Creator-only ACLs enabled by default (for review): Required by b/584840569 so auto-created datasets do not inherit projectReaders / projectWriters / projectOwners legacy primitive roles. Pre-existing datasets and BigQuery IAM roles (e.g. roles/bigquery.dataViewer) are unaffected; only deployments relying on legacy project-level primitive roles to share a driver-auto-created dataset see a behavior change. Please flag if you think a compatibility opt-out property is warranted.
  • No JVM-wide IN_FLIGHT_DATASET_CREATIONS latch: Dropped static in-JVM serialization (CountDownLatch) because it blocked uncancellably on latch.await() and only serialized within a single JVM (still failing on 409 across processes). Non-SA concurrent auto-creation now consistently hits the 409 fail-closed path with clear guidance to pre-create the dataset.
  • Follow-up bug filed: Caching datasets.get metadata per connection with 404 invalidation (to remove the per-query datasets.get RPC that also existed prior to this stack) is tracked separately in b/592250778.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances security and concurrency handling when auto-creating destination datasets for large query results. Specifically, it ensures that auto-created datasets are restricted to creator-only OWNER access by stripping default project-wide group ACLs, and enforces a minimum default table lifetime of 1 hour. It also introduces JVM-wide synchronization to safely coordinate concurrent dataset creations and handles rollback deletions if ACL updates fail. Extensive unit and integration tests have been added to verify these behaviors. There are no review comments to address, so I have no additional feedback to provide.

@keshavdandeva
keshavdandeva force-pushed the jdbc/large-results-3-dataset-acls branch from 7d63e05 to 863e0a5 Compare December 1, 2026 17:51
@keshavdandeva
keshavdandeva force-pushed the jdbc/large-results-3-dataset-acls branch from 863e0a5 to 88ab641 Compare December 1, 2026 20:09

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant