Skip to content

ci: protect main with rulesets and push releases with a deploy key - #13

Merged
kalaspuff merged 1 commit into
mainfrom
fctl/47-protect-main
Oct 18, 2026
Merged

kalaspuff merged 1 commit into
mainfrom
fctl/47-protect-main

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

The same rules as hyperstructure/fctl#97 (its ADR 0021 has the reasoning).

What changes

  • .github/rulesets/main.json, the ruleset to apply to main:
    • squash-merged pull requests only, linear history, no force pushes or deletion;
    • passing check and Conventional Commits;
    • a code owner's approval, from someone who didn't push the last commit.
    • Deploy keys bypass it. Organization owners bypass it on pull requests only.
  • .github/rulesets/release-tags.json: only deploy keys create, move or delete v* tags. fctl's web app and fctl.sh pin these tags.
  • .github/CODEOWNERS: @kalaspuff.
  • Release workflow: the job runs in production and checks out over SSH with RELEASE_DEPLOY_KEY, so its push gets past the rulesets. Every run, a dry run too, starts from main.
    • Unlike a GITHUB_TOKEN push, that push starts workflows. CI checks the tag, which it never did before, and the Release workflow runs again and finds nothing due.
  • Docs: AGENTS.md and the commit and release skills.

Order

  1. An admin creates the production environment (main only), adds the release deploy key and sets RELEASE_DEPLOY_KEY.
  2. Merge this. Its own Release run then checks out with the key.
  3. Apply the rulesets from these files.

Verified

  • npm run check passes. Biome formatted the JSON.
  • npm test and npm run build pass.
  • actionlint passes.

Refs hyperstructure/fctl#22.

Session: https://app.fctl.sh/s/ses_01M58A7MAFDWKZDCA239GR6H6G

Related pull requests

The repository is public, and agents in fctl sessions can push branches
and change workflows. Rulesets keep them off main and the release tags
(hyperstructure/fctl's ADR 0021):

- .github/rulesets/main.json: squash-merged pull requests with passing
  checks (check, Conventional Commits) and a code owner's approval from
  someone who did not push the last commit; linear history, no force
  pushes or deletion. Deploy keys bypass it, and organization owners on
  pull requests only.
- .github/rulesets/release-tags.json: only deploy keys create, move or
  delete v* tags.
- .github/CODEOWNERS: kalaspuff. fctl-sh[bot] cannot be a code owner.

GitHub Actions is not on the bypass list, so the Release workflow now
pushes its release commit and tag with RELEASE_DEPLOY_KEY, a deploy key
kept in the production environment (main only), and every run starts
from main. Such a push starts workflows: CI checks the tag, and the
Release workflow runs again and finds nothing due.

Refs hyperstructure/fctl#22
kalaspuff pushed a commit to hyperstructure/fctl that referenced this pull request Oct 18, 2026
Branch protection for `main` and the release tags, done so that agents
can't get around it. The design is in ADR 0021.

## What changes

- **`.github/rulesets/main.json`**, the ruleset to apply to `main`:
- squash-merged pull requests only, linear history, no force pushes or
deletion;
- passing `cargo xtask check`, `cargo xtask dev --smoke` and
`Conventional Commits` (from GitHub Actions);
- a code owner's approval, from someone who didn't push the last commit.
- Deploy keys bypass it. Organization owners bypass it on pull requests
only.
- **`.github/rulesets/release-tags.json`**: only deploy keys create,
move or delete `v*` tags.
- **`.github/CODEOWNERS`**: `@kalaspuff`. Agents act as fctl-sh[bot],
which can't be a code owner, so they can't approve their own changes or
anyone else's.
- **Release workflow:** `prepare` runs in `production` and checks out
over SSH with `RELEASE_DEPLOY_KEY`, so its push of the release commit
and tag gets past the rulesets.
- That push starts CI, which redeploys app.fctl.sh, so `Publish` no
longer dispatches CI and no longer needs `actions: write`.
- Every run, a dry run too, now starts from `main`, which is what the
release skill already says.
- **Docs:** AGENTS.md, the commit and release skills,
`docs/development.md` and ADR 0021 (with its row in the ADR index).

## Why not #22 as written

- **GitHub Actions on the bypass list:** any workflow could then push to
`main`, including one an agent writes on a branch. Agent tokens have
`workflows: write`.
- **No required approval:** an agent could merge its own pull request.

Either way, code would reach `main`, and `main` deploys with the
production secrets. Requiring a code owner, not just any approval, also
stops an approval from fctl-sh[bot] counting on a pull request someone
else pushed to last.

## Order

1. An admin adds the release deploy key and puts `RELEASE_DEPLOY_KEY`
into `production`.
2. Merge this. Before the key exists, the checkout falls back to the
token, which still works while there's no ruleset.
3. Apply the rulesets from these files.

ADR 0021 replaces ADR 0006's note that `main` is protected only by
convention. ADRs are never rewritten, so 0006 stays as it is.

## Verified

- actionlint 1.7.12 passes.
- `cargo test -p xtask` passes; it reads `release.yml`.
- The ruleset JSON parses. The fields follow GitHub's REST reference for
repository rulesets.
- The push with the deploy key gets its first real test at the next
release. If it fails, the push is atomic, so nothing is half-released.

Refs #22.

Session: https://app.fctl.sh/s/ses_01M58A7MAFDWKZDCA239GR6H6G


## Related pull requests

- #97: fctl's rulesets, the Release workflow's deploy
key, ADR 0021
- hyperstructure/design#13: design's rulesets and Release workflow
- hyperstructure/fctl-site#19: fctl-site's ruleset
- hyperstructure/sandbox#5: sandbox's ruleset, now with a required
approval

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
@kalaspuff
kalaspuff merged commit 1cf2518 into main Oct 18, 2026
3 checks passed
@kalaspuff
kalaspuff deleted the fctl/47-protect-main branch October 18, 2026 21:36
kalaspuff pushed a commit to hyperstructure/fctl-site that referenced this pull request Oct 18, 2026
The same rules as hyperstructure/fctl#97 (its ADR 0021 has the
reasoning). `main` deploys fctl.sh, including `/install`, which people
pipe to `sh`.

