-
Notifications
You must be signed in to change notification settings - Fork 45
Use fresh GitHub token permissions for action installs #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,15 +74,6 @@ export async function POST( | |
| if (!entry.manifest.compatibility.providers.includes('github')) { | ||
| return NextResponse.json({ error: 'Action does not support GitHub' }, { status: 400 }); | ||
| } | ||
| if (requiresWorkflowWrite(entry.manifest.files) && !hasWorkflowWrite(auth.installation.permissions)) { | ||
| return NextResponse.json( | ||
| { | ||
| error: | ||
| 'GitHub App needs Workflows: write permission to install actions into .github/workflows. Update the sh1pt GitHub App permissions, accept the installation update in GitHub, then retry.', | ||
| }, | ||
| { status: 403 }, | ||
| ); | ||
| } | ||
|
|
||
| let render; | ||
| try { | ||
|
|
@@ -102,6 +93,24 @@ export async function POST( | |
| if (!token.ok || !token.data) { | ||
| return NextResponse.json({ error: token.error ?? 'Could not mint installation token' }, { status: token.status || 500 }); | ||
| } | ||
| if (token.data.permissions) { | ||
| await admin | ||
| .from('github_installations') | ||
| .update({ permissions: token.data.permissions, updated_at: new Date().toISOString() }) | ||
| .eq('id', auth.installation.id); | ||
| } | ||
| if ( | ||
| requiresWorkflowWrite(entry.manifest.files) && | ||
| !hasFreshWorkflowWrite(token.data.permissions, auth.installation.permissions) | ||
| ) { | ||
| return NextResponse.json( | ||
| { | ||
| error: | ||
| 'GitHub App needs Workflows: write permission to install actions into .github/workflows. Update the sh1pt GitHub App permissions, accept the installation update in GitHub, then retry.', | ||
| }, | ||
| { status: 403 }, | ||
| ); | ||
| } | ||
|
Comment on lines
78
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In the previous code, a missing |
||
|
|
||
| const outcome = await openPackPullRequest({ | ||
| client: { token: token.data.token }, | ||
|
|
@@ -145,6 +154,14 @@ function hasWorkflowWrite(permissions: Record<string, string> | null | undefined | |
| return permissions?.workflows === 'write'; | ||
| } | ||
|
|
||
| function hasFreshWorkflowWrite( | ||
| tokenPermissions: Record<string, string> | null | undefined, | ||
| storedPermissions: Record<string, string> | null | undefined, | ||
| ): boolean { | ||
| if (tokenPermissions) return hasWorkflowWrite(tokenPermissions); | ||
| return hasWorkflowWrite(storedPermissions); | ||
| } | ||
|
|
||
| function normalizeInputs(value: unknown): { ok: true; value: RenderInputs } | { ok: false; error: string } { | ||
| if (value === undefined) return { ok: true, value: {} }; | ||
| if (!value || typeof value !== 'object' || Array.isArray(value)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
update()call's result isawaited but never destructured for{ error }. If the row update fails (network hiccup, RLS policy, wrong primary key type), the failure is invisible — no log, no side-effect on the current request. The PR explicitly lists "refresh stored installation permissions from the token response" as a goal, so a silent failure here defeats that goal without any signal for debugging.