From dc7bd6858b66c4153e7ad30ddfbae8b742a46cf4 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 17 Sep 2026 11:28:17 -0700 Subject: [PATCH 1/6] Pass publishing secrets to Gradle without reshaping them configure_publishing_secrets.py base64-decoded NEXUS_PASS64 and GPG_KEY64 and wrote the plaintext to $GITHUB_ENV. GitHub masks the value of a secret as it was given, so a decoded value is a string it has never seen, and the runner prints $GITHUB_ENV variables in the env: header of every later step. That put the Maven Central password and the armored signing subkey into public logs. Drop the script and hand each secret straight to Gradle under the name the publishing plugin reads, so nothing is ever decoded in a workflow step and every value stays masked. This needs the plaintext secrets NEXUS_PASS and GPG_KEY; the base64 variants stay for the other diffplug repos, which decode them inside Gradle. Publishing also goes back to --no-configuration-cache, to keep the signing key out of the configuration cache. Co-Authored-By: Claude Opus 5 (1M context) --- .../scripts/configure_publishing_secrets.py | 59 ------------------- .github/workflows/ci.yml | 13 ++-- .github/workflows/deploy.yml | 25 ++++---- 3 files changed, 19 insertions(+), 78 deletions(-) delete mode 100644 .github/scripts/configure_publishing_secrets.py diff --git a/.github/scripts/configure_publishing_secrets.py b/.github/scripts/configure_publishing_secrets.py deleted file mode 100644 index 9dd1ef9f98..0000000000 --- a/.github/scripts/configure_publishing_secrets.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python3 -import base64 -import os -import re -import uuid - - -def decode_secret(env_var_name: str) -> str: - raw = os.environ.get(env_var_name, "") - if not raw: - return "" - # MIME Base64: ignore non-base64 chars (newlines, carriage returns, spaces, etc.) - cleaned = re.sub(r"[^A-Za-z0-9+/=]", "", raw) - if not cleaned: - return "" - return base64.b64decode(cleaned).decode("utf-8").strip() - - -def main(): - github_env = os.environ.get("GITHUB_ENV") - if not github_env: - return - - env_updates = {} - - # 1. Maven Central Password - maven_central_password = decode_secret("NEXUS_PASS64") - if maven_central_password: - env_updates["ORG_GRADLE_PROJECT_mavenCentralPassword"] = maven_central_password - - # 2. GPG Signing Key - gpg_key = decode_secret("GPG_KEY64") - if gpg_key: - env_updates["ORG_GRADLE_PROJECT_signingInMemoryKey"] = gpg_key - env_updates["ORG_GRADLE_PROJECT_signingInMemoryKeyId"] = "0x4272C851" - - # 3. GPG Passphrase - gpg_passphrase = os.environ.get("GPG_PASSPHRASE", "") - if gpg_passphrase: - env_updates["ORG_GRADLE_PROJECT_signingInMemoryKeyPassword"] = gpg_passphrase - - with open(github_env, "a", encoding="utf-8") as f: - for key, value in env_updates.items(): - if "\n" in value or "\r" in value: - delimiter = f"EOF_{uuid.uuid4().hex}" - f.write(f"{key}<<{delimiter}\n{value}\n{delimiter}\n") - else: - f.write(f"{key}={value}\n") - - if "ORG_GRADLE_PROJECT_mavenCentralPassword" in env_updates: - print("Configured ORG_GRADLE_PROJECT_mavenCentralPassword=***") - if "ORG_GRADLE_PROJECT_signingInMemoryKey" in env_updates: - print("Configured ORG_GRADLE_PROJECT_signingInMemoryKey=***") - if "ORG_GRADLE_PROJECT_signingInMemoryKeyPassword" in env_updates: - print("Configured ORG_GRADLE_PROJECT_signingInMemoryKeyPassword=***") - - -if __name__ == "__main__": - main() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1aa253424..5524d7e861 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -200,12 +200,11 @@ jobs: - uses: gradle/actions/setup-gradle@v6 with: cache-read-only: true - - name: Configure publishing secrets - env: - NEXUS_PASS64: ${{ secrets.NEXUS_PASS64 }} - GPG_KEY64: ${{ secrets.GPG_KEY64 }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - run: python3 .github/scripts/configure_publishing_secrets.py - - run: ./gradlew publishToMavenCentral + # each secret is stored in the exact form the build consumes, so GitHub masks it in the logs + - run: ./gradlew publishToMavenCentral --no-configuration-cache env: ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.NEXUS_USER }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.NEXUS_PASS }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: "0x4272C851" + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0391573a0a..5943b794c1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,13 +1,16 @@ # NEXUS_USER -# NEXUS_PASS64 (base64 NOTE: `base64` and `openssl base64` failed, had to use Java -# byte[] data = "{{password}}".getBytes(StandardCharsets.UTF_8); -# String encoded = new String(Base64.getEncoder().encode(data), StandardCharsets.UTF_8); -# System.out.println(encoded); +# NEXUS_PASS # GPG_PASSPHRASE -# GPG_KEY64 (base64) -# gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy +# GPG_KEY +# gpg --export-secret-subkeys --armor SUBKEY_ID! | pbcopy +# subkeys only, so the primary key never lands in CI # GRADLE_KEY # GRADLE_SECRET +# +# Store each secret in the exact form the build consumes. GitHub masks the value it was given, +# so anything a workflow step decodes or reshapes is no longer masked and lands in the log. +# That is why the base64 variants (NEXUS_PASS64, GPG_KEY64) were deleted on 2026-09-17; do not +# reintroduce them. name: deploy on: @@ -33,16 +36,14 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.NEXUS_USER }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.NEXUS_PASS }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: "0x4272C851" + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} steps: - uses: actions/checkout@v7 with: persist-credentials: false - - name: Configure publishing secrets - env: - NEXUS_PASS64: ${{ secrets.NEXUS_PASS64 }} - GPG_KEY64: ${{ secrets.GPG_KEY64 }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - run: python3 .github/scripts/configure_publishing_secrets.py - name: Configure git credentials for JGit run: | git config --local http.https://github.com/.extraheader "AUTHORIZATION: basic $(echo -n x-access-token:${{ secrets.GITHUB_TOKEN }} | base64 -w0)" From bb0003dc2ffca0c51dea90351d42b2335bc400c1 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 17 Sep 2026 12:19:53 -0700 Subject: [PATCH 2/6] Harden CI permissions, environment, and CODEOWNERS The publishing secrets are now reachable only from the maven-central environment, whose deployment branch policy allows main and release only, so a push to any other branch can no longer read them. GITHUB_TOKEN drops to contents:read by default; the five test jobs opt back into checks:write for the JUnit reporter, and changelog-print and scheduled-cleanup declare read. Flip the repo's default workflow permissions to read-only once this merges. renovate-changelog.yml took github.head_ref and github.base_ref straight into shell commands. A branch name is attacker-controlled text, so it moves to env vars. The publish job was not exploitable (checkout of a fork branch fails first), but the pattern shouldn't stay. CODEOWNERS covers the paths that can move secrets or change what ships. It only bites once branch protection requires approvals and code owner review. Co-Authored-By: Claude Opus 5 (1M context) --- .github/CODEOWNERS | 8 ++++++++ .github/workflows/changelog-print.yml | 3 +++ .github/workflows/ci.yml | 23 +++++++++++++++++++++++ .github/workflows/deploy.yml | 1 + .github/workflows/renovate-changelog.yml | 19 ++++++++++++++----- .github/workflows/scheduled-cleanup.yml | 3 +++ 6 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000000..9e49a3c84c --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,8 @@ +# Changes to these paths can move secrets, publish artifacts, or change what ships to users, +# so they need an owner's review. Takes effect once branch protection on main requires +# approvals and "require review from Code Owners". +/.github/ @nedtwigg +/build-logic/ @nedtwigg +/settings.gradle.kts @nedtwigg +/build.gradle.kts @nedtwigg +/gradle.properties @nedtwigg diff --git a/.github/workflows/changelog-print.yml b/.github/workflows/changelog-print.yml index dc0223f036..e55cc0037c 100644 --- a/.github/workflows/changelog-print.yml +++ b/.github/workflows/changelog-print.yml @@ -4,6 +4,9 @@ on: push: branches: [main] +permissions: + contents: read + jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5524d7e861..83a2659641 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,10 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +# least privilege by default; jobs opt in to more below +permissions: + contents: read + jobs: sanity-check: name: Sanity Check @@ -35,6 +39,9 @@ jobs: build-gradle: name: Gradle (Java ${{ matrix.jre }}, ${{ matrix.os }}) needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs strategy: fail-fast: false matrix: @@ -63,6 +70,9 @@ jobs: build-maven: name: Maven (Java ${{ matrix.jre }}, ${{ matrix.os }}) needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs strategy: fail-fast: false matrix: @@ -91,6 +101,9 @@ jobs: test-npm: name: NPM needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -111,6 +124,9 @@ jobs: test-shfmt: name: Shfmt needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -138,6 +154,9 @@ jobs: test-idea: name: IntelliJ IDEA needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -188,6 +207,10 @@ jobs: name: Publish Snapshots needs: final-status if: github.event.repository.fork == false && github.ref == 'refs/heads/main' + # only this environment holds the publishing secrets, and only main/release may use it + environment: maven-central + permissions: + contents: read runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5943b794c1..7107d33bbf 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -31,6 +31,7 @@ jobs: build: runs-on: ubuntu-latest name: deploy + environment: maven-central permissions: contents: write env: diff --git a/.github/workflows/renovate-changelog.yml b/.github/workflows/renovate-changelog.yml index 7d5905148a..be4f44f42f 100644 --- a/.github/workflows/renovate-changelog.yml +++ b/.github/workflows/renovate-changelog.yml @@ -20,20 +20,29 @@ jobs: ref: ${{ github.head_ref }} fetch-depth: 0 - uses: actions/setup-python@v7 + # branch and PR fields arrive through env, never spliced into the shell: a branch name is + # attacker-controlled text, and ${{ }} would run it as part of the command - name: Update Changelogs + env: + BASE_REF: ${{ github.base_ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_URL: ${{ github.event.pull_request.html_url }} run: | python3 .github/scripts/update_renovate_changelogs.py \ - --base-ref "origin/${{ github.base_ref }}" \ - --pr-number "${{ github.event.pull_request.number }}" \ - --pr-url "${{ github.event.pull_request.html_url }}" + --base-ref "origin/$BASE_REF" \ + --pr-number "$PR_NUMBER" \ + --pr-url "$PR_URL" - name: Commit and push changes + env: + HEAD_REF: ${{ github.head_ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} run: | if [ -n "$(git status --porcelain CHANGES.md plugin-gradle/CHANGES.md plugin-maven/CHANGES.md)" ]; then git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add CHANGES.md plugin-gradle/CHANGES.md plugin-maven/CHANGES.md - git commit -m "Update changelogs for default formatter version bump (#${{ github.event.pull_request.number }})" - git push origin HEAD:${{ github.head_ref }} + git commit -m "Update changelogs for default formatter version bump (#$PR_NUMBER)" + git push origin "HEAD:$HEAD_REF" else echo "No changelog updates needed." fi diff --git a/.github/workflows/scheduled-cleanup.yml b/.github/workflows/scheduled-cleanup.yml index e0c5a031ef..8d4089309b 100644 --- a/.github/workflows/scheduled-cleanup.yml +++ b/.github/workflows/scheduled-cleanup.yml @@ -6,6 +6,9 @@ on: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + jobs: sanity: name: Sanity 🦢 From 64ce1eaad30275d1500cbe7d60181d04611710a8 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 17 Sep 2026 12:41:18 -0700 Subject: [PATCH 3/6] Publish only from the release branch Snapshot publishing on main is gone: the job is removed from ci.yml, so no workflow outside a release can touch publishing credentials. The maven-central environment's branch policy now allows only `release`, which only nedtwigg can push to, so the secrets are unreachable from main, from any topic branch, and from any fork. CONTRIBUTING.md no longer advertises snapshots; publishToMavenLocal is the way to test an unreleased change. Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/ci.yml | 29 ----------------------------- .github/workflows/deploy.yml | 4 ++++ CONTRIBUTING.md | 19 +++---------------- 3 files changed, 7 insertions(+), 45 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 83a2659641..f34b197ce0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -202,32 +202,3 @@ jobs: exit 1 fi echo "All required jobs completed successfully." - - publish-snapshots: - name: Publish Snapshots - needs: final-status - if: github.event.repository.fork == false && github.ref == 'refs/heads/main' - # only this environment holds the publishing secrets, and only main/release may use it - environment: maven-central - permissions: - contents: read - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - uses: actions/setup-java@v6 - with: - distribution: "temurin" - java-version: 21 - - uses: gradle/actions/setup-gradle@v6 - with: - cache-read-only: true - # each secret is stored in the exact form the build consumes, so GitHub masks it in the logs - - run: ./gradlew publishToMavenCentral --no-configuration-cache - env: - ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.NEXUS_USER }} - ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.NEXUS_PASS }} - ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }} - ORG_GRADLE_PROJECT_signingInMemoryKeyId: "0x4272C851" - ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7107d33bbf..d7d2dfa8da 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,6 +7,8 @@ # GRADLE_KEY # GRADLE_SECRET # +# NEXUS_PASS and GPG_KEY are environment secrets on `maven-central`, not org secrets. +# # Store each secret in the exact form the build consumes. GitHub masks the value it was given, # so anything a workflow step decodes or reshapes is no longer masked and lands in the log. # That is why the base64 variants (NEXUS_PASS64, GPG_KEY64) were deleted on 2026-09-17; do not @@ -31,6 +33,8 @@ jobs: build: runs-on: ubuntu-latest name: deploy + # holds the publishing secrets; its branch policy allows only `release`, which only + # nedtwigg can push to, so nothing else in the repo can reach them environment: maven-central permissions: contents: write diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af502cc437..3f2ebda035 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -211,25 +211,12 @@ pluginManagement { ### Gradle - snapshot builds -Snapshot builds are automatically published to Maven Central Snapshots on every commit to `main`. In any project, you can use the following snippet in your `settings.gradle` (for Gradle 6.0+). - -```gradle -pluginManagement { - repositories { - maven { - url 'https://central.sonatype.com/repository/maven-snapshots/' - content { - includeGroup 'com.diffplug.spotless' - } - } - gradlePluginPortal() - } -} -``` +We don't publish snapshots. Publishing credentials are reachable only from the `release` branch, so +`main` cannot publish anything. Use the local workflow above to test an unreleased change. ### Maven -Run `./gradlew publishToMavenLocal` to publish this to your local repository. You can also use snapshot artifacts from `https://central.sonatype.com/repository/maven-snapshots/`. +Run `./gradlew publishToMavenLocal` to publish this to your local repository. ## License From b22168f475b449195d7191f80b70b00391f1bf12 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 17 Sep 2026 15:26:39 -0700 Subject: [PATCH 4/6] Sign with the new subkey 0xFA5C18CFB74EC7C6 Replaces 0x4272C851, whose encrypted copy was exposed in public CI logs. The old subkey is not revoked, so existing signatures stay valid. Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/deploy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d7d2dfa8da..0cb64bc702 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -43,7 +43,8 @@ jobs: ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.NEXUS_USER }} ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.NEXUS_PASS }} ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }} - ORG_GRADLE_PROJECT_signingInMemoryKeyId: "0x4272C851" + # signing subkey issued 2026-09-17, replacing 0x4272C851 whose encrypted copy was exposed + ORG_GRADLE_PROJECT_signingInMemoryKeyId: "0xFA5C18CFB74EC7C6" ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} steps: - uses: actions/checkout@v7 From 2e77d4d70f0e683132c9147f04fc7e74553e8dae Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 17 Sep 2026 15:52:09 -0700 Subject: [PATCH 5/6] Add a second code owner A single code owner cannot approve their own pull request, which would block every change to these paths. Co-Authored-By: Claude Opus 5 (1M context) --- .github/CODEOWNERS | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9e49a3c84c..00483c1e0b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,8 +1,8 @@ # Changes to these paths can move secrets, publish artifacts, or change what ships to users, # so they need an owner's review. Takes effect once branch protection on main requires # approvals and "require review from Code Owners". -/.github/ @nedtwigg -/build-logic/ @nedtwigg -/settings.gradle.kts @nedtwigg -/build.gradle.kts @nedtwigg -/gradle.properties @nedtwigg +/.github/ @nedtwigg @edgartwigg +/build-logic/ @nedtwigg @edgartwigg +/settings.gradle.kts @nedtwigg @edgartwigg +/build.gradle.kts @nedtwigg @edgartwigg +/gradle.properties @nedtwigg @edgartwigg From 06632dd4a18c770b3ace14d8560c1fd71fe943bb Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Thu, 17 Sep 2026 16:07:23 -0700 Subject: [PATCH 6/6] Link the key change to the incident Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0cb64bc702..943910749a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -44,6 +44,7 @@ jobs: ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.NEXUS_PASS }} ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }} # signing subkey issued 2026-09-17, replacing 0x4272C851 whose encrypted copy was exposed + # in public CI logs: https://github.com/diffplug/spotless/issues/3089 ORG_GRADLE_PROJECT_signingInMemoryKeyId: "0xFA5C18CFB74EC7C6" ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} steps: