fix: configure JD01 workspace git proxy
This commit is contained in:
@@ -623,24 +623,55 @@ async function distributeGithubIdentity(config: UniDeskConfig, target: DeploySsh
|
||||
`host=${shellQuote(identitySpec.host)}`,
|
||||
`egress_mode=${shellQuote(target.egress.mode)}`,
|
||||
`proxy_url=${target.egress.mode === "http-connect-proxy" ? shellQuote(target.egress.proxyUrl) : "''"}`,
|
||||
"git_ssh_proxy=/tmp/unidesk-git-ssh-http-connect.py",
|
||||
"ssh_dir=\"$HOME/.ssh\"",
|
||||
"git_ssh_proxy=\"$ssh_dir/unidesk-git-ssh-http-connect.py\"",
|
||||
"ssh_config=\"$ssh_dir/config\"",
|
||||
"if [ \"$egress_mode\" = \"http-connect-proxy\" ]; then",
|
||||
" curl -fsSL --max-time 20 -x \"$proxy_url\" \"https://$host\" -o /dev/null",
|
||||
"else",
|
||||
" curl -fsSL --max-time 20 \"https://$host\" -o /dev/null",
|
||||
"fi",
|
||||
"tmp_config=$(mktemp)",
|
||||
"touch \"$ssh_config\"",
|
||||
"chmod 600 \"$ssh_config\"",
|
||||
"awk '/^# BEGIN unidesk managed github-ssh-identity$/{skip=1; next} /^# END unidesk managed github-ssh-identity$/{skip=0; next} !skip{print}' \"$ssh_config\" > \"$tmp_config\"",
|
||||
"if [ \"$egress_mode\" = \"http-connect-proxy\" ]; then",
|
||||
" cat > \"$git_ssh_proxy\" <<'UNIDESK_GIT_SSH_PROXY'",
|
||||
proxyPython,
|
||||
"UNIDESK_GIT_SSH_PROXY",
|
||||
" chmod 700 \"$git_ssh_proxy\"",
|
||||
" export UNIDESK_GIT_SSH_HTTP_PROXY=\"$proxy_url\"",
|
||||
" export GIT_SSH_COMMAND=\"ssh -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -i $HOME/.ssh/id_ed25519 -o 'ProxyCommand=$git_ssh_proxy %h %p'\"",
|
||||
" auth_output=$(ssh -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -i $HOME/.ssh/id_ed25519 -o \"ProxyCommand=$git_ssh_proxy %h %p\" -T \"git@$host\" 2>&1 || true)",
|
||||
" {",
|
||||
" printf '%s\\n' '# BEGIN unidesk managed github-ssh-identity'",
|
||||
" printf 'Host %s\\n' \"$host\"",
|
||||
" printf ' HostName %s\\n' \"$host\"",
|
||||
" printf '%s\\n' ' User git'",
|
||||
" printf ' IdentityFile %s/.ssh/id_ed25519\\n' \"$HOME\"",
|
||||
" printf '%s\\n' ' IdentitiesOnly yes'",
|
||||
" printf '%s\\n' ' BatchMode yes'",
|
||||
" printf '%s\\n' ' StrictHostKeyChecking yes'",
|
||||
" printf ' UserKnownHostsFile %s/.ssh/known_hosts\\n' \"$HOME\"",
|
||||
" printf ' ProxyCommand env UNIDESK_GIT_SSH_HTTP_PROXY=%s %s %%h %%p\\n' \"$proxy_url\" \"$git_ssh_proxy\"",
|
||||
" printf '%s\\n' '# END unidesk managed github-ssh-identity'",
|
||||
" cat \"$tmp_config\"",
|
||||
" } > \"$ssh_config\"",
|
||||
"else",
|
||||
" export GIT_SSH_COMMAND=\"ssh -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -i $HOME/.ssh/id_ed25519\"",
|
||||
" auth_output=$(ssh -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$HOME/.ssh/known_hosts -i $HOME/.ssh/id_ed25519 -T \"git@$host\" 2>&1 || true)",
|
||||
" {",
|
||||
" printf '%s\\n' '# BEGIN unidesk managed github-ssh-identity'",
|
||||
" printf 'Host %s\\n' \"$host\"",
|
||||
" printf ' HostName %s\\n' \"$host\"",
|
||||
" printf '%s\\n' ' User git'",
|
||||
" printf ' IdentityFile %s/.ssh/id_ed25519\\n' \"$HOME\"",
|
||||
" printf '%s\\n' ' IdentitiesOnly yes'",
|
||||
" printf '%s\\n' ' BatchMode yes'",
|
||||
" printf '%s\\n' ' StrictHostKeyChecking yes'",
|
||||
" printf ' UserKnownHostsFile %s/.ssh/known_hosts\\n' \"$HOME\"",
|
||||
" printf '%s\\n' '# END unidesk managed github-ssh-identity'",
|
||||
" cat \"$tmp_config\"",
|
||||
" } > \"$ssh_config\"",
|
||||
"fi",
|
||||
"rm -f \"$tmp_config\"",
|
||||
"chmod 600 \"$ssh_config\"",
|
||||
"auth_output=$(ssh -F \"$ssh_config\" -T \"git@$host\" 2>&1 || true)",
|
||||
"printf '%s\\n' \"$auth_output\"",
|
||||
"printf '%s\\n' \"$auth_output\" | grep -q 'successfully authenticated'",
|
||||
].join("\n");
|
||||
|
||||
Reference in New Issue
Block a user