Skip to content

feat(plugins)!: Move egress credentials into plugin hooks - #536

Merged
dcramer merged 23 commits into
mainfrom
codex/github-oauth-write-attribution
Jun 8, 2026
Merged

dcramer merged 23 commits into
mainfrom
codex/github-oauth-write-attribution

Conversation

@dcramer

@dcramer dcramer commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

GitHub writes now use requester-owned GitHub App user tokens, while safe GitHub reads still use the app installation token. The GitHub plugin owns the GitHub App credential flow through code hooks, so core no longer has a GitHub-specific credential broker or hard-coded GitHub permission routing.

Breaking Plugin API

credentials.type: "github-app" is removed from the public plugin manifest contract. Before this branch, GitHub App egress auth was declared as a core-managed manifest credential:

defineJuniorPlugin({
  manifest: {
    name: "github",
    credentials: {
      type: "github-app",
      domains: ["api.github.com", "github.com"],
      authTokenEnv: "GITHUB_TOKEN",
      authTokenPlaceholder: "ghp_host_managed_credential",
      appIdEnv: "GITHUB_APP_ID",
      privateKeyEnv: "GITHUB_APP_PRIVATE_KEY",
      installationIdEnv: "GITHUB_INSTALLATION_ID",
    },
  },
});

After this branch, hook-owned providers declare egress domains and implement grant selection plus credential issuance in code:

defineJuniorPlugin({
  manifest: {
    name: "provider",
    domains: ["api.provider.com"],
    oauth: {
      clientIdEnv: "PROVIDER_CLIENT_ID",
      clientSecretEnv: "PROVIDER_CLIENT_SECRET",
      authorizeEndpoint: "https://provider.com/oauth/authorize",
      tokenEndpoint: "https://provider.com/oauth/token",
    },
  },
  hooks: {
    grantForEgress(ctx) {
      return ctx.request.method === "GET"
        ? { name: "read", access: "read" }
        : { name: "write", access: "write" };
    },
    async issueCredential(ctx) {
      const tokens = await ctx.tokens.credentialSubject?.get();
      if (!tokens) {
        return {
          type: "needed",
          message: "Connect provider first.",
          authorization: {
            type: "oauth",
            provider: "provider",
            scope: "write",
          },
        };
      }

      return {
        type: "lease",
        lease: {
          expiresAt: new Date(Date.now() + 60_000).toISOString(),
          authorization: {
            type: "oauth",
            provider: "provider",
            scope: "write",
          },
          headerTransforms: [
            {
              domain: "api.provider.com",
              headers: {
                authorization: `Bearer ${tokens.accessToken}`,
              },
            },
          ],
        },
      };
    },
  },
});

GitHub Plugin Setup

Apps still install the built-in GitHub plugin with githubPlugin(). The plugin now accepts GitHub App permission and OAuth scope options directly, and it requires the GitHub App OAuth client env vars for requester-owned write tokens:

githubPlugin({
  appPermissions: {
    contents: "write",
    issues: "write",
    pull_requests: "write",
  },
  additionalUserScopes: ["read:org"],
});

Deterministic Egress Auth

Core selects the owning provider from the egress domain and asks the plugin for the grant required by the outbound request. The GitHub plugin maps safe API methods, GraphQL safe methods, and git-upload-pack to installation-read; GET /user to user-read; and write REST URLs, non-read GraphQL/API methods, and git-receive-pack to user-write.

Missing plugin-issued credentials now produce auth-required signals that can start OAuth. Upstream 403 responses clear the cached lease and preserve provider, grant, account, and permission details so failed bash output reports the deterministic permission failure instead of relying on prompt steering. Docs and specs were updated for plugin-owned credentials, GitHub write permissions, OAuth account resolution, and the trusted-plugin-* to plugin-* terminology cleanup.

@vercel

vercel Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview, Comment Jun 8, 2026 12:59am

Request Review

@dcramer
dcramer marked this pull request as ready for review June 5, 2026 16:28
@dcramer dcramer changed the title feat(github): Use user OAuth for write attribution feat(github)!: Use user OAuth for write attribution Jun 5, 2026
@dcramer
dcramer force-pushed the codex/github-oauth-write-attribution branch from 2d71841 to babbcb0 Compare June 6, 2026 04:50
@dcramer
dcramer force-pushed the codex/github-oauth-write-attribution branch from babbcb0 to cd5272d Compare June 6, 2026 12:55
Only treat Git smart HTTP service parameters as grant evidence on Git smart HTTP paths. This prevents unrelated GitHub URLs from forcing user-write credentials just because they include a service query parameter.

Show the safe git service value in sandbox egress request logs so info/refs read and push negotiations are distinguishable without logging arbitrary query strings.

Co-Authored-By: GPT-5 Codex <[email protected]>
Treat upstream 403 responses as permission denials, not stale credentials. Passing the response through while keeping the cached lease avoids reissuing the same credential on retries.

Add GitHub permission and SSO response headers to warning attributes so GitHub App permission failures are easier to diagnose.

