Skip to content

fix(ingestion): supply GCP credentials in a runtime that has none - #841

Merged
jirhiker merged 1 commit into
stagingfrom
fix/serverless-gcp-credentials
Aug 19, 2026
Merged

fix(ingestion): supply GCP credentials in a runtime that has none#841
jirhiker merged 1 commit into
stagingfrom
fix/serverless-gcp-credentials

Conversation

@jirhiker

Copy link
Copy Markdown
Member

The import failure is fixed — database_connectivity now reaches the Cloud SQL
connector, which fails on DefaultCredentialsError. Dagster+ Serverless runs
outside GCP, so there is no metadata server and google.auth.default() finds
nothing.

Approach

The service account key travels as a Dagster+ secret and is written to a file at
runtime, because GOOGLE_APPLICATION_CREDENTIALS names a path rather than
holding a value. Mode 600, in the process temporary directory, discarded with
the run.

Ordering matters. It runs before importing db.engine — that module
builds its connector at import time and resolves credentials right then, so
doing it afterwards would be too late. The dlt pipeline calls it too: gcsfs
resolves credentials the same way, so the raw zone would have failed identically
once the loader got that far. Fixing one and not the other would just move the
error.

Behaviour

Situation Result
GOOGLE_APPLICATION_CREDENTIALS already set Left alone — a developer's gcloud login is never shadowed
No key configured Not an error. Locally google.auth finds its own; in Serverless it fails loudly, which is correct
A path supplied instead of the key Rejected with a message saying so, rather than failing deep inside google.auth
Called repeatedly Writes once

Six tests cover these. 48 pass overall.

Before this helps

A key has to exist — Terraform deliberately does not mint one, since that would
put a long-lived credential in state:

gcloud iam service-accounts keys create /dev/stdout \
  --iam-account ocotillo-ingestion@waterdatainitiative-271000.iam.gserviceaccount.com

Then export it as INGESTION_GCP_CREDENTIALS_JSON and run the new phase:

./automated_ingestion/scripts/set_code_location_env.sh credentials

Still ahead

After this, database_connectivity should authenticate and fail on the missing
Postgres role — terraform apply with cloud_sql_instance set, then
ingestion_role.sql with the IAM CREATE ROLE lines uncommented.

🤖 Generated with Claude Code

With the import fixed, database_connectivity reaches the Cloud SQL connector
and fails on DefaultCredentialsError. Dagster+ Serverless runs outside GCP, so
there is no metadata server and google.auth.default() finds nothing.

The service account key travels as a Dagster+ secret and is written to a file
at runtime, because GOOGLE_APPLICATION_CREDENTIALS names a path rather than
holding a value. The file is mode 600 in the process temporary directory, which
the container discards with the run.

Called before importing db.engine rather than after: that module builds its
connector at import time and resolves credentials right then, so doing it
afterwards would be too late. The dlt pipeline calls it too -- gcsfs resolves
credentials the same way, so the raw zone would have failed identically once
the loader got that far.

Existing credentials are never shadowed, so a developer's gcloud login is used
as-is. An unset key is not an error: locally google.auth finds its own, and in
Serverless it fails loudly, which is correct in both cases. A path supplied
instead of the key itself is rejected with a message saying so, since that
mistake would otherwise surface deep inside google.auth.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Coverage

79.28% total — gate is 75%.

Coverage for the Python files changed in this PR
Name Stmts Miss Cover Missing
automated_ingestion/defs/resources.py 11 5 55% 46-58
automated_ingestion/shared/credentials.py 27 1 96% 54
automated_ingestion/sources/san_acacia/dlt_pipeline.py 40 3 92% 178-184
TOTAL 78 9 88%

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Your pull request is automatically being deployed to Dagster Cloud.

Location Status Link Updated
ocotillo-automated-ingestion View in Cloud Aug 19, 2026 at 03:21 AM (UTC)

@jirhiker
jirhiker merged commit 8c1c32d into staging Aug 19, 2026
10 checks passed
@jirhiker
jirhiker deleted the fix/serverless-gcp-credentials branch August 19, 2026 03:19
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