From b887b38f3dca97ecc79af7c55e66fbb8a7a3afe4 Mon Sep 17 00:00:00 2001 From: rebuildup Date: Sat, 21 Nov 2026 14:53:00 +0900 Subject: [PATCH] =?UTF-8?q?feat(devices):=20rex=20=E5=B0=82=E7=94=A8=20SSH?= =?UTF-8?q?=20alias=20=E3=82=92=20devices.conf=20=E3=81=AB=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=99=E3=82=8B=20(#207)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit device-* は ClearAllForwardings yes で hardening されているため、 rex CLI の ssh:// endpoint が使う -L streamlocal 転送が成立せず timeout していた。接続情報を複製せず同一 Infisical /devices 由来の rex- alias を生成し、HostKeyAlias で既存の host key 検証を共有する。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- script/devices.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/script/devices.ts b/script/devices.ts index ab00ce5..ea974e6 100644 --- a/script/devices.ts +++ b/script/devices.ts @@ -40,8 +40,12 @@ export function validateRegistry(values:unknown[]):Device[] { return nodes.sort((a,b)=>a.id.localeCompare(b.id)); } function quotePath(p:string){if(/[\r\n"%]/.test(p))throw Error('unsupported path');return '"'+p.replaceAll('\\','/')+'"';} -export function renderSSH(nodes:Device[],home:string):string { - return marker+nodes.map(n=>`Host device-${n.id} +// The rex-* aliases mirror device-* but permit forwarding: the rex CLI reaches a +// remote server over ssh -L streamlocal forwarding, which ClearAllForwardings +// would otherwise strip. Host key verification still resolves through the same +// HostKeyAlias entry, so no second trust decision is introduced. +function sshBlock(n:Device,home:string,alias:string,forwarding:boolean){ + return `Host ${alias} HostName ${n.host} Port ${n.port} User ${n.user} @@ -55,8 +59,7 @@ export function renderSSH(nodes:Device[],home:string):string { UpdateHostKeys no ForwardAgent no ForwardX11 no - ClearAllForwardings yes - ProxyCommand none +${forwarding?'':' ClearAllForwardings yes\n'} ProxyCommand none ProxyJump none PermitLocalCommand no ControlMaster no @@ -65,7 +68,10 @@ export function renderSSH(nodes:Device[],home:string):string { ConnectionAttempts 1 ServerAliveInterval 15 ServerAliveCountMax 3 -`).join('\n')+'\nHost *\n'; +`; +} +export function renderSSH(nodes:Device[],home:string):string { + return marker+nodes.flatMap(n=>[sshBlock(n,home,`device-${n.id}`,false),sshBlock(n,home,`rex-${n.id}`,true)]).join('\n')+'\nHost *\n'; } export class IdentityMismatch extends Error {} export function assertIdentity(n:Device,output:string){