## What changes

- **`.github/rulesets/main.json`**, the ruleset to apply to `main`:
- squash-merged pull requests only, linear history, no force pushes or
deletion;
  - passing `build` and `Conventional Commits`;
- a code owner's approval, from someone who didn't push the last commit.
- Deploy keys bypass it, so fctl's CI can still pin `fctl-docs.ref` with
`SITE_DEPLOY_KEY`. Organization owners bypass it on pull requests only.
- **`.github/CODEOWNERS`**: `@kalaspuff`.
- **Docs:** AGENTS.md and the commit skill.

No workflow change: nothing here pushes to `main` except fctl's docs
pin.

## Verified

- `npm run check` passes. Its two warnings, in 404.html and 500.html,
are already on `main`.
- `npm test` and `npm run build` pass. The build fetches fctl's docs
without signing in.

Refs hyperstructure/fctl#22.

Session: https://app.fctl.sh/s/ses_01M58A7MAFDWKZDCA239GR6H6G


## Related pull requests

- hyperstructure/fctl#97: fctl's rulesets, the Release workflow's deploy
key, ADR 0021
- hyperstructure/design#13: design's rulesets and Release workflow
- #19: fctl-site's ruleset
- hyperstructure/sandbox#5: sandbox's ruleset, now with a required
approval

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
kalaspuff pushed a commit to hyperstructure/sandbox that referenced this pull request Oct 18, 2026
Merging a change to the image publishes it within minutes, and every
fctl host pulls it. `main`'s ruleset required a pull request but **no
approval**, so an agent in an fctl session could merge its own change
into the image every session runs in. These are the same rules as
hyperstructure/fctl#97 (its ADR 0021 has the reasoning).

## What changes

- **`.github/rulesets/main.json`**: `main`'s ruleset as it should be
applied.
- **Kept:** squash-merged pull requests, `Conventional Commits` and
`ShellCheck and actionlint` passing, no force pushes or deletion, and
the existing `require_extra_approval_for_unattributed_changes`.
- **New:** a code owner's approval, from someone who didn't push the
last commit; stale approvals dismissed; linear history; checks must come
from GitHub Actions; organization owners may bypass on pull requests
only.
- **`.github/CODEOWNERS`**: `@kalaspuff`.
- **Docs:** AGENTS.md and the commit skill.

The ruleset already exists (id 25341995), so an admin updates it with
`PUT` from this file rather than creating a new one.

Refs hyperstructure/fctl#22.

Session: https://app.fctl.sh/s/ses_01M58A7MAFDWKZDCA239GR6H6G


## Related pull requests

- hyperstructure/fctl#97: fctl's rulesets, the Release workflow's deploy
key, ADR 0021
- hyperstructure/design#13: design's rulesets and Release workflow
- hyperstructure/fctl-site#19: fctl-site's ruleset
- #5: sandbox's ruleset, now with a required
approval

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant