Skip to content

Enforce admin app token permissions and add a sandboxed agent workflow - #49

Open
rgarcia wants to merge 9 commits into
mainfrom
hypeship/scope-admin-app-tokens
Open

rgarcia wants to merge 9 commits into
mainfrom
hypeship/scope-admin-app-tokens

Conversation

@rgarcia

@rgarcia rgarcia commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

actions/create-github-app-token called without any permission-* inputs mints a token carrying every permission the app installation holds, including administration and workflows write. This PR requests only what each token is used for downstream. Repository scope is unchanged unless noted.

Workflow Job Before After Why
vuln-remediation.yml scan all app permissions on the calling repo contents: read used only by actions/checkout

This one matters more than most. Checkout persists the token in .git/config, and the same job then runs npm install -g @socketsecurity/cli and the Socket scan. Every repo that calls this reusable workflow gave that third-party code a token with admin and workflow write on its own repo. The fix and pr tokens in this workflow already had permission filters and are unchanged.

That checkout now also sets persist-credentials: false, so the token isn't left in .git/config while the Socket CLI installs and runs. The scan reads the local tree and never uses git credentials.

Testing (vuln-remediation)

  • python3 -m unittest discover -s scripts -p test_vuln_remediation_workflow.py: 20 OK.
  • actionlint: no findings.

Action version: permission inputs only work from v2.0.4

actions/create-github-app-token before v2.0.4, v1.12.0 included, ignores permission-* inputs: it reads INPUT_PERMISSION_*, but the runner exports INPUT_PERMISSION-*. The scan, fix, pr, container-remediation and pr-risk admin-app tokens in this repo had therefore been minted with every app permission. They now use v3.3.0, and actions.lock is updated.

New: sandboxed-agent.yml, a standard way to run agents in CI

A reusable workflow that runs Pi with --approve in a Docker Sandbox: a microVM with its own kernel and Docker daemon on the GitHub-hosted runner. It replaces two copies of hand-rolled runner plumbing (a token helper, gh/git wrappers, and the app key written next to the agent), and is meant to become the standard way to run agents in CI here.

  • Credentials: none enter the sandbox.
    • GitHub tokens are minted on the runner by mint-token.mjs, limited to the caller's repository and the caller's app-permissions. The sbx proxy adds them to GitHub requests and refreshes them every 30 minutes.
    • OpenAI and OpenRouter credentials come from the existing llm-credentials action and are added the same way.
    • The agent sees only placeholders. The app key is in a 0600 file outside the workspace, which is the only host path the sandbox can read.
  • Check runs: the app has no checks permission, and the proxy replaces any credential the agent sends. gh pr checks inside the sandbox therefore reads check runs from checks-relay.mjs, which answers with the job's read-only GITHUB_TOKEN.
  • Merge gate: with merge: true, the agent writes ready:<pr>. merge-gate.sh then runs on the runner, outside the agent's reach. It waits for checks, requires Cursor Bugbot and every check to pass on the head commit, and merges with --match-head-commit.
  • Teardown: removes the sandbox and the stored secret, revokes every minted token, and deletes the key file.
  • Pins: sbx is pinned to v0.54.0 by SHA-256. Node.js inside the sandbox is checked against nodejs.org's SHASUMS256.txt.
  • Limitation: Anthropic models aren't supported yet. Their federation gives the agent an identity token to exchange, which the proxy can't do on its behalf. The workflow fails early with that message.

The callers that use it are kernel/hypeship#1662 and kernel/kernel-tinker-rl#17. Merge this PR first.

Testing

  • scripts/test_sandboxed_agent.py, 12 tests, run by the new sandboxed-agent-tests.yml:
    • The app key reaches only the two minting steps.
    • No sandbox step gets a GitHub credential, and the state directory is outside the workspace.
    • The job token is read-only.
    • The merge token is minted only for a ready: outcome.
    • Teardown always runs.
    • Merge-gate scenarios run against a stubbed gh: green, BugBot missing, neutral or failing, a failing or pending check, red statuses, and a PR the agent already merged.
  • actionlint and shellcheck are clean.
  • A live end-to-end run from a temporary caller in hypeship passed; see kernel/hypeship#1662 for the in-sandbox checks. Merging a real PR through the gate was not exercised live.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 51dce82. Configure here.

fetch(`https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/installation`, {
headers: { Authorization: `Bearer ${u}.${s.sign(key, "base64url")}`, Accept: "application/vnd.github+json", "User-Agent": "sandboxed-agent" },
}).then((r) => r.json()).then((j) => { if (!j.id) throw new Error("no installation for this repository"); console.log(j.id); });
' "$STATE/app-key.pem")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

App key path uses wrong argv

High Severity

The inline node -e installer reads the app private key from process.argv[1]. For node -e, that slot is [eval], and the pem path is process.argv[2]. readFileSync fails, so installation lookup never runs and the agent cannot mint GitHub credentials.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 51dce82. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

False positive: with node -e '<code>' <arg>, process.argv is [<node>, <arg>]. There's no [eval] entry, so the pem path is argv[1]. Checked locally: node -e 'console.log(process.argv)' /tmp/x.pem prints ["/usr/bin/node","/tmp/x.pem"]. The live end-to-end run also got past this step and minted tokens that the in-sandbox gh and git push used.

@rgarcia rgarcia changed the title Scope admin app tokens to least-privilege permissions Enforce admin app token permissions and add a sandboxed agent workflow Nov 22, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant