Skip to content

加固 PR-Agent workflow 的 secrets 暴露面#276

Merged
H-Chris233 merged 1 commit into
Open-Less:mainfrom
H-Chris233:fix/issue-222-pr-agent-hardening
May 6, 2026
Merged

加固 PR-Agent workflow 的 secrets 暴露面#276
H-Chris233 merged 1 commit into
Open-Less:mainfrom
H-Chris233:fix/issue-222-pr-agent-hardening

Conversation

@H-Chris233
Copy link
Copy Markdown
Collaborator

@H-Chris233 H-Chris233 commented May 5, 2026

User description

变更

  • 不再通过 the-pr-agent/pr-agent@... wrapper action 运行 PR-Agent,改为直接使用 digest-pinned Docker action:docker://pragent/pr-agent@sha256:a0b36966ca3a197ca739fa1e65c16703076fc1c744cd423ca203b8c21707d71c
  • 保留 pull_request_target 对所有 PR 的自动触发,包含外部 fork PR 和 synchronize 新 commit。
  • issue_comment 手动触发路径限制为 OWNER/MEMBER/COLLABORATOR,避免任意评论滥用带 secrets 的 job。
  • 更新 workflow 注释,明确当前模型:便利优先,runtime image digest pinning + 不 checkout PR head code 降低风险。

影响

  • 每个 PR 打开/重开/ready_for_review 会自动跑 PR-Agent。
  • 每次 PR 新 commit 会通过 synchronize 自动再次触发。
  • 外部 fork PR 仍会进入带 OPENAI_KEYpull_request_target 路径;这是为了保持自动审查便利性而接受的剩余风险。
  • PR-Agent 升级需要手动更新镜像 digest。

验证

  • python - <<'PY' ... yaml.safe_load(...):workflow YAML 可解析,并断言 usesdocker://...@sha256: 形式。
  • git diff --check:通过。
  • grep 确认 workflow 中无 the-pr-agent/pr-agent@pragent/pr-agent:github_action 残留。

Closes #222


PR Type

Bug fix, Enhancement


Description

  • Pin PR-Agent runtime container to an immutable Docker image digest (removes mutable action ref)

  • Restrict issue_comment trigger to OWNER/MEMBER/COLLABORATOR to prevent abuse

  • Update workflow comments to document current security model and permissions


Diagram Walkthrough

flowchart LR
    A["pull_request_target (all PRs)"] -- "trigger" --> C["Job: pr_agent_job"]
    B["issue_comment (trusted members)"] -- "trigger" --> C
    C -- "runs" --> D["Pinned Docker image (digest)"]
Loading

File Walkthrough

Relevant files
Configuration changes
pr-agent.yml
Pin PR-Agent runtime and restrict comment trigger               

.github/workflows/pr-agent.yml

  • Replaced uses: the-pr-agent/pr-agent@main with a digest-pinned Docker
    image docker://pragent/pr-agent@sha256:...
  • Added author_association check for issue_comment trigger to restrict
    to OWNER/MEMBER/COLLABORATOR
  • Updated inline comments to document the security rationale and
    permission requirements
+19/-4   

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7e9f4f545

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/pr-agent.yml Outdated
@H-Chris233 H-Chris233 force-pushed the fix/issue-222-pr-agent-hardening branch from b7e9f4f to 44f0ef0 Compare May 5, 2026 23:45
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

PR Reviewer Guide 🔍

(Review updated until commit bd4547b)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

222 - Partially compliant

Compliant requirements:

  • Pin the PR-Agent runtime to an immutable digest.
  • Apply trust checks to the issue_comment path.
  • Update workflow comments to match the new model.

Non-compliant requirements:

  • Reduce the workflow permissions to the minimum required.
  • Remove or gate the secrets-backed execution path for external pull requests.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44f0ef0b0e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

${{
github.event.sender.type != 'Bot' &&
(
github.event_name == 'pull_request_target' ||
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Gate pull_request_target on same-repo PRs

For an external fork PR opened or synchronized via pull_request_target, this branch evaluates true before any repository-owner check, so the secrets-bearing PR-Agent job still runs automatically with OPENAI_KEY and write-scoped GITHUB_TOKEN. The trusted-member gate only applies to issue_comment, leaving the external-PR auto path that this hardening change says it removes; add a check such as comparing github.event.pull_request.head.repo.full_name with github.repository for this event.

Useful? React with 👍 / 👎.

The workflow must keep reviewing every PR and every pushed commit automatically, including fork PRs, so the hardening focuses on pinning the code that actually runs in the secrets-bearing job. The wrapper action commit still delegates to a mutable Docker tag, so the workflow now calls the PR-Agent container by immutable digest directly.

Constraint: Maintainer preference is automatic PR-Agent coverage for each PR and synchronize event.

Constraint: Issue Open-Less#222 requires removing mutable third-party execution refs from the secrets-bearing path.

Rejected: Pin only the action repository commit | the wrapper Dockerfile still resolves pragent/pr-agent:github_action at runtime.

Rejected: Require trusted comment triggers for fork PRs | too inconvenient because new commits would not be reviewed automatically.

Confidence: medium

Scope-risk: moderate

Directive: If fork PR automation remains required, keep the runtime container digest-pinned and do not checkout PR head code in this workflow.

Tested: Parsed .github/workflows/pr-agent.yml with PyYAML and asserted docker:// sha256 form; git diff --check; grep confirmed no action ref or github_action tag remains in the workflow.

Not-tested: Live GitHub Actions execution or Docker Hub digest pull from this host.

Related: Open-Less#222
@H-Chris233 H-Chris233 force-pushed the fix/issue-222-pr-agent-hardening branch from 44f0ef0 to bd4547b Compare May 5, 2026 23:51
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Persistent review updated to latest commit 44f0ef0

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Persistent review updated to latest commit bd4547b

@H-Chris233 H-Chris233 merged commit 7f1df50 into Open-Less:main May 6, 2026
2 checks passed
@H-Chris233 H-Chris233 deleted the fix/issue-222-pr-agent-hardening branch May 9, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security(ci): pin PR-Agent action,降低 pull_request_target secrets 暴露面

1 participant