Secrets and rotation
The secret inventory, setting and rotating secrets with wrangler, the optional bulk helper, and when to require secrets.
Secret inventory
| Secret | Lives in | Used by |
|---|---|---|
NOTIFY_API_KEY, SLACK_BOT_TOKEN, SLACK_TARGETS | Worker secrets (runtime) | The Worker |
CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID | GitHub repository secrets | Deploy workflows only, if you deploy with Actions |
ZUDO_SLACK_NOTIFY_URL, ZUDO_SLACK_NOTIFY_API_KEY | The sender env file, outside the repository | Senders only |
| A backup of the values above | Wherever you keep secrets | You |
Worker secrets are the runtime values.
NOTIFY_API_KEYis shared with every sender;SLACK_BOT_TOKENandSLACK_TARGETSstay on the Worker.GitHub repository secrets hold Cloudflare deploy credentials only. Never put the Slack token or relay key there.
The sender env file holds the API URL (for example
https:) and the relay key. Keep it outside the checkout, for example at/ / notify. example. com/ v1/ notify "$HOME/.. config/ zudo- slack- notify/ sender. env" Your own backup is optional but worth having: the Worker cannot show you a secret once it is set.
Senders never hold SLACK_BOT_TOKEN or a Cloudflare token.
Set or rotate a secret with wrangler
From app/, wrangler secret put prompts for the value, so it never appears on the command line or in shell history:
cd app
pnpm exec wrangler secret put NOTIFY_API_KEY
pnpm exec wrangler secret put SLACK_BOT_TOKEN
pnpm exec wrangler secret put SLACK_TARGETSSLACK_TARGETS is a JSON object of aliases to channel IDs, for example {"general":"C0123456789"}. Run pnpm exec wrangler secret list to see which names are set. To revoke one, run pnpm exec wrangler secret delete NAME; the Worker then answers 503 server_misconfigured again.
pnpm ops:push-secrets
Optional bulk helper. pnpm ops:push-secrets, run from the repository root, runs scripts/ and uploads all three Worker secrets from an env file in one go.
Env file resolution:
--env-file <path>first, then theZUDO_SLACK_NOTIFY_WORKER_ENVenvironment variable. With neither, it exits2withpass --env-file <path> or set ZUDO_SLACK_NOTIFY_WORKER_ENV. There is no default location. The file isKEY=valuelines; comments, blank lines, anexportprefix, and one pair of surrounding quotes are accepted. Keep it outside the repository.Uploads only the non-empty values of
NOTIFY_API_KEY,SLACK_BOT_TOKEN, andSLACK_TARGETS, in a singlewrangler secret bulkrun againstapp/. The temporary file it hands to wrangler is private and is removed afterwards.Never prints values. Output is one line per name:
NAME: set,NAME: skipped (empty), orNAME: would set (dry run). Validation errors name the key and the rule, never the value.Validates shape first, with the same checks the Worker applies at runtime (it imports them from
app/): the key is 32 to 256 printable ASCII characters without whitespace, the token issrc/ notification. ts xoxb-followed by 5 to 495 letters, digits, or dashes, and the targets are a JSON object of at most 16 KiB with 1 to 100 aliases, each lowercase kebab-case (^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$, at most 64 characters) and mapped to a channel ID matching^[CGD][A-Z0-9]{8,63}$.If any non-empty value is invalid, it uploads nothing at all. It also fails if every value is empty.
--dry-runvalidates and reports which names it would upload, without uploading.
Exit codes: 0 success (or a valid dry run), 1 a value failed validation, nothing was left to upload, or wrangler failed, 2 a usage problem (unknown argument, missing --env-file path, unreadable env file, or no env file given by flag or ZUDO_SLACK_NOTIFY_WORKER_ENV).
pnpm ops:push-secrets --env-file "$HOME/.config/zudo-slack-notify/worker.env" --dry-run
pnpm ops:push-secrets --env-file "$HOME/.config/zudo-slack-notify/worker.env"
export ZUDO_SLACK_NOTIFY_WORKER_ENV="$HOME/.config/zudo-slack-notify/worker.env"
pnpm ops:push-secretsEmpty means skip, not delete
A blank value in the env file leaves the deployed secret untouched, and the script prints the wrangler secret delete command for each skipped name. To revoke one, delete it explicitly from app/:
cd app
pnpm exec wrangler secret delete SLACK_BOT_TOKENDeleting a secret makes the Worker answer 503 server_misconfigured again.
Rotate the relay key
Generate a new key:
openssl rand -hex 32.Update the Worker secret:
pnpm exec wrangler secret put NOTIFY_API_KEYfromapp/(or edit your worker env file and runpnpm ops:push-secrets).Update
ZUDO_SLACK_NOTIFY_API_KEYin every sender env file.
The old key stops working as soon as the new secret is live, so update every sender file around the same time. Until they match, senders get 401 unauthorized (CLI exit 1).
Rotate the Slack token
In the Slack app dashboard, reinstall the app or regenerate the token and copy the new
xoxb-value.Update the Worker secret:
pnpm exec wrangler secret put SLACK_BOT_TOKENfromapp/.
No sender change is needed. A revoked or stale token shows up as slack_rejected with invalid_auth, token_revoked, or token_expired in the message.
Change targets
Update SLACK_TARGETS with pnpm exec wrangler secret put SLACK_TARGETS from app/. Invite the bot to any new channel first, or sends fail with not_in_channel. An alias removed from the map returns 403 target_not_allowed.
When to add [secrets] required
app/ deliberately has no [secrets] required block yet. The first deploy can happen before the Slack token exists, so the Worker must be able to deploy without it and fail closed. Once Slack is wired and all three secrets exist on the deployed Worker, add:
[secrets]
required = ["NOTIFY_API_KEY", "SLACK_BOT_TOKEN", "SLACK_TARGETS"]so a later deploy cannot silently ship without them. Keep the top-level scalars above every [table] in the file.
Smoke test variables for the bundled deploy workflows
Optional CI configuration, only relevant if you deploy with the bundled GitHub Actions workflows. Set these as GitHub repository variables (not secrets):
| Variable | Required | Meaning |
|---|---|---|
APP_BASE_URL | By the app smoke job | Bare API origin, no path, for example https: |
DOC_BASE_URL | By the doc smoke job | Bare docs origin, no path, for example https: |
SLACK_WIRED | No | Set to true after the first delivered message to retire the 503 server_misconfigured tolerance |
scripts/ has no built-in origin defaults. If the origin for the mode being run is missing or empty, it exits non-zero with APP_BASE_URL is required (or DOC_BASE_URL).
The app smoke test posts to / without credentials and inspects the status. SLACK_WIRED selects what is acceptable:
SLACK_WIRED | Unauthenticated POST answer |
|---|---|
not true (default) | 401 passes, and 503 with code server_misconfigured is also tolerated |
true | Only 401 passes; any 503 fails |
Any success response fails in both modes, since an unauthenticated POST must never succeed. deploy-app.yml passes the repository variables to the script as APP_BASE_URL and SLACK_WIRED; deploy-doc.yml passes DOC_BASE_URL.
Set SLACK_WIRED to true after the first delivered message, as described in Send the first message. After that, a 503 means a secret went missing and the smoke run fails.