Permissioning Ci Workflows 标志

Permissioning Ci Workflows

社区
wdm0006
permissioning-ci-workflows

确保 CI 作业只获得所需凭据,并能识别没有凭据的情况——明确声明 `permissions:`,因为默认 GITHUB_TOKEN 的权限范围由仓库设置决定;读取 403 响应中的 x-accepted-github-permissions 标头,而不是猜测缺少哪项权限;留意一次 API 调用可能需要两项权限;了解来自 fork 的拉取请求会获得只读令牌且无法使用仓库密钥;注意按事件条件执行的步骤在重新运行时可能被跳过,导致作业在问题未解决时仍显示成功;了解为什么 `pull_request_target` 不是解决办法;优先选择完全不需要凭据的检查。当工作流步骤需要评论 PR、推送提交、创建 issue、上传报告、调用其他仓库的 API,或在所有构建和测试步骤都通过时仍因 403 失败,请使用此技能。

Add to TypingMind

概览

发布者wdm0006
代码仓库python-skills
技能名称permissioning-ci-workflows
星标数
111
复刻数
17
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 wdm0006 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Permissioning Ci Workflows AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/wdm0006/python-skills/tree/main/skills/common/ci-permissions
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wdm0006/python-skills.git /tmp/python-skills
mkdir -p .claude/skills
cp -r /tmp/python-skills/skills/common/ci-permissions .claude/skills/permissioning-ci-workflows
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Permissioning Ci Workflows,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Permissioning Ci Workflows。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Permissioning Ci Workflows 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Permissioning CI Workflows

A job that only reads code and runs tests needs no thought about credentials. The moment a step comments on a pull request, pushes a commit, opens an issue, uploads a report, or calls another repository's API, it depends on two things that are invisible in the YAML: which scopes the token carries, and whether the run was allowed to have secrets at all.

Both fail in the same shape — every build, lint, and test step green, one trailing step red — which is why they get re-run instead of fixed.

For the cost side of workflows (triggers, concurrency, caching, matrix), see running-github-actions-efficiently. This skill is about what a workflow is allowed to do.

Declare permissions; never inherit them

The default GITHUB_TOKEN permission set is a repository/organization setting (permissive vs. restricted), not a property of your YAML. Identical workflow files therefore behave differently across repos and across orgs — and a repo that tightens the default later breaks a workflow nobody touched.

Declare a read-only floor at workflow level and grant writes per job:

yaml
permissions:
  contents: read          # floor for every job in this workflow

jobs:
  test:
    runs-on: ubuntu-latest
    # inherits contents: read — nothing else

  comment:
    runs-on: ubuntu-latest
    permissions:          # REPLACES the workflow-level set, does not merge
      contents: read
      issues: write
      pull-requests: write

A permissions: block sets every scope you did not name to none, and a job-level block replaces the workflow-level set rather than merging with it. That is the point at workflow level and the trap at job level: restate every scope the job needs, not only the one you came to add.

One API call can need two scopes

Scopes do not map one-to-one onto endpoints. The clearest case: commenting on a pull request goes through the issues API (POST /repos/{owner}/{repo}/issues/{number}/comments), and because a pull request is an issue and a pull request, the token check requires issues: write and pull-requests: write. With only the first it returns 403 after everything else in the run has already passed.

Do not guess the missing scope from the endpoint's noun. The 403 response names what it will accept:

console
$ gh api -i repos/OWNER/REPO/issues/123/comments -f body=probe
HTTP/2.0 403
x-accepted-github-permissions: issues=write; pull_requests=write

Read that header out of the failing run's log, or reproduce the single call with gh api -i against a scratch resource. It is a one-line answer to a question that otherwise costs a round of guess-and-push.

The failure hides behind the step's own condition

Steps that write to a PR are usually gated on the event that should trigger them:

yaml
- name: Comment on PR
  if: github.event.action == 'opened'
  uses: actions/github-script@v7

Pushing a commit to that PR re-runs the workflow as synchronize. The step is skipped, the job goes green, and the permission was never granted — so the next PR fails identically and the fix looks like it landed.

Any red check whose step is event-conditioned is not verified by pushing a commit. Re-verify it on the event that runs it: a fresh PR, a workflow_dispatch path, or a temporary condition change reverted in the same PR. A green run that skipped the step under test is the same defect as a test that never asserted — see writing-defect-reports on not filing a red gate as an aside.

A fork pull request has a read-only token and no secrets

On pull_request from a fork, GITHUB_TOKEN is read-only regardless of your permissions: block, and repository and organization secrets are not passed into the run. This is not configurable per workflow, and it is correct: a contributor you have never met is proposing code that your runner is about to execute.

