Skip to content

Relax Develocity access key format validation - #1061

Merged
bigdaz merged 2 commits into
mainfrom
relax-access-key-format-validation
Sep 1, 2026
Merged

bigdaz merged 2 commits into
mainfrom
relax-access-key-format-validation

Conversation

@bigdaz

@bigdaz bigdaz commented Sep 1, 2026

Copy link
Copy Markdown
Member

Develocity access keys have the format server=key[;server=key]*. The short-lived-token code validated that format with:

/^([^;=\s]+=\w+)(;[^;=\s]+=\w+)*$/

This is too strict about key, and an OIDC token value fails it. There were two independent problems:

  1. \w+ rejects the ., -, _ and = padding a JWT contains.
  2. Even had the regex passed, parse split each entry with hostKey.split('=') and took pair[1], so a key containing = would have been silently truncated β€” a worse failure than rejection, since the mangled key would then be sent to the server.

Change

Drop accessKeyRegexp and the separate isValid gate; validate structurally in parse instead, asserting only what is needed to split the value:

  • split on ;, then split each entry on its first = only
  • hostname: non-empty and free of whitespace (it cannot contain = or ; by construction)
  • key: non-empty and free of whitespace β€” nothing else is assumed about its shape

Two small intentional behaviour deltas beyond the fix:

  • The whole value is now trimmed, so a trailing newline on a secret no longer rejects the key. Internal whitespace still rejects.
  • Empty entries (host=key;, ;host=key) still reject, as before.

Testing

Added cases to short-lived-token.test.ts: a JWT-shaped key value, first-separator-only splitting (host1=a=b== β†’ key a=b==), surrounding-whitespace tolerance, a raw() round-trip preserving == padding, and a table of nine rejection cases. 32 tests pass; prettier, eslint and ./build are clean.

πŸ€– Generated with Claude Code

bigdaz and others added 2 commits September 1, 2026 14:48
The access key format is `server=key[;server=key]*`. Validation asserted
`\w+` for the key, which rejects the `.`, `-`, `_` and `=` padding present
in an OIDC token value. Parsing then split each entry on every `=`, so a
key containing `=` would have been silently truncated rather than rejected.

Replace the regex with structural validation in `parse`: split on `;`, then
split each entry on its *first* `=` only. A hostname must be non-empty and
free of whitespace (it cannot contain `=` or `;` by construction), and a key
must be non-empty and free of whitespace. Nothing further is assumed about
the shape of the key. The whole value is now trimmed, so a trailing newline
on a secret no longer rejects the key.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Parsing previously returned `null` silently, so a mistyped access key
surfaced only as the generic "Failed to fetch short-lived token" warning,
with no indication that the value itself was the problem.

Report the position of the offending entry and the reason (missing
separator, empty server name or key, embedded whitespace) along with the
expected format. The access key is a secret and is not yet registered for
masking at parse time, so no part of the value is included in the message.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@bigdaz
bigdaz enabled auto-merge (squash) September 1, 2026 20:56
@bigdaz
bigdaz merged commit 02d4784 into main Sep 1, 2026
137 checks passed
@bigdaz
bigdaz deleted the relax-access-key-format-validation branch September 1, 2026 20:59
jprinet added a commit to gradle/develocity-actions that referenced this pull request Sep 2, 2026
Develocity access keys have the format `server=key[;server=key]*`. The
short-lived-token code validated that format with:

    /^([^;=\s]+=\w+)(;[^;=\s]+=\w+)*$/

This is too strict about `key`, and an OIDC token value fails it, making
Workload Identity unusable with these actions. There were two independent
problems:

1. `\w+` rejects the `.`, `-`, `_` and `=` padding a JWT contains.
2. Even had the regex passed, `parse` split each entry with
   `hostKey.split('=')` and took `pair[1]`, so a key containing `=` would
   have been silently truncated β€” a worse failure than rejection, since
   the mangled key would then be sent to the server.

Drop `accessKeyRegexp` and the separate `isValid` gate; validate
structurally in `parse` instead, asserting only what is needed to split
the value: split on `;`, then split each entry on its first `=` only,
requiring a non-empty, whitespace-free hostname and key.

The fix is applied verbatim from gradle/actions#1061 so this copy of
`short-lived-token.ts` stays in sync with upstream. It lives in
`build-scan-shared`, so it covers setup-maven, setup-npm and
maven-publish-build-scan.

Two intentional behaviour deltas beyond the fix:

- The whole value is now trimmed, so a trailing newline on a secret no
  longer rejects the key. Internal whitespace still rejects.
- Empty entries (`host=key;`, `;host=key`) still reject, as before.

Fixes gradle/dv#72981

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
cdsap added a commit to gradle/develocity-ci-injection that referenced this pull request Oct 26, 2026
## Changes

**OIDC pre-step.** In `gradle-build.yml` and `gradle-release.yml`, a
step before `setup-gradle` mints a GitHub OIDC token with audience
`https://ge.solutions-team.gradle.com` and passes it as
`develocity-access-key` in `host=token` form. `setup-gradle` exchanges
it for a short-lived Develocity token.

**setup-gradle `v4` β†’ `v6.4.0` (pinned SHA).** v4 predates
gradle/actions#1061, so it rejects JWT-shaped access keys. v6.4.0 is the
first release that accepts them, and is the same pin used in #567 and
#2101. Its default cache provider (`enhanced`) is free for public
repositories, so caching is left at the default.

**Permissions.**
- `gradle-build.yml` had no `permissions` block. It now declares
`contents: read` and `id-token: write`. The job only checks out and
builds.
- `gradle-release.yml` gains `id-token: write` next to its existing
`contents: write` / `pull-requests: write`. Its runs from `main` match
the `GitHub Actions - gradle release` rule (`*release*.yml`).

The tests use a mock Develocity server and don't depend on the access
key, so test behavior is unchanged.

PRs from forks get no OIDC token, just as they get no secrets today: the
pre-step warns and `setup-gradle` runs unauthenticated.

## Verification

- [x] `Gradle initScript test` on this branch ([run
39668728805](https://github.com/gradle/develocity-ci-injection/actions/runs/39668728805)):
short-lived token exchanged, Build Scan
[naj76njkorkmu](https://ge.solutions-team.gradle.com/s/naj76njkorkmu)
published, build successful
- Attempt 1 also authenticated and published
[omw6nb2nrgvyq](https://ge.solutions-team.gradle.com/s/omw6nb2nrgvyq),
but one TestKit test failed with a daemon `StreamCorruptedException`
(Gradle 8.13), unrelated to this change. Attempt 2 passed.
- [ ] `Gradle initScript release` was not run, since it publishes a
release. Its first run will be the next release from `main`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant