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:
2026-11-06 20:56:08 +07:00
parent b8986003c9
commit da05aeb503
3 changed files with 18 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "labuh", "name": "labuh",
"version": "0.1.1", "version": "0.1.2",
"private": true, "private": true,
"type": "module", "type": "module",
"description": "Every deploy request in one harbour: an agent reviews it, a person gives the Gas.", "description": "Every deploy request in one harbour: an agent reviews it, a person gives the Gas.",

View File

@@ -162,7 +162,7 @@ export class CodexClient {
async initialize() { async initialize() {
await this.request('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 }, capabilities: { experimentalApi: false, requestAttestation: false },
}); });
this.send({ method: 'initialized' }); this.send({ method: 'initialized' });

View File

@@ -37,6 +37,7 @@ export type MrInfo = {
projectPath: string; projectPath: string;
webUrl: string; webUrl: string;
sshUrl: string; sshUrl: string;
httpUrl: string;
iid: number; iid: number;
title: string; title: string;
description: string; description: string;
@@ -90,6 +91,7 @@ export async function loadMr(ref: MrRef, sha?: string): Promise<MrInfo> {
projectPath: project.path_with_namespace, projectPath: project.path_with_namespace,
webUrl: project.web_url, webUrl: project.web_url,
sshUrl: project.ssh_url_to_repo, sshUrl: project.ssh_url_to_repo,
httpUrl: project.http_url_to_repo,
iid: mr.iid, iid: mr.iid,
title: mr.title, title: mr.title,
description: mr.description ?? '', 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 // 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 // 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. // `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) { 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 { try {
const { stdout } = await git('rev-parse', 'HEAD'); const { stdout } = await git('rev-parse', 'HEAD');
if (stdout.trim() === mr.sha) { if (stdout.trim() === mr.sha) {
@@ -129,8 +142,9 @@ export async function checkout(mr: MrInfo, dir: string) {
} catch { } catch {
await run('mkdir', ['-p', dir]); await run('mkdir', ['-p', dir]);
await git('init', '-q'); 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('config', 'core.symlinks', 'false');
await git('fetch', '-q', '--depth=50', 'origin', `refs/merge-requests/${mr.iid}/head`); await git('fetch', '-q', '--depth=50', 'origin', `refs/merge-requests/${mr.iid}/head`);
try { try {