GitHub ActionsへのSSHをcomment-runでpiping-tunnelを使ってするためのコメント
code:md(js)
@github-actions run
<details>
<summary>🌐 SSH debug over Piping Server</summary>
`js
const crypto = require('crypto');
const pathLen = 64;
const aPath = randomString(pathLen);
const bPath = randomString(pathLen);
const commentUserId = context.payload.comment.user.login;
const clientHostPort = Math.floor(Math.random() * 55536) + 10000;
console.log(execSync(`
chmod 755 "$HOME"
ls -lA /home
authorized_keys_file="$(sshd -T 2>/dev/null | grep -E '^authorizedkeysfile ' | cut -d ' ' -f 2)"
authorized_keys_file="$(cd && realpath -m "$authorized_keys_file")"
sshd_config_dir="$(dirname "$authorized_keys_file")"
(umask 0077 && mkdir "$sshd_config_dir")
echo $authorized_keys_file;
# sudo apt install -y socat;
ls -l piping-tunnel-linux-amd64/
sudo mv piping-tunnel-linux-amd64/piping-tunnel /usr/local/bin/piping-tunnel
`).toString());
// Comment new session
const commentBody = `\
Run the command below.
\\`\bash
socat TCP-LISTEN:${clientHostPort} 'EXEC:curl -NsS https\\://ppng.io/${bPath}!!EXEC:curl -NsST - https\\://ppng.io/${aPath}'
\\`\
Run the command below in another terminal.
\\`\bash
ssh -p ${clientHostPort} runner@localhost
\\`\
`;
await githubClient.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
execSync(piping-tunnel server -p 22 ${aPath} ${bPath});
function randomString(len){
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const randomArr = new Uint32Array(new Uint8Array(crypto.randomBytes(len * 4)).buffer);
return ...randomArr.map(n => chars.charAt(n % chars.length)).join(''); }
`
Thanks Cryolite!
</details>