Commit c0393ae
feat(gcp): add BigQuery resource ingestion (#2433)
### Type of change
- [x] New feature (non-breaking change that adds functionality)
### Summary
Add BigQuery support to the GCP intel module, covering four resource
types:
- **Datasets** (`GCPBigQueryDataset`) — with `Database` ontology label
- **Tables** (`GCPBigQueryTable`) — TABLE, VIEW, MATERIALIZED_VIEW,
EXTERNAL (enriched via `tables.get` for numBytes, numRows, description,
etc.)
- **Routines** (`GCPBigQueryRoutine`) — stored procedures, UDFs,
table-valued functions
- **Connections** (`GCPBigQueryConnection`) — external data source
connections (Cloud SQL, AWS, Azure, GCP Service Account, Spark, etc.)
**Graph structure:**
```
(GCPProject)-[:RESOURCE]->(GCPBigQueryDataset)-[:HAS_TABLE]->(GCPBigQueryTable)
(GCPProject)-[:RESOURCE]->(GCPBigQueryDataset)-[:HAS_ROUTINE]->(GCPBigQueryRoutine)
(GCPProject)-[:RESOURCE]->(GCPBigQueryConnection)
(GCPBigQueryTable)-[:USES_CONNECTION]->(GCPBigQueryConnection)
(GCPBigQueryRoutine)-[:USES_CONNECTION]->(GCPBigQueryConnection)
(GCPBigQueryConnection)-[:CONNECTS_TO]->(GCPCloudSQLInstance)
(GCPBigQueryConnection)-[:CONNECTS_WITH]->(AWSRole)
(GCPBigQueryConnection)-[:CONNECTS_WITH]->(EntraServicePrincipal)
(GCPBigQueryConnection)-[:CONNECTS_WITH]->(GCPServiceAccount)
```
**Cross-cloud relationships:** BigQuery connections that reference
external identity providers are linked to existing Cartography nodes:
- `aws.accessRole.iamRoleId` → `AWSRole.id` (ARN)
- `azure.federatedApplicationClientId` → `EntraServicePrincipal.id`
- `cloudResource.serviceAccountId` → `GCPServiceAccount.email`
**Implementation details:**
- Uses BigQuery v2 discovery API (`build_client("bigquery", "v2")`) —
consistent with all other GCP modules
- Connections use a separate API service
(`bigqueryconnection.googleapis.com` v1)
- The BigQuery Connection API does not support a wildcard location —
locations are discovered from datasets + default multi-region locations
(us, eu), then queried individually
- Connection IDs are normalized from the short dot-separated format
(`project_number.location.name`) to the full resource name
(`projects/.../locations/.../connections/...`) for consistent
relationship matching
- Tables are enriched via per-table `tables.get` calls for fields not
available in `tables.list` (numBytes, numRows, description,
friendlyName, externalDataConfiguration)
- Returns `None` on API disabled / permission denied (403/404) —
preserves existing data (no cleanup on failure)
- Child resources (tables, routines) are aggregated across all datasets
into a single `load()` call for performance
- Uses direct indexing for required API fields (fail-fast on missing
data)
- Follows the flat-file pattern (like bigtable) with one file per
resource type
- Ontology mapping uses `dataset_id` (required field) for the Database
name instead of `friendly_name` (optional)
**Setup requirements** (documented in
`docs/root/modules/gcp/config.md`):
- APIs: `bigquery.googleapis.com`, `bigqueryconnection.googleapis.com`
- IAM roles: `roles/bigquery.dataViewer`,
`roles/bigquery.connectionUser`
### Related issues or links
- Fixes #2128
- Supersedes #2229
### How was this tested?
- Integration tests covering all 4 resource types with mock API
responses
- Verifies all node properties, relationships (RESOURCE, HAS_TABLE,
HAS_ROUTINE, USES_CONNECTION, CONNECTS_TO, CONNECTS_WITH), and Database
ontology label
- Tested against live GCP project with BigQuery Omni (AWS cross-cloud)
connections
- Linter passes (`make test_lint`)
### Checklist
#### General
- [x] I have read the [contributing
guidelines](https://cartography-cncf.github.io/cartography/dev/developer-guide.html).
- [x] The linter passes locally (`make lint`).
- [x] I have added/updated tests that prove my fix is effective or my
feature works.
#### Proof of functionality
- [x] New or updated unit/integration tests.
#### If you are adding or modifying a synced entity
- [x] Included Cartography sync logs from a real environment
demonstrating successful synchronization of the new/modified entity.
#### If you are changing a node or relationship
- [x] Updated the [schema
documentation](https://github.com/cartography-cncf/cartography/tree/master/docs/root/modules).
#### If you are implementing a new intel module
- [x] Used the NodeSchema [data
model](https://cartography-cncf.github.io/cartography/dev/writing-intel-modules.html#defining-a-node).
### Notes for reviewers
This builds on the work started in #2229 but addresses all review
feedback:
- Uses discovery API instead of `google.cloud.bigquery` client
- One model per file in `cartography/models/gcp/bigquery/`
- Standard error handling with `is_api_disabled_error()` + 403/404
handling
- No catch-all exceptions — let errors propagate
- No datetime conversion — passes native API values
- Aggregates child resources across parents for single `load()` call
- Integration tests (not unit tests) following the standard pattern
- Passes credentials through to `build_client()` instead of using ADC
independently
- Required fields use direct indexing (`data["field"]`) for fail-fast
semantics
---------
Signed-off-by: Jeremy Chapeau <jeremy@subimage.io>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 305cce0 commit c0393ae
16 files changed
Lines changed: 1934 additions & 1 deletion
File tree
- cartography
- intel/gcp
- models
- gcp/bigquery
- ontology/mapping/data
- docs/root/modules/gcp
- tests
- data/gcp
- integration/cartography/intel/gcp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | | - | |
| 72 | + | |
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| |||
82 | 86 | | |
83 | 87 | | |
84 | 88 | | |
| 89 | + | |
| 90 | + | |
85 | 91 | | |
86 | 92 | | |
87 | 93 | | |
| |||
549 | 555 | | |
550 | 556 | | |
551 | 557 | | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
552 | 614 | | |
553 | 615 | | |
554 | 616 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
0 commit comments