fix(automation,vault): drain direct rsync stdout, guard ssh2 ed25519 keygen, and match succeeded badge
This commit is contained in:
parent
41e79c3df3
commit
3791f83bf6
4 changed files with 48 additions and 20 deletions
|
|
@ -91,6 +91,37 @@ export function computeOpenSshFingerprint(publicKeyLine: string): string {
|
|||
return `SHA256:${hash}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an OpenSSH Ed25519 keypair, retrying around ssh2's BitString
|
||||
* leading-zero stripping bug when a generated public key starts with 0x00.
|
||||
*/
|
||||
export function generateValidEd25519KeyPair(opts: {
|
||||
comment: string;
|
||||
passphrase?: string;
|
||||
}): { privateKey: string; publicKey: string; fingerprint: string } {
|
||||
let lastErr: unknown;
|
||||
for (let attempt = 0; attempt < 16; attempt++) {
|
||||
const kp = opts.passphrase
|
||||
? ssh2.utils.generateKeyPairSync('ed25519', {
|
||||
comment: opts.comment,
|
||||
passphrase: opts.passphrase,
|
||||
cipher: 'aes256-ctr',
|
||||
rounds: 16,
|
||||
})
|
||||
: ssh2.utils.generateKeyPairSync('ed25519', {
|
||||
comment: opts.comment,
|
||||
});
|
||||
const publicKey = kp.public.trim();
|
||||
try {
|
||||
const fingerprint = computeOpenSshFingerprint(publicKey);
|
||||
return { privateKey: kp.private, publicKey, fingerprint };
|
||||
} catch (err) {
|
||||
lastErr = err;
|
||||
}
|
||||
}
|
||||
throw lastErr instanceof Error ? lastErr : new Error('Failed to generate valid Ed25519 keypair');
|
||||
}
|
||||
|
||||
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
||||
|
||||
export type VaultCredentialInput = DistributiveOmit<
|
||||
|
|
@ -483,25 +514,16 @@ export class VaultService {
|
|||
this.assertWriteUnlocked();
|
||||
this.autoInitializedEmpty = false;
|
||||
|
||||
const keyPair = options.passphrase
|
||||
? ssh2.utils.generateKeyPairSync('ed25519', {
|
||||
comment: options.comment ?? options.id,
|
||||
passphrase: options.passphrase,
|
||||
cipher: 'aes256-ctr',
|
||||
rounds: 16,
|
||||
})
|
||||
: ssh2.utils.generateKeyPairSync('ed25519', {
|
||||
comment: options.comment ?? options.id,
|
||||
});
|
||||
|
||||
const publicKey = keyPair.public.trim();
|
||||
const fingerprint = computeOpenSshFingerprint(publicKey);
|
||||
const { privateKey, publicKey, fingerprint } = generateValidEd25519KeyPair({
|
||||
comment: options.comment ?? options.id,
|
||||
passphrase: options.passphrase,
|
||||
});
|
||||
|
||||
return this.upsertCredential({
|
||||
id: options.id,
|
||||
name: options.name,
|
||||
type: 'ssh-key',
|
||||
privateKey: keyPair.private,
|
||||
privateKey,
|
||||
publicKey,
|
||||
passphrase: options.passphrase || undefined,
|
||||
fingerprint,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue