Compare commits

..
2 Commits
23 changed files with 392 additions and 287 deletions

No files matched your search

+1 -2
View File
@@ -40,11 +40,10 @@ jobs:
ref: ${{ fromJSON(steps.release-please.outputs.pr).headBranchName }}
token: ${{ steps.app-token.outputs.token }}
- uses: actions/setup-node@v7
- uses: actions/setup-node@v6
if: steps.release-please.outputs.prs_created == 'true'
with:
node-version-file: package.json
package-manager-cache: false
- run: npm ci
if: steps.release-please.outputs.prs_created == 'true'
+1 -1
View File
@@ -23,7 +23,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v11
- uses: actions/stale@v10
with:
operations-per-run: 100
days-before-stale: ${{ env.DAYS_BEFORE_STALE }}
+4 -3
View File
@@ -23,7 +23,7 @@ jobs:
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- uses: actions/setup-node@v6
with:
node-version-file: package.json
@@ -37,7 +37,7 @@ jobs:
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@v7
- uses: actions/setup-node@v7
- uses: actions/setup-node@v6
with:
node-version-file: package.json
- run: npm ci
@@ -62,9 +62,10 @@ jobs:
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@v7
- uses: actions/setup-node@v7
- uses: actions/setup-node@v6
with:
node-version-file: package.json
cache: 'npm'
- run: npm ci
- run: npm run build
- uses: ./ # Uses the action in the root directory
@@ -22,17 +22,16 @@ jobs:
COMMIT_MESSAGE: 'feat: update permission inputs'
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- uses: actions/setup-node@v6
with:
node-version-file: package.json
package-manager-cache: false
- name: Install dependencies
run: npm ci
- name: Run permission inputs update script
run: node scripts/update-permission-inputs.js
- name: Commit changes
id: auto-commit
uses: stefanzweifel/git-auto-commit-action@d0b01107b5db882071f96de5dd4b54961ea93f4c # v7.2.1
uses: stefanzweifel/git-auto-commit-action@4a55954c782fc1ea30b9056cd3e7a2b40ca8887d # v7.2.0
with:
commit_message: ${{ env.COMMIT_MESSAGE }}
- name: Update PR title
+1 -1
View File
@@ -1,3 +1,3 @@
{
".": "3.4.0"
".": "3.4.0-beta"
}
+2 -9
View File
@@ -1,18 +1,11 @@
# Changelog
## [3.4.0](https://github.com/actions/create-github-app-token/compare/v3.3.0...v3.4.0) (2026-11-18)
## [3.4.0-beta](https://github.com/actions/create-github-app-token/compare/v3.3.0...v3.4.0-beta) (2026-11-17)
### Features
* bump actions/setup-node from 6 to 7 ([#410](https://github.com/actions/create-github-app-token/issues/410)) ([09c1ab7](https://github.com/actions/create-github-app-token/commit/09c1ab7079f14af5f0d64c9325739c49a8541f56))
* bump actions/stale from 10 to 11 ([#409](https://github.com/actions/create-github-app-token/issues/409)) ([679345a](https://github.com/actions/create-github-app-token/commit/679345a20e2e07130130e6cf0301b9e897f18cd5))
* bump stefanzweifel/git-auto-commit-action from 7.2.0 to 7.2.1 in the github-actions group ([#408](https://github.com/actions/create-github-app-token/issues/408)) ([660c44c](https://github.com/actions/create-github-app-token/commit/660c44c8ce22207448fbba2730cd2913052c9de3))
### Bug Fixes
* **deps:** bump undici ([#406](https://github.com/actions/create-github-app-token/issues/406)) ([18e9994](https://github.com/actions/create-github-app-token/commit/18e9994c8d13ac7c7e2bbcc3355a1a4f31d30de7))
* 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)
+2 -2
View File
@@ -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
+72 -122
View File
@@ -2103,7 +2103,6 @@ var require_dispatcher = __commonJS({
var require_dispatcher_base = __commonJS({
"node_modules/@actions/http-client/node_modules/undici/lib/dispatcher/dispatcher-base.js"(exports2, module2) {
"use strict";
var buffer = require("node:buffer");
var Dispatcher = require_dispatcher();
var {
ClientDestroyedError,
@@ -2115,7 +2114,6 @@ var require_dispatcher_base = __commonJS({
var kOnClosed = /* @__PURE__ */ Symbol("onClosed");
var kInterceptedDispatch = /* @__PURE__ */ Symbol("Intercepted Dispatch");
var kWebSocketOptions = /* @__PURE__ */ Symbol("webSocketOptions");
var kEventSourceOptions = /* @__PURE__ */ Symbol("eventSourceOptions");
var DispatcherBase = class extends Dispatcher {
constructor(opts) {
super();
@@ -2124,7 +2122,6 @@ var require_dispatcher_base = __commonJS({
this[kClosed] = false;
this[kOnClosed] = [];
this[kWebSocketOptions] = opts?.webSocket ?? {};
this[kEventSourceOptions] = opts?.eventSource ?? {};
}
get webSocketOptions() {
return {
@@ -2132,11 +2129,6 @@ var require_dispatcher_base = __commonJS({
maxPayloadSize: this[kWebSocketOptions].maxPayloadSize ?? 128 * 1024 * 1024
};
}
get eventSourceOptions() {
return {
maxEventSize: this[kEventSourceOptions].maxEventSize ?? buffer.kStringMaxLength
};
}
get destroyed() {
return this[kDestroyed];
}
@@ -6284,6 +6276,7 @@ var require_client_h1 = __commonJS({
socket[kSocketUsed] = false;
socket[kParser] = new Parser(client, socket, llhttpInstance);
addListener(socket, "error", function(err) {
assert(err.code !== "ERR_TLS_CERT_ALTNAME_INVALID");
const parser = this[kParser];
if (err.code === "ECONNRESET" && parser.statusCode && !parser.shouldKeepAlive) {
const parserErr = parser.finish();
@@ -6967,6 +6960,7 @@ var require_client_h2 = __commonJS({
client[kHTTP2Session] = session;
socket[kHTTP2Session] = session;
util.addListener(socket, "error", function(err) {
assert(err.code !== "ERR_TLS_CERT_ALTNAME_INVALID");
this[kError] = err;
this[kClient][kOnError](err);
});
@@ -7025,6 +7019,7 @@ var require_client_h2 = __commonJS({
}
}
function onHttp2SessionError(err) {
assert(err.code !== "ERR_TLS_CERT_ALTNAME_INVALID");
this[kSocket][kError] = err;
this[kClient][kOnError](err);
}
@@ -7718,10 +7713,9 @@ var require_client = __commonJS({
// h2
maxConcurrentStreams,
allowH2,
webSocket,
eventSource
webSocket
} = {}) {
super({ webSocket, eventSource });
super({ webSocket });
if (keepAlive !== void 0) {
throw new InvalidArgumentError("unsupported keepAlive, use pipelining=0 instead");
}
@@ -8618,7 +8612,7 @@ var require_agent = __commonJS({
return opts && opts.connections === 1 ? new Client(origin, opts) : new Pool(origin, opts);
}
var Agent3 = class extends DispatcherBase {
constructor({ factory = defaultFactory, maxRedirections = 0, connect, tls, ...options } = {}) {
constructor({ factory = defaultFactory, maxRedirections = 0, connect, ...options } = {}) {
if (typeof factory !== "function") {
throw new InvalidArgumentError("factory must be a function.");
}
@@ -8632,11 +8626,8 @@ var require_agent = __commonJS({
if (connect && typeof connect !== "function") {
connect = { ...connect };
}
if (tls && typeof tls !== "function") {
tls = { ...tls };
}
this[kInterceptors] = options.interceptors?.Agent && Array.isArray(options.interceptors.Agent) ? options.interceptors.Agent : [createRedirectInterceptor({ maxRedirections })];
this[kOptions] = { ...util.deepClone(options), connect, tls };
this[kOptions] = { ...util.deepClone(options), connect };
this[kOptions].interceptors = options.interceptors ? { ...options.interceptors } : void 0;
this[kMaxRedirections] = maxRedirections;
this[kFactory] = factory;
@@ -14364,9 +14355,8 @@ var require_fetch = __commonJS({
}
);
response.body = { stream, source: null, length: null };
if (!fetchParams.controller.resume) {
fetchParams.controller.on("terminated", onAborted);
}
fetchParams.controller.onAborted = onAborted;
fetchParams.controller.on("terminated", onAborted);
fetchParams.controller.resume = async () => {
while (true) {
let bytes;
@@ -14466,6 +14456,7 @@ var require_fetch = __commonJS({
headersList.append(bufferToLowerCasedHeaderName(rawHeaders[i]), rawHeaders[i + 1].toString("latin1"), true);
}
location = headersList.get("location", true);
this.body = new Readable({ read: resume });
const decoders = [];
const willFollow = location && request2.redirect === "follow" && redirectStatusSet.has(status);
if (request2.method !== "HEAD" && request2.method !== "CONNECT" && !nullBodyStatus.includes(status) && !willFollow) {
@@ -14473,7 +14464,7 @@ var require_fetch = __commonJS({
const codings = contentEncoding ? contentEncoding.toLowerCase().split(",") : [];
const maxContentEncodings = 5;
if (codings.length > maxContentEncodings) {
this.abort(new Error(`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`));
reject(new Error(`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`));
return true;
}
for (let i = codings.length - 1; i >= 0; --i) {
@@ -14503,7 +14494,6 @@ var require_fetch = __commonJS({
}
}
}
this.body = new Readable({ read: resume });
const onError = this.onError.bind(this);
resolve2({
status,
@@ -14529,6 +14519,9 @@ var require_fetch = __commonJS({
if (this.abort) {
fetchParams.controller.off("terminated", this.abort);
}
if (fetchParams.controller.onAborted) {
fetchParams.controller.off("terminated", fetchParams.controller.onAborted);
}
fetchParams.controller.ended = true;
this.body.push(null);
},
@@ -17602,16 +17595,6 @@ var require_receiver = __commonJS({
if (isControlFrame(this.#info.opcode)) {
this.#loop = this.parseControlFrame(body);
this.#state = parserStates.INFO;
const socket = this.ws[kResponse].socket;
if (this.#loop && socket.writableNeedDrain) {
this.#loop = false;
socket.once("drain", () => {
if (this.destroyed) return;
this.#loop = true;
this.run(callback);
});
return;
}
} else {
if (!this.#info.compressed) {
if (!this.writeFragments(body)) {
@@ -18305,7 +18288,6 @@ var require_util8 = __commonJS({
var require_eventsource_stream = __commonJS({
"node_modules/@actions/http-client/node_modules/undici/lib/web/eventsource/eventsource-stream.js"(exports2, module2) {
"use strict";
var buffer = require("node:buffer");
var { Transform } = require("node:stream");
var { isASCIINumber, isValidLastEventId } = require_util8();
var BOM = [239, 187, 191];
@@ -18313,28 +18295,24 @@ var require_eventsource_stream = __commonJS({
var CR = 13;
var COLON = 58;
var SPACE = 32;
var defaultMaxEventSize = buffer.kStringMaxLength;
var DATA = Buffer.from("data");
var EVENT = Buffer.from("event");
var ID = Buffer.from("id");
var RETRY = Buffer.from("retry");
var minParserItems = 1024;
var maxParserItems = 131072;
var bytesPerParserItem = 128;
function isASCIINumberBytes(buffer2, start) {
if (start >= buffer2.length) {
function isASCIINumberBytes(buffer, start) {
if (start >= buffer.length) {
return false;
}
for (let i = start; i < buffer2.length; i++) {
if (buffer2[i] < 48 || buffer2[i] > 57) {
for (let i = start; i < buffer.length; i++) {
if (buffer[i] < 48 || buffer[i] > 57) {
return false;
}
}
return true;
}
function isValidLastEventIdBytes(buffer2, start) {
for (let i = start; i < buffer2.length; i++) {
if (buffer2[i] === 0) {
function isValidLastEventIdBytes(buffer, start) {
for (let i = start; i < buffer.length; i++) {
if (buffer[i] === 0) {
return false;
}
}
@@ -18351,11 +18329,6 @@ var require_eventsource_stream = __commonJS({
}
return true;
}
function createMaxEventSizeExceededError() {
const error2 = new Error("EventSource message size exceeded");
error2.aborted = false;
return error2;
}
var EventSourceStream = class extends Transform {
/**
* @type {eventSourceSettings}
@@ -18382,13 +18355,6 @@ var require_eventsource_stream = __commonJS({
pos = 0;
lineChunkIndex = 0;
linePos = 0;
lineLength = 0;
eventSize = 0;
eventFieldSizes = { data: 0, event: 0, id: 0, retry: 0 };
dataLineCount = 0;
maxEventSize;
maxDataLines;
maxBufferedChunks;
event = {
data: void 0,
event: void 0,
@@ -18397,7 +18363,6 @@ var require_eventsource_stream = __commonJS({
};
/**
* @param {object} options
* @param {number} [options.maxEventSize]
* @param {eventSourceSettings} options.eventSourceSettings
* @param {Function} [options.push]
*/
@@ -18405,10 +18370,6 @@ var require_eventsource_stream = __commonJS({
options.readableObjectMode = true;
super(options);
this.state = options.eventSourceSettings || {};
this.maxEventSize = options.maxEventSize ?? defaultMaxEventSize;
const parserItemLimit = this.maxEventSize > 0 ? Math.min(maxParserItems, Math.max(minParserItems, Math.floor(this.maxEventSize / bytesPerParserItem))) : 0;
this.maxDataLines = parserItemLimit;
this.maxBufferedChunks = parserItemLimit;
if (options.push) {
this.push = options.push;
}
@@ -18424,10 +18385,6 @@ var require_eventsource_stream = __commonJS({
callback();
return;
}
if (this.maxEventSize > 0 && this.chunks.length >= this.maxBufferedChunks && chunk[0] !== LF && chunk[0] !== CR) {
callback(createMaxEventSizeExceededError());
return;
}
this.chunks.push(chunk);
if (this.checkBOM) {
if (this.handleBOM()) {
@@ -18464,32 +18421,18 @@ var require_eventsource_stream = __commonJS({
if (byte === CR) {
this.crlfCheck = true;
}
try {
this.parseLine(this.readLine(), this.event);
} catch (error2) {
callback(error2);
return;
}
this.parseLine(this.readLine(), this.event);
this.consumeCurrentByte();
this.eventEndCheck = true;
continue;
}
if (this.maxEventSize > 0 && ++this.lineLength > this.maxEventSize + 7) {
callback(createMaxEventSizeExceededError());
return;
}
this.advanceCursor();
}
callback();
}
_destroy(error2, callback) {
this.chunks.length = 0;
this.clearEvent();
super._destroy(error2, callback);
}
/**
* @param {Buffer} line
* @param {EventSourceStreamEvent} event
* @param {EventStreamEvent} event
*/
parseLine(line, event) {
if (line.length === 0) {
@@ -18509,12 +18452,6 @@ var require_eventsource_stream = __commonJS({
}
}
if (isFieldName(line, fieldLength, DATA)) {
if (this.maxEventSize > 0 && this.dataLineCount >= this.maxDataLines) {
throw createMaxEventSizeExceededError();
}
const valueBytes = line.length - valueStart;
const dataSize = this.eventFieldSizes.data + (event.data === void 0 ? 0 : 1) + valueBytes;
this.setEventFieldSize("data", dataSize);
const value = line.toString("utf8", valueStart);
if (event.data === void 0) {
event.data = value;
@@ -18522,38 +18459,27 @@ var require_eventsource_stream = __commonJS({
event.data += `
${value}`;
}
this.dataLineCount++;
return;
}
if (isFieldName(line, fieldLength, RETRY)) {
if (isASCIINumberBytes(line, valueStart)) {
this.setEventFieldSize("retry", line.length - valueStart);
event.retry = line.toString("utf8", valueStart);
}
return;
}
if (isFieldName(line, fieldLength, ID)) {
if (isValidLastEventIdBytes(line, valueStart)) {
this.setEventFieldSize("id", line.length - valueStart);
event.id = line.toString("utf8", valueStart);
}
return;
}
if (isFieldName(line, fieldLength, EVENT)) {
if (valueStart < line.length) {
this.setEventFieldSize("event", line.length - valueStart);
event.event = line.toString("utf8", valueStart);
const value = line.toString("utf8", valueStart);
if (value.length > 0) {
event.event = value;
}
}
}
setEventFieldSize(field, size) {
const eventSize = this.eventSize - this.eventFieldSizes[field] + size;
if (this.maxEventSize > 0 && eventSize > this.maxEventSize) {
throw createMaxEventSizeExceededError();
}
this.eventSize = eventSize;
this.eventFieldSizes[field] = size;
}
/**
* @param {EventSourceStreamEvent} event
*/
@@ -18580,12 +18506,6 @@ ${value}`;
this.event.event = void 0;
this.event.id = void 0;
this.event.retry = void 0;
this.eventSize = 0;
this.dataLineCount = 0;
this.eventFieldSizes.data = 0;
this.eventFieldSizes.event = 0;
this.eventFieldSizes.id = 0;
this.eventFieldSizes.retry = 0;
}
hasPendingEvent() {
return this.event.data !== void 0 || this.event.event !== void 0 || this.event.id !== void 0 || this.event.retry !== void 0;
@@ -18610,15 +18530,13 @@ ${value}`;
syncLineStartToCursor() {
this.lineChunkIndex = this.chunkIndex;
this.linePos = this.pos;
this.lineLength = 0;
this.dropConsumedChunks();
}
dropConsumedChunks() {
if (this.lineChunkIndex > 0) {
const consumed = this.lineChunkIndex;
this.chunks.splice(0, consumed);
this.lineChunkIndex = 0;
this.chunkIndex -= consumed;
while (this.lineChunkIndex > 0) {
this.chunks.shift();
this.lineChunkIndex--;
this.chunkIndex--;
}
if (this.chunkIndex === this.chunks.length) {
this.chunks.length = 0;
@@ -18721,7 +18639,6 @@ var require_eventsource = __commonJS({
var { delay } = require_util8();
var { kEnumerableProperty } = require_util();
var { environmentSettingsObject } = require_util2();
var { getGlobalDispatcher } = require_global2();
var experimentalWarned = false;
var defaultReconnectionTime = 3e3;
var CONNECTING = 0;
@@ -18862,7 +18779,6 @@ var require_eventsource = __commonJS({
this.#state.origin = response.urlList[response.urlList.length - 1].origin;
const eventSourceStream = new EventSourceStream({
eventSourceSettings: this.#state,
maxEventSize: this.#dispatcher.eventSourceOptions?.maxEventSize,
push: (event) => {
this.dispatchEvent(createFastMessageEvent(
event.type,
@@ -18995,8 +18911,7 @@ var require_eventsource = __commonJS({
{
key: "dispatcher",
// undici only
converter: webidl.converters.any,
defaultValue: () => getGlobalDispatcher()
converter: webidl.converters.any
}
]);
module2.exports = {
@@ -24076,17 +23991,47 @@ async function pRetry(input, options = {}) {
throw new Error("Retry attempts exhausted without throwing an error.");
}
// lib/create-oidc-auth.js
async function createOidcAuth(clientId, core, request2) {
const audience = `${process.env.GITHUB_SERVER_URL || "https://github.com"}/login/oauth`;
const token = await core.getIDToken(audience);
const auth5 = async ({ installationId, repositoryNames, permissions }) => {
const { data } = await request2(
"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 };
};
auth5.hook = (hookRequest, route, parameters) => {
const endpoint2 = hookRequest.endpoint(route, parameters);
const url = new URL(endpoint2.url);
url.searchParams.set("client_id", clientId);
endpoint2.url = url.toString();
endpoint2.headers.authorization = `Bearer ${token}`;
return hookRequest(endpoint2);
};
return auth5;
}
// lib/main.js
async function main(clientId, privateKey, enterprise, owner, repositories, permissions, core, createAppAuth2, request2, skipTokenRevoke) {
if (enterprise && (owner || repositories.length > 0)) {
throw new Error("Cannot use 'enterprise' input with 'owner' or 'repositories' inputs");
}
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 auth5 = createAppAuth2({
appId: clientId,
privateKey,
request: request2
});
if (!privateKey) {
core.info("No 'private-key' provided; authenticating with GitHub Actions OIDC.");
}
const auth5 = privateKey ? createAppAuth2({ appId: clientId, privateKey, request: request2 }) : await createOidcAuth(clientId, core, request2);
const { authentication, installationId, appSlug } = await pRetry(
() => getTokenFromTarget(request2, auth5, target, permissions),
createTokenRetryOptions(core, getTokenRetryDescription(target))
@@ -24307,7 +24252,12 @@ async function run() {
}
const privateKey = 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 (!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 = getInput("enterprise");
const owner = getInput("owner");
+31 -116
View File
@@ -2101,7 +2101,6 @@ var require_dispatcher = __commonJS({
var require_dispatcher_base = __commonJS({
"node_modules/@actions/http-client/node_modules/undici/lib/dispatcher/dispatcher-base.js"(exports2, module2) {
"use strict";
var buffer = require("node:buffer");
var Dispatcher = require_dispatcher();
var {
ClientDestroyedError,
@@ -2113,7 +2112,6 @@ var require_dispatcher_base = __commonJS({
var kOnClosed = /* @__PURE__ */ Symbol("onClosed");
var kInterceptedDispatch = /* @__PURE__ */ Symbol("Intercepted Dispatch");
var kWebSocketOptions = /* @__PURE__ */ Symbol("webSocketOptions");
var kEventSourceOptions = /* @__PURE__ */ Symbol("eventSourceOptions");
var DispatcherBase = class extends Dispatcher {
constructor(opts) {
super();
@@ -2122,7 +2120,6 @@ var require_dispatcher_base = __commonJS({
this[kClosed] = false;
this[kOnClosed] = [];
this[kWebSocketOptions] = opts?.webSocket ?? {};
this[kEventSourceOptions] = opts?.eventSource ?? {};
}
get webSocketOptions() {
return {
@@ -2130,11 +2127,6 @@ var require_dispatcher_base = __commonJS({
maxPayloadSize: this[kWebSocketOptions].maxPayloadSize ?? 128 * 1024 * 1024
};
}
get eventSourceOptions() {
return {
maxEventSize: this[kEventSourceOptions].maxEventSize ?? buffer.kStringMaxLength
};
}
get destroyed() {
return this[kDestroyed];
}
@@ -6282,6 +6274,7 @@ var require_client_h1 = __commonJS({
socket[kSocketUsed] = false;
socket[kParser] = new Parser(client, socket, llhttpInstance);
addListener(socket, "error", function(err) {
assert(err.code !== "ERR_TLS_CERT_ALTNAME_INVALID");
const parser = this[kParser];
if (err.code === "ECONNRESET" && parser.statusCode && !parser.shouldKeepAlive) {
const parserErr = parser.finish();
@@ -6965,6 +6958,7 @@ var require_client_h2 = __commonJS({
client[kHTTP2Session] = session;
socket[kHTTP2Session] = session;
util.addListener(socket, "error", function(err) {
assert(err.code !== "ERR_TLS_CERT_ALTNAME_INVALID");
this[kError] = err;
this[kClient][kOnError](err);
});
@@ -7023,6 +7017,7 @@ var require_client_h2 = __commonJS({
}
}
function onHttp2SessionError(err) {
assert(err.code !== "ERR_TLS_CERT_ALTNAME_INVALID");
this[kSocket][kError] = err;
this[kClient][kOnError](err);
}
@@ -7716,10 +7711,9 @@ var require_client = __commonJS({
// h2
maxConcurrentStreams,
allowH2,
webSocket,
eventSource
webSocket
} = {}) {
super({ webSocket, eventSource });
super({ webSocket });
if (keepAlive !== void 0) {
throw new InvalidArgumentError("unsupported keepAlive, use pipelining=0 instead");
}
@@ -8616,7 +8610,7 @@ var require_agent = __commonJS({
return opts && opts.connections === 1 ? new Client(origin, opts) : new Pool(origin, opts);
}
var Agent3 = class extends DispatcherBase {
constructor({ factory = defaultFactory, maxRedirections = 0, connect, tls, ...options } = {}) {
constructor({ factory = defaultFactory, maxRedirections = 0, connect, ...options } = {}) {
if (typeof factory !== "function") {
throw new InvalidArgumentError("factory must be a function.");
}
@@ -8630,11 +8624,8 @@ var require_agent = __commonJS({
if (connect && typeof connect !== "function") {
connect = { ...connect };
}
if (tls && typeof tls !== "function") {
tls = { ...tls };
}
this[kInterceptors] = options.interceptors?.Agent && Array.isArray(options.interceptors.Agent) ? options.interceptors.Agent : [createRedirectInterceptor({ maxRedirections })];
this[kOptions] = { ...util.deepClone(options), connect, tls };
this[kOptions] = { ...util.deepClone(options), connect };
this[kOptions].interceptors = options.interceptors ? { ...options.interceptors } : void 0;
this[kMaxRedirections] = maxRedirections;
this[kFactory] = factory;
@@ -14362,9 +14353,8 @@ var require_fetch = __commonJS({
}
);
response.body = { stream, source: null, length: null };
if (!fetchParams.controller.resume) {
fetchParams.controller.on("terminated", onAborted);
}
fetchParams.controller.onAborted = onAborted;
fetchParams.controller.on("terminated", onAborted);
fetchParams.controller.resume = async () => {
while (true) {
let bytes;
@@ -14464,6 +14454,7 @@ var require_fetch = __commonJS({
headersList.append(bufferToLowerCasedHeaderName(rawHeaders[i]), rawHeaders[i + 1].toString("latin1"), true);
}
location = headersList.get("location", true);
this.body = new Readable({ read: resume });
const decoders = [];
const willFollow = location && request2.redirect === "follow" && redirectStatusSet.has(status);
if (request2.method !== "HEAD" && request2.method !== "CONNECT" && !nullBodyStatus.includes(status) && !willFollow) {
@@ -14471,7 +14462,7 @@ var require_fetch = __commonJS({
const codings = contentEncoding ? contentEncoding.toLowerCase().split(",") : [];
const maxContentEncodings = 5;
if (codings.length > maxContentEncodings) {
this.abort(new Error(`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`));
reject(new Error(`too many content-encodings in response: ${codings.length}, maximum allowed is ${maxContentEncodings}`));
return true;
}
for (let i = codings.length - 1; i >= 0; --i) {
@@ -14501,7 +14492,6 @@ var require_fetch = __commonJS({
}
}
}
this.body = new Readable({ read: resume });
const onError = this.onError.bind(this);
resolve2({
status,
@@ -14527,6 +14517,9 @@ var require_fetch = __commonJS({
if (this.abort) {
fetchParams.controller.off("terminated", this.abort);
}
if (fetchParams.controller.onAborted) {
fetchParams.controller.off("terminated", fetchParams.controller.onAborted);
}
fetchParams.controller.ended = true;
this.body.push(null);
},
@@ -17600,16 +17593,6 @@ var require_receiver = __commonJS({
if (isControlFrame(this.#info.opcode)) {
this.#loop = this.parseControlFrame(body);
this.#state = parserStates.INFO;
const socket = this.ws[kResponse].socket;
if (this.#loop && socket.writableNeedDrain) {
this.#loop = false;
socket.once("drain", () => {
if (this.destroyed) return;
this.#loop = true;
this.run(callback);
});
return;
}
} else {
if (!this.#info.compressed) {
if (!this.writeFragments(body)) {
@@ -18303,7 +18286,6 @@ var require_util8 = __commonJS({
var require_eventsource_stream = __commonJS({
"node_modules/@actions/http-client/node_modules/undici/lib/web/eventsource/eventsource-stream.js"(exports2, module2) {
"use strict";
var buffer = require("node:buffer");
var { Transform } = require("node:stream");
var { isASCIINumber, isValidLastEventId } = require_util8();
var BOM = [239, 187, 191];
@@ -18311,28 +18293,24 @@ var require_eventsource_stream = __commonJS({
var CR = 13;
var COLON = 58;
var SPACE = 32;
var defaultMaxEventSize = buffer.kStringMaxLength;
var DATA = Buffer.from("data");
var EVENT = Buffer.from("event");
var ID = Buffer.from("id");
var RETRY = Buffer.from("retry");
var minParserItems = 1024;
var maxParserItems = 131072;
var bytesPerParserItem = 128;
function isASCIINumberBytes(buffer2, start) {
if (start >= buffer2.length) {
function isASCIINumberBytes(buffer, start) {
if (start >= buffer.length) {
return false;
}
for (let i = start; i < buffer2.length; i++) {
if (buffer2[i] < 48 || buffer2[i] > 57) {
for (let i = start; i < buffer.length; i++) {
if (buffer[i] < 48 || buffer[i] > 57) {
return false;
}
}
return true;
}
function isValidLastEventIdBytes(buffer2, start) {
for (let i = start; i < buffer2.length; i++) {
if (buffer2[i] === 0) {
function isValidLastEventIdBytes(buffer, start) {
for (let i = start; i < buffer.length; i++) {
if (buffer[i] === 0) {
return false;
}
}
@@ -18349,11 +18327,6 @@ var require_eventsource_stream = __commonJS({
}
return true;
}
function createMaxEventSizeExceededError() {
const error2 = new Error("EventSource message size exceeded");
error2.aborted = false;
return error2;
}
var EventSourceStream = class extends Transform {
/**
* @type {eventSourceSettings}
@@ -18380,13 +18353,6 @@ var require_eventsource_stream = __commonJS({
pos = 0;
lineChunkIndex = 0;
linePos = 0;
lineLength = 0;
eventSize = 0;
eventFieldSizes = { data: 0, event: 0, id: 0, retry: 0 };
dataLineCount = 0;
maxEventSize;
maxDataLines;
maxBufferedChunks;
event = {
data: void 0,
event: void 0,
@@ -18395,7 +18361,6 @@ var require_eventsource_stream = __commonJS({
};
/**
* @param {object} options
* @param {number} [options.maxEventSize]
* @param {eventSourceSettings} options.eventSourceSettings
* @param {Function} [options.push]
*/
@@ -18403,10 +18368,6 @@ var require_eventsource_stream = __commonJS({
options.readableObjectMode = true;
super(options);
this.state = options.eventSourceSettings || {};
this.maxEventSize = options.maxEventSize ?? defaultMaxEventSize;
const parserItemLimit = this.maxEventSize > 0 ? Math.min(maxParserItems, Math.max(minParserItems, Math.floor(this.maxEventSize / bytesPerParserItem))) : 0;
this.maxDataLines = parserItemLimit;
this.maxBufferedChunks = parserItemLimit;
if (options.push) {
this.push = options.push;
}
@@ -18422,10 +18383,6 @@ var require_eventsource_stream = __commonJS({
callback();
return;
}
if (this.maxEventSize > 0 && this.chunks.length >= this.maxBufferedChunks && chunk[0] !== LF && chunk[0] !== CR) {
callback(createMaxEventSizeExceededError());
return;
}
this.chunks.push(chunk);
if (this.checkBOM) {
if (this.handleBOM()) {
@@ -18462,32 +18419,18 @@ var require_eventsource_stream = __commonJS({
if (byte === CR) {
this.crlfCheck = true;
}
try {
this.parseLine(this.readLine(), this.event);
} catch (error2) {
callback(error2);
return;
}
this.parseLine(this.readLine(), this.event);
this.consumeCurrentByte();
this.eventEndCheck = true;
continue;
}
if (this.maxEventSize > 0 && ++this.lineLength > this.maxEventSize + 7) {
callback(createMaxEventSizeExceededError());
return;
}
this.advanceCursor();
}
callback();
}
_destroy(error2, callback) {
this.chunks.length = 0;
this.clearEvent();
super._destroy(error2, callback);
}
/**
* @param {Buffer} line
* @param {EventSourceStreamEvent} event
* @param {EventStreamEvent} event
*/
parseLine(line, event) {
if (line.length === 0) {
@@ -18507,12 +18450,6 @@ var require_eventsource_stream = __commonJS({
}
}
if (isFieldName(line, fieldLength, DATA)) {
if (this.maxEventSize > 0 && this.dataLineCount >= this.maxDataLines) {
throw createMaxEventSizeExceededError();
}
const valueBytes = line.length - valueStart;
const dataSize = this.eventFieldSizes.data + (event.data === void 0 ? 0 : 1) + valueBytes;
this.setEventFieldSize("data", dataSize);
const value = line.toString("utf8", valueStart);
if (event.data === void 0) {
event.data = value;
@@ -18520,38 +18457,27 @@ var require_eventsource_stream = __commonJS({
event.data += `
${value}`;
}
this.dataLineCount++;
return;
}
if (isFieldName(line, fieldLength, RETRY)) {
if (isASCIINumberBytes(line, valueStart)) {
this.setEventFieldSize("retry", line.length - valueStart);
event.retry = line.toString("utf8", valueStart);
}
return;
}
if (isFieldName(line, fieldLength, ID)) {
if (isValidLastEventIdBytes(line, valueStart)) {
this.setEventFieldSize("id", line.length - valueStart);
event.id = line.toString("utf8", valueStart);
}
return;
}
if (isFieldName(line, fieldLength, EVENT)) {
if (valueStart < line.length) {
this.setEventFieldSize("event", line.length - valueStart);
event.event = line.toString("utf8", valueStart);
const value = line.toString("utf8", valueStart);
if (value.length > 0) {
event.event = value;
}
}
}
setEventFieldSize(field, size) {
const eventSize = this.eventSize - this.eventFieldSizes[field] + size;
if (this.maxEventSize > 0 && eventSize > this.maxEventSize) {
throw createMaxEventSizeExceededError();
}
this.eventSize = eventSize;
this.eventFieldSizes[field] = size;
}
/**
* @param {EventSourceStreamEvent} event
*/
@@ -18578,12 +18504,6 @@ ${value}`;
this.event.event = void 0;
this.event.id = void 0;
this.event.retry = void 0;
this.eventSize = 0;
this.dataLineCount = 0;
this.eventFieldSizes.data = 0;
this.eventFieldSizes.event = 0;
this.eventFieldSizes.id = 0;
this.eventFieldSizes.retry = 0;
}
hasPendingEvent() {
return this.event.data !== void 0 || this.event.event !== void 0 || this.event.id !== void 0 || this.event.retry !== void 0;
@@ -18608,15 +18528,13 @@ ${value}`;
syncLineStartToCursor() {
this.lineChunkIndex = this.chunkIndex;
this.linePos = this.pos;
this.lineLength = 0;
this.dropConsumedChunks();
}
dropConsumedChunks() {
if (this.lineChunkIndex > 0) {
const consumed = this.lineChunkIndex;
this.chunks.splice(0, consumed);
this.lineChunkIndex = 0;
this.chunkIndex -= consumed;
while (this.lineChunkIndex > 0) {
this.chunks.shift();
this.lineChunkIndex--;
this.chunkIndex--;
}
if (this.chunkIndex === this.chunks.length) {
this.chunks.length = 0;
@@ -18719,7 +18637,6 @@ var require_eventsource = __commonJS({
var { delay } = require_util8();
var { kEnumerableProperty } = require_util();
var { environmentSettingsObject } = require_util2();
var { getGlobalDispatcher } = require_global2();
var experimentalWarned = false;
var defaultReconnectionTime = 3e3;
var CONNECTING = 0;
@@ -18860,7 +18777,6 @@ var require_eventsource = __commonJS({
this.#state.origin = response.urlList[response.urlList.length - 1].origin;
const eventSourceStream = new EventSourceStream({
eventSourceSettings: this.#state,
maxEventSize: this.#dispatcher.eventSourceOptions?.maxEventSize,
push: (event) => {
this.dispatchEvent(createFastMessageEvent(
event.type,
@@ -18993,8 +18909,7 @@ var require_eventsource = __commonJS({
{
key: "dispatcher",
// undici only
converter: webidl.converters.any,
defaultValue: () => getGlobalDispatcher()
converter: webidl.converters.any
}
]);
module2.exports = {
+48
View File
@@ -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
View File
@@ -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),
+6 -1
View File
@@ -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");
+9 -9
View File
@@ -1,12 +1,12 @@
{
"name": "create-github-app-token",
"version": "3.4.0",
"version": "3.4.0-beta",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "create-github-app-token",
"version": "3.4.0",
"version": "3.4.0-beta",
"license": "MIT",
"dependencies": {
"@actions/core": "^3.0.1",
@@ -20,7 +20,7 @@
"c8": "^12.0.0",
"esbuild": "^0.28.2",
"open-cli": "^9.0.0",
"undici": "^8.12.4",
"undici": "^8.11.2",
"yaml": "^2.9.1"
},
"engines": {
@@ -57,9 +57,9 @@
}
},
"node_modules/@actions/http-client/node_modules/undici": {
"version": "6.29.1",
"resolved": "https://registry.npmjs.org/undici/-/undici-6.29.1.tgz",
"integrity": "sha512-EvRlUt/QqAEvXdQeRMYUfwOQsfzpDztykrG2owGEE/rBOBoYv9uF39ZzsNDh4lTFHhTr2XOZjKkYgueD12ZmGA==",
"version": "6.29.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-6.29.0.tgz",
"integrity": "sha512-R+RODBqp6i2pPflGdq+xIOUkl+RNfGgHwoinecKu/JCuf2uO06cOKoDbI2P7Dn6KcswdKwrczbU6IYJ6K8X+wg==",
"license": "MIT",
"engines": {
"node": ">=18.17"
@@ -1806,9 +1806,9 @@
}
},
"node_modules/undici": {
"version": "8.12.4",
"resolved": "https://registry.npmjs.org/undici/-/undici-8.12.4.tgz",
"integrity": "sha512-8Mx+uNKKER2bA4AdtedkqRbwUCIJFr2nJckXRe5yrDqzePqwLP7VNcctN8/XdmDSbF7mS+jJKIszlL+vbam1VA==",
"version": "8.11.2",
"resolved": "https://registry.npmjs.org/undici/-/undici-8.11.2.tgz",
"integrity": "sha512-u4UB2/IrKdU6lFxumHmmo1a3fCQO5tzQllRorfoRS63txhrB7xTpSn1PftwC4qEHkOaqP95fCWW4lJzwErwzhQ==",
"dev": true,
"license": "MIT",
"engines": {
+2 -2
View File
@@ -2,7 +2,7 @@
"name": "create-github-app-token",
"private": true,
"type": "module",
"version": "3.4.0",
"version": "3.4.0-beta",
"description": "GitHub Action for creating a GitHub App Installation Access Token",
"engines": {
"node": ">=24.4.0"
@@ -27,7 +27,7 @@
"c8": "^12.0.0",
"esbuild": "^0.28.2",
"open-cli": "^9.0.0",
"undici": "^8.12.4",
"undici": "^8.11.2",
"yaml": "^2.9.1"
}
}
+1
View File
@@ -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).
+3 -3
View File
@@ -1,6 +1,6 @@
import { readdirSync } from "node:fs";
import { execFile } from "node:child_process";
import { promisify, stripVTControlCharacters } from "node:util";
import { promisify } from "node:util";
import { snapshot, test } from "node:test";
@@ -60,8 +60,8 @@ for (const file of testFiles) {
({ stderr, stdout } = error);
}
const trimmedStderr = stripVTControlCharacters(stderr).replace(/\r?\n$/, "");
const trimmedStdout = stripVTControlCharacters(stdout).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);
else t.assert.strictEqual(trimmedStderr, "");
+62 -2
View File
@@ -148,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
+4 -1
View File
@@ -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;
+24
View File
@@ -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;
+18
View File
@@ -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
View File
@@ -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}`;