dynamic construction of oidc issuer (#195)

Signed-off-by: Brian DeHamer <bdehamer@github.com>
This commit is contained in:
Brian DeHamer
2024-08-09 07:42:36 -07:00
committed by GitHub
parent f9d4126c51
commit d58ddf9f24
6 changed files with 213 additions and 62 deletions
Generated Vendored
+19 -1
View File
@@ -68862,14 +68862,19 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = run;
const attest_1 = __nccwpck_require__(74113);
const core = __importStar(__nccwpck_require__(42186));
const VALID_SERVER_URLS = [
'https://github.com',
new RegExp('^https://[a-z0-9-]+\\.ghe\\.com$')
];
/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
*/
async function run() {
try {
const issuer = getIssuer();
// Calculate subject from inputs and generate provenance
const predicate = await (0, attest_1.buildSLSAProvenancePredicate)();
const predicate = await (0, attest_1.buildSLSAProvenancePredicate)(issuer);
core.setOutput('predicate', predicate.params);
core.setOutput('predicate-type', predicate.type);
}
@@ -68879,6 +68884,19 @@ async function run() {
core.setFailed(error.message);
}
}
// Derive the current OIDC issuer based on the server URL
function getIssuer() {
const serverURL = process.env.GITHUB_SERVER_URL || 'https://github.com';
// Ensure the server URL is a valid GitHub server URL
if (!VALID_SERVER_URLS.some(valid_url => serverURL.match(valid_url))) {
throw new Error(`Invalid server URL: ${serverURL}`);
}
let host = new URL(serverURL).hostname;
if (host === 'github.com') {
host = 'githubusercontent.com';
}
return `https://token.actions.${host}`;
}
/***/ }),