Skip to content

Commit 87b671a

Browse files
committed
Add ClawHub OIDC validation
1 parent b07fdd3 commit 87b671a

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

.github/workflows/clawhub-publish.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,63 @@ jobs:
3131
- name: Dry-run ClawHub package
3232
run: npm run clawhub:dry-run
3333

34+
- name: Validate trusted publisher OIDC
35+
run: |
36+
node --input-type=module <<'NODE'
37+
const pkg = await import("./package.json", { with: { type: "json" } });
38+
const requestUrl = process.env.ACTIONS_ID_TOKEN_REQUEST_URL;
39+
const requestToken = process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;
40+
if (!requestUrl || !requestToken) {
41+
throw new Error("GitHub Actions OIDC environment is not available.");
42+
}
43+
44+
const oidcUrl = new URL(requestUrl);
45+
oidcUrl.searchParams.set("audience", "clawhub");
46+
const oidcResponse = await fetch(oidcUrl, {
47+
headers: { Authorization: `Bearer ${requestToken}` },
48+
});
49+
const oidcBody = await oidcResponse.json();
50+
if (!oidcResponse.ok || !oidcBody.value) {
51+
throw new Error(`GitHub OIDC request failed: ${oidcResponse.status}`);
52+
}
53+
54+
const token = oidcBody.value;
55+
const [, payload] = token.split(".");
56+
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
57+
console.log("OIDC claims:", JSON.stringify({
58+
aud: claims.aud,
59+
repository: claims.repository,
60+
repository_id: claims.repository_id,
61+
repository_owner: claims.repository_owner,
62+
repository_owner_id: claims.repository_owner_id,
63+
workflow: claims.workflow,
64+
workflow_ref: claims.workflow_ref,
65+
job_workflow_ref: claims.job_workflow_ref,
66+
ref: claims.ref,
67+
sha: claims.sha,
68+
}, null, 2));
69+
70+
const mintResponse = await fetch("https://clawhub.ai/api/v1/publish/token/mint", {
71+
method: "POST",
72+
headers: {
73+
Accept: "application/json",
74+
"Content-Type": "application/json",
75+
},
76+
body: JSON.stringify({
77+
packageName: pkg.default.name,
78+
version: pkg.default.version,
79+
githubOidcToken: token,
80+
}),
81+
});
82+
const mintText = await mintResponse.text();
83+
console.log(`ClawHub mint status: ${mintResponse.status}`);
84+
if (!mintResponse.ok) {
85+
console.log(mintText);
86+
process.exit(1);
87+
}
88+
console.log("ClawHub trusted publisher token mint succeeded.");
89+
NODE
90+
3491
- name: Publish ClawHub package
3592
env:
3693
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)