feat: detach tokens from extension versions - #2065
Conversation
As future plans may want us to delete tokens, instead accumulate them and flag as deactivated. Summary: - Added V1_72__ExtensionVersion_PublishedBy.sql migration: new published_by_id column (FK → user_data), backfilled from published_with_id, and changed the published_with_id FK to ON DELETE SET NULL. - Added publishedBy field to ExtensionVersion (mirroring the removedBy precedent), fixed a pre-existing bug where displayName was silently excluded from equals(). - Repointed every read path (isVerified in LocalRegistryService/RelevanceService, toExtensionJson, OrphanNamespaceMigration) from getPublishedWith().getUser() to getPublishedBy(). - Redesigned PublisherComplianceChecker to iterate by publisher instead of by token, so it stays correct once tokens are deleted. - Renamed/added/deleted JPA repository methods so no query joins through personal_access_token anymore. - Rewrote ~12 raw jOOQ joins across ExtensionVersionJooqRepository and AdminStatisticCalculationsRepository to join user_data directly via published_by_id. - Applied the migration through real Flyway (via a temporary git stash of the Java changes) and regenerated jOOQ code. - Updated all affected test fixtures and mocks. - Verified: 841 unit tests + 922 integration tests (Testcontainers Postgres) all pass, and a manual SQL check confirms deleting a personal_access_token row no longer errors and correctly nulls published_with_id while leaving published_by_id intact. Note: Known follow-up (out of scope): FixTargetPlatformsJobRequestHandler still republishes using the original token and would NPE if that token were ever deleted — this is a pre-existing gap in the publish pipeline's identity model, not introduced by this change.
autumnfound
left a comment
There was a problem hiding this comment.
LGTM! Covers data migration, new field, and looks to cover all cases where the PAT was used in joins. We also have the index I'd expect for the field to keep the lookups zippy!
gnugomez
left a comment
There was a problem hiding this comment.
overall LGTM!
that's such a cleanup ◡̈
| .collect(Collectors.groupingBy(PersonalAccessToken::getUser)); | ||
| publisherTokens.keySet().forEach(user -> { | ||
| var accessTokens = publisherTokens.get(user); | ||
| if (!accessTokens.isEmpty() && !isCompliant(user)) { |
There was a problem hiding this comment.
question: I think here we're now skipping an additional check that was made before where we would first check if the non compliant user had access tokens before performing the deactivation of its extensions.
Is that something we're doing on purpose?
Signed-off-by: Tamas Cservenak <tamas@cservenak.net>
…ension-version # Conflicts: # server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java
As user alone is not enough, and it is not tokens ONLY that user can authenticate, when publishing.
…ions Fixes four correctness bugs and two minor nits surfaced by review of the token-detachment changes: - publishedWithTt was never actually set on publish: AccessTokenAuthentication's token type was resolved but discarded by every caller between LocalRegistryService.publish and PublishExtensionVersionHandler. Thread it through so the trusted-publisher flag is recorded for versions actually published via a token. - published_with_tt was selected by several ExtensionVersionJooqRepository queries but never read back into ExtensionVersion#publishedWithTt. While fixing that, found three of those queries' outer "latest" subquery select lists didn't even project the column through, so reading it would have thrown at runtime once the mapping was added - fixed those too. - AdminService#forgetUser's canDeleteUser guard didn't account for extension_version.published_by_id, which is permanent and never cleared (not even once the version is soft-deleted). A user whose already-removed version still references them via published_by_id could pass the guard and then hit entityManager.remove(user), violating that FK (added with no ON DELETE clause). Guard on the already-computed allVersions list instead. - AccessTokenService#useAccessToken could return a non-null AccessTokenAuthentication wrapping a null userData() for a token with no associated user (the column has no NOT NULL constraint at the schema level), which every caller dereferences unguarded. Treat a token with no user as invalid at the source instead. - Removed a dead PersonalAccessToken fixture from ExtensionVersionJooqRepositoryTest that nothing read. - Removed a redundant setActive(false) immediately before entityManager.remove(token) for one-time tokens. Added/extended tests for all four correctness fixes, including ExtensionVersionJooqRepositoryTest coverage verified against real Postgres.
|
Reviewed this branch and pushed a follow-up commit (
All four correctness fixes have new/extended tests; full suite (664 tests across the affected packages) passes. |
|
While looking at how trusted publishing interacts with this PR's changes, found a related fragility worth flagging separately from the fixes already pushed here. The problem: That couples trusted publishing's continued function to that one person remaining a namespace member, in a way that fails silently and confusingly:
The token's own scope ( Suggested fix: for a TPT-authenticated request, skip the membership check in Related, smaller issue also worth noting: |
Detach tokens from extension version, and allow to delete tokens, instead to preserve them as today.
Summary:
So, now: