Skip to content

safe-outputs.github-app mint includes permissions of handlers that set their own github-token #73522

Done

Description

@ekbritecore

Analysis

computePermissionsForSafeOutputs(safeOutputs, excludePerHandlerApps) (pkg/workflow/safe_outputs_permissions.go:134) skips a handler's permissions only when the handler has its own github-app (getHandlerGitHubApp, safe_output_handlers.go:776). A handler with its own github-token still adds its scopes to the global App mint, even though it never uses that token.

Example:

safe-outputs:
  github-app: { client-id: ..., private-key: ... }
  create-issue: {}
  dispatch-workflow:
    github-token: ${{ secrets.GITHUB_TOKEN }}
    workflows: [fixer]
  • What happens: the safe_outputs and conclusion App mints get permission-actions: write, while dispatch_workflow runs with GITHUB_TOKEN, checked in GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG.
  • Why it matters: the App token then holds actions: write it doesn't need: it could dispatch, cancel or re-run workflows and delete logs. That's in jobs that process agent output.
  • Workaround: none in frontmatter, since github-app.permissions rejects actions.

Seen on v0.93.5 and v1.0.1.

Implementation Plan

  1. Add getHandlerGitHubToken(config, fieldName) next to getHandlerGitHubApp. It reads GitHubToken directly, or from the embedded BaseSafeOutputConfig.
  2. In computePermissionsForSafeOutputs, when computing permissions for the App mint (excludePerHandlerApps == true), also skip handlers with a non-empty handler-level github-token.
  3. Leave job-level GITHUB_TOKEN permissions (excludePerHandlerApps == false) unchanged: a handler token of secrets.GITHUB_TOKEN still needs them.
  4. The conclusion mint should use the same exclusion. If it switches to computeConclusionJobPermissions (Conclusion job's GitHub App token is minted with safe-output permissions, not the conclusion job's #73521), apply the exclusion there for the App fields only.

Tests

In safe_outputs_permissions_test.go:

  • the config above gives no actions in the App-mint permissions, and keeps actions: write in the job permissions;
  • without the handler github-token, the App mint keeps actions: write.

Acceptance criterion

A handler that sets github-token contributes nothing to the global safe-outputs.github-app mint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions