Skip to content

fix(git-node): check the tag signature and not the commit one #907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions lib/promote_release.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,28 @@ export default class ReleasePromotion extends Session {

async verifyTagSignature() {
const { cli, version } = this;
const [needle, haystack] = await Promise.all([forceRunAsync(
const verifyTagPattern = /gpg:[^\n]+\ngpg:\s+using RSA key ([^\n]+)\ngpg:\s+issuer "([^"]+)"\ngpg:\s+Good signature from "([^<]+) <\2>"/;
const [verifyTagOutput, haystack] = await Promise.all([forceRunAsync(
'git', ['--no-pager',
'log', '-1',
`refs/tags/v${version}`,
'--format=* **%an** <<%ae>>\n `%GF`'
], { captureStdout: true }), fs.readFile('README.md')]);
if (haystack.includes(needle)) {
return;
'verify-tag',
`v${version}`
], { ignoreFailure: false, captureStderr: true }), fs.readFile('README.md')]);
const match = verifyTagPattern.exec(verifyTagOutput);
if (match == null) {
cli.warn('git was not able to verify the tag:');
cli.info(verifyTagOutput);
} else {
const [, keyID, email, name] = match;
const needle = `* **${name}** <<${email}>>\n ${'`'}${keyID}${'`'}`;
if (haystack.includes(needle)) {
return;
}
cli.warn('Tag was signed with an undocumented identity/key pair!');
cli.info('Expected to find the following entry in the README:');
cli.info(needle);
cli.info('If you are using a subkey, it might be OK.');
}
cli.warn('Tag was signed with an undocumented identity/key pair!');
cli.info('Expected to find the following entry in the README:');
cli.info(needle);
cli.info('If you are using a subkey, it might be OK.');
cli.info(`Otherwise consider removing the tag (git tag -d v${version
cli.info(`If that doesn't sound right, consider removing the tag (git tag -d v${version
}), check your local config, and start the process over.`);
if (!await cli.prompt('Do you want to proceed anyway?', { defaultAnswer: false })) {
throw new Error('Aborted');
Expand Down Expand Up @@ -383,7 +391,6 @@ export default class ReleasePromotion extends Session {
{ cause: err }
);
}
await forceRunAsync('git', ['tag', '--verify', `v${version}`], { ignoreFailure: false });
this.cli.info('Using the existing tag');
}
}
Expand Down
17 changes: 14 additions & 3 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
ignoreFailure = true,
spawnArgs,
input,
captureStderr = false,

Check warning on line 15 in lib/run.js

View check run for this annotation

Codecov / codecov/patch

lib/run.js#L15

Added line #L15 was not covered by tests
captureStdout = false
} = {}) {
if (cmd instanceof URL) {
cmd = fileURLToPath(cmd);
}
let stdio = 'inherit';
if (captureStdout || input != null) {
stdio = [input == null ? 'inherit' : 'pipe', captureStdout ? 'pipe' : 'inherit', 'inherit'];
if (captureStderr || captureStdout || input != null) {
stdio = [
input == null ? 'inherit' : 'pipe',
captureStdout ? 'pipe' : 'inherit',
captureStderr ? 'pipe' : 'inherit'
];

Check warning on line 27 in lib/run.js

View check run for this annotation

Codecov / codecov/patch

lib/run.js#L22-L27

Added lines #L22 - L27 were not covered by tests
}
return new Promise((resolve, reject) => {
const opt = Object.assign({
Expand All @@ -30,6 +35,12 @@
debuglog('[Spawn]', `${cmd} ${(args || []).join(' ')}`, opt);
}
const child = spawn(cmd, args, opt);
let stderr;
if (!captureStdout && captureStderr) {
stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (chunk) => { stderr += chunk; });
}

Check warning on line 43 in lib/run.js

View check run for this annotation

Codecov / codecov/patch

lib/run.js#L38-L43

Added lines #L38 - L43 were not covered by tests
let stdout;
if (captureStdout) {
stdout = '';
Expand All @@ -51,7 +62,7 @@
stdout = stdout.split(/\r?\n/g);
if (stdout[stdout.length - 1] === '') stdout.pop();
}
return resolve(stdout);
return resolve(stdout ?? stderr);

Check warning on line 65 in lib/run.js

View check run for this annotation

Codecov / codecov/patch

lib/run.js#L65

Added line #L65 was not covered by tests
});
if (input != null) child.stdin.end(input);
});
Expand Down
Loading