Skip to content

repo-memory: push with a GitHub App token (github-app) so memory branches can be protected by rulesets #73207

Done

Description

@ekbritecore

Analysis

push_repo_memory always pushes with the workflow's GITHUB_TOKEN. In pkg/workflow/repo_memory.go, the push step built by buildSinglePushRepoMemoryStep sets GH_TOKEN: ${{ github.token }}, and tools.repo-memory has no option for another credential. Its keys in v0.93.5 and v1.0.1 are allowed-extensions, branch-name, branch-prefix, create-orphan, description, file-glob, format-json, id, ledger, max-file-count, max-file-size, max-patch-size, target-repo, validation and wiki.

That makes memory branches impossible to protect with repository rulesets:

  • Rulesets accept only installed GitHub Apps as bypass actors. The built-in GitHub Actions integration (GITHUB_TOKEN) can't be added; the API answers Actor GitHub Actions integration must be part of the ruleset source or owner organization.
  • So a ruleset on memory/** with Restrict updates / Restrict creations blocks gh-aw's own memory pushes.
  • Without such a ruleset, anyone with write access, and any workflow with contents: write, can push ordinary commits to a memory branch.

Repo-memory content is read back by agents as trusted, accumulated knowledge, so being able to say "only this workflow's app may write it" matters. It's the same reason tools.github.github-app and safe-outputs support GitHub App tokens. It would also give target-repo a natural credential for writing memory in another repository, which GITHUB_TOKEN can't do.

Implementation Plan

Please implement the following changes:

  1. Update the schema (pkg/parser/schemas/main_workflow_schema.json): add an optional github-app object to tools.repo-memory, in both the object form and each array entry. Use the same shape as tools.github.github-app: client-id (or legacy app-id), private-key, owner, repositories, ignore-if-missing.

  2. Parse it (pkg/workflow/repo_memory.go): add GitHubApp *GitHubAppConfig to RepoMemoryEntry, filled with the existing parseAppConfig (safe_outputs_app_config.go), the way target-repo is applied in applyRepoMemoryIdentityFields.

  3. Mint and use the token in push_repo_memory (buildPushRepoMemoryJob / buildSinglePushRepoMemoryStep), when an entry sets github-app:

    • add a pinned actions/create-github-app-token step before the push, with permission-contents: write;
    • default owner and repositories to the entry's target-repo, or the current repository;
    • use the step's token for that entry's GH_TOKEN instead of github.token;
    • keep the current behaviour unchanged when github-app is absent.

    With every entry on an app, the job's own contents: write could drop to read.

  4. Validation (app_token_permissions_validation.go): make sure the minted token for repo-memory requests only contents: write, and fail compilation if github-app is set without client-id/private-key (unless ignore-if-missing).

  5. Agent-side clone (generateRepoMemorySteps): optionally use the same app token for the clone when target-repo is private and outside the current repository. Otherwise leave it on github.token.

  6. Add tests:

    • Compiler: a workflow with tools.repo-memory.github-app emits a token-mint step in push_repo_memory, and the push step's GH_TOKEN references that step's output, not github.token.
    • Array form: per-entry apps mint per-entry tokens, and entries without github-app keep github.token.
    • Schema: invalid github-app (missing private-key) is rejected.
  7. Update the docs (repo-memory reference): document github-app, with a recipe for a memory/** ruleset (Restrict updates and creations; bypass: the app, plus an admin team if desired).

  8. Follow guidelines: run make agent-finish.

Acceptance Criteria

  • tools.repo-memory accepts github-app (object and array forms), and push_repo_memory pushes with a token minted from that app (Contents: write only).
  • A repository can enforce a ruleset on memory/** that restricts updates and creations to that app, and the workflow's memory pushes still succeed.
  • Workflows without github-app compile and push exactly as before.
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