Skip to content

Commit 463c5bb

Browse files
authored
Merge pull request #11 from Alipsa/copilot/sub-pr-8-another-one
Improve GPG signing documentation security and modernize approach
2 parents b08b7fa + a0c3395 commit 463c5bb

1 file changed

Lines changed: 48 additions & 9 deletions

File tree

docs/PUBLISHING.md

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,50 @@ gpg --list-keys --keyid-format SHORT
3232
# Upload your public key to a key server
3333
gpg --keyserver keyserver.ubuntu.com --send-keys ABCD1234
3434

35-
# Export your secret key ring (for Gradle signing)
36-
gpg --export-secret-keys ABCD1234 > ~/.gnupg/secring.gpg
35+
# Export your secret key ring (legacy approach for GPG < 2.1)
36+
# WARNING: This creates a plaintext secret key file!
37+
gpg --export-secret-keys -o ~/.gnupg/secring.gpg ABCD1234
38+
chmod 600 ~/.gnupg/secring.gpg # Set strict permissions
3739
```
3840

41+
**Note:** The above method uses the legacy keyring format. Modern GPG (2.1+) doesn't use `secring.gpg` by default. See the recommended approach below.
42+
3943
### 3. Configure Credentials
4044

41-
Add credentials to your `~/.gradle/gradle.properties` (NOT the project's `gradle.properties`):
45+
#### Recommended: Modern In-Memory Signing (GPG 2.1+)
46+
47+
For modern GPG versions, use the in-memory signing approach with the `signingKey` property:
48+
49+
```bash
50+
# Export your private key in ASCII-armored format
51+
gpg --armor --export-secret-keys ABCD1234
52+
```
53+
54+
Add to your `~/.gradle/gradle.properties` (NOT the project's `gradle.properties`):
4255

4356
```properties
4457
# Sonatype OSSRH credentials
4558
sonatypeUsername=your-sonatype-username
4659
sonatypePassword=your-sonatype-password
4760

48-
# GPG signing configuration
61+
# GPG signing configuration (modern approach)
62+
signing.keyId=ABCD1234
63+
signing.password=your-gpg-passphrase
64+
signing.key=-----BEGIN PGP PRIVATE KEY BLOCK-----\n...(paste output from gpg --armor --export-secret-keys)...\n-----END PGP PRIVATE KEY BLOCK-----
65+
```
66+
67+
**Note:** The `signing.key` value should be the entire ASCII-armored private key block from the `gpg --armor --export-secret-keys ABCD1234` command output. When storing as a single-line property, replace actual newlines with the literal string `\n`.
68+
69+
#### Alternative: Legacy Keyring File (GPG < 2.1)
70+
71+
If you're using an older GPG version or prefer the legacy approach:
72+
73+
```properties
74+
# Sonatype OSSRH credentials
75+
sonatypeUsername=your-sonatype-username
76+
sonatypePassword=your-sonatype-password
77+
78+
# GPG signing configuration (legacy approach)
4979
signing.keyId=ABCD1234
5080
signing.password=your-gpg-passphrase
5181
signing.secretKeyRingFile=/path/to/.gnupg/secring.gpg
@@ -54,17 +84,26 @@ signing.secretKeyRingFile=/path/to/.gnupg/secring.gpg
5484
**Important Security Notes:**
5585
- Never commit credentials to version control
5686
- Use environment variables in CI/CD instead of files
87+
- The modern in-memory approach (`signing.key`) is preferred as it doesn't require a plaintext key file on disk
88+
- If using `secretKeyRingFile`, ensure the file has strict permissions (0600)
5789
- Consider using GPG agent for passphrase management
5890

59-
### Alternative: Environment Variables
91+
### 4. Environment Variables for CI/CD
6092

61-
For CI/CD environments, use environment variables:
93+
For CI/CD environments, use environment variables. The modern in-memory approach is recommended:
6294

6395
```bash
96+
# Recommended: Modern in-memory signing
6497
export ORG_GRADLE_PROJECT_sonatypeUsername=your-username
6598
export ORG_GRADLE_PROJECT_sonatypePassword=your-password
6699
export ORG_GRADLE_PROJECT_signingKeyId=ABCD1234
67100
export ORG_GRADLE_PROJECT_signingPassword=your-passphrase
101+
# In CI/CD, reference the key from a secret (preferred)
102+
export ORG_GRADLE_PROJECT_signingKey="$GPG_PRIVATE_KEY_SECRET"
103+
# Or export directly from GPG (for local testing)
104+
# export ORG_GRADLE_PROJECT_signingKey="$(gpg --armor --export-secret-keys ABCD1234)"
105+
106+
# Alternative: Legacy keyring file
68107
export ORG_GRADLE_PROJECT_signingSecretKeyRingFile=/path/to/secring.gpg
69108
```
70109

@@ -175,11 +214,11 @@ For automated releases, add secrets to your GitHub repository:
175214
2. Add these repository secrets:
176215
- `SONATYPE_USERNAME`
177216
- `SONATYPE_PASSWORD`
178-
- `GPG_KEY_ID` (the key ID, e.g., ABCD1234)
179-
- `GPG_SIGNING_KEY` (base64-encoded secret key)
217+
- `GPG_KEY_ID` (the 8-character short key ID, e.g., ABCD1234)
218+
- `GPG_SIGNING_KEY` (ASCII-armored private key from `gpg --armor --export-secret-keys`)
180219
- `GPG_SIGNING_PASSWORD`
181220

182-
Example workflow step:
221+
Example workflow step using modern in-memory signing:
183222
```yaml
184223
- name: Publish to Maven Central
185224
env:

0 commit comments

Comments
 (0)