diff --git a/.changeset/artifacts-token-header.md b/.changeset/artifacts-token-header.md new file mode 100644 index 00000000..9267bf03 --- /dev/null +++ b/.changeset/artifacts-token-header.md @@ -0,0 +1,5 @@ +--- +"@cloudflare/computer": patch +--- + +`codemode:artifacts` tells code to clone and push with a token in a header, as [the docs](https://github.com/cloudflare/computer/blob/main/docs/17_isolate_javascript.md#codemodeartifacts) do, rather than calling `share()`'s URL clone-ready: git saves a clone's URL, token and all, in `.git/config`. diff --git a/docs/17_isolate_javascript.md b/docs/17_isolate_javascript.md index ac30674d..e10bb8a6 100644 --- a/docs/17_isolate_javascript.md +++ b/docs/17_isolate_javascript.md @@ -603,7 +603,8 @@ import { clone, push } from "codemode:git"; export default async function () { const { remote } = await get("site"); const { plaintext } = await createToken("site", "write", "15m"); - const headers = { Authorization: `Bearer ${plaintext}` }; + // The plaintext ends in an `?expires=` hint that isn't part of the token. + const headers = { Authorization: `Bearer ${plaintext.split("?expires=")[0]}` }; await clone({ url: remote, dir: "site", headers }); // ...change and commit files... return push({ dir: "site", ref: "main", headers }); diff --git a/packages/computer/src/modules/artifacts.test.ts b/packages/computer/src/modules/artifacts.test.ts index 22c1967c..6fe635c5 100644 --- a/packages/computer/src/modules/artifacts.test.ts +++ b/packages/computer/src/modules/artifacts.test.ts @@ -150,4 +150,12 @@ describe("createArtifactsModule share", () => { expect(description).toContain("createToken(name"); expect(description).toContain("share(name"); }); + + it("tells code to send a token in a header, not in the URL", () => { + const description = createArtifactsModule().description ?? ""; + expect(description).toContain('headers: { Authorization: "Bearer " }'); + expect(description).toContain('plaintext.split("?expires=")[0]'); + expect(description).toContain(".git/config"); + expect(description).not.toContain("clone-ready"); + }); }); diff --git a/packages/computer/src/modules/artifacts.ts b/packages/computer/src/modules/artifacts.ts index 9e575e6e..14d76644 100644 --- a/packages/computer/src/modules/artifacts.ts +++ b/packages/computer/src/modules/artifacts.ts @@ -95,7 +95,7 @@ export function createArtifactsModule( }, }); return Object.assign(create, { - description: `Git repositories stored in Cloudflare Artifacts: \`create(name)\`, \`get(name)\`, \`list()\`, \`importArtifact(name, source)\`, and \`deleteArtifact(name)\`.${allowNetwork ? "" : " Importing from a remote URL is not allowed."} \`createToken(name, scope?, ttl?)\` mints a git token ("read" by default). \`share(name, { scope?, ttl? })\` returns a clone-ready URL with a token embedded; it is a credential, so never print or return it. \`ttl\` is seconds or a duration like "15m".`, + description: `Git repositories stored in Cloudflare Artifacts: \`create(name)\`, \`get(name)\`, \`list()\`, \`importArtifact(name, source)\`, and \`deleteArtifact(name)\`.${allowNetwork ? "" : " Importing from a remote URL is not allowed."} \`createToken(name, scope?, ttl?)\` mints a git token ("read" by default): to clone or push with the git module, pass \`get(name)\`'s \`remote\` as the URL and the token in \`headers: { Authorization: "Bearer " }\`, not in the URL, which git saves in \`.git/config\`. The token is \`plaintext\` up to its \`?expires=\` hint, which isn't part of it: \`plaintext.split("?expires=")[0]\`. \`share(name, { scope?, ttl? })\` returns the remote URL with a token embedded, for git in a shell command: pass it in \`env\`, not in the command text. Tokens and shared URLs are credentials, so never print or return them. \`ttl\` is seconds or a duration like "15m".`, }); }