The consequence is that every credentialed gate — a cross-repo API read, a registry publish, a report upload, a comment — does nothing on exactly the contributions you control least. Worse, the usual workaround makes it invisible:

yaml
# BAD — on a fork PR this is green and verified nothing.
- name: Validate against the upstream registry
  if: ${{ secrets.REGISTRY_TOKEN != '' }}
  env:
    TOKEN: ${{ secrets.REGISTRY_TOKEN }}
  run: ./scripts/validate.sh

Split the check by what it needs instead of skipping it by what it has:

  • The half that needs no external truth — schema, structure, denylists of known-bad patterns, anything decidable from files in the repo — must run on every PR, standalone, with a read-only token. Land that half first; it is a real gate on day one.
  • The half that needs a credential runs where credentials exist: post-merge on push, on a schedule, or in a workflow_run triggered by the completed PR build.

Then say which is which in the contributing docs, so a fork PR going green is not read as full verification.

pull_request_target is not the workaround

pull_request_target runs in the base repository's context: writable token, full secrets, and the workflow file from the base ref. That is what makes it useful for labeling and greeting — and what makes this catastrophic:

yaml
# BAD — hands a writable token and every secret to whoever opened the PR.
on: pull_request_target
jobs:
  build:
    steps:
      - uses: actions/checkout@v4
        with: { ref: ${{ github.event.pull_request.head.sha }} }
      - run: npm ci && npm test        # executes the contributor's code

Any step that runs head-ref content under pull_request_target — a build, a dependency install with lifecycle scripts, a test, a linter with a repo-local plugin — executes untrusted code with your credentials in the environment. Use pull_request_target only for steps that never execute head content: labels, greetings, size and metadata checks done through the API.

Prefer a check that needs no credential at all

Every credentialed check is one that cannot run on a fork, cannot run offline, and breaks when the token rotates. Before granting a scope, ask whether the check needs the network at all.

  • When the truth lives in another repository, do not have this repo reach in. Have the owning repo publish it outward as a generated, versioned artifact that the consumer commits and validates against — the consumer's check then needs no token, runs on forks, and states which upstream version it was checked against. See shipping-across-surfaces on never hand-maintaining a snapshot of a surface you don't own.
  • Never hand-maintain the allowlist instead. Copying another system's valid values into a constant in this repo removes the token and keeps the coupling, with nothing to detect drift.
  • Coverage and quality reports that exist only behind a third-party upload token vanish on fork PRs and during that service's outages. Run the tool in the job and print the report into the log (--cov-report=term-missing or the equivalent), so the number is in the run everyone can already read.

Checklist

Scopes:
- [ ] Every workflow declares permissions explicitly; none rely on the repo default
- [ ] Workflow-level floor is read-only; writes granted per job
- [ ] Job-level permissions blocks restate contents: read (they replace, not merge)
- [ ] Missing scope taken from the 403's x-accepted-github-permissions, not guessed
- [ ] PR-comment steps carry issues: write AND pull-requests: write

Forks:
- [ ] Known which gates do nothing on a fork PR (read-only token, no secrets)
- [ ] Credential-free half of each gate runs standalone on every PR
- [ ] No step silently skipped on an empty secret and reported as passing
- [ ] pull_request_target used only for steps that never run head-ref content

Verification:
- [ ] Event-conditioned steps re-verified on the event that runs them, not by a push
- [ ] Green run confirmed to have actually executed the step, not skipped it
- [ ] Checks that could be decided from repo contents don't take a token

常见问题

Permissioning Ci Workflows AI 技能有什么作用?

确保 CI 作业只获得所需凭据,并能识别没有凭据的情况——明确声明 `permissions:`,因为默认 GITHUB_TOKEN 的权限范围由仓库设置决定;读取 403 响应中的 x-accepted-github-permissions 标头,而不是猜测缺少哪项权限;留意一次 API 调用可能需要两项权限;了解来自 fork 的拉取请求会获得只读令牌且无法使用仓库密钥;注意按事件条件执行的步骤在重新运行时可能被跳过,导致作业在问题未解决时仍显示成功;了解为什么 `pull_request_target` 不是解决办法;优先选择完全不需要凭据的检查。当工作流步骤需要评论 PR、推送提交、创建 issue、上传报告、调用其他仓库的 API,或在所有构建和测试步骤都通过时仍因 403 失败,请使用此技能。

为什么在 TypingMind 中使用 Permissioning Ci Workflows?

因为您只需安装一次,就能搭配任何模型使用。Permissioning Ci Workflows 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Permissioning Ci Workflows?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/wdm0006/python-skills/tree/main/skills/common/ci-permissions。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Permissioning Ci Workflows?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Permissioning Ci Workflows 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Permissioning Ci Workflows 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Permissioning Ci Workflows AI 技能免费吗?

是的。wdm0006 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