zudo-slack-notify

Type to search...

to open search from anywhere

Secrets and rotation

The secret inventory, setting and rotating secrets with wrangler, the optional bulk helper, and when to require secrets.

Secret inventory

SecretLives inUsed by
NOTIFY_API_KEY, SLACK_BOT_TOKEN, SLACK_TARGETSWorker secrets (runtime)The Worker
CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_IDGitHub repository secretsDeploy workflows only, if you deploy with Actions
ZUDO_SLACK_NOTIFY_URL, ZUDO_SLACK_NOTIFY_API_KEYThe sender env file, outside the repositorySenders only
A backup of the values aboveWherever you keep secretsYou
  • Worker secrets are the runtime values. NOTIFY_API_KEY is shared with every sender; SLACK_BOT_TOKEN and SLACK_TARGETS stay 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://notify.example.com/v1/notify) and the relay key. Keep it outside the checkout, for example at "$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_TARGETS

SLACK_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/push-worker-secrets.mjs and uploads all three Worker secrets from an env file in one go.

  • Env file resolution: --env-file <path> first, then the ZUDO_SLACK_NOTIFY_WORKER_ENV environment variable. With neither, it exits 2 with pass --env-file <path> or set ZUDO_SLACK_NOTIFY_WORKER_ENV. There is no default location. The file is KEY=value lines; comments, blank lines, an export prefix, 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, and SLACK_TARGETS, in a single wrangler secret bulk run against app/. 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), or NAME: 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/src/notification.ts): the key is 32 to 256 printable ASCII characters without whitespace, the token is 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-run validates 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-secrets

Empty 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_TOKEN

Deleting a secret makes the Worker answer 503 server_misconfigured again.

Rotate the relay key

  1. Generate a new key: openssl rand -hex 32.

  2. Update the Worker secret: pnpm exec wrangler secret put NOTIFY_API_KEY from app/ (or edit your worker env file and run pnpm ops:push-secrets).

  3. Update ZUDO_SLACK_NOTIFY_API_KEY in 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

  1. In the Slack app dashboard, reinstall the app or regenerate the token and copy the new xoxb- value.

  2. Update the Worker secret: pnpm exec wrangler secret put SLACK_BOT_TOKEN from app/.

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/wrangler.toml 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):

VariableRequiredMeaning
APP_BASE_URLBy the app smoke jobBare API origin, no path, for example https://notify.example.com
DOC_BASE_URLBy the doc smoke jobBare docs origin, no path, for example https://docs.example.com
SLACK_WIREDNoSet to true after the first delivered message to retire the 503 server_misconfigured tolerance

scripts/smoke.sh 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 /v1/notify without credentials and inspects the status. SLACK_WIRED selects what is acceptable:

SLACK_WIREDUnauthenticated POST answer
not true (default)401 passes, and 503 with code server_misconfigured is also tolerated
trueOnly 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.

Revision History

CreatedUpdated