0.1.2: servers fetch checkouts over HTTPS
- With GITLAB_TOKEN set (a server has no SSH key), the reviewer's checkout is fetched over HTTPS. git gets the token through its environment, so it is never written into the checkout the reviewer container reads. - Without it (a laptop), checkouts still use SSH and the operator's key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -162,7 +162,7 @@ export class CodexClient {
|
||||
|
||||
async initialize() {
|
||||
await this.request('initialize', {
|
||||
clientInfo: { name: 'labuh', title: 'Labuh', version: '0.1.1' },
|
||||
clientInfo: { name: 'labuh', title: 'Labuh', version: '0.1.2' },
|
||||
capabilities: { experimentalApi: false, requestAttestation: false },
|
||||
});
|
||||
this.send({ method: 'initialized' });
|
||||
|
||||
@@ -37,6 +37,7 @@ export type MrInfo = {
|
||||
projectPath: string;
|
||||
webUrl: string;
|
||||
sshUrl: string;
|
||||
httpUrl: string;
|
||||
iid: number;
|
||||
title: string;
|
||||
description: string;
|
||||
@@ -90,6 +91,7 @@ export async function loadMr(ref: MrRef, sha?: string): Promise<MrInfo> {
|
||||
projectPath: project.path_with_namespace,
|
||||
webUrl: project.web_url,
|
||||
sshUrl: project.ssh_url_to_repo,
|
||||
httpUrl: project.http_url_to_repo,
|
||||
iid: mr.iid,
|
||||
title: mr.title,
|
||||
description: mr.description ?? '',
|
||||
@@ -118,8 +120,19 @@ export async function loadJob(projectId: number, jobId: number): Promise<{ id: n
|
||||
// A shallow clone of exactly the reviewed commit, read-only for the reviewer. Symlinks are
|
||||
// checked out as plain files holding their target, so an MR cannot add a link that makes
|
||||
// `cat` or a glob read something outside the checkout.
|
||||
// A laptop fetches over SSH with the operator's key. A server has no key: with GITLAB_TOKEN set,
|
||||
// git fetches over HTTPS and gets the token through its environment, so the token is never
|
||||
// written into the checkout the reviewer reads.
|
||||
function gitAccess(mr: MrInfo): { url: string; env: NodeJS.ProcessEnv } {
|
||||
const token = process.env.GITLAB_TOKEN;
|
||||
if (!token) return { url: mr.sshUrl, env: process.env };
|
||||
const header = `Authorization: Basic ${Buffer.from(`oauth2:${token}`).toString('base64')}`;
|
||||
return { url: mr.httpUrl, env: { ...process.env, GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'http.extraHeader', GIT_CONFIG_VALUE_0: header, GIT_TERMINAL_PROMPT: '0' } };
|
||||
}
|
||||
|
||||
export async function checkout(mr: MrInfo, dir: string) {
|
||||
const git = (...args: string[]) => run('git', args, { cwd: dir, maxBuffer: 16 * 1024 * 1024 });
|
||||
const access = gitAccess(mr);
|
||||
const git = (...args: string[]) => run('git', args, { cwd: dir, env: access.env, maxBuffer: 16 * 1024 * 1024 });
|
||||
try {
|
||||
const { stdout } = await git('rev-parse', 'HEAD');
|
||||
if (stdout.trim() === mr.sha) {
|
||||
@@ -129,8 +142,9 @@ export async function checkout(mr: MrInfo, dir: string) {
|
||||
} catch {
|
||||
await run('mkdir', ['-p', dir]);
|
||||
await git('init', '-q');
|
||||
await git('remote', 'add', 'origin', mr.sshUrl);
|
||||
await git('remote', 'add', 'origin', access.url);
|
||||
}
|
||||
await git('remote', 'set-url', 'origin', access.url);
|
||||
await git('config', 'core.symlinks', 'false');
|
||||
await git('fetch', '-q', '--depth=50', 'origin', `refs/merge-requests/${mr.iid}/head`);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user