Co-Authored-By: GPT-5 Codex <[email protected]>
Stop labeling egress grant names and access levels as credential fields in sandbox logs. user-write and installation-read are selected grants; plugins issue credential leases for those grants.

Rename the related GitHub hook test descriptions to keep the grant and lease vocabulary precise.

Co-Authored-By: GPT-5 Codex <[email protected]>
Add an explicit GitHub plugin test showing that GET info/refs with service=git-receive-pack selects the user-write grant. Keep the broader service-parameter guardrail focused on false positives.

Co-Authored-By: GPT-5 Codex <[email protected]>
Document the exact GitHub App permissions needed for committing and pushing code. Local commits do not call GitHub; push and REST Git database writes require Contents write, with workflow-file changes requiring Workflows write.

Classify fork creation with an explicit github.fork-create grant reason and include grant reasons in egress logs so permission denials identify the GitHub surface involved.

Co-Authored-By: GPT-5 Codex <[email protected]>
Comment thread packages/junior-github/index.js Resolved
Record upstream 403 responses from credential-injected egress as host-owned permission-denied signals instead of treating them as missing authorization. Failed bash results now include provider, grant, upstream target, and GitHub permission headers when available.

Update GitHub skill guidance so agents do not treat Token scopes: none as read-only proof for GitHub App user-to-server tokens.

Co-Authored-By: GPT-5 Codex <[email protected]>
Reuse cached egress lease headers without carrying stale request-specific grant reasons into logs or permission-denied signals. This keeps a cached GitHub user-write lease from reporting a previous GraphQL reason when a later git receive-pack request is denied.

Clarify GitHub skill guidance so agents treat permission_denied as an upstream GitHub 403 observed by egress, not as a Junior runtime block.

Co-Authored-By: GPT-5 Codex <[email protected]>
Add explicit upstream source and message fields to sandbox egress permission-denied signals, and format those failures into deterministic bash tool output. The agent-facing result now states that Junior forwarded the request after injecting the selected grant, so upstream GitHub 403s are not mistaken for missing user tokens or local runtime blocks.

Update the GitHub skill guidance and credential spec to use the new evidence shape when diagnosing provider 403s.

Co-Authored-By: GPT-5 Codex <[email protected]>
Let code plugins own request-specific egress grant selection and credential issuance instead of declaring plugin-managed credentials in plugin.yaml. This keeps GitHub App and user-token behavior in the GitHub plugin while generic OAuth and API-header plugins stay on the default broker path.

BREAKING CHANGE: plugin-managed credentials are no longer valid in plugin.yaml. Code plugins that own sandbox egress credentials must declare domains in code and register grantForEgress plus issueCredential hooks.

Co-Authored-By: GPT-5 Codex <[email protected]>
@dcramer dcramer changed the title feat(github)!: Use user OAuth for write attribution feat(plugins)!: Move egress credentials into plugin hooks Jun 8, 2026
Rename the remaining heartbeat, dashboard, and reporting surfaces to use plugin terminology consistently. This keeps the plugin API and runtime language on the hard-cutover naming.

Co-Authored-By: GPT-5 Codex <[email protected]>

@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 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 83c677d. Configure here.

Comment thread packages/junior-github/index.js Resolved
Let plugin credential hooks distinguish user authorization needs from operational unavailability. Map unavailable plugin results into the existing egress credential-unavailable path, and have the GitHub plugin use it for missing or invalid App setup.

Co-Authored-By: GPT-5 Codex <[email protected]>
@dcramer
dcramer merged commit fcaf0f9 into main Jun 8, 2026
16 checks passed
@dcramer
dcramer deleted the codex/github-oauth-write-attribution branch June 8, 2026 01:09
dcramer added a commit that referenced this pull request Nov 17, 2026
Sandbox egress credentials have no design doc yet, so changes have no
stated intent to check against. This PR adds
`design/sandbox-credentials.md` and lists it in the `design/README.md`
index.

The doc sets these goals:
- No real credentials in the Sandbox.
- Inject a credential only into requests that send the plugin
placeholder.
- Never replace a credential that a request already carries.
- Use the least access that works.
- Each plugin owns its own write policy.

It also sets the Sentry rules: Sandbox code cannot create releases or
uploads with the Actor's account, and cannot delete orgs or projects
(see #3550).

The intent comes from `policies/security.md`, from #210,
#381, #490 and #536, and from the comments in
`junior-github/src/egress-policy.ts`,
`chat/sandbox/noninteractive-command.ts` and
`chat/sandbox/prepare-workspace.ts`.

**Open intent questions**
- **Missing auth header:** fill one only when the plugin says its tools
send none, as git does today. Sentry stays strict. The alternative is to
never fill it.
- **Child agents:** Threads and Tasks use the parent Turn's Actor
credentials. I treated that as intended and left it out of the doc.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3Ac9056086d12016c72d052e066ae38509 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3Ac9056086d12016c72d052e066ae38509)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3Ac9056086d12016c72d052e066ae38509/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — d34cb6b5 Deployed Jun 8, 2026 by vercel[bot]
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.

2 participants