Swadhin Biswas feat(arch): phase 1-4 github parity (sync, daemons, ui, queues) · 4/1/2026
d0c5c9d
25 lines · 1.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { execSync } from 'child_process';
import { z } from 'zod';

export function authorizeSshCommand(keyId: string, originalCommand: string): boolean {
  // Validate basic git SSH patterns: git-upload-pack 'owner/repo.git'
  const commandMatch = originalCommand.match(/^(git-receive-pack|git-upload-pack|git-upload-archive)\s+'(.+)'$/);
  
  if (!commandMatch) {
    return false; // Reject interactive shell access or unknown commands
  }
  
  const [_, gitCommand, repository] = commandMatch;
  const isPush = gitCommand === 'git-receive-pack';
  
  // Here we would lookup the specific public key via Db or API to determine
  // if user tied to keyId has WRITE or READ access to `repository`.
  console.log(`Intercepted SSH command [${gitCommand}] for repo [${repository}] authenticated via key [${keyId}]`);

  // E.g.
  // const user = await db.query(Keys).where(eq(keyId)).first();
  // const hasAccess = await checkPermissions(user, repository, isPush ? 'WRITE' : 'READ');

  return true; // Simplified placeholder
}