Request icon
Script icon
Docker icon
Set icon
If icon
Log icon
SlackIncomingWebhook icon
Fail icon
Return icon
Schedule icon

Supabase Storage Bucket Egress Bandwidth & Quota Guardrail

Audit Supabase storage egress, detect bandwidth surges, enforce CDN caching policies, and alert teams via Slack with Kestra.

Categories
CloudData

Automated FinOps guardrail and quota sentinel for cloud-hosted Supabase storage buckets. Inspects egress bandwidth consumption, evaluates monthly tier allocations, identifies hotlinked public assets, applies defensive CDN caching and transfer caps, persists metrics in the Kestra KV store, and dispatches real-time Slack alerts.

How it works

  1. Billing Usage Ingestion: fetch_billing_usage queries the Supabase Management API (GET /v1/projects/{ref}/billing/usage) with an encrypted Bearer token to inspect current month-to-date egress bandwidth consumption.
  2. Storage Bucket Inventory: fetch_storage_buckets retrieves metadata for all hosted buckets (GET /v1/projects/{ref}/storage/buckets), classifying public versus private access and identifying buckets without file transfer limits.
  3. Quota & Risk Evaluation: evaluate_egress_and_buckets calculates bandwidth usage in gigabytes, computes percentage utilization against the tier limit, detects runaway egress risks, and assigns a severity rating (NOMINAL, WARNING, or CRITICAL).
  4. Telemetry State Persistence: persist_usage_telemetry stores the complete telemetry payload inside Kestra KV store under supabase_storage_egress_{ref} for historical trending and cross-flow consumption.
  5. Defensive Policy Enforcement: If egress exceeds 80% or 95% of the monthly allocation, apply_cdn_caching_guardrail proactively updates public bucket configurations via PUT /v1/projects/{ref}/storage/buckets/{bucketId} to enforce a 5 MB transfer cap and edge CDN caching.
  6. Slack Alerting & Fail Gate: notify_slack_guardrail_breach dispatches an operational incident message to Slack. If usage reaches the 95% critical threshold, enforce_critical_quota_escalation terminates the flow with an execution failure to trigger on-call escalation.

Architecture diagram

flowchart TD
    A[periodic_egress_guardrail_schedule Trigger] --> B[fetch_billing_usage HTTP Request]
    B --> C[fetch_storage_buckets HTTP Request]
    C --> D[evaluate_egress_and_buckets Python Script]
    D --> E[persist_usage_telemetry KV Set]
    E --> F[guardrail_decision_gate Flowable If]
    F -- Threshold Exceeded --> G[apply_cdn_caching_guardrail If]
    G -- Auto Remediate True --> H[update_bucket_policy HTTP PUT]
    H --> I[log_remediation_action Log]
    I --> J[notify_slack_guardrail_breach Slack Webhook]
    G -- Auto Remediate False --> J
    J --> K[enforce_critical_quota_escalation If]
    K -- Critical Quota --> L[fail_on_critical_quota Fail]
    K -- Warning Only --> M[return_telemetry_summary Return]
    F -- Nominal Usage --> N[log_nominal_storage_metrics Log]
    N --> M

Key capabilities

  • Proactive Egress Budget Protection: Prevents runaway billing surprises by monitoring consumption before monthly tier quotas are depleted.
  • Hotlinking & Viral Surge Detection: Pinpoints public storage buckets lacking file size restrictions that are vulnerable to asset scraping or viral spikes.
  • Automated Defensive Remediation: Applies immediate transfer caps and CDN caching rules to mitigate downstream bandwidth drain.
  • Historical Telemetry Tracking: Maintains current and past consumption records in the native Kestra KV store without requiring external metrics stores.
  • Multi-Level Incident Escalation: Delivers structured warnings at 80% utilization and triggers automated pipeline failures at 95% utilization for on-call notification.

What you get

  • Continuous, automated FinOps monitoring of Supabase storage bandwidth.
  • Early warning detection for viral downloads and asset hotlinking.
  • Proactive rate limiting and defensive CDN caching policy deployment.
  • Detailed Slack notifications containing bucket risk tallies and usage percentages.
  • Centralized telemetry in Kestra KV store for cross-execution tracking.

Who it's for

  • FinOps and Cloud Operations engineers managing cloud infrastructure budgets.
  • Platform Engineers maintaining Supabase production instances and storage buckets.
  • Site Reliability Engineers establishing automated safeguards against service exhaustion.
  • Data and Full-Stack teams serving public media assets and user uploads.

Why orchestrate this with Kestra

  • Native KV Store Integration: Store operational state directly in Kestra without provisioning external databases.
  • Declarative HTTP Orchestration: Query and mutate Supabase Management endpoints using standard declarative tasks with built-in retries and timeouts.
  • Secure Credential Isolation: Mask API access tokens and Slack webhooks securely with Kestra secret management.
  • Deterministic Branching: Manage warning thresholds, defensive updates, and emergency escalation paths in a single auditable workflow.

Prerequisites

  • A Supabase project with an active management API personal access token.
  • Docker daemon available to Kestra workers for isolated Python script execution.
  • A Slack Incoming Webhook URL configured for alert delivery.

Secrets

  • SUPABASE_ACCESS_TOKEN: Supabase personal access token with permissions to read project billing usage and update storage buckets.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL for team alerts.

Quick start

  1. Register SUPABASE_ACCESS_TOKEN and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Import this blueprint into the company.finops namespace.
  3. Set project_ref to your Supabase project ID and verify bandwidth_cap_gb matches your subscription tier (for example, 50 GB for Pro tier).
  4. Run a manual execution to audit current egress levels and record initial metrics in the KV store.
  5. Enable periodic_egress_guardrail_schedule for automated 6-hour continuous audits.

How to extend

  • Edge CDN Cache Purge: Add an io.kestra.plugin.core.http.Request task to trigger a Cloudflare or Fastly CDN cache purge on affected asset paths.
  • PagerDuty Incident Escalation: Integrate io.kestra.plugin.pagerduty.notifications.PagerDutyAlert inside the critical branch for immediate on-call dispatch.
  • Automated Project Tier Upgrade: Trigger a subflow to request a bandwidth quota increase or upgrade the project plan when legitimate traffic growth occurs.
  • Multi-Project Fleet Supervision: Wrap this flow in a parent loop to iterate across all project references in your Supabase organization.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.