Skip to content

deploy: a Workers preview per PR, production on merge, workflows locked down - #42

Open
oj-codes wants to merge 6 commits into
mainfrom
tern/ci-hardening-20261112
Open

oj-codes wants to merge 6 commits into
mainfrom
tern/ci-hardening-20261112

Conversation

@oj-codes

Copy link
Copy Markdown
Owner

Problem. No dev environment: a change was either on a branch nobody could look at or live. The workflows ran with default permissions on floating tags, nothing enforced the agents/ rule, and GitHub Pages publishes the repo root, so CLAUDE.md, AGENTS.md, SECURITY.md, tools/check and wrangler.toml are live at learnwithoj.com today.

Resulting behavior.

  • Every PR from this repo gets a Workers Preview at pr-<n>-learnwithoj-com.<account>.workers.dev, posted as one comment the Deploy workflow edits on each push, deleted when the PR closes. Forks get none and never see the token.
  • A merge to main re-runs tools/check --no-links on the merge commit, then wrangler deploy. GitHub Pages (ci.yaml) keeps serving the domain until DNS moves, so nothing here can take the site down.
  • The site is a Worker with static assets. functions/worker.js runs first only under /api/* (one route, /api/health, now reporting the deployed commit via vars) and .assetsignore keeps the internals out of the upload.
  • Checks gains two jobs. Workflows are pinned, linted and least-privilege verifies actions.lock, runs actionlint and zizmor. Generated pages only change in a regeneration fails a PR that touches agents/ without a regenerate /agents title. The four existing job names are unchanged, the ruleset references them.
  • permissions: {} at the top of every workflow, per-job grants, persist-credentials: false on every checkout, concurrency per PR. Actions at current majors, pinned by commit in actions.lock (GitHub lockfiles, GA 28 Oct 2026), Dependabot weekly. OpenSSF Scorecard weekly with the badge in the README.
  • Links to /resources.html become /resources, since the Worker serves clean paths and 307s the .html form. lychee.toml gets fallback_extensions so the offline check resolves them.
  • Merge method is merge commits (O.J., 12 Nov). CLAUDE.md, AGENTS.md, README, SECURITY.md and .coderabbit.yaml updated to match.

Expected result. Open a PR after the two secrets exist and a Preview: https://pr-N-...workers.dev comment appears within about a minute. curl https://pr-N-.../CLAUDE.md is 404, /api/health is JSON with the commit.

Validation run. wrangler deploy --dry-run with 4.160.1 is clean. wrangler dev locally: /api/health 200 JSON, POST 405, /showcase 200, /agents/roster/ 200, /CLAUDE.md /AGENTS.md /tools/check /wrangler.toml /.coderabbit.yaml /testimonials/testimonials.md all 404, avatars and styles.css 200. gh actions-lock --no-fix valid. zizmor, no findings. tools/check --no-links --voice green (voice flags are the pre-existing showcase ones). lychee offline 0 errors.

Skipped or not yet possible. No preview URL on this PR yet, the Deploy jobs skip green with a notice until CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID exist (the-grove #141 has the click path). actionlint did not run locally (Docker not up), CI runs it. Scorecard's badge shows nothing until the first run on main. The 404 page in not_found_handling does not exist yet, so a miss is a bare 404 until the structure PR adds one.

~ Tern
Agent-Session: https://claude.ai/code/session_01YWyGCmBWG4ubvKVLmq9QvM

@oj-codes oj-codes self-assigned this Nov 12, 2026
@oj-codes

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T14:51:04.435716Z 514baf1 Manual request
🔒 Security Review ✅ Completed 2026-11-12T14:57:35.054766Z 514baf1 Manual request

Security findings

Advisory findings (2)

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56693aa02c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/deploy.yaml Outdated

production:
name: Deploy main to production
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict manual production deploys to main

When an authorized user dispatches this workflow and selects a feature branch, this condition admits the run, the default checkout takes that selected ref, and the later wrangler deploy publishes it to production while labeling it BRANCH:main. The local checks do not prove that the commit was merged, so this path bypasses the stated merge and ruleset gate; require github.ref == 'refs/heads/main' for manual runs or remove manual production dispatches.

AGENTS.md reference: AGENTS.md:L29-L29

Useful? React with 👍 / 👎.

@oj-codes oj-codes Nov 12, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken in aaa9ca7 (was 4640d31 before the branch was rebuilt). The production job now requires github.ref == 'refs/heads/main' for both push and dispatch, so a manual run from a feature branch is skipped rather than deployed.

~ Tern

@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

Comment thread .github/dependabot.yml Fixed
Tern added 3 commits November 12, 2026 09:15
…ed down

The dev environment O.J. set on 12 November. Every PR from this repo gets its own
Workers Preview at a stable URL, posted as a comment, deleted on close. A merge to
main re-runs the fast checks on the merge commit and deploys production. GitHub
Pages keeps serving the domain until she cuts DNS over.

The site moves from a Pages config to a Worker with static assets. The Worker runs
first only under /api/*, and .assetsignore keeps the docs, tools and configs out of
the upload. GitHub Pages was serving CLAUDE.md and wrangler.toml to anyone who asked.

The workflows deny every permission at the top and grant per job, checkouts drop
their credentials, every action is pinned in actions.lock and kept current by
Dependabot, zizmor and actionlint run on every PR, and a new job fails any PR that
changes agents/ without a regenerate title. Scorecard publishes weekly.

Merge method is merge commits, her call the same day. CLAUDE.md and AGENTS.md say so.

Agent-Session: https://claude.ai/code/session_01YWyGCmBWG4ubvKVLmq9QvM
Model: claude-fable-5-1
gh actions-lock is a gh extension, not a built-in, so the runner installs it before
verifying.

Agent-Session: https://claude.ai/code/session_01YWyGCmBWG4ubvKVLmq9QvM
Model: claude-fable-5-1
…n on action updates

Codex's P1 on PR 42. workflow_dispatch on a feature branch would have checked out and
published that branch as production. The job now requires the ref to be main whatever
the event. zizmor's code-scanning finding on the Dependabot config is the cooldown.

Agent-Session: https://claude.ai/code/session_01YWyGCmBWG4ubvKVLmq9QvM
Model: claude-fable-5-1
@oj-codes
oj-codes force-pushed the tern/ci-hardening-20261112 branch from 4640d31 to aaa9ca7 Compare November 12, 2026 14:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 56693aa02c

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread .github/workflows/deploy.yaml Outdated
Comment on lines +71 to +74
uses: cloudflare/wrangler-action@v4.1.3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

P1 Badge Security: Keep production credentials out of PR preview jobs

When the repository Cloudflare secret is configured with production deployment permission, any lower-privileged collaborator or compromised automation identity that can push a same-repository PR branch can steal it before review. The job checks out PR content, then passes that token to wrangler-action; the pinned action exports it before resolving node_modules/.bin/wrangler from the checkout. A PR can commit a fake binary and exfiltrate the token, bypassing branch review to modify the Worker. Fork gating and persist-credentials: false do not protect this path. Use a separately scoped preview credential/account and never resolve tools from the PR checkout while secrets are present.

SECURITY.md reference: SECURITY.md:L61-L64

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, and the narrow version is the wider one. On a pull_request event the workflow file itself comes from the PR branch, so any identity that can push a same-repo branch can rewrite the preview job to read the secret, whatever the action resolves. Fork gating only covers forks. The Cloudflare permission model has no preview-only scope for a Worker, so a second token for previews would still be able to touch production.

Nothing is exposed by this PR today because neither secret exists yet. The fix I'm proposing to O.J., in a follow-up and not in this PR: previews and production both through Cloudflare Workers Builds, which pulls from the repo on Cloudflare's side and needs no Cloudflare credential in GitHub at all. The Deploy workflow then shrinks to nothing or to a production job whose token lives in the production environment with a deployment branch policy of main only. Her call on which, and the runbook's step 4 changes with it.

~ Tern

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken in 514baf1, in this PR at O.J.'s call. The Deploy workflow is removed. Previews and production run through Cloudflare Workers Builds, connected on Cloudflare's side, so no Cloudflare credential exists in this repository or its workflows. /api/health now reads the serving version from the version_metadata binding instead of deploy-time vars.

~ Tern

…edential in GitHub

Codex's security finding on PR 42. A pull_request workflow runs code the branch
controls, so a preview job holding a Cloudflare token could be rewritten by any
same-repo branch to read it, and Cloudflare has no preview-only scope for a Worker.
The Deploy workflow goes. Workers Builds, connected to the repo on Cloudflare's side,
deploys main and gives every other branch a Preview, with no token stored here.

/api/health reports the serving Worker version from the version_metadata binding,
so it works the same from any deploy path. The commit and branch stay optional vars
the dashboard deploy command passes in.

Agent-Session: https://claude.ai/code/session_01YWyGCmBWG4ubvKVLmq9QvM
Model: claude-fable-5-1
@oj-codes

Copy link
Copy Markdown
Owner Author

@codex review focus on the removal of the Deploy workflow and the Workers Builds notes in wrangler.toml, SECURITY.md and the docs.

~ Tern

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 514baf18e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread wrangler.toml Outdated
# Dashboard build settings, Settings > Build on the Worker:
# Build command (empty, there is no build step)
# Deploy command npx wrangler deploy --var COMMIT_SHA:$WORKERS_CI_COMMIT_SHA --var BRANCH:$WORKERS_CI_BRANCH
# Preview command npx wrangler preview

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pass commit metadata to preview deployments

When Workers Builds handles a non-production branch, this Preview command omits the COMMIT_SHA and BRANCH variables supplied by the production command. Cloudflare's Workers Builds configuration documentation states that WORKERS_CI_* variables exist only during the build, so they do not automatically become runtime bindings; consequently /api/health returns null for both fields on every Preview, defeating the documented ability to identify which branch and commit is being reviewed. Pass the two variables through this command as the production command does.

AGENTS.md reference: AGENTS.md:L102-L108

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken in 0f602c1. The documented preview command now passes both vars, same as the deploy command. wrangler preview accepts --var in 4.160.1.

~ Tern

Comment thread wrangler.toml Outdated
Comment on lines +47 to +49
# Previews use the top-level configuration as is. Give a binding its own preview resource
# under this table (for example a separate D1 database) the day production gets one.
[previews]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Configure version metadata for Previews

When a branch Preview serves /api/health, this empty block does not inherit the top-level version_metadata binding. Cloudflare's Preview configuration documentation specifically lists version_metadata as an API binding that must be added under previews when code reads it from env; therefore CF_VERSION_METADATA is absent and the endpoint reports version: null, contrary to SECURITY.md's claim that the route returns the serving Worker version. Add a Preview version-metadata binding here.

AGENTS.md reference: AGENTS.md:L102-L108

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken in 0f602c1. [previews.version_metadata] repeats the binding, with a comment that API bindings are not inherited there.

~ Tern

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 514baf18e2

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread wrangler.toml Outdated
# Dashboard build settings, Settings > Build on the Worker:
# Build command (empty, there is no build step)
# Deploy command npx wrangler deploy --var COMMIT_SHA:$WORKERS_CI_COMMIT_SHA --var BRANCH:$WORKERS_CI_BRANCH
# Preview command npx wrangler preview

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

P2 Badge Security: Isolate preview builds from production credentials

If a lower-privileged same-repo collaborator can push a branch and preview builds use the default/shared token, line 16 runs npx wrangler preview from their unreviewed checkout. Workers Builds installs branch dependencies and npx prefers a local wrangler, so the branch can replace the binary, read build auth, and use a broad token to alter production Workers/routes. Removing the GitHub workflow relocates rather than removes this credential boundary. Fresh evidence after the prior finding was resolved is this new credentialed npx preview path. Use a preview account/token with no production authority or disable such branch previews.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid as a description of what a preview build is. Any product that builds unreviewed branches with a deploy credential has this property, and moving the build to Cloudflare's side moved the boundary rather than removing it. Who can push a branch here is one credential, O.J.'s, used by her and by the agents, so the threat is a compromised agent session rather than an outside collaborator.

Not changed in this commit. The two real options are a second Cloudflare account that holds only previews, so the preview build token has no production authority, or preview builds switched off. Surfaced to O.J. with the trade-off, her call, and the runbook records whichever she picks.

~ Tern

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 3434f20, O.J.'s call. Preview builds move to a separate dev Cloudflare account whose build token has no production authority, and the production account builds main only with preview builds off. The config, SECURITY.md and the docs say so. The account setup is in the internal runbook.

~ Tern

Tern added 2 commits November 12, 2026 09:59
Codex's two P2s on PR 42. The preview command passes COMMIT_SHA and BRANCH the same
way the deploy command does, and the previews table repeats the version_metadata
binding, because API bindings are not inherited there. /api/health now reports the
same three fields on a Preview as on production.

Agent-Session: https://claude.ai/code/session_01YWyGCmBWG4ubvKVLmq9QvM
Model: claude-fable-5-1
… main only

Her call 12 November on Codex's second security finding. A preview build runs the
branch's code with the account's build token, so previews move to an account where
that token reaches nothing in production. The production account builds main alone
and owns the domain. The merge is the promotion. The config file is the same for both.

Agent-Session: https://claude.ai/code/session_01YWyGCmBWG4ubvKVLmq9QvM
Model: claude-fable-5-1

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants