{
  "schema": "epok.setup-manifest/1",
  "id": "gcp-cloudrun-otel-traces",
  "version": "1.0.0",
  "title": "Google Cloud Run traces -> Epok with the OpenTelemetry SDK (OTLP/HTTP direct)",
  "summary": "Points the OpenTelemetry SDK of an existing Cloud Run service at Epok with the standard OTEL_* variables (OTLP/HTTP protobuf, x-api-key header) and rolls a new revision. No collector, no new GCP resources.",
  "provider": "gcp",
  "signal": "traces",
  "source": "otlp_traces_cloudrun",
  "tool": "gcloud",
  "estimated_minutes": 3,
  "last_verified": null,
  "prerequisites": {
    "cli": [
      {
        "name": "gcloud",
        "min_version": "470.0.0",
        "check": "gcloud --version",
        "version_regex": "Google Cloud SDK ([0-9]+\\.[0-9]+\\.[0-9]+)"
      },
      {
        "name": "python3",
        "min_version": "3.8.0",
        "check": "python3 --version",
        "version_regex": "Python ([0-9]+\\.[0-9]+\\.[0-9]+)"
      },
      {
        "name": "curl",
        "min_version": "7.68.0",
        "check": "curl --version",
        "version_regex": "^curl ([0-9]+\\.[0-9]+\\.[0-9]+)"
      }
    ],
    "permissions": [
      "roles/run.developer",
      "roles/iam.serviceAccountUser",
      "roles/run.invoker",
      "roles/secretmanager.admin"
    ],
    "permissions_note": "roles/secretmanager.admin (create the secret, bind the runtime service account, delete on uninstall) is for the default key store only; the Secret Manager API (secretmanager.googleapis.com) must be enabled. roles/iam.serviceAccountUser on the service's runtime service account (to roll a revision); roles/run.invoker only for the verify request when the service requires authentication. The app must already use an OpenTelemetry SDK that reads the standard OTEL_* variables and flushes spans before the response (Cloud Run throttles CPU between requests); examples/otel-traces/service shows the minimum.",
    "check_commands": [
      "test -n \"$(gcloud auth list --filter=status:ACTIVE --format='value(account)')\"",
      "gcloud run services describe \"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\" --format='value(status.url)' | grep -q '^https://'",
      "[ \"$EPOK_KEY_STORE\" = env ] || gcloud services list --enabled --project=\"$PROJECT_ID\" --filter=config.name=secretmanager.googleapis.com --format='value(config.name)' | grep -q secretmanager"
    ]
  },
  "inputs": [
    {
      "name": "PROJECT_ID",
      "required": true,
      "actor": "agent",
      "pattern": "^[a-z][a-z0-9-]{4,28}[a-z0-9]$",
      "description": "GCP project of the service.",
      "how_to_get": "gcloud config get-value project"
    },
    {
      "name": "REGION",
      "required": true,
      "actor": "agent",
      "pattern": "^[a-z]+-[a-z]+[0-9]+$",
      "description": "Cloud Run region of the service.",
      "how_to_get": "gcloud run services list --format='value(metadata.name,region)'"
    },
    {
      "name": "CLOUD_RUN_SERVICE",
      "required": true,
      "actor": "agent",
      "pattern": "^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$",
      "description": "Cloud Run service name (confirm with the human)."
    },
    {
      "name": "OTEL_SERVICE_NAME",
      "required": true,
      "actor": "agent",
      "pattern": "^[A-Za-z0-9._-]{1,128}$",
      "description": "service.name for the spans (how the service appears in Epok).",
      "how_to_get": "Ask the human, or use the workload name."
    },
    {
      "name": "EPOK_VERIFY_PATH",
      "default": "/",
      "actor": "agent",
      "pattern": "^/[A-Za-z0-9_./?=&-]*$",
      "description": "Path verify requests. Pick one your instrumented HTTP server handles (the example app traces /work)."
    },
    {
      "name": "EPOK_KEY_STORE",
      "default": "secretmanager",
      "actor": "agent",
      "pattern": "^(secretmanager|env)$",
      "description": "Where the key lives. secretmanager (default, recommended): a Secret Manager secret mounted as OTEL_EXPORTER_OTLP_HEADERS with --update-secrets. env (NOT RECOMMENDED): the header as a plain env var, readable by anyone with run.services.get; use only when Secret Manager is unavailable and the human agrees."
    },
    {
      "name": "EPOK_KEY_SECRET",
      "default": "epok-otlp-headers",
      "actor": "agent",
      "pattern": "^[A-Za-z0-9_-]{1,255}$",
      "description": "Secret Manager secret id (EPOK_KEY_STORE=secretmanager). An existing secret is reused, not overwritten; its value must be x-api-key=<key>."
    },
    {
      "name": "EPOK_LABELS",
      "default": "managed-by=epok",
      "actor": "agent",
      "pattern": "^[a-z][a-z0-9_-]{0,62}=[a-z0-9_-]{0,63}(,[a-z][a-z0-9_-]{0,62}=[a-z0-9_-]{0,63}){0,15}$",
      "description": "Comma-separated key=value labels for the secret (GCP label rules)."
    },
    {
      "name": "EPOK_API_KEY",
      "required": true,
      "secret": true,
      "scope": "ingest",
      "actor": "human",
      "pattern": "^[A-Za-z0-9_.-]{8,200}$",
      "description": "Epok ingest-scope API key, dedicated to this workload.",
      "how_to_get": "A human creates it: Epok -> Settings -> API Keys -> New key (scope: ingest, name: traces-<workload>). Agents must ask for it, never create or guess it, and never write it to a file or a commit."
    },
    {
      "name": "EPOK_READ_API_KEY",
      "required": true,
      "secret": true,
      "scope": "read",
      "actor": "human",
      "pattern": "^[A-Za-z0-9_.-]{8,200}$",
      "description": "Epok API key with read scope, used only by verify to look the canary trace up. May be the same key as EPOK_API_KEY if that key also has read scope.",
      "how_to_get": "A human creates it: Epok -> Settings -> API Keys (scope: read). Agents must ask for it."
    },
    {
      "name": "EPOK_INGEST_HOST",
      "default": "https://ingest.epok.cloud",
      "actor": "agent",
      "pattern": "^(https://[A-Za-z0-9.-]+|http://(127\\.0\\.0\\.1|localhost))(:[0-9]{1,5})?$",
      "description": "Epok OTLP/HTTP ingest base URL, no trailing slash. The exporter appends /v1/traces. Change only if Epok support tells you to."
    },
    {
      "name": "EPOK_API_HOST",
      "default": "https://app.epok.cloud",
      "actor": "agent",
      "pattern": "^(https://[A-Za-z0-9.-]+|http://(127\\.0\\.0\\.1|localhost))(:[0-9]{1,5})?$",
      "description": "Epok API base URL used by verify, no trailing slash."
    },
    {
      "name": "EPOK_TENANT_ID",
      "required": true,
      "actor": "agent",
      "pattern": "^[0-9]{1,10}$",
      "description": "Your Epok tenant (account) id, used in the verify API path.",
      "how_to_get": "Epok -> Settings -> Account (the numeric account id), or ask the human."
    },
    {
      "name": "NONCE",
      "generate": "nonce",
      "actor": "agent",
      "pattern": "^[0-9a-f]{24}$",
      "description": "Canary token: verify sends one request with W3C traceparent trace id 00000000<NONCE> and looks that trace up in Epok. Generated by the runner if not set (24 lowercase hex)."
    }
  ],
  "cost_notes": "One Secret Manager secret (about $0.06/month per active version, plus $0.03 per 10,000 accesses; Cloud Run reads it when an instance starts). No other new GCP resources; one new revision. Exporting adds a few ms per request (the flush before the response). Epok bills the decoded OTLP bytes: about 1-2 KB per 3-span trace (the Python SDK sends uncompressed protobuf unless OTEL_EXPORTER_OTLP_COMPRESSION=gzip; Epok meters after decompression either way, so gzip saves egress, not Epok cost).",
  "notes": [
    "Default key store: Secret Manager. The secret value is the header string x-api-key=<key>, mounted as OTEL_EXPORTER_OTLP_HEADERS with --update-secrets=OTEL_EXPORTER_OTLP_HEADERS=<secret>:latest; the runtime service account gets roles/secretmanager.secretAccessor on that secret only. The key never appears in the service configuration.",
    "EPOK_KEY_STORE=env is NOT RECOMMENDED: it sets OTEL_EXPORTER_OTLP_HEADERS=x-api-key=<key> as a plain env var, visible to anyone with run.services.get and in the console.",
    "Cloud Run throttles CPU outside requests: flush the span processor before the response (the example app does), or deploy with --no-cpu-throttling, or run a collector sidecar. Without one of these the last spans of an idle instance wait for the next request.",
    "Uninstall removes the OTEL_* variables and the secret mount this setup set, then the binding and the secret. If the service had its own values for them before, restore those by hand."
  ],
  "steps": [
    {
      "id": "inspect-service",
      "actor": "agent",
      "destructive": false,
      "idempotent": true,
      "description": "Read the service URL and its runtime service account. Prints EPOK_SERVICE_URL and EPOK_RUNTIME_SA.",
      "run": "URL=\"$(gcloud run services describe \"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\" --format='value(status.url)')\"\ntest -n \"$URL\" || { echo \"service $CLOUD_RUN_SERVICE has no URL\" >&2; exit 1; }\necho \"EPOK_SERVICE_URL=$URL\"\nSA=\"$(gcloud run services describe \"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\" --format='value(spec.template.spec.serviceAccountName)')\"\nif [ -z \"$SA\" ]; then\n  NUM=\"$(gcloud projects describe \"$PROJECT_ID\" --format='value(projectNumber)')\"\n  SA=\"$NUM-compute@developer.gserviceaccount.com\"   # Cloud Run default runtime identity\nfi\necho \"EPOK_RUNTIME_SA=$SA\"",
      "exports": [
        "EPOK_SERVICE_URL",
        "EPOK_RUNTIME_SA"
      ]
    },
    {
      "id": "store-key",
      "actor": "agent",
      "destructive": false,
      "idempotent_check": "case \"$EPOK_KEY_STORE\" in\n  env) exit 0 ;;   # nothing to store (not recommended)\n  secretmanager) gcloud secrets describe \"$EPOK_KEY_SECRET\" --project=\"$PROJECT_ID\" --format='value(name)' >/dev/null 2>&1 ;;\nesac",
      "on_exists": "skip",
      "description": "EPOK_KEY_STORE=secretmanager (default): create the Secret Manager secret EPOK_KEY_SECRET whose value is the header string x-api-key=<key> (from stdin, never on the command line). Skipped if the secret exists, and always skipped with EPOK_KEY_STORE=env.",
      "run": "# The secret value is the whole header string, mounted as OTEL_EXPORTER_OTLP_HEADERS. Read from stdin.\npython3 -c 'import os, sys; sys.stdout.write(\"x-api-key=\" + os.environ[\"EPOK_API_KEY\"])' | gcloud secrets create \"$EPOK_KEY_SECRET\" --project=\"$PROJECT_ID\" \\\n  --replication-policy=automatic --labels=\"$EPOK_LABELS\" --data-file=- --format='value(name)'"
    },
    {
      "id": "grant-runtime-sa",
      "actor": "agent",
      "destructive": false,
      "idempotent": true,
      "description": "Give the service's runtime service account roles/secretmanager.secretAccessor on that one secret. No-op with EPOK_KEY_STORE=env.",
      "run": "if [ \"$EPOK_KEY_STORE\" = env ]; then echo \"EPOK_KEY_STORE=env: no IAM change (not recommended)\"; exit 0; fi\ngcloud secrets add-iam-policy-binding \"$EPOK_KEY_SECRET\" --project=\"$PROJECT_ID\" \\\n  --member=\"serviceAccount:$EPOK_RUNTIME_SA\" --role=roles/secretmanager.secretAccessor --format='value(etag)' >/dev/null\necho \"$EPOK_RUNTIME_SA may read secret $EPOK_KEY_SECRET (roles/secretmanager.secretAccessor on that secret only)\""
    },
    {
      "id": "configure-export",
      "actor": "agent",
      "destructive": false,
      "idempotent": true,
      "description": "Set OTEL_SERVICE_NAME, OTEL_TRACES_EXPORTER, OTEL_EXPORTER_OTLP_PROTOCOL and OTEL_EXPORTER_OTLP_ENDPOINT, and mount the secret as OTEL_EXPORTER_OTLP_HEADERS with --update-secrets (default; with EPOK_KEY_STORE=env the header is a plain env var instead). Other variables are kept. Waits for the new revision to be ready.",
      "run": "python3 -c '\nimport json, os, subprocess, sys\ne = os.environ\nvariables = {\"OTEL_SERVICE_NAME\": e[\"OTEL_SERVICE_NAME\"], \"OTEL_TRACES_EXPORTER\": \"otlp\",\n             \"OTEL_EXPORTER_OTLP_PROTOCOL\": \"http/protobuf\", \"OTEL_EXPORTER_OTLP_ENDPOINT\": e[\"EPOK_INGEST_HOST\"]}\nflags = {\"--update-env-vars\": variables}\nif e[\"EPOK_KEY_STORE\"] == \"secretmanager\":\n    flags[\"--update-secrets\"] = {\"OTEL_EXPORTER_OTLP_HEADERS\": e[\"EPOK_KEY_SECRET\"] + \":latest\"}\nelif e[\"EPOK_KEY_STORE\"] == \"env\":\n    variables[\"OTEL_EXPORTER_OTLP_HEADERS\"] = \"x-api-key=\" + e[\"EPOK_API_KEY\"]   # NOT RECOMMENDED\nelse:\n    sys.exit(\"EPOK_KEY_STORE must be secretmanager or env\")\nsubprocess.run([\"gcloud\", \"run\", \"services\", \"update\", e[\"CLOUD_RUN_SERVICE\"], \"--region=\" + e[\"REGION\"],\n                \"--project=\" + e[\"PROJECT_ID\"], \"--quiet\", \"--flags-file=/dev/stdin\",\n                \"--format=value(status.latestReadyRevisionName)\"], input=json.dumps(flags), text=True, check=True)\n'",
      "timeout_seconds": 900
    }
  ],
  "verify": {
    "emit": "URL=\"$(gcloud run services describe \"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\" --format='value(status.url)')\"\nTOKEN=\"$(gcloud auth print-identity-token --audiences=\"$URL\" 2>/dev/null || gcloud auth print-identity-token)\"\ncurl -fsS -o /dev/null -w \"HTTP %{http_code}\\n\" -H \"Authorization: Bearer $TOKEN\" \\\n  -H \"traceparent: 00-00000000$NONCE-00f067aa0ba902b7-01\" \"$URL$EPOK_VERIFY_PATH\"",
    "call": "printf 'header = \"X-API-Key: %s\"\\n' \"$EPOK_READ_API_KEY\" | curl -K - -fsS \\\n  \"$EPOK_API_HOST/api/v1/tenants/$EPOK_TENANT_ID/traces/00000000$NONCE\" | python3 -c '\nimport json, sys\nd = json.load(sys.stdin)\nspans = [e for es in d.get(\"services\", {}).values() for e in es\n         if e.get(\"fields\", {}).get(\"record_type\") == \"span\"]\nids = {e.get(\"span_id\") for e in spans}\nservices = sorted({e.get(\"service\") for e in spans})\nout = {\n    \"trace_id\": d.get(\"trace_id\"),\n    \"spans\": len(spans),\n    \"services\": services,\n    \"roots\": sum(1 for e in spans if e.get(\"parent_span_id\") not in ids),\n    \"children\": sum(1 for e in spans if e.get(\"parent_span_id\") in ids),\n    \"error_spans\": sum(1 for e in spans if e.get(\"fields\", {}).get(\"span_status\") == \"error\"),\n}\nout[\"ok\"] = True if spans and services == [sys.argv[1]] else None\nprint(json.dumps(out))' \"$OTEL_SERVICE_NAME\"",
    "success": {
      "field": "ok",
      "is": "non_null"
    },
    "timeout_seconds": 180,
    "poll_seconds": 10,
    "reemit_seconds": 60
  },
  "failure_modes": [
    {
      "id": "permission-denied",
      "step": [
        "inspect-service",
        "configure-export"
      ],
      "symptom": "PERMISSION_DENIED on describe or update, or 'Permission iam.serviceaccounts.actAs denied'.",
      "check": "gcloud auth list --filter=status:ACTIVE --format='value(account)'",
      "fix": "The caller lacks roles/run.developer or roles/iam.serviceAccountUser on the runtime service account. Stop and ask a human. Never grant IAM to yourself.",
      "stop_and_ask": true
    },
    {
      "id": "revision-not-ready",
      "step": "configure-export",
      "symptom": "The update fails with 'Revision ... is not ready' or the container failed to start.",
      "check": "gcloud run revisions list --service=\"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\" --limit=3",
      "fix": "Setting env vars does not change code, so the app crashed on start for its own reason (read its logs) or an OTEL_* value is malformed. Cloud Run keeps serving the previous revision. Run uninstall to remove the variables and stop and ask.",
      "stop_and_ask": true
    },
    {
      "id": "secret-not-available",
      "step": [
        "store-key",
        "grant-runtime-sa",
        "configure-export"
      ],
      "symptom": "PERMISSION_DENIED / SERVICE_DISABLED on gcloud secrets, or the revision fails with 'Permission denied on secret' / 'secret ... not found'.",
      "check": "gcloud services list --enabled --project=\"$PROJECT_ID\" --filter=config.name=secretmanager.googleapis.com; gcloud secrets get-iam-policy \"$EPOK_KEY_SECRET\" --project=\"$PROJECT_ID\"",
      "fix": "The Secret Manager API is disabled, you lack roles/secretmanager.admin, or the runtime service account lacks secretAccessor (re-run grant-runtime-sa). Stop and ask; do not fall back to EPOK_KEY_STORE=env without the human's agreement. 'already been set with a different type': the service already has OTEL_EXPORTER_OTLP_HEADERS as a plain env var; ask before removing it.",
      "stop_and_ask": true
    },
    {
      "id": "emit-unauthorized",
      "step": "verify",
      "symptom": "The emit curl fails with HTTP 401 or 403 from Cloud Run (not from Epok).",
      "check": "gcloud run services get-iam-policy \"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\"",
      "fix": "Your identity lacks roles/run.invoker, or the service sits behind IAP/ingress=internal. Ask the human for a way to send one request (or for them to send it with the traceparent header shown).",
      "stop_and_ask": true
    },
    {
      "id": "sdk-not-exporting",
      "step": "verify",
      "symptom": "Requests succeed but the trace never arrives.",
      "check": "gcloud logging read 'resource.type=\"cloud_run_revision\" AND resource.labels.service_name=\"'\"$CLOUD_RUN_SERVICE\"'\" AND textPayload:(\"otlp\" OR \"Failed to export\" OR \"401\")' --project=\"$PROJECT_ID\" --limit=20 --freshness=15m",
      "fix": "'Failed to export ... 401/403' = key (see epok-auth-rejected). No export log lines at all = the app has no OpenTelemetry SDK, or it does not read OTEL_* variables, or spans are buffered under CPU throttling (flush before the response). Stop and ask before changing application code.",
      "stop_and_ask": false
    },
    {
      "id": "epok-auth-rejected",
      "step": "verify",
      "symptom": "Spans never arrive; exporter or collector logs show HTTP 401 or 403 from the Epok ingest host.",
      "check": "Ask the human which key they gave you and its scope (do not print it).",
      "fix": "The ingest key is wrong, revoked, or not ingest scope. Stop and ask the human for a new ingest-scope key. Do not retry in a loop.",
      "stop_and_ask": true
    },
    {
      "id": "verify-read-auth",
      "step": "verify",
      "symptom": "The verify call fails with HTTP 401 or 403 on every poll.",
      "check": "Does EPOK_READ_API_KEY have read scope, and is EPOK_TENANT_ID its tenant?",
      "fix": "403 = the key lacks read scope or belongs to another tenant. Stop and ask the human.",
      "stop_and_ask": true
    },
    {
      "id": "trace-not-found",
      "step": "verify",
      "symptom": "The verify call keeps failing with HTTP 404 (Trace not found) until the timeout.",
      "check": "Re-read the emit output: did the request/invocation succeed? Then check the failure modes for this runtime.",
      "fix": "The canary trace did not reach Epok, or your code does not continue an incoming W3C traceparent (then spans arrive under another trace id: look for OTEL_SERVICE_NAME in Epok -> Traces). Report; do not change sampling or keys to make it pass.",
      "stop_and_ask": false
    },
    {
      "id": "wrong-service-name",
      "step": "verify",
      "symptom": "Verify finds the trace but ok is null and services is not [OTEL_SERVICE_NAME].",
      "check": "Look at services in the verify JSON.",
      "fix": "Something else sets service.name (OTEL_RESOURCE_ATTRIBUTES or code). Report it to the human; do not edit application code without asking.",
      "stop_and_ask": true
    }
  ],
  "uninstall": [
    {
      "id": "remove-export-config",
      "actor": "agent",
      "destructive": true,
      "description": "Remove the OTEL_* variables and the OTEL_EXPORTER_OTLP_HEADERS secret mount this setup set and roll a new revision. A missing service counts as done.",
      "run": "if ! gcloud run services describe \"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\" --format='value(metadata.name)' >/dev/null 2>&1; then\n  echo \"service $CLOUD_RUN_SERVICE not found; nothing to do\"; exit 0\nfi\ngcloud run services update \"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\" --quiet \\\n  --remove-env-vars=OTEL_SERVICE_NAME,OTEL_TRACES_EXPORTER,OTEL_EXPORTER_OTLP_PROTOCOL,OTEL_EXPORTER_OTLP_ENDPOINT\"$([ \"$EPOK_KEY_STORE\" = env ] && echo ,OTEL_EXPORTER_OTLP_HEADERS)\" \\\n  $([ \"$EPOK_KEY_STORE\" = env ] || echo --remove-secrets=OTEL_EXPORTER_OTLP_HEADERS) \\\n  --format='value(status.latestReadyRevisionName)'",
      "timeout_seconds": 900
    },
    {
      "id": "remove-secret-access",
      "actor": "agent",
      "destructive": true,
      "skip_if_failed": [
        "remove-export-config"
      ],
      "description": "Remove the runtime service account's secretAccessor binding on the secret. Not run while the service may still mount it.",
      "run": "if [ \"$EPOK_KEY_STORE\" = env ]; then echo \"EPOK_KEY_STORE=env: nothing to unbind\"; exit 0; fi\n# Uninstall may run in a fresh session: derive the runtime SA again (same rule as inspect-service).\nSA=\"${EPOK_RUNTIME_SA:-}\"\nif [ -z \"$SA\" ] && gcloud run services describe \"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\" --format='value(metadata.name)' >/dev/null 2>&1; then\n  SA=\"$(gcloud run services describe \"$CLOUD_RUN_SERVICE\" --region=\"$REGION\" --project=\"$PROJECT_ID\" --format='value(spec.template.spec.serviceAccountName)')\"\n  if [ -z \"$SA\" ]; then SA=\"$(gcloud projects describe \"$PROJECT_ID\" --format='value(projectNumber)')-compute@developer.gserviceaccount.com\"; fi\nfi\nif [ -z \"$SA\" ]; then echo \"service gone and EPOK_RUNTIME_SA unset: the binding is removed with the secret by delete-key-secret\"; exit 0; fi\nif OUT=\"$(gcloud secrets remove-iam-policy-binding \"$EPOK_KEY_SECRET\" --project=\"$PROJECT_ID\" --member=\"serviceAccount:$SA\" --role=roles/secretmanager.secretAccessor 2>&1)\"; then echo \"binding removed\"\nelif grep -qiE \"not found|NOT_FOUND|does not have\" <<< \"$OUT\"; then echo \"binding or secret already gone\"; else echo \"$OUT\" >&2; exit 1; fi"
    },
    {
      "id": "delete-key-secret",
      "actor": "agent",
      "destructive": true,
      "skip_if_failed": [
        "remove-export-config"
      ],
      "description": "Delete the Secret Manager secret (already gone counts as done). Skip this step if another service still mounts it.",
      "run": "if [ \"$EPOK_KEY_STORE\" = env ]; then echo \"EPOK_KEY_STORE=env: no secret to delete\"; exit 0; fi\nif OUT=\"$(gcloud secrets delete \"$EPOK_KEY_SECRET\" --project=\"$PROJECT_ID\" --quiet 2>&1)\"; then echo \"deleted secret $EPOK_KEY_SECRET\"\nelif grep -qiE \"not found|NOT_FOUND\" <<< \"$OUT\"; then echo \"secret already gone\"; else echo \"$OUT\" >&2; exit 1; fi"
    }
  ]
}
