Skip to content

Commit 8a24862

Browse files
authored
fix(ssh-compute): set correct ssh public key (#20)
1 parent caaca82 commit 8a24862

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

dist/main/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,20 +111,29 @@ export async function run(): Promise<void> {
111111
});
112112

113113
// Get public key from the private key
114+
const privateKeyObject = sshpk.parsePrivateKey(correctPrivateKeyData, 'ssh-private');
115+
114116
const pubKeyObject = createPublicKey({
115-
key: sshpk.parsePrivateKey(correctPrivateKeyData, 'ssh').toBuffer('pkcs8').toString(),
117+
key: privateKeyObject.toBuffer('pem').toString(),
116118
format: 'pem',
117119
});
118120

119-
const publicKey = pubKeyObject.export({
121+
const publicKeyPem = pubKeyObject.export({
120122
format: 'pem',
121123
type: 'spki',
122124
});
123125

124-
await fs.writeFile(`${sshKeysDir}/${SSH_PUBLIC_KEY_FILENAME}`, publicKey, {
125-
mode: 0o644,
126-
flag: 'wx',
127-
});
126+
const publicKeyPemObject = sshpk.parseKey(publicKeyPem);
127+
publicKeyPemObject.comment = privateKeyObject.comment;
128+
129+
await fs.writeFile(
130+
`${sshKeysDir}/${SSH_PUBLIC_KEY_FILENAME}`,
131+
publicKeyPemObject.toString('ssh'),
132+
{
133+
mode: 0o644,
134+
flag: 'wx',
135+
},
136+
);
128137

129138
if (container) {
130139
cmd.push('--container', container);

0 commit comments

Comments
 (0)