Skip to content

Commit 7ffa89a

Browse files
committed
Allow docker agent to request reviews
Signed-off-by: Derek Misler <derek.misler@docker.com>
1 parent 956bbc7 commit 7ffa89a

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

.github/workflows/review-pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ jobs:
232232
add-prompt-files: ${{ inputs.add-prompt-files }}
233233
model: ${{ inputs.model }}
234234
github-token: ${{ steps.app-token.outputs.token || github.token }}
235+
trusted-bot-app-id: ${{ secrets.CAGENT_REVIEWER_APP_ID }}
235236
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
236237
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
237238
google-api-key: ${{ secrets.GOOGLE_API_KEY }}

action.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ inputs:
7878
description: "Additional arguments to pass to cagent run"
7979
required: false
8080
default: ""
81+
trusted-bot-app-id:
82+
description: "GitHub App ID of a trusted bot that can bypass comment-based auth checks (e.g., for self-review triggers)"
83+
required: false
84+
default: ""
8185
add-prompt-files:
8286
description: "Comma-separated list of files to append to the prompt (e.g., 'AGENTS.md,CLAUDE.md')"
8387
required: false
@@ -190,10 +194,12 @@ runs:
190194
shell: bash
191195
env:
192196
ACTION_PATH: ${{ github.action_path }}
193-
# Get author_association from comment events (the main risk)
194-
COMMENT_ASSOCIATION: ${{ github.event.comment.author_association }}
197+
TRUSTED_BOT_APP_ID: ${{ inputs.trusted-bot-app-id }}
195198
DEBUG: ${{ inputs.debug }}
196199
run: |
200+
# Read comment fields directly from the event payload (cannot be overridden by workflow env vars)
201+
COMMENT_ASSOCIATION=$(jq -r '.comment.author_association // empty' "$GITHUB_EVENT_PATH")
202+
197203
# Only enforce auth for comment-triggered events
198204
# This prevents abuse via /commands while allowing PR-triggered workflows to run
199205
if [ -z "$COMMENT_ASSOCIATION" ]; then
@@ -202,6 +208,20 @@ runs:
202208
exit 0
203209
fi
204210
211+
# Allow a trusted GitHub App bot to bypass auth (e.g., auto-triage posts /review).
212+
# Verified via user type + app ID from the event payload to prevent spoofing.
213+
if [ -n "$TRUSTED_BOT_APP_ID" ]; then
214+
COMMENT_USER_TYPE=$(jq -r '.comment.user.type // empty' "$GITHUB_EVENT_PATH")
215+
COMMENT_APP_ID=$(jq -r '.comment.performed_via_github_app.id // empty' "$GITHUB_EVENT_PATH")
216+
217+
if [ "$COMMENT_USER_TYPE" = "Bot" ] && [ -n "$COMMENT_APP_ID" ] && [ "$COMMENT_APP_ID" = "$TRUSTED_BOT_APP_ID" ]; then
218+
COMMENT_USER_LOGIN=$(jq -r '.comment.user.login // empty' "$GITHUB_EVENT_PATH")
219+
echo "ℹ️ Skipping auth check (trusted bot: $COMMENT_USER_LOGIN, app_id: $COMMENT_APP_ID)"
220+
echo "authorized=bot" >> $GITHUB_OUTPUT
221+
exit 0
222+
fi
223+
fi
224+
205225
echo "Using comment author_association: $COMMENT_ASSOCIATION"
206226
207227
# Allowed roles (hardcoded for security - cannot be overridden)

review-pr/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ inputs:
5353
description: "Comma-separated list of files to append to the prompt (e.g., 'AGENTS.md,CLAUDE.md')"
5454
required: false
5555
default: ""
56+
trusted-bot-app-id:
57+
description: "GitHub App ID of a trusted bot that can bypass comment-based auth checks"
58+
required: false
59+
default: ""
5660

5761
outputs:
5862
exit-code:
@@ -464,6 +468,7 @@ runs:
464468
nebius-api-key: ${{ inputs.nebius-api-key }}
465469
mistral-api-key: ${{ inputs.mistral-api-key }}
466470
github-token: ${{ steps.resolve-token.outputs.token }}
471+
trusted-bot-app-id: ${{ inputs.trusted-bot-app-id }}
467472
extra-args: ${{ inputs.model && format('--model={0}', inputs.model) || '' }}
468473

469474
# ========================================
@@ -551,6 +556,7 @@ runs:
551556
nebius-api-key: ${{ inputs.nebius-api-key }}
552557
mistral-api-key: ${{ inputs.mistral-api-key }}
553558
github-token: ${{ steps.resolve-token.outputs.token }}
559+
trusted-bot-app-id: ${{ inputs.trusted-bot-app-id }}
554560
extra-args: ${{ inputs.model && format('--model={0}', inputs.model) || '' }}
555561
add-prompt-files: ${{ inputs.add-prompt-files }}
556562

0 commit comments

Comments
 (0)