Skip to content

CI resilience (detection): B-SHAPIN class + lib/rules/actions_policy.ex (AP001/AP002) #605

Closed as not planned

Description

@hyperpolymath

Context — the estate-wide "Actions-policy CI outage"

An onboarding stamp sets allowed_actions=selected + sha_pinning_required=true but never populates patterns_allowed (→ mode-1 startup_failure on 91 hyperpolymath repos). A second mode: sha_pinning_required=true with tag-pinned workflow files (mode-2).

Hypatia is the fleet detection owner: it already has estate-wide REST access (HYPATIA_SCAN_PAT) and half the detector — scripts/ci-health/detect.sh class B-ALLOWLIST already reads repos/<r>/actions/permissions (.allowed_actions) and .../selected-actions (.patterns_allowed), which is live mode-1 detection, and remediate.sh already PUTs the mode-1 fix keeping sha_pinning. Two gaps: mode-2 is not detected, and detection lives only in bash (bypasses the neurosymbolic baseline + dispatch).

Decision of record

Estate default = allowed_actions=all + sha_pinning_required=true. Where hypatia remediates, align to that target (co-set + GET-verify), consistent with gitbot-fleet.

Changes

  1. scripts/ci-health/detect.sh — add class B-SHAPIN (mode-2). Read .sha_pinning_required from actions/permissions; when true, scan .github/workflows/*.yml for uses: owner/act@<non-40-hex> (reuse the tag-vs-SHA regex from fixer/src/sha_pins.rs / lib/mix/tasks/hypatia.verify_action_shas.ex) → emit a HIGH finding "sha_pinning_required=true + N tag-pinned uses → startup_failure". Today it reads .allowed_actions/.patterns_allowed only, never .sha_pinning_required.

  2. NEW lib/rules/actions_policy.ex — promote detection out of bash into the engine. Rules AP001 (allowlist-blocks-reusables) + AP002 (sha-pin-required-vs-tag-pins), modelled exactly on lib/rules/branch_protection.ex (same @github_api_base, "return [] cleanly without GITHUB_TOKEN" convention, severity→confidence map). Read repos/{o}/{r}/actions/permissions + /selected-actions; correlate AP002 with the existing file-level WH004/check_unpinned_actions so a repo whose live setting guarantees a startup_failure is escalated HIGH before it runs. Register in lib/rules/rules.ex alias list + audit fan-out; add test/rules/actions_policy_test.exs. Optionally add standards/hypatia-rules/HYP-S008-actions-policy.a2ml so rule_loader.ex carries routing/recipe.

  3. scripts/ci-health/remediate.sh — add B-SHAPIN file-side remediation. Open a signed PR converting @vN → resolved 40-hex SHAs (reuse scripts/fix-scripts/fix-pin-action-sha.sh), parallel to the existing D-BURN PR path. Keep the B-ALLOWLIST PUT. Route findings through lib/fleet_dispatcher.ex (TriangleRouter → robot-repo-automaton/rhodibot/sustainabot via Kin Gate) instead of only upserting a tracking issue.

Draft artifact

# ci-health/detect.sh: add after B-ALLOWLIST
SP=$(gh api repos/$O/$R/actions/permissions --jq .sha_pinning_required)
if [ "$SP" = true ]; then
  TAGS=$(grep -rhnE 'uses:\s+[^@]+@([^ ]{1,39}$|v[0-9]|main|master|stable)' .github/workflows/ || true)
  if [ -n "$TAGS" ]; then
    emit_finding HIGH B-SHAPIN "$R" "sha_pinning_required=true + tag/branch-pinned uses -> startup_failure" "$TAGS"
  fi
fi
# lib/rules/actions_policy.ex (modelled on branch_protection.ex)
defmodule Hypatia.Rules.ActionsPolicy do
  @github_api_base "https://api.github.com"
  def audit(owner, repo) do
    with {:ok, perm} <- get("#{@github_api_base}/repos/#{owner}/#{repo}/actions/permissions"),
         {:ok, sel}  <- get(".../selected-actions") do
      f1 = if perm["allowed_actions"] == "selected" and sel["patterns_allowed"] == [] and uses_external?(repo),
             do: [finding("AP001", :high, "empty allowlist blocks external reusables")], else: []
      f2 = if perm["sha_pinning_required"] and tag_pinned_uses(repo) != [],
             do: [finding("AP002", :high, "sha_pinning_required vs tag-pinned uses", correlate: WH004)], else: []
      f1 ++ f2
    else _ -> [] end   # returns [] cleanly without GITHUB_TOKEN, per convention
  end
end

Acceptance criteria

  • detect.sh emits B-SHAPIN HIGH for a sha_pinning=true repo with a tag-pinned uses:; silent for a fully SHA-pinned repo.
  • Hypatia.Rules.ActionsPolicy.audit/2 returns AP001 for empty-selected-with-external, AP002 for sha-pin-vs-tag, [] without a token; registered + covered by actions_policy_test.exs.
  • AP002 findings correlate to the file-level WH004/check_unpinned_actions for the same repo.
  • A mode-2 finding flows through fleet_dispatcher to a fixer (not just a tracking issue).

Open question

hypatia-scan-reusable.yml clones only hyperpolymath/hypatia, not standards/hypatia-rules, yet rule_loader.ex sources the *.a2ml catalogue (incl. HYP-S008) from standards — confirm the scanner actually loads it at runtime, else the a2ml rule is dormant.

Model tier

Opus for lib/rules/actions_policy.ex (neurosymbolic pipeline + correlation + baseline/dispatch integration); Sonnet for the detect.sh/remediate.sh bash classes.

Related

Consumes the source-of-truth in hyperpolymath/standards; findings dispatched to hyperpolymath/gitbot-fleet (robot-repo-automaton).

Activity

  1. hyperpolymath commented on Jul 11, 2026

    @hyperpolymath
    OwnerAuthor

    Part of the estate-wide CI-resilience remediation set (Actions-policy startup_failure, root-caused by the 2026-07-11 estate scan). One owner per responsibility:

    Decision of record: estate default = allowed_actions=all + sha_pinning_required=true. The one-off sweep of the 91 broken hyperpolymath repos is intentionally deferred to gitbot-fleet#362 (self-healing behind the kill-switch), not a manual PUT.

  2. added
    enhancement
    on Aug 3, 2026
  3. added
    cicd
    and removed on Aug 26, 2026
  4. added
    priority:p1
    scope:estate
    status:ready
    on Sep 30, 2026
  5. hyperpolymath commented on Sep 30, 2026

    @hyperpolymath
    OwnerAuthor

    Consolidated into the roadmap tracker #886 during the 2026-09-30 issue sweep. The idea is kept there as a checklist item; reopen this issue when work starts.

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

    cicdenhancementpriority:p1scope:estatestatus:ready

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions