Compare commits

...
Author SHA1 Message Date
Andrew BeveridgeandClaude Opus 4.6 33368a8140 Fix gdrive-validator: Cloud Run IAM + Pushbullet API key newline
The daily GDrive validator has never worked since deployment (Dec 2024).
Two bugs:

1. Gen 2 Cloud Functions are backed by Cloud Run, which has its own IAM
   policy separate from the Cloud Function IAM. The existing
   cloudfunctionsv2.FunctionIamMember grants roles/cloudfunctions.invoker
   on the function resource, but the actual HTTP invocation from Cloud
   Scheduler hits Cloud Run and needs roles/run.invoker there. Added
   cloudrun.IamMember to grant this.

2. The Pushbullet API key in Secret Manager had a trailing newline,
   causing "Invalid header value" errors. Added .strip() to the env var
   read as a defensive fix (also fixed the secret value separately).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 18:50:49 -05:00
2 changed files with 18 additions and 3 deletions

No files matched your search

+17 -2
View File
@@ -197,7 +197,7 @@ gdrive_validator_function = cloudfunctionsv2.Function(
),
)
# Allow Cloud Scheduler to invoke the function
# Allow Cloud Scheduler to invoke the function (Cloud Functions v2 IAM)
gdrive_validator_invoker = cloudfunctionsv2.FunctionIamMember(
"gdrive-validator-scheduler-invoker",
project=PROJECT_ID,
@@ -207,7 +207,7 @@ gdrive_validator_invoker = cloudfunctionsv2.FunctionIamMember(
member=f"serviceAccount:service-{get_project_number()}@gcp-sa-cloudscheduler.iam.gserviceaccount.com",
)
# Allow function's service account to invoke itself (for Cloud Scheduler)
# Allow function's service account to invoke itself (Cloud Functions v2 IAM)
gdrive_validator_sa_invoker = cloudfunctionsv2.FunctionIamMember(
"gdrive-validator-sa-invoker",
project=PROJECT_ID,
@@ -217,6 +217,21 @@ gdrive_validator_sa_invoker = cloudfunctionsv2.FunctionIamMember(
member=gdrive_validator_sa.email.apply(lambda email: f"serviceAccount:{email}"),
)
# Gen 2 Cloud Functions are backed by Cloud Run - the Cloud Run service also needs
# roles/run.invoker for the OIDC token from Cloud Scheduler to be accepted.
# The cloudfunctionsv2.FunctionIamMember above sets IAM on the Cloud Function resource,
# but the actual HTTP invocation hits Cloud Run which has its own IAM policy.
gdrive_validator_run_invoker = cloudrun.IamMember(
"gdrive-validator-run-invoker",
project=PROJECT_ID,
location=REGION,
service=gdrive_validator_function.service_config.service.apply(
lambda svc: svc.split("/")[-1] if svc else "gdrive-validator"
),
role="roles/run.invoker",
member=gdrive_validator_sa.email.apply(lambda email: f"serviceAccount:{email}"),
)
# Cloud Scheduler job to trigger validation daily
gdrive_validator_scheduler = cloudscheduler.Job(
"gdrive-validator-scheduler",
@@ -28,7 +28,7 @@ logger = logging.getLogger(__name__)
# Configuration from environment variables
GDRIVE_FOLDER_ID = os.environ.get("GDRIVE_FOLDER_ID", "1laRKAyxo0v817SstfM5XkpbWiNKNAMSX")
PUSHBULLET_API_KEY = os.environ.get("PUSHBULLET_API_KEY", "")
PUSHBULLET_API_KEY = os.environ.get("PUSHBULLET_API_KEY", "").strip()
# Set to "true" to receive daily summary even when no issues found
# Set to "false" to only receive notifications when issues are detected