|
| 1 | +name: OSS guardrails |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + # Tier 1a: secret scanning. Runs on every PR including forks (no secrets needed). |
| 14 | + secret-scan: |
| 15 | + name: Secret scan (gitleaks) |
| 16 | + runs-on: ubuntu-latest |
| 17 | + env: |
| 18 | + GITLEAKS_VERSION: "8.21.2" |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + # Full history so gitleaks scans the entire PR commit range, |
| 23 | + # not just the head commit (default shallow checkout). |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Run gitleaks |
| 27 | + env: |
| 28 | + # sha256 of gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz from the |
| 29 | + # release's published checksums file. Update together with the version. |
| 30 | + GITLEAKS_SHA256: "5bc41815076e6ed6ef8fbecc9d9b75bcae31f39029ceb55da08086315316e3ba" |
| 31 | + run: | |
| 32 | + curl -sSfL -o gitleaks.tar.gz \ |
| 33 | + "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" |
| 34 | + echo "${GITLEAKS_SHA256} gitleaks.tar.gz" | sha256sum -c - |
| 35 | + tar -xzf gitleaks.tar.gz gitleaks |
| 36 | + # git-mode (default): scans tracked content and history only. |
| 37 | + # Never use --no-git: it would read gitignored local dirs. |
| 38 | + # --redact: matched secret content never appears in public CI logs. |
| 39 | + ./gitleaks detect --source . --redact --no-banner --verbose |
| 40 | +
|
| 41 | + # Tier 1b: structural reference checks. Generic patterns, safe to publish, |
| 42 | + # no secrets needed — runs on every PR including forks. |
| 43 | + structural-scan: |
| 44 | + name: Structural reference scan |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Scan tracked files for forbidden reference shapes |
| 50 | + run: | |
| 51 | + set -u |
| 52 | + violations=0 |
| 53 | +
|
| 54 | + scan() { |
| 55 | + local label="$1" pattern="$2" |
| 56 | + local matches rc=0 |
| 57 | + # Tracked files only; exclude this workflow (it defines the patterns). |
| 58 | + matches=$(git grep -nIE "$pattern" -- . ':(exclude).github/workflows/oss-guardrails.yml') || rc=$? |
| 59 | + if [ "$rc" -gt 1 ]; then |
| 60 | + # Fail closed: a grep hard error must not pass as "no match". |
| 61 | + echo "::error::git grep failed (exit ${rc}) while scanning for: ${label}" |
| 62 | + violations=1 |
| 63 | + elif [ "$rc" -eq 0 ]; then |
| 64 | + echo "::error::Forbidden reference shape: ${label}" |
| 65 | + # file:line only |
| 66 | + echo "${matches}" | cut -d: -f1,2 |
| 67 | + violations=1 |
| 68 | + fi |
| 69 | + } |
| 70 | +
|
| 71 | + # Real org slug in an MCP URL — only the <org-slug> placeholder is allowed. |
| 72 | + scan "real org slug in MCP URL (use <org-slug>)" 'organizations/[A-Za-z0-9_-]+/mcp' |
| 73 | +
|
| 74 | + # Internal source-path citations (e.g. internal/foo/bar.go). |
| 75 | + scan "internal source-path citation" 'internal/[A-Za-z0-9_-]+(/[A-Za-z0-9_.-]+)+\.[A-Za-z]+' |
| 76 | +
|
| 77 | + # Bare commit-SHA citation shape (e.g. "file.md @ 1a2b3c4"). |
| 78 | + scan "bare commit-SHA citation" '@ [0-9a-f]{7,40}([^A-Za-z0-9]|$)' |
| 79 | +
|
| 80 | + exit "${violations}" |
| 81 | +
|
| 82 | + # Tier 2: forbidden-term scan against a private denylist. |
| 83 | + # The denylist lives in the FORBIDDEN_TERMS secret (newline-separated) because |
| 84 | + # the list itself is sensitive and must never be committed. |
| 85 | + # GitHub does not expose secrets to fork-PR workflows, so this job is skipped |
| 86 | + # on fork PRs (visible as skipped) and re-runs on the merge push to master. |
| 87 | + # Maintainers run it manually against fork-PR heads before merging. |
| 88 | + forbidden-terms: |
| 89 | + name: Forbidden terms (denylist — skipped on fork PRs, runs on merge) |
| 90 | + runs-on: ubuntu-latest |
| 91 | + if: >- |
| 92 | + github.event_name == 'push' || |
| 93 | + (github.event_name == 'pull_request' && |
| 94 | + github.event.pull_request.head.repo.full_name == github.repository) |
| 95 | + env: |
| 96 | + FORBIDDEN_TERMS: ${{ secrets.FORBIDDEN_TERMS }} |
| 97 | + steps: |
| 98 | + - uses: actions/checkout@v4 |
| 99 | + |
| 100 | + - name: Scan tracked files against denylist |
| 101 | + run: | |
| 102 | + set -u |
| 103 | + # Fail loud on absent/empty secret — an empty pattern list would |
| 104 | + # silently match nothing and pass the check without scanning. |
| 105 | + # Normalize the secret: strip CR (a CRLF-pasted secret would embed |
| 106 | + # \r in every pattern and silently match nothing), trim per-line |
| 107 | + # whitespace, drop empty lines. |
| 108 | + printf '%s\n' "${FORBIDDEN_TERMS}" \ |
| 109 | + | tr -d '\r' \ |
| 110 | + | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^[[:space:]]*$/d' \ |
| 111 | + > "${RUNNER_TEMP}/terms.txt" |
| 112 | +
|
| 113 | + if [ ! -s "${RUNNER_TEMP}/terms.txt" ]; then |
| 114 | + echo "::error::FORBIDDEN_TERMS secret is unset, empty, or contains no usable terms after normalization. Failing loud — refusing to skip the scan silently." |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | +
|
| 118 | + # Single git grep pass — tracked files only by construction, and |
| 119 | + # exit codes are unambiguous (0 match, 1 no match, >1 error). |
| 120 | + rc=0 |
| 121 | + raw=$(git grep -nIiF -f "${RUNNER_TEMP}/terms.txt") || rc=$? |
| 122 | +
|
| 123 | + if [ "$rc" -gt 1 ]; then |
| 124 | + # Fail closed: a grep hard error must not pass as "no match". |
| 125 | + echo "::error::git grep failed (exit ${rc}) during the denylist scan." |
| 126 | + exit 1 |
| 127 | + elif [ "$rc" -eq 0 ]; then |
| 128 | + # Report file:line only — never the matched content, which would |
| 129 | + # echo a forbidden term into publicly readable logs. |
| 130 | + echo "::error::Forbidden term(s) found at the following file:line locations (content withheld):" |
| 131 | + printf '%s\n' "${raw}" | cut -d: -f1,2 |
| 132 | + exit 1 |
| 133 | + fi |
| 134 | +
|
| 135 | + # Sync parity: packaged plugin skills must match canonical skills/. |
| 136 | + # No path filter — this job must report a status on every PR so it can be a |
| 137 | + # required check without deadlocking docs-only PRs (a path-filtered required |
| 138 | + # check never reports and leaves the PR perpetually pending). |
| 139 | + sync-parity: |
| 140 | + name: Plugin skill sync parity |
| 141 | + runs-on: ubuntu-latest |
| 142 | + steps: |
| 143 | + - uses: actions/checkout@v4 |
| 144 | + |
| 145 | + - name: Verify packaged plugin skills are synced |
| 146 | + run: | |
| 147 | + scripts/sync-agent-plugin-skills.sh |
| 148 | + # status --porcelain covers modified AND untracked files, so a sync |
| 149 | + # that creates a new packaged skill file also fails parity until |
| 150 | + # the file is committed (git diff --exit-code misses untracked). |
| 151 | + drift=$(git status --porcelain -- plugins/last9/skills) |
| 152 | + if [ -n "${drift}" ]; then |
| 153 | + echo "::error::Packaged plugin skills are out of sync with skills/:" |
| 154 | + echo "${drift}" |
| 155 | + exit 1 |
| 156 | + fi |
0 commit comments