-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(config)!: replace kbpgp with gpg CLI
#37147
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
929abc8
feat(config): replace `kbpgp` with `gnupg`
viceice d0dab97
docs: update pgp docs
viceice dfc52eb
test: inline key
viceice d489c01
fix: quote file paths to allow spaces
viceice 7880abb
Merge remote-tracking branch 'origin/main' into feat/gnupg
viceice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 63 additions & 5 deletions
68
lib/config/decrypt/kbpgp.spec.ts → lib/config/decrypt/gnupg.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import os from 'node:os'; | ||
| import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is'; | ||
| import { mkdtemp, outputFile, rm } from 'fs-extra'; | ||
| import { quote } from 'shlex'; | ||
| import upath from 'upath'; | ||
| import { logger } from '../../logger'; | ||
| import { exec } from '../../util/exec'; | ||
|
|
||
| const keyImported = new Set<string>(); | ||
|
|
||
| export async function tryDecryptGnupg( | ||
| privateKey: string, | ||
| encryptedStr: string, | ||
| ): Promise<string | null> { | ||
| const tmpDir = await mkdtemp(upath.join(os.tmpdir(), 'renovate-gpg-')); | ||
|
|
||
| if (!keyImported.has(privateKey)) { | ||
| try { | ||
| const keyFilePath = upath.join(tmpDir, 'key.pem'); | ||
| await outputFile(keyFilePath, privateKey); | ||
| const { stdout, stderr } = await exec( | ||
| `gpg --batch --no-tty --yes --import ${quote(keyFilePath)}`, | ||
| ); | ||
| keyImported.add(privateKey); | ||
|
|
||
| logger.debug({ stdout, stderr }, 'Private key import result'); | ||
| } catch (err) { | ||
| logger.debug(`Private key import failed: ${err.message}`); | ||
| // cleanup temp dir | ||
| await rm(tmpDir, { recursive: true, force: true }); | ||
| return null; | ||
| } | ||
| } | ||
| try { | ||
| const startBlock = '-----BEGIN PGP MESSAGE-----\n\n'; | ||
| const endBlock = '\n-----END PGP MESSAGE-----\n'; | ||
| let armoredMessage = encryptedStr.trim(); | ||
| if (!armoredMessage.startsWith(startBlock)) { | ||
| armoredMessage = `${startBlock}${armoredMessage}`; | ||
| } | ||
| if (!armoredMessage.endsWith(endBlock)) { | ||
| armoredMessage = `${armoredMessage}${endBlock}`; | ||
| } | ||
| const encryptedFilePath = upath.join(tmpDir, 'msg.pem'); | ||
| await outputFile(encryptedFilePath, armoredMessage); | ||
|
|
||
| const { stdout, stderr } = await exec( | ||
| `gpg --batch --no-tty --yes --decrypt ${quote(encryptedFilePath)}`, | ||
| ); | ||
|
|
||
| logger.debug({ stderr }, 'Decrypted config using gnupg'); | ||
| return stdout; | ||
| } catch (err) { | ||
| if ( | ||
| 'exitCode' in err && | ||
| err.exitCode === 2 && | ||
| isNonEmptyStringAndNotWhitespace(err.stdout) | ||
| ) { | ||
| // gpg returns exit code 2 when it cannot fully decrypt the message, but stdout may contain what we need | ||
| logger.debug( | ||
| `Decryption failed, but stdout is available: ${err.message}`, | ||
| ); | ||
| return err.stdout; | ||
| } | ||
| logger.debug(`Decryption failed using gnupg: ${err.message}`); | ||
| return null; | ||
| /* v8 ignore next -- coverage bug */ | ||
| } finally { | ||
| // cleanup temp dir | ||
| await rm(tmpDir, { recursive: true, force: true }); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth then deprecating this library? Looks like it's only Renovate using it: https://deps.dev/npm/%40renovatebot%2Fkbpgp/4.0.3/dependents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, but i'm thinking of using https://github.com/renovatebot/pgp (dotnet wasm variant) instead of the cli 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've raised renovatebot/kbpgp#216 for the deprecation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a plan - is that something that needs much validation ahead of next week's major release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it's only used by self-hosted users and they can switch to openpgp if there is any isssue