mirror of
https://github.com/actions/create-github-app-token.git
synced 2026-12-01 14:55:26 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
305e4aec4e | ||
|
|
8240f10d3a | ||
|
|
64ab729a62 | ||
|
|
f3a828e4b9 | ||
|
|
655017ffa7 | ||
|
|
12461a3a79 | ||
|
|
a47236f79f | ||
|
|
a69c19ddfd | ||
|
|
d5cb7ae41d | ||
|
|
575da866bd | ||
|
|
e85f677b44 | ||
|
|
9419396df4 | ||
|
|
941de883d0 | ||
|
|
7e4e05d60a | ||
|
|
d6ebfe3883 |
No files matched your search
@@ -18,7 +18,7 @@ jobs:
|
||||
name: release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- uses: ./
|
||||
id: app-token
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
manifest-file: .release-please-manifest.json
|
||||
target-branch: ${{ github.ref_name }}
|
||||
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v7
|
||||
if: steps.release-please.outputs.prs_created == 'true'
|
||||
with:
|
||||
ref: ${{ fromJSON(steps.release-please.outputs.pr).headBranchName }}
|
||||
@@ -51,12 +51,15 @@ jobs:
|
||||
- run: npm run build
|
||||
if: steps.release-please.outputs.prs_created == 'true'
|
||||
|
||||
- uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0
|
||||
- run: git add dist
|
||||
if: steps.release-please.outputs.prs_created == 'true'
|
||||
|
||||
- uses: dsanders11/github-app-commit-action@2bbcd331016d8c950b05a24b56e7eb9cb50d545e # v2.1.0
|
||||
if: steps.release-please.outputs.prs_created == 'true'
|
||||
with:
|
||||
commit_author: "${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>"
|
||||
commit_message: "chore: update dist files"
|
||||
file_pattern: dist/**
|
||||
message: "chore: update dist files"
|
||||
token: ${{ steps.app-token.outputs.token }}
|
||||
fail-on-no-changes: false
|
||||
|
||||
- name: Update major version tag
|
||||
id: update-major-tag
|
||||
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
name: integration
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
# do not run from forks, as forks don’t have access to repository secrets
|
||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: package.json
|
||||
@@ -61,7 +61,7 @@ jobs:
|
||||
# do not run from forks, as forks don’t have access to repository secrets
|
||||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: package.json
|
||||
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
env:
|
||||
COMMIT_MESSAGE: 'feat: update permission inputs'
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version-file: package.json
|
||||
@@ -31,7 +31,7 @@ jobs:
|
||||
run: node scripts/update-permission-inputs.js
|
||||
- name: Commit changes
|
||||
id: auto-commit
|
||||
uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7.1.0
|
||||
uses: stefanzweifel/git-auto-commit-action@4a55954c782fc1ea30b9056cd3e7a2b40ca8887d # v7.2.0
|
||||
with:
|
||||
commit_message: ${{ env.COMMIT_MESSAGE }}
|
||||
- name: Update PR title
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "3.2.0"
|
||||
".": "3.4.0-beta"
|
||||
}
|
||||
@@ -1,5 +1,25 @@
|
||||
# Changelog
|
||||
|
||||
## [3.4.0-beta](https://github.com/actions/create-github-app-token/compare/v3.3.0...v3.4.0-beta) (2026-11-17)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support GitHub Actions OIDC authentication ([#411](https://github.com/actions/create-github-app-token/issues/411)) ([8240f10](https://github.com/actions/create-github-app-token/commit/8240f10d3ae05b4d450da83e8e247111a36eaf2c))
|
||||
|
||||
## [3.3.0](https://github.com/actions/create-github-app-token/compare/v3.2.0...v3.3.0) (2026-10-12)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* update permission inputs ([#399](https://github.com/actions/create-github-app-token/issues/399)) ([a47236f](https://github.com/actions/create-github-app-token/commit/a47236f79f79fcbc3532af49fe3a5ded89529b6e))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **deps:** bump nested undici from 6.24.0 to 6.29.0 ([#403](https://github.com/actions/create-github-app-token/issues/403)) ([12461a3](https://github.com/actions/create-github-app-token/commit/12461a3a794e67c032f1eff5bb95ece9427eb4fb))
|
||||
* **deps:** bump the production-dependencies group across 1 directory with 3 updates ([#395](https://github.com/actions/create-github-app-token/issues/395)) ([a69c19d](https://github.com/actions/create-github-app-token/commit/a69c19ddfdf8e1ab093900e0064524ce9309c807))
|
||||
|
||||
## [3.2.0](https://github.com/actions/create-github-app-token/compare/v3.1.1...v3.2.0) (2026-05-12)
|
||||
|
||||
|
||||
|
||||
@@ -386,7 +386,7 @@ steps:
|
||||
**Optional:** Comma or newline-separated list of repositories to grant access to.
|
||||
|
||||
> [!NOTE]
|
||||
> If `owner` is set and `repositories` is empty, access will be scoped to all repositories in the provided repository owner's installation. If `owner` and `repositories` are empty, access will be scoped to only the current repository.
|
||||
> If `owner` is set explicitly and `repositories` is empty, access will be scoped to all repositories in the provided repository owner's installation. If `owner` and `repositories` are empty, access will be scoped to only the current repository.
|
||||
>
|
||||
> Repository entries may include an owner, for example `owner/repo1`. The owner portion must match the `owner` input, or the current repository owner if `owner` is unset.
|
||||
|
||||
|
||||
+9
-5
@@ -13,8 +13,8 @@ inputs:
|
||||
required: false
|
||||
deprecationMessage: "Use 'client-id' instead."
|
||||
private-key:
|
||||
description: "GitHub App private key"
|
||||
required: true
|
||||
description: "GitHub App private key. If omitted, authenticate using GitHub Actions OIDC (requires client-id and id-token: write, and a private app owned by the workflow repository's organization)."
|
||||
required: false
|
||||
owner:
|
||||
description: "The owner of the GitHub App installation (defaults to current repository owner)"
|
||||
required: false
|
||||
@@ -44,6 +44,8 @@ inputs:
|
||||
description: "The level of permission to create and retrieve the access token for repository attestations. Can be set to 'read' or 'write'."
|
||||
permission-checks:
|
||||
description: "The level of permission to grant the access token for checks on code. Can be set to 'read' or 'write'."
|
||||
permission-code-quality:
|
||||
description: "The level of permission to grant the access token to view and manage code quality data. Can be set to 'read' or 'write'."
|
||||
permission-codespaces:
|
||||
description: "The level of permission to grant the access token to create, edit, delete, and list Codespaces. Can be set to 'read' or 'write'."
|
||||
permission-contents:
|
||||
@@ -82,8 +84,10 @@ inputs:
|
||||
description: "The level of permission to grant the access token to manage access to an organization. Can be set to 'read' or 'write'."
|
||||
permission-organization-announcement-banners:
|
||||
description: "The level of permission to grant the access token to view and manage announcement banners for an organization. Can be set to 'read' or 'write'."
|
||||
permission-organization-copilot-agent-settings:
|
||||
description: "The level of permission to grant the access token to view and manage Copilot cloud agent settings for an organization. Can be set to 'read' or 'write'."
|
||||
permission-organization-copilot-seat-management:
|
||||
description: "The level of permission to grant the access token for managing access to GitHub Copilot for members of an organization with a Copilot Business subscription. This property is in public preview and is subject to change. Can be set to 'write'."
|
||||
description: "The level of permission to grant the access token for managing access to GitHub Copilot for members of an organization with a Copilot Business subscription. This property is in public preview and is subject to change. Can be set to 'read' or 'write'."
|
||||
permission-organization-custom-org-roles:
|
||||
description: "The level of permission to grant the access token for custom organization roles management. Can be set to 'read' or 'write'."
|
||||
permission-organization-custom-properties:
|
||||
@@ -92,6 +96,8 @@ inputs:
|
||||
description: "The level of permission to grant the access token for custom repository roles management. Can be set to 'read' or 'write'."
|
||||
permission-organization-events:
|
||||
description: "The level of permission to grant the access token to view events triggered by an activity in an organization. Can be set to 'read'."
|
||||
permission-organization-external-properties-for-repos:
|
||||
description: "The level of permission to grant the access token for managing external custom properties for repositories in an organization. Can be set to 'read', 'write', or 'admin'."
|
||||
permission-organization-hooks:
|
||||
description: "The level of permission to grant the access token to manage the post-receive hooks for an organization. Can be set to 'read' or 'write'."
|
||||
permission-organization-packages:
|
||||
@@ -136,8 +142,6 @@ inputs:
|
||||
description: "The level of permission to grant the access token to list and manage repositories a user is starring. Can be set to 'read' or 'write'."
|
||||
permission-statuses:
|
||||
description: "The level of permission to grant the access token for commit statuses. Can be set to 'read' or 'write'."
|
||||
permission-team-discussions:
|
||||
description: "The level of permission to grant the access token to manage team discussions and related comments. Can be set to 'read' or 'write'."
|
||||
permission-vulnerability-alerts:
|
||||
description: "The level of permission to grant the access token to manage Dependabot alerts. Can be set to 'read' or 'write'."
|
||||
permission-workflows:
|
||||
|
||||
Vendored
+1250
-393
File diff suppressed because it is too large.
Load diff
Vendored
+1179
-385
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,48 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* Creates an auth strategy compatible with `@octokit/auth-app` that authenticates
|
||||
* as a GitHub App using a GitHub Actions OIDC token instead of a private key.
|
||||
*
|
||||
* @param {string} clientId
|
||||
* @param {Pick<import("@actions/core"), "getIDToken">} core
|
||||
* @param {import("@octokit/request").request} request
|
||||
*/
|
||||
export async function createOidcAuth(clientId, core, request) {
|
||||
const audience = `${process.env.GITHUB_SERVER_URL || "https://github.com"}/login/oauth`;
|
||||
const token = await core.getIDToken(audience);
|
||||
|
||||
/**
|
||||
* @param {{ installationId: number, repositoryNames?: string[], permissions?: Record<string, string> }} options
|
||||
*/
|
||||
const auth = async ({ installationId, repositoryNames, permissions }) => {
|
||||
const { data } = await request(
|
||||
"POST /app/installations/{installation_id}/access_tokens{?client_id}",
|
||||
{
|
||||
installation_id: installationId,
|
||||
client_id: clientId,
|
||||
repositories: repositoryNames,
|
||||
permissions,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
},
|
||||
);
|
||||
|
||||
return { token: data.token, expiresAt: data.expires_at };
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {import("@octokit/request").request} hookRequest
|
||||
* @param {string} route
|
||||
* @param {Record<string, unknown>} [parameters]
|
||||
*/
|
||||
auth.hook = (hookRequest, route, parameters) => {
|
||||
const endpoint = hookRequest.endpoint(route, parameters);
|
||||
const url = new URL(endpoint.url);
|
||||
url.searchParams.set("client_id", clientId);
|
||||
endpoint.url = url.toString();
|
||||
endpoint.headers.authorization = `Bearer ${token}`;
|
||||
return hookRequest(endpoint);
|
||||
};
|
||||
|
||||
return auth;
|
||||
}
|
||||
+13
-5
@@ -1,5 +1,6 @@
|
||||
import pRetry from "p-retry";
|
||||
import isNetworkError from "is-network-error";
|
||||
import { createOidcAuth } from "./create-oidc-auth.js";
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
@@ -31,13 +32,20 @@ export async function main(
|
||||
throw new Error("Cannot use 'enterprise' input with 'owner' or 'repositories' inputs");
|
||||
}
|
||||
|
||||
// The enterprise installation lookup endpoint doesn't accept OIDC tokens
|
||||
if (enterprise && !privateKey) {
|
||||
throw new Error("The 'enterprise' input requires 'private-key'; OIDC authentication is not supported for enterprise installations.");
|
||||
}
|
||||
|
||||
const target = resolveInstallationTarget(enterprise, owner, repositories, core);
|
||||
|
||||
const auth = createAppAuth({
|
||||
appId: clientId,
|
||||
privateKey,
|
||||
request,
|
||||
});
|
||||
if (!privateKey) {
|
||||
core.info("No 'private-key' provided; authenticating with GitHub Actions OIDC.");
|
||||
}
|
||||
|
||||
const auth = privateKey
|
||||
? createAppAuth({ appId: clientId, privateKey, request })
|
||||
: await createOidcAuth(clientId, core, request);
|
||||
|
||||
const { authentication, installationId, appSlug } = await pRetry(
|
||||
() => getTokenFromTarget(request, auth, target, permissions),
|
||||
|
||||
@@ -24,7 +24,12 @@ async function run() {
|
||||
}
|
||||
const privateKey = core.getInput("private-key");
|
||||
if (!privateKey) {
|
||||
throw new Error("The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.");
|
||||
if (!process.env.ACTIONS_ID_TOKEN_REQUEST_URL || !process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN) {
|
||||
throw new Error("The 'private-key' input must be set to a non-empty string, or the workflow must have 'id-token: write' permissions to authenticate with OIDC. If using a secret or variable, ensure it is available in this workflow context.");
|
||||
}
|
||||
if (!core.getInput("client-id")) {
|
||||
throw new Error("The 'client-id' input is required for OIDC authentication. The deprecated 'app-id' input is only supported with 'private-key'.");
|
||||
}
|
||||
}
|
||||
const enterprise = core.getInput("enterprise");
|
||||
const owner = core.getInput("owner");
|
||||
|
||||
Generated
+346
-410
File diff suppressed because it is too large.
Load diff
+8
-8
@@ -2,7 +2,7 @@
|
||||
"name": "create-github-app-token",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"version": "3.2.0",
|
||||
"version": "3.4.0-beta",
|
||||
"description": "GitHub Action for creating a GitHub App Installation Access Token",
|
||||
"engines": {
|
||||
"node": ">=24.4.0"
|
||||
@@ -17,17 +17,17 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^3.0.1",
|
||||
"@octokit/auth-app": "^8.2.0",
|
||||
"@octokit/auth-app": "^8.3.1",
|
||||
"@octokit/request": "^10.0.8",
|
||||
"is-network-error": "^1.3.2",
|
||||
"p-retry": "^8.0.0"
|
||||
"p-retry": "^8.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@octokit/openapi": "^22.0.0",
|
||||
"c8": "^11.0.0",
|
||||
"esbuild": "^0.28.0",
|
||||
"@octokit/openapi": "^24.0.0",
|
||||
"c8": "^12.0.0",
|
||||
"esbuild": "^0.28.2",
|
||||
"open-cli": "^9.0.0",
|
||||
"undici": "^8.2.0",
|
||||
"yaml": "^2.8.4"
|
||||
"undici": "^8.11.2",
|
||||
"yaml": "^2.9.1"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"title": "App Permissions",
|
||||
"type": "object",
|
||||
"description": "The permissions granted to the user access token.",
|
||||
"description": "The permissions granted to the fine-grained access token.",
|
||||
"properties": {
|
||||
"actions": {
|
||||
"type": "string",
|
||||
@@ -43,6 +43,14 @@
|
||||
"write"
|
||||
]
|
||||
},
|
||||
"code_quality": {
|
||||
"type": "string",
|
||||
"description": "The level of permission to grant the access token to view and manage code quality data.",
|
||||
"enum": [
|
||||
"read",
|
||||
"write"
|
||||
]
|
||||
},
|
||||
"codespaces": {
|
||||
"type": "string",
|
||||
"description": "The level of permission to grant the access token to create, edit, delete, and list Codespaces.",
|
||||
@@ -272,9 +280,27 @@
|
||||
"type": "string",
|
||||
"description": "The level of permission to grant the access token for managing access to GitHub Copilot for members of an organization with a Copilot Business subscription. This property is in public preview and is subject to change.",
|
||||
"enum": [
|
||||
"read",
|
||||
"write"
|
||||
]
|
||||
},
|
||||
"organization_copilot_agent_settings": {
|
||||
"type": "string",
|
||||
"description": "The level of permission to grant the access token to view and manage Copilot cloud agent settings for an organization.",
|
||||
"enum": [
|
||||
"read",
|
||||
"write"
|
||||
]
|
||||
},
|
||||
"organization_external_properties_for_repos": {
|
||||
"type": "string",
|
||||
"description": "The level of permission to grant the access token for managing external custom properties for repositories in an organization.",
|
||||
"enum": [
|
||||
"read",
|
||||
"write",
|
||||
"admin"
|
||||
]
|
||||
},
|
||||
"organization_announcement_banners": {
|
||||
"type": "string",
|
||||
"description": "The level of permission to grant the access token to view and manage announcement banners for an organization.",
|
||||
@@ -362,14 +388,6 @@
|
||||
"write"
|
||||
]
|
||||
},
|
||||
"team_discussions": {
|
||||
"type": "string",
|
||||
"description": "The level of permission to grant the access token to manage team discussions and related comments.",
|
||||
"enum": [
|
||||
"read",
|
||||
"write"
|
||||
]
|
||||
},
|
||||
"email_addresses": {
|
||||
"type": "string",
|
||||
"description": "The level of permission to grant the access token to manage the email addresses belonging to a user.",
|
||||
|
||||
@@ -34,3 +34,4 @@ We have tests both for the `main.js` and `post.js` scripts.
|
||||
|
||||
- If you do not expect an error, take [main-token-permissions-set.test.js](main-token-permissions-set.test.js) as a starting point.
|
||||
- If your test has an expected error, take [main-missing-client-and-app-id.test.js](main-missing-client-and-app-id.test.js) as a starting point.
|
||||
- To authenticate with GitHub Actions OIDC instead of a private key, pass `OIDC_ENV` to `test()`, as in [main-oidc-token-permissions-set.test.js](main-oidc-token-permissions-set.test.js).
|
||||
+7
-11
@@ -11,13 +11,6 @@ snapshot.setDefaultSnapshotSerializers([
|
||||
(value) => (typeof value === "string" ? value : undefined),
|
||||
]);
|
||||
|
||||
function normalizeStderr(stderr) {
|
||||
return stderr
|
||||
.replaceAll(/\u001B\[[0-9;]*m/g, "")
|
||||
.replaceAll(process.cwd(), "<cwd>")
|
||||
.replaceAll(/:\d+:\d+/g, ":<line>:<column>");
|
||||
}
|
||||
|
||||
// Get all files in tests directory
|
||||
const files = readdirSync("tests");
|
||||
|
||||
@@ -54,9 +47,12 @@ for (const file of testFiles) {
|
||||
} = process.env;
|
||||
let stderr, stdout;
|
||||
try {
|
||||
({ stderr, stdout } = await execFileAsync("node", [`tests/${file}`], {
|
||||
env,
|
||||
}));
|
||||
// Omit stack traces so snapshots don't change with Node.js or dependency updates
|
||||
({ stderr, stdout } = await execFileAsync(
|
||||
"node",
|
||||
["--stack-trace-limit=0", `tests/${file}`],
|
||||
{ env },
|
||||
));
|
||||
} catch (error) {
|
||||
if (!(error instanceof Error) || !("stderr" in error) || !("stdout" in error)) {
|
||||
throw error;
|
||||
@@ -64,7 +60,7 @@ for (const file of testFiles) {
|
||||
|
||||
({ stderr, stdout } = error);
|
||||
}
|
||||
const trimmedStderr = normalizeStderr(stderr).replace(/\r?\n$/, "");
|
||||
const trimmedStderr = stderr.replace(/\r?\n$/, "");
|
||||
const trimmedStdout = stdout.replace(/\r?\n$/, "");
|
||||
await t.test("stderr", (t) => {
|
||||
if (trimmedStderr) t.assert.snapshot(trimmedStderr);
|
||||
|
||||
+69
-61
@@ -74,13 +74,7 @@ null
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-installation-not-found.test.js > stderr 1`] = `
|
||||
Error: No enterprise installation found matching the enterprise slug "test-enterprise".
|
||||
at getTokenFromEnterprise (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at process.processTicksAndRejections (node:internal/process/task_queues:<line>:<column>)
|
||||
at async pRetry (file://<cwd>/node_modules/p-retry/index.js:<line>:<column>)
|
||||
at async main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at async test (file://<cwd>/tests/main.js:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-enterprise-installation-not-found.test.js:<line>:<column>
|
||||
[Error: No enterprise installation found matching the enterprise slug "test-enterprise".]
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-installation-not-found.test.js > stdout 1`] = `
|
||||
@@ -92,13 +86,7 @@ GET /enterprises/test-enterprise/installation
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-mutual-exclusivity-owner.test.js > stderr 1`] = `
|
||||
Error: Cannot use 'enterprise' input with 'owner' or 'repositories' inputs
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-enterprise-mutual-exclusivity-owner.test.js:<line>:<column>
|
||||
[Error: Cannot use 'enterprise' input with 'owner' or 'repositories' inputs]
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-mutual-exclusivity-owner.test.js > stdout 1`] = `
|
||||
@@ -106,13 +94,7 @@ exports[`main-enterprise-mutual-exclusivity-owner.test.js > stdout 1`] = `
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-mutual-exclusivity-repositories.test.js > stderr 1`] = `
|
||||
Error: Cannot use 'enterprise' input with 'owner' or 'repositories' inputs
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-enterprise-mutual-exclusivity-repositories.test.js:<line>:<column>
|
||||
[Error: Cannot use 'enterprise' input with 'owner' or 'repositories' inputs]
|
||||
`;
|
||||
|
||||
exports[`main-enterprise-mutual-exclusivity-repositories.test.js > stdout 1`] = `
|
||||
@@ -166,17 +148,77 @@ GITHUB_REPOSITORY_OWNER missing, must be set to '<owner>'
|
||||
`;
|
||||
|
||||
exports[`main-missing-private-key.test.js > stderr 1`] = `
|
||||
The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.
|
||||
The 'private-key' input must be set to a non-empty string, or the workflow must have 'id-token: write' permissions to authenticate with OIDC. If using a secret or variable, ensure it is available in this workflow context.
|
||||
`;
|
||||
|
||||
exports[`main-missing-private-key.test.js > stdout 1`] = `
|
||||
::error::The 'private-key' input must be set to a non-empty string. If using a secret or variable, ensure it is available in this workflow context.
|
||||
::error::The 'private-key' input must be set to a non-empty string, or the workflow must have 'id-token: write' permissions to authenticate with OIDC. If using a secret or variable, ensure it is available in this workflow context.
|
||||
`;
|
||||
|
||||
exports[`main-missing-repository.test.js > stderr 1`] = `
|
||||
GITHUB_REPOSITORY missing, must be set to '<owner>/<repo>'
|
||||
`;
|
||||
|
||||
exports[`main-oidc-custom-server-url.test.js > stdout 1`] = `
|
||||
Input 'repositories' is not set. Creating token for all repositories owned by actions.
|
||||
No 'private-key' provided; authenticating with GitHub Actions OIDC.
|
||||
::debug::ID token url is http://127.0.0.1:<port>/token?api-version=2.0&audience=https%253A%252F%252Fgithub.example.com%252Flogin%252Foauth
|
||||
::add-mask::oidc-token
|
||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
|
||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
|
||||
::set-output name=installation-id::123456
|
||||
|
||||
::set-output name=app-slug::github-actions
|
||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
::save-state name=expiresAt::2016-07-11T22:14:10Z
|
||||
--- OIDC REQUESTS ---
|
||||
GET /token?api-version=2.0&audience=https%3A%2F%2Fgithub.example.com%2Flogin%2Foauth
|
||||
--- REQUESTS ---
|
||||
GET /users/actions/installation?client_id=Iv1.0123456789abcdef
|
||||
POST /app/installations/123456/access_tokens?client_id=Iv1.0123456789abcdef
|
||||
null
|
||||
`;
|
||||
|
||||
exports[`main-oidc-enterprise-requires-private-key.test.js > stderr 1`] = `
|
||||
The 'enterprise' input requires 'private-key'; OIDC authentication is not supported for enterprise installations.
|
||||
`;
|
||||
|
||||
exports[`main-oidc-enterprise-requires-private-key.test.js > stdout 1`] = `
|
||||
::error::The 'enterprise' input requires 'private-key'; OIDC authentication is not supported for enterprise installations.
|
||||
`;
|
||||
|
||||
exports[`main-oidc-missing-client-id.test.js > stderr 1`] = `
|
||||
The 'client-id' input is required for OIDC authentication. The deprecated 'app-id' input is only supported with 'private-key'.
|
||||
`;
|
||||
|
||||
exports[`main-oidc-missing-client-id.test.js > stdout 1`] = `
|
||||
::error::The 'client-id' input is required for OIDC authentication. The deprecated 'app-id' input is only supported with 'private-key'.
|
||||
`;
|
||||
|
||||
exports[`main-oidc-token-permissions-set.test.js > stdout 1`] = `
|
||||
Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
|
||||
No 'private-key' provided; authenticating with GitHub Actions OIDC.
|
||||
::debug::ID token url is http://127.0.0.1:<port>/token?api-version=2.0&audience=https%253A%252F%252Fgithub.com%252Flogin%252Foauth
|
||||
::add-mask::oidc-token
|
||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
|
||||
::set-output name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
|
||||
::set-output name=installation-id::123456
|
||||
|
||||
::set-output name=app-slug::github-actions
|
||||
::save-state name=token::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
::save-state name=expiresAt::2016-07-11T22:14:10Z
|
||||
--- OIDC REQUESTS ---
|
||||
GET /token?api-version=2.0&audience=https%3A%2F%2Fgithub.com%2Flogin%2Foauth
|
||||
--- REQUESTS ---
|
||||
GET /repos/actions/create-github-app-token/installation?client_id=Iv1.0123456789abcdef
|
||||
POST /app/installations/123456/access_tokens?client_id=Iv1.0123456789abcdef
|
||||
{"repositories":["create-github-app-token"],"permissions":{"issues":"write"}}
|
||||
`;
|
||||
|
||||
exports[`main-private-key-with-escaped-newlines.test.js > stdout 1`] = `
|
||||
Inputs 'owner' and 'repositories' are not set. Creating token for this repository (actions/create-github-app-token).
|
||||
::add-mask::ghs_16C7e42F292c6912E7710c838347Ae178B4a
|
||||
@@ -227,15 +269,7 @@ POST /app/installations/123456/access_tokens
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-client-error.test.js > stderr 1`] = `
|
||||
RequestError [HttpError]: Forbidden
|
||||
at fetchWrapper (file://<cwd>/node_modules/@octokit/request/dist-bundle/index.js:<line>:<column>)
|
||||
at process.processTicksAndRejections (node:internal/process/task_queues:<line>:<column>)
|
||||
at async hook (file://<cwd>/node_modules/@octokit/auth-app/dist-node/index.js:<line>:<column>)
|
||||
at async getTokenFromOwner (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at async pRetry (file://<cwd>/node_modules/p-retry/index.js:<line>:<column>)
|
||||
at async main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at async test (file://<cwd>/tests/main.js:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-token-get-owner-set-client-error.test.js:<line>:<column> {
|
||||
[RequestError [HttpError]: Forbidden] {
|
||||
status: 403,
|
||||
request: {
|
||||
method: 'GET',
|
||||
@@ -323,17 +357,7 @@ POST /app/installations/123456/access_tokens
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-repo-invalid-format.test.js > stderr 1`] = `
|
||||
Error: Invalid repository 'octocat/hello-world/extra'. Expected 'repository' or 'owner/repository'.
|
||||
at parseRepositoryInput (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at Array.map (<anonymous>)
|
||||
at normalizeRepositoryTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at resolveInstallationTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-token-get-owner-set-repo-invalid-format.test.js:<line>:<column>
|
||||
[Error: Invalid repository 'octocat/hello-world/extra'. Expected 'repository' or 'owner/repository'.]
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-repo-invalid-format.test.js > stdout 1`] = `
|
||||
@@ -380,15 +404,7 @@ POST /app/installations/123456/access_tokens
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-repo-owner-mismatch.test.js > stderr 1`] = `
|
||||
Error: Repository 'octocat/hello-world' includes owner 'octocat', which does not match the resolved owner 'actions'.
|
||||
at normalizeRepositoryTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at resolveInstallationTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-token-get-owner-set-repo-owner-mismatch.test.js:<line>:<column>
|
||||
[Error: Repository 'octocat/hello-world' includes owner 'octocat', which does not match the resolved owner 'actions'.]
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-set-repo-owner-mismatch.test.js > stdout 1`] = `
|
||||
@@ -490,15 +506,7 @@ POST /app/installations/123456/access_tokens
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-unset-repo-owner-mismatch.test.js > stderr 1`] = `
|
||||
Error: Repository 'octocat/hello-world' includes owner 'octocat', which does not match the resolved owner 'actions'.
|
||||
at normalizeRepositoryTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at resolveInstallationTarget (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at main (file://<cwd>/lib/main.js:<line>:<column>)
|
||||
at run (file://<cwd>/main.js:<line>:<column>)
|
||||
at file://<cwd>/main.js:<line>:<column>
|
||||
at ModuleJob.run (node:internal/modules/esm/module_job:<line>:<column>)
|
||||
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:<line>:<column>)
|
||||
at async file://<cwd>/tests/main-token-get-owner-unset-repo-owner-mismatch.test.js:<line>:<column>
|
||||
[Error: Repository 'octocat/hello-world' includes owner 'octocat', which does not match the resolved owner 'actions'.]
|
||||
`;
|
||||
|
||||
exports[`main-token-get-owner-unset-repo-owner-mismatch.test.js > stdout 1`] = `
|
||||
|
||||
@@ -13,7 +13,10 @@ for (const [key, value] of Object.entries({
|
||||
const _error = console.error;
|
||||
console.error = (err) => _error(err?.message ?? err);
|
||||
|
||||
// Verify `main` exits with an error when `private-key` is not set.
|
||||
delete process.env.ACTIONS_ID_TOKEN_REQUEST_URL;
|
||||
delete process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
|
||||
|
||||
// Verify a missing private-key without OIDC permissions produces an actionable error.
|
||||
const { default: promise } = await import("../main.js");
|
||||
await promise;
|
||||
process.exitCode = 0;
|
||||
@@ -0,0 +1,24 @@
|
||||
import { OIDC_ENV, test } from "./main.js";
|
||||
|
||||
// Verify the OIDC audience is derived from `GITHUB_SERVER_URL`, using an `owner` target.
|
||||
await test((mockPool) => {
|
||||
process.env.GITHUB_SERVER_URL = "https://github.example.com";
|
||||
process.env.INPUT_OWNER = process.env.GITHUB_REPOSITORY_OWNER;
|
||||
delete process.env.INPUT_REPOSITORIES;
|
||||
|
||||
mockPool
|
||||
.intercept({
|
||||
path: `/users/${process.env.INPUT_OWNER}/installation?client_id=${OIDC_ENV["INPUT_CLIENT-ID"]}`,
|
||||
method: "GET",
|
||||
headers: {
|
||||
accept: "application/vnd.github.v3+json",
|
||||
"user-agent": "actions/create-github-app-token",
|
||||
authorization: "Bearer oidc-token",
|
||||
},
|
||||
})
|
||||
.reply(
|
||||
200,
|
||||
{ id: "123456", app_slug: "github-actions" },
|
||||
{ headers: { "content-type": "application/json" } },
|
||||
);
|
||||
}, OIDC_ENV);
|
||||
@@ -0,0 +1,17 @@
|
||||
import { OIDC_ENV } from "./main.js";
|
||||
|
||||
for (const [key, value] of Object.entries({
|
||||
...OIDC_ENV,
|
||||
ACTIONS_ID_TOKEN_REQUEST_URL: "https://oidc.example/token",
|
||||
INPUT_ENTERPRISE: "test-enterprise",
|
||||
})) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
|
||||
const _error = console.error;
|
||||
console.error = (err) => _error(err?.message ?? err);
|
||||
|
||||
// Verify `main` exits with an error when OIDC authentication is used with the `enterprise` input.
|
||||
const { default: promise } = await import("../main.js");
|
||||
await promise;
|
||||
process.exitCode = 0;
|
||||
@@ -0,0 +1,18 @@
|
||||
import { OIDC_ENV } from "./main.js";
|
||||
|
||||
for (const [key, value] of Object.entries({
|
||||
...OIDC_ENV,
|
||||
"INPUT_CLIENT-ID": "",
|
||||
"INPUT_APP-ID": "123456",
|
||||
ACTIONS_ID_TOKEN_REQUEST_URL: "https://oidc.example/token",
|
||||
})) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
|
||||
const _error = console.error;
|
||||
console.error = (err) => _error(err?.message ?? err);
|
||||
|
||||
// Verify the deprecated `app-id` input is rejected for OIDC authentication.
|
||||
const { default: promise } = await import("../main.js");
|
||||
await promise;
|
||||
process.exitCode = 0;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { OIDC_ENV, test } from "./main.js";
|
||||
|
||||
// Verify `main` authenticates with an OIDC token when `private-key` isn’t set, and that the
|
||||
// OIDC audience falls back to https://github.com when `GITHUB_SERVER_URL` isn’t set.
|
||||
await test(() => {
|
||||
delete process.env.GITHUB_SERVER_URL;
|
||||
process.env["INPUT_PERMISSION-ISSUES"] = "write";
|
||||
}, OIDC_ENV);
|
||||
+61
-5
@@ -1,5 +1,7 @@
|
||||
// Base for all `main` tests.
|
||||
// @ts-check
|
||||
import { createServer } from "node:http";
|
||||
|
||||
import { createMockAgent } from "./mock-agent.js";
|
||||
|
||||
export const DEFAULT_ENV = {
|
||||
@@ -42,6 +44,48 @@ x3WQZRiXlWejSMUAHuMwXrhGlltF3lw83+xAjnqsVp75kGS6OH61
|
||||
"INPUT_PERMISSION-ADMINISTRATION": "",
|
||||
};
|
||||
|
||||
// Authenticate with GitHub Actions OIDC instead of a private key.
|
||||
export const OIDC_ENV = {
|
||||
...DEFAULT_ENV,
|
||||
"INPUT_PRIVATE-KEY": "",
|
||||
ACTIONS_ID_TOKEN_REQUEST_TOKEN: "runner-token",
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts a local server that mimics the Actions OIDC token endpoint, because
|
||||
* `core.getIDToken()` uses `@actions/http-client`, which `MockAgent` can't intercept.
|
||||
*/
|
||||
async function startOidcServer() {
|
||||
/** @type {string[]} */
|
||||
const requests = [];
|
||||
const server = createServer((request, response) => {
|
||||
requests.push(`${request.method} ${request.url}`);
|
||||
const authorized = request.headers.authorization === "Bearer runner-token";
|
||||
response.writeHead(authorized ? 200 : 401, {
|
||||
"content-type": "application/json",
|
||||
});
|
||||
response.end(JSON.stringify(authorized ? { value: "oidc-token" } : { message: "Unauthorized" }));
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve(undefined)));
|
||||
const { port } = /** @type {import("node:net").AddressInfo} */ (server.address());
|
||||
process.env.ACTIONS_ID_TOKEN_REQUEST_URL = `http://127.0.0.1:${port}/token?api-version=2.0`;
|
||||
|
||||
// `core.getIDToken()` logs the token URL, so replace the random port to keep snapshots stable.
|
||||
const write = process.stdout.write.bind(process.stdout);
|
||||
process.stdout.write = /** @type {any} */ (
|
||||
(/** @type {unknown} */ chunk, /** @type {any[]} */ ...args) =>
|
||||
write(
|
||||
typeof chunk === "string" ? chunk.replaceAll(`127.0.0.1:${port}`, "127.0.0.1:<port>") : chunk,
|
||||
...args
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
requests,
|
||||
close: () => new Promise((resolve) => server.close(() => resolve(undefined))),
|
||||
};
|
||||
}
|
||||
|
||||
export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
process.env[key] = value;
|
||||
@@ -55,6 +99,12 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
|
||||
// Calling `auth({ type: "app" })` to obtain a JWT doesn’t make network requests, so no need to intercept.
|
||||
|
||||
// Without a private key, the action authenticates with an OIDC token and passes `client_id`.
|
||||
const oidcServer = env["INPUT_PRIVATE-KEY"] ? undefined : await startOidcServer();
|
||||
const clientIdQuery = oidcServer ? `?client_id=${env["INPUT_CLIENT-ID"]}` : "";
|
||||
// JWT creation is not idempotent, so the `authorization` header is only asserted for OIDC.
|
||||
const authorization = oidcServer ? { authorization: "Bearer oidc-token" } : {};
|
||||
|
||||
// Mock installation ID and app slug request
|
||||
const mockInstallationId = "123456";
|
||||
const mockAppSlug = "github-actions";
|
||||
@@ -71,12 +121,12 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
|
||||
mockPool
|
||||
.intercept({
|
||||
path: `${basePath}/repos/${owner}/${repo}/installation`,
|
||||
path: `${basePath}/repos/${owner}/${repo}/installation${clientIdQuery}`,
|
||||
method: "GET",
|
||||
headers: {
|
||||
accept: "application/vnd.github.v3+json",
|
||||
"user-agent": "actions/create-github-app-token",
|
||||
// Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
|
||||
...authorization,
|
||||
},
|
||||
})
|
||||
.reply(
|
||||
@@ -92,12 +142,12 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
|
||||
mockPool
|
||||
.intercept({
|
||||
path: `${basePath}/app/installations/${mockInstallationId}/access_tokens`,
|
||||
path: `${basePath}/app/installations/${mockInstallationId}/access_tokens${clientIdQuery}`,
|
||||
method: "POST",
|
||||
headers: {
|
||||
accept: "application/vnd.github.v3+json",
|
||||
"user-agent": "actions/create-github-app-token",
|
||||
// Note: Intentionally omitting the `authorization` header, since JWT creation is not idempotent.
|
||||
...authorization,
|
||||
},
|
||||
})
|
||||
.reply(
|
||||
@@ -113,12 +163,18 @@ export async function test(cb = (_mockPool) => {}, env = DEFAULT_ENV) {
|
||||
const { default: promise } = await import("../main.js");
|
||||
await promise;
|
||||
|
||||
if (oidcServer) {
|
||||
await oidcServer.close();
|
||||
console.log("--- OIDC REQUESTS ---");
|
||||
console.log(oidcServer.requests.join("\n"));
|
||||
}
|
||||
|
||||
console.log("--- REQUESTS ---");
|
||||
const calls = mockAgent
|
||||
.getCallHistory()
|
||||
.calls()
|
||||
.map((call) => {
|
||||
const route = `${call.method} ${call.path}`;
|
||||
const route = `${call.method} ${call.path}${new URL(call.fullUrl).search}`;
|
||||
if (call.method === "GET") return route;
|
||||
|
||||
return `${route}\n${call.body}`;
|
||||
|
||||
Reference in new issue
Block a user