Skip to content

Protect main in fctl, fctl-site and design once they are public #22

Closed

Description

@fctl-sh

Protect main in hyperstructure/fctl, fctl-site and design once the repositories are public.

Why not now

GitHub Free has no branch protection or rulesets for private repositories: the API answers 403 Upgrade to GitHub Pro or make this repository public to enable this feature. Until then, main is protected by convention only: AGENTS.md, the commit skills, and CI checking pull request titles (fctl#21, design#1, fctl-site#1).

What to set up

One repository ruleset per repository, named main, on the default branch:

  • Pull request required before merging, with 0 approvals while there's one maintainer (raise it when there are more). Squash is the only merge method.
  • Required status checks:
    • fctl: cargo xtask check and Conventional Commits
    • fctl-site: build and Conventional Commits
    • design: check and Conventional Commits
  • Linear history required; force pushes and deletion blocked.
  • Bypass list:
    • GitHub Actions (integration 15368), always: the Release workflows in fctl and design push their chore(release): vX.Y.Z commits to main.
    • In fctl-site, the SITE_DEPLOY_KEY deploy key (bypass actor type DeployKey): fctl's CI pushes docs: pin hyperstructure/fctl@… to it.
    • Repository admins, pull_request only: they can still merge a pull request whose checks are stuck.

Plus a tag ruleset on v* in fctl and design: only the bypass actors (GitHub Actions) may create, move or delete release tags, because installed CLIs, hosts and lockfiles depend on them.

How

The fctl-sh GitHub App has administration: write on the organization, so an agent can apply these with POST /repos/hyperstructure/<repo>/rulesets. For fctl:

{
  "name": "main",
  "target": "branch",
  "enforcement": "active",
  "conditions": { "ref_name": { "include": ["~DEFAULT_BRANCH"], "exclude": [] } },
  "bypass_actors": [
    { "actor_id": 15368, "actor_type": "Integration", "bypass_mode": "always" },
    { "actor_id": 5, "actor_type": "RepositoryRole", "bypass_mode": "pull_request" }
  ],
  "rules": [
    { "type": "deletion" },
    { "type": "non_fast_forward" },
    { "type": "required_linear_history" },
    { "type": "pull_request", "parameters": {
        "required_approving_review_count": 0, "dismiss_stale_reviews_on_push": true,
        "require_code_owner_review": false, "require_last_push_approval": false,
        "required_review_thread_resolution": false, "allowed_merge_methods": ["squash"] } },
    { "type": "required_status_checks", "parameters": {
        "strict_required_status_checks_policy": false,
        "required_status_checks": [ { "context": "cargo xtask check" }, { "context": "Conventional Commits" } ] } }
  ]
}

Afterwards, check that each of these still works:

  • fctl: a release from the Release workflow pushes its commit and tag (v0.7.0).
  • fctl-site: a docs change in fctl pins fctl-docs.ref, and fctl.sh deploys (#99 → eb9f7c1, deploy).
  • design: a release from the Release workflow pushes its commit and tag (v0.5.1).
  • A direct push to main from an agent is refused (verified).
  • ADR 0006's note about convention-only protection is updated (by ADR 0021, which replaces it; kalaspuff decided that this settles it).

Activity

  1. fctl-sh commented on Oct 18, 2026

    @fctl-sh
    ContributorAuthor

    Rulesets are on in all four repositories. They differ from the plan above in two ways (ADR 0021, #97):

    • GitHub Actions isn't on the bypass list. Otherwise any workflow could push to main, including one an agent writes on a branch. The Release workflows in fctl and design now push with RELEASE_DEPLOY_KEY, a deploy key kept in the production environment, and deploy keys bypass the rules.
    • Merging needs a code owner's approval (@kalaspuff), from someone who didn't push the last commit. With 0 approvals, an agent could merge its own pull request. fctl-sh[bot] can't be a code owner.

    The rules in force on main (from gh api repos/hyperstructure/<repo>/rules/branches/main):

    Repository Ruleset Required checks (GitHub Actions, 15368)
    fctl 25359162, plus 25359163 for v* tags cargo xtask check, cargo xtask dev --smoke, Conventional Commits
    design 25359165, plus 25359166 for v* tags check, Conventional Commits
    fctl-site 25359168 build, Conventional Commits
    sandbox 25341995 (updated) Conventional Commits, ShellCheck and actionlint

    Every main ruleset: squash-merged pull requests, a code owner's approval (last push approved, stale approvals dismissed), linear history, no force pushes or deletion. The files in .github/rulesets/ are what was applied.

    Verified on 2026-10-18 by 21:41 UTC, as fctl-sh[bot]:

    • current_user_can_bypass is never on all six rulesets.
    • A direct push of an empty commit to fctl's main was refused, and main stayed at ed7ab1d:
      remote: error: GH013: Repository rule violations found for refs/heads/main.
      remote: - Changes must be made through a pull request.
      remote: - 3 of 3 required status checks are expected.
       ! [remote rejected] ... -> main (push declined due to repository rule violations)
      
    • Creating refs/tags/v0.0.0-ruleset-check in fctl was refused (422). Creating refs/tags/fctl-47-ruleset-control worked, so the refusal is the tag ruleset's; I deleted that tag at once.
    • codeowners/errors reports nothing in any of the four repositories.
    • fctl's Release dry run (run 39168646688) ran in production and checked out over SSH with the deploy key ([email protected]:hyperstructure/fctl.git).

    Still to see:

    • The first two items above. fctl's next release has to push its commit and tag through the rules, and fctl.sh's next docs pin has to get through fctl-site's rules. The last pin (21:37:19) came before fctl-site's ruleset (21:38:10).
    • design. Its next release has to push through its rules. Its first Release run after the change (39168567707) checked out over HTTPS without a key, because the run itself created the production environment. Since then, a dry run from main (39169050203) ran in production and checked out over SSH with RELEASE_DEPLOY_KEY ([email protected]:hyperstructure/design.git).
    • "Allow GitHub Actions to create and approve pull requests" is off in all four repositories, and the default workflow token is read-only. kalaspuff checked with gh api repos/hyperstructure/<repo>/actions/permissions/workflow: read can_approve=false in each. An agent's token can't read that setting.
    • The ADR 0006 item. ADRs are never rewritten (docs/adr/README.md), so ADR 0021 replaces 0006's note instead. A person can decide whether that settles the item.
  2. fctl-sh commented on Oct 18, 2026

    @fctl-sh
    ContributorAuthor

    Everything on the checklist is done and verified, so I'm closing this.

    One thing unrelated to the rules: CI on fctl's release commit failed in cargo xtask check, on a flaky host test. So that run's own deploy was skipped, and the next push to main deployed 0.7.0 a couple of minutes later. I'm filing that as its own issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions