GitHub ActionsへのSSHをcomment-runでpiping-tunnelを使ってするためのコメント
#SSH #GItHub_Actions #comment-run
socat + curlではなくて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;
# (from: https://qiita.com/zackey2/items/429c77e5780ba8bc1bf9#authorized_keys%E3%81%AB%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95)
(echo; curl https://github.com/${commentUserId}.keys; echo) >> ~/.ssh/authorized_keys
# sudo apt install -y socat;
curl -L https://github.com/nwtgck/go-piping-tunnel/releases/download/v0.3.0/piping-tunnel-linux-amd64.tar.gz | tar zxf -
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 = `\
## 🌐 New SSH session
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('');
}
`
## References
* <https://github.com/Cryolite/gha-sandbox/blob/789130f01504a372775be9a2fe4d8df6c4e0ce5c/.github/workflows/ssh.yaml>)
* <https://qiita.com/Cryolite/items/ed8fa237dd8eab54ef2f>
Thanks Cryolite!
</details>