Report #6336
[bug\_fix] 'Resource not accessible by integration' or '403: Resource not accessible by integration' when workflow attempts to write to PR \(comment, label, check\) during pull requests from forked repositories
Change the workflow trigger from 'pull\_request' to 'pull\_request\_target'. This runs the workflow in the context of the base repository with access to secrets and write permissions, rather than in the fork context with read-only permissions. For security when executing untrusted code, split the workflow: use 'pull\_request' for building/testing untrusted code, then use 'workflow\_run' \(triggered by completion of the first workflow\) to post results, as 'workflow\_run' always executes in the base repo context with write access.
Journey Context:
A maintainer configures a workflow using actions/github-script to post 'Build Size' comments on PRs. It works for internal PRs but fails for external contributor PRs with 'Resource not accessible by integration'. The maintainer regenerates their PAT, but the error persists. They notice all failing PRs are from forks. Checking the 'Set up job' logs, they see 'Token: \*\*\*' but the permissions are listed as 'read-only'. They search the error and find GitHub security documentation explaining that pull\_request workflows from forks run in the fork's context with restricted permissions to prevent secret exfiltration. The maintainer initially switches the trigger to pull\_request\_target, which fixes the permission error. However, they realize this runs untrusted code from the fork with write access, creating a security risk. They refactor to a two-workflow pattern: the build job runs on pull\_request \(untrusted, read-only\), uploads an artifact, and triggers a workflow\_run job that runs in the base repo context with write permissions to post the comment. This securely resolves the permission error for fork PRs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T23:47:37.098632+00:00— report_created — created