Skip to content

feat: add permissions input to narrow minted installation tokens#141

Merged
MarshallOfSound merged 4 commits intomainfrom
sam/permissions-input
Apr 24, 2026
Merged

feat: add permissions input to narrow minted installation tokens#141
MarshallOfSound merged 4 commits intomainfrom
sam/permissions-input

Conversation

@MarshallOfSound
Copy link
Copy Markdown
Member

@MarshallOfSound MarshallOfSound commented Apr 24, 2026

Adds an optional permissions input so callers can mint installation tokens scoped to a subset of the App's installation permissions rather than always receiving the full scope.

The underlying @electron/github-app-auth library already accepts an `AuthNarrowing` argument with a permissions field; this plumbs a YAML-parsed input through to it.

Example

- uses: electron/github-app-auth-action@v2
  id: app-read
  with:
    creds: \${{ secrets.APP_CREDS }}
    org: electron
    permissions: |
      contents: read

Levels accepted: read, write, admin. Invalid shapes / levels / YAML syntax all fail the step with a clear message.

Why

For agent-driven workflows and other automation that runs in multiple phases with different needs, it's valuable to mint tightly-scoped tokens per step rather than reusing a full-scope token. If one phase only needs to read, it should have a read-only token; a later phase that writes can mint its own write token. Today the action only exposes the full-scope path.

Implementation notes

  • Input is parsed with `js-yaml` (safe `load`, no code-execution schema). Block-map form is the expected shape, matching GitHub's own `permissions:` workflow syntax.
  • Empty input preserves the prior unnarrowed behavior so this is fully backward compatible.
  • Added unit tests for both the wiring into `getTokenForOrg`/`getTokenForRepo` and for the parser itself. 24/24 passing locally.
  • `dist/` rebuilt via `yarn all`.

Adds an optional `permissions` input, parsed as YAML, that forwards to
the underlying `@electron/github-app-auth` library's `AuthNarrowing`
argument. Callers can now mint installation tokens scoped to a subset
of the App's permissions — e.g. a read-only token for a checkout-only
job, or a contents-write token for a push job — rather than always
receiving the App's full installation scope.

Leaving the input empty preserves prior behavior (unnarrowed token).
@MarshallOfSound MarshallOfSound requested review from a team as code owners April 24, 2026 22:50
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 24, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedyaml@​2.8.39910010087100

View full report

Copy link
Copy Markdown
Member

@dsanders11 dsanders11 left a comment

Choose a reason for hiding this comment

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

No js-yaml.

The post step called revokeInstallationAccessToken() without awaiting
it, so the surrounding try/catch never saw rejections — a 401 (most
commonly because the caller already revoked the token mid-job) turned
into an unhandled promise rejection that crashed the post script and
failed the job.

Await the call and treat 401 as a successful no-op so the post step is
robust against double-revocation.
@MarshallOfSound MarshallOfSound merged commit 5f70a37 into main Apr 24, 2026
10 checks passed
@MarshallOfSound MarshallOfSound deleted the sam/permissions-input branch April 24, 2026 23:15
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 2.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants