Skip to content

Tokens cleanup - #2015

Merged
netomi merged 18 commits into
eclipse-openvsx:trusted-publishingfrom
cstamas:tokens-cleanup
Jul 30, 2026
Merged

netomi merged 18 commits into
eclipse-openvsx:trusted-publishingfrom
cstamas:tokens-cleanup

Conversation

@cstamas

@cstamas cstamas commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Just some cleanup and added token TYPE (LLT for "long lived token" and OTT for "one time token") for now. Token type of published version exposed.

Changes:

  • Added new call to create "one time" token
  • PersonalAccessToken entity (and DB table) got new field type (enum; so far all token was LLT).
  • enforce expiration times, if set on use (this matters most OTT)
  • jooq code regenerated to pick up this and previous (index uniqueness) changes
  • OTT tokens does not have delete URL set, nor send emails, and on use are immediately deactivated
  • repository methods renamed personalAccessTokens... to make clear what it is about, methods grouped together
  • Extension JSON exposes publishedWith (token type; OTT or PAT) along with existing publishedBy.
  • NO WebUI required changes (but improvements may be done now; ExtVersion has exposed publishedWith).

@cstamas
cstamas requested review from gnugomez and netomi July 29, 2026 17:09
@cstamas
cstamas marked this pull request as ready for review July 30, 2026 08:53

@Schema(description = "The token type used to publish this version")
@NotNull
private String publishedWith;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: could this be considered sensitive? wouldn't it be better to expose a boolean for tokens that are coming from TP?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is they type of the token: LLT or OTT. But yes, if the goal is to show "coming from TP" then we can make it different, but right now it is publishedWith == "OTT".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@cstamas
cstamas requested review from gnugomez and netomi July 30, 2026 12:09
As it is either sent to use to UI (then it is LLT) or
sent to client/app for TP publisher (then is OTT).
* Component handling "Personal Access Tokens".
*/
@Component
public class PersonalAccessTokens {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would give it a service name, like PersonalAccessTokenService

In the code we often used

AdminService admins;

which I read as a abbrev for adminService.

That would be now the first occasion where we use that as a classname.

} finally {
tokens.deactivateAccessToken(user, token.getId());
}
return publish(content, tokens.createAccessToken(user, "One time use publish token", true).getValue());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we not deactivating them anymore after publishing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are auto-deactivating them on "first use"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, the current pattern that we use is that we call useAccessToken(...) at the start of the operation and then perform the operation. If we already deactivate the token at the start we need to make sure that nothing later on would check the status again.

There is also the verify endpoint to check if a token is valid, if you would use that e.g. with a trusted publishing token, it would be deactivated.

@netomi

netomi commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Actually I do not get why we split off everything into PersonalAccessTokens and keep AccessTokenService around. All it does it to delegate to PersonalAccessTokens, so what do we gain by that?

@cstamas

cstamas commented Jul 30, 2026 •

Copy link
Copy Markdown
Member Author

Yes, I asked this I think in my initial PR for tokens (the in memory one), I can easily undo this. I just wanted to align all the names as codebase was inconsistent with using buth "AccessToken" and "PersonalAccessToken".
Will then undo this.

@netomi
netomi merged commit 51f57d5 into eclipse-openvsx:trusted-publishing Jul 30, 2026
@cstamas
cstamas deleted the tokens-cleanup branch July 30, 2026 15:04
netomi pushed a commit that referenced this pull request Jul 31, 2026
* Tokens cleanup

Just some cleanup and added token TYPE (PAT and OTT) for now.

* Token handling and notif

* Set or not the delete URL

* Tidy up

* Remove unused method

* Expose token type

* Cleanup enum

* We do not consume here

* enforce OTT tokens expire; quickly

* Fix migration: set LLT and OTT based on description

* Add dedicated flag for TP instead

* No need to reveal type at all

As it is either sent to use to UI (then it is LLT) or
sent to client/app for TP publisher (then is OTT).

* Collapse all back to original place

* Reformat

* Make verify not "use"; unsure why would anyone verify OTT but let it be

* Set the access TS as before
netomi added a commit that referenced this pull request Aug 21, 2026
* feat: Trusted Publishing support (#1980)

* Trusted Publishing support

How the finished flow works

1. A namespace owner registers a trusted publisher via `POST /user/namespace/{ns}/trusted-publishing/create` (body: provider, owner, repo, workflow, optional extension/environment). The provider resolves names to stable IDs (GitHub repos API, GitLab projects API) and the claims are stored in a new trusted_publisher table (JSONB column, migration V1_70). List and delete endpoints exist alongside it, all owner-only.
2. CI exchanges its OIDC ID token via POST /api/-/trusted-publishing/token (CSRF-exempted like /api/-/publish). The manager picks the provider by `iss`, validates the JWT (signature, issuer, audience, forbidden headers), and matches claims against registrations.
3. On match, it mints a short-lived `PersonalAccessToken` (default 15 min, `ovsx.trusted-publishing.token-expiry`) owned by the registering user, so the existing publish pipeline — permissions, auditing, expiry — is reused unchanged.

Key decisions baked in

- Matching is anchored on stable numeric IDs (repository_id/repository_owner_id, project_id/namespace_id) to block resurrection attacks, plus the workflow path with the @<ref> suffix stripped (any branch/tag can publish), plus environment only if pinned.
- The OIDC decoder is built lazily — `JwtDecoders.fromIssuerLocation()` does network discovery, which previously ran in the constructor and would have made app startup depend on external issuers.
- The tests for both providers added, also got offline matches() tests covering ref-independence, ID mismatch, and pinned environments.

Note: namespace-scoped tokens (the minted token has the registering user's full publish rights).
This is server-side work only; no CLI or WebUI changes added.

* Regenerate jOOQ classes with TP

* Fix response: it is 403 not 400

* Add trustedPublishingUrl and sort out inputs

* Add TODO and remove it for now

* feat: adding trusted publishers widget

* feat: adds promo banner on user tokens page

* feat: conditionally render namespace trusted publishers

* feat: scope TP widget to the namespace trustedPublishingUrl

---------

Signed-off-by: Thomas Neidhart <[email protected]>
Co-authored-by: Jordi Gómez <[email protected]>
Co-authored-by: Thomas Neidhart <[email protected]>

* fix import due to react-router bump

* increment migration number after rebase

* feat: adding TP enabled flag (#2002)

* feat: adding TP enabled flag in version response

* feat(webui): using TP enabled check to show/hide entrypoints

* Fix: the build fails due flyway migration conflict (#2003)

Fix the flyway migration conflict.

* Do not use properties duplicated across (#2004)

* Do not use properties duplicated across

Instead, use the proper config bean as source of truth.

* reformat

* feat: add support for trusted publishing to cli (#2001)

* Multiple TP fixes (#2010)

* Enforce eclipse agreement and new TP provider endpoint

Enforces signed agreement on TP creation.
Also, introduces new endpoint to query supported TP providers
without NS.

* Expose status for TP

* Swap out version TP enabled for audience (if enabled)

Drop superfluous call.

* Drop unused

* Audience does not belong here (is exposed via version API)

* Fix TP duplication search

* Rename, document

* Mark it as nullable

* feat: adapting webui to new TP status endpoint (#2017)

* Tokens cleanup (#2015)

* Tokens cleanup

Just some cleanup and added token TYPE (PAT and OTT) for now.

* Token handling and notif

* Set or not the delete URL

* Tidy up

* Remove unused method

* Expose token type

* Cleanup enum

* We do not consume here

* enforce OTT tokens expire; quickly

* Fix migration: set LLT and OTT based on description

* Add dedicated flag for TP instead

* No need to reveal type at all

As it is either sent to use to UI (then it is LLT) or
sent to client/app for TP publisher (then is OTT).

* Collapse all back to original place

* Reformat

* Make verify not "use"; unsure why would anyone verify OTT but let it be

* Set the access TS as before

* Align DDL with expectation (#2019)

The extension name is not optional.

* Allow TP registration only for existing active extensions (#2020)

* Reconnect TP to Extension (#2021)

It was Namespace+extensionName, now reworked DDL to make
TP has a FK on extension instead.

* adapt frontend to backend changes (#2022)

* increment migration number after rebase

* fix test after rebase: findAccessTokens was renamed to findPersonalAccessTokens

* remove empty file after rebase

* Introduce TPT token type + token scoping (#2034)

Improving existing TP and generally access tokens. Now system supports three types of tokens, and tokens can be scoped (by Ns or Ext). TP uses dedicated TPT tokens and is always scoped to Ext).

Changes:
* added `AccessTokenAction` that callers has to set (accepted by `PersonalAccessToken useAccessToken(String tokenValue, AccessTokenAction accessTokenAction)` method).
* added `AccessTokenScope` that is able to "scope" (limit usability by action) the tokens, handled by `AccessTokenService`
* extended config for all three supported token types
* refactored `ExtensionService` to make sure extension file is processed only once, and also to be able to extract before actual install the NS+name (for token validation)
* DDL changes for `personal_access_token` table, added new FKs to extension, namespace and trusted publisher (latter can be deleted, in which case link is nullified).
* UI receives now only `LLT` tokens (rest are hidden)

* Reformat (#2035)

* feat: Configure active providers (#2045)

For now keep only "github" as active, but it is now matter
of configuration (providerIds as comma separated list).

* feat: PAT improvements (UUIDv7 for random + hashing) (#2048)

* feat: UUID use cleanup

Introduce faster `java-uuid-generator` library from Tatu.
For now just as "drop in replacement", but we should also
do cluster-wide-sync using Redis maybe?

* More fixes

* Tidy up

* Tidy up

* Javadoc

* Merge pull request #2 from cstamas/trusted-publishing-tokens-hash

Hash token values, also PAT table got version column that is 0 for existing tokens, and current version is 1.
"On the fly" upgrade added but also a job.

Changes:
* token config got hashAlg + salt
* token table got version smallint field (initialized to 0 on migration)
* new job upgrades token (replaces value with hash(value + salt) and sets version = 1)
* use token upgrade on the fly if (needed)
* tests reworked to use less mocks

* One more test fix

* Streamline update

* Apply fixes

As DDL on main drifted from TP

* Update pull request branches in workflow

Removed 'trusted-publishing' branch from pull request triggers.

Signed-off-by: Thomas Neidhart <[email protected]>

* Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Signed-off-by: Thomas Neidhart <[email protected]>

* fix: stop leaking a notched DOM attribute from the publisher role filter

Select injects notched:true into its custom `input` whenever displayEmpty
is set and variant defaults to 'outlined', regardless of what that input
is. The custom InputBase here doesn't consume that prop, so it fell through
to the DOM as an invalid boolean attribute. This Select never rendered the
outlined chrome anyway (the border comes from the wrapping Paper), so
variant='standard' is both the fix and the semantically correct setting.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix formatting

* suppress error log in test for expected error

* fix javadoc

---------

Signed-off-by: Thomas Neidhart <[email protected]>
Signed-off-by: Thomas Neidhart <[email protected]>
Co-authored-by: Tamas Cservenak <[email protected]>
Co-authored-by: Jordi Gómez <[email protected]>
Co-authored-by: Jordi Gómez Hidalgo <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
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.

3 participants