Repository navigation
fix: encode user IDs in labels without loss - #122
Conversation
Record the creator of a task in the label creator-user-hash (the first 128 bits of the SHA-256 of the sub, in hex) and the annotation creator-user-id (the sub itself), instead of the label creator-user-id with @ replaced by _. Any sub now fits, also one that is longer than 63 characters or has characters that labels don't allow, and IDs such as a@b and a_b are told apart. Kubernetes selects a user's tasks by the hash label; TESK API then checks the annotation (and its hash) of each job, and of each task it gets, so that only the exact ID counts. USER_ID in the task log shows the sub unchanged. Tasks created before have only the old label. They belong to no user by default (group managers and admins see them as before); the setting tesk.api.authorisation.legacy-user-labels matches them by the old label for a transition. The selector then names no creator, and the creator is checked after listing. Refs #119 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document the label creator-user-hash and the annotation creator-user-id (access control), the setting TESK_API_AUTHORISATION_LEGACY_USER_LABELS (access control, configuration), and what operators do about tasks with only the old label when they upgrade. Refs #119 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rename the old label's constant to LABEL_LEGACY_USERID_KEY and point out that the annotation shares its key. Remove isMemberInNonManagedGroups, which the list filter no longer uses. Move the internal flag of TesTaskLog to the end of the class, hide it from the API description and name it in the notes on regenerating the model. Split the tests of User#isCreator. Docs: listing with the transition setting affects users authorised by the claim too; deleting old tasks by label deletes running ones, too, and their ConfigMaps can be deleted the same way; a rolling update with several replicas briefly mixes both encodings. Refs #119 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideSchema and migrationsDefine the persisted creator-label and annotation keys, hash encoding, validation of creator metadata, and legacy-object detection that the rest of the authorization flow relies on.
Data structuresAdd a non-serialized marker to task logs so authorization can distinguish a legacy label value from a verified user ID.
APIChange task retrieval authorization to use the creator-aware check while preserving group-manager and administrator access.
Uses of the APIFilter Kubernetes task listings by group-manager rights or the verified creator, while adjusting selectors for legacy-label transition mode.
ImplementationUpdate the authenticated user model to retain the exact subject, recognize verified and optionally legacy creators, and build suitable Kubernetes label selectors.
Write the hash label and full-subject annotation to created Kubernetes objects, and reconstruct verified or legacy creator metadata in task logs.
ConfigurationExpose and default the opt-in legacy-label matching setting, then pass it from authorization properties into the authenticated user.
DocumentationExplain creator identity, legacy-task access and the transition setting in access-control and configuration documentation.
Document upgrade and rollback implications, cleanup of legacy tasks, and the manually maintained task-log model field.
TestsVerify creator hashing, exact and legacy authorization, Kubernetes listing filters, and conversion of creator metadata into and out of Kubernetes objects.
Exercise end-to-end behavior for exact IDs, long subjects, legacy tasks, authorization modes, and listings.
Other changesFiles not grouped.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #122 +/- ##
==========================================
+ Coverage 65.00% 65.62% +0.62%
==========================================
Files 66 67 +1
Lines 2626 2668 +42
Branches 272 280 +8
==========================================
+ Hits 1707 1751 +44
Misses 769 769
+ Partials 150 148 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Use Hashing.sha256 instead of MessageDigest, so that hash() has no unreachable branch for a missing SHA-256 implementation. The values are unchanged (the test vectors in CreatorLabelsTest still pass). Refs #119 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cover the branch of KubernetesClientWrapper#groupOf for jobs without labels: the filter leaves them out, also with only the creator annotation and with the legacy-label setting on. Refs #119 Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/CreatorLabels.java" line_range="50" />
<code_context>
+
+ /** Whether the object was created before the hash label: it has none */
+ public static boolean isLegacy(V1ObjectMeta metadata) {
+ return get(metadata.getLabels(), LABEL_USERHASH_KEY) == null;
+ }
+
</code_context>
<issue_to_address>
**Hybrid metadata grants legacy access**
When the transition setting is enabled and a hashless object has both an annotation and a colliding legacy creator label, `User.isCreatorOf` treats any object without a hash label as legacy, and `legacyCreator` ignores its annotation. With the transition setting enabled, a hashless object carrying an annotation for one `sub` and a colliding old label for another is authorized to the wrong user.
Treat an object as legacy only when it has no creator annotation as well as no hash label, and add a mixed-metadata test.
</issue_to_address>
### Comment 2
<location path="src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java" line_range="80" />
<code_context>
taskMasterJob.getMetadata().putAnnotationsItem(ANN_TESTASK_NAME_KEY, task.getName());
// creating user and owning group
- taskMasterJob.getMetadata().putLabelsItem(LABEL_USERID_KEY, user.getUsername());
+ CreatorLabels.put(taskMasterJob.getMetadata(), user.getUsername());
if (task.getTags() != null && task.getTags().containsKey("GROUP_NAME")) {
taskMasterJob
</code_context>
<issue_to_address>
**Creator tasks disappear or return 403s**
When a multi-replica deployment is rolling out and serves requests from both versions, `CreatorLabels.put` writes only the hash label and new replicas select by it, while old replicas look for the legacy label, so requests routed across versions cannot consistently list or authorize a creator's tasks and return missing tasks or 403s.
Preserve compatibility between the old and new creator labels during rolling updates so both versions can find and authorize the same tasks.
Also at `src/main/java/uk/ac/ebi/tsc/tesk/config/security/User.java:184`.
</issue_to_address>Linked issues
#119 Encode user IDs in labels without loss · 6 of 7 met · 1 to check by hand
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Use a fixed-length hash label and full-ID annotation on the taskmaster job, ConfigMap, and executor jobs so arbitrary sub values fit and distinct IDs are distinguishable. |
✅ Met | CreatorLabels.put writes the hash label and full-ID annotation, and the converter applies it to all three object types. |
| 2 | Select tasks by hash, then verify the annotation against the user's exact ID; apply creator checks to listed, fetched, and cancelled tasks. | ✅ Met | Listing filters each selected job with isCreatorOf, which validates the annotation against its hash; get authorization uses isCreator on the task log. Cancellation calls getTask first, so it goes through the same post-authorization check. |
| 3 | Show the full sub unchanged in logs[0].metadata.USER_ID. |
✅ Met | The converter takes the verified ID from the annotation for new tasks and puts it in USER_ID. |
| 4 | Provide an off-by-default transition setting that matches tasks with only the old label by its old encoding, and document the upgrade steps. | ✅ Met | The setting is wired through authorization properties; legacy matching applies only when the hash label is absent. The access-control, configuration, and upgrading docs describe the setting and operator steps. |
| 5 | Keep admin and group-manager behaviour unchanged. | ✅ Met | Admins have no label selector and are not post-list filtered; managers retain tasks in managed groups through the group-manager check. |
| 6 | Document the labels, the transition setting, and what operators need to do about old tasks. | ✅ Met | The change adds the Task creators section and configuration and upgrade guidance, including listing and deleting old tasks. |
| 7 | Check whether the taskmaster (tesk-core) reads these labels. | 👀 Check by hand (external system) | The upgrade docs state that tesk-core copies executor jobs' labels and annotations without reading these labels; verify that behavior in the external tesk-core implementation. |
Sourcery assessment
Needs a human reviewer. 2 findings to address first, and if the creator hash and annotation checks or the post-listing filter are wrong, a user could be allowed to see or act on another user’s tasks; any task data accessed before a revert cannot be taken back. The opt-in legacy matching also deliberately restores a lossy identity comparison, so an ID collision could grant access while it is enabled.
Blocking findings: src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/CreatorLabels.java:50, src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java:80
Treat an object as created before the hash label only if it has neither the hash label nor the creator annotation. An object with the annotation but without the hash label names no creator, also when the legacy-label setting is on, instead of falling back to the old label. Refs #119 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Say that a task with only the hash label or only the annotation names no creator, also with the legacy-label setting, and that the kubectl selector for old tasks also lists objects with the annotation. Name and describe the new tests more precisely. Refs #119 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
TESK API stored the creator of a task in the label
creator-user-idas thesubwith@replaced by_. That encoding loses information (a@banda_bget the same value) and doesn't fit everysub(label values allow at most 63 characters from[A-Za-z0-9._-]), so such users couldn't create tasks.creator-user-hash(the first 32 hex digits, 128 bits, of the SHA-256 of thesubin UTF-8) and the annotationcreator-user-id(thesubitself), on the taskmaster's job, its ConfigMap and the executors' jobs (CreatorLabels). The old label isn't written any more.suband the label is its hash (User#isCreatorOf, applied to every listed job for users with a label selector; admins andnoauth, which have none, are unchanged). Getting and cancelling a task checkUser#isCreatoron the task log, whoseUSER_IDnow holds the verifiedsub. Group managers and admins keep their rights.USER_IDinlogs[0].metadatashows thesubunchanged (e.g.[email protected]).tesk.api.authorisation.legacy-user-labels(TESK_API_AUTHORISATION_LEGACY_USER_LABELS, defaultfalse) matches them by the old encoding for a transition; it only applies to tasks without the hash label. With it, the label selector of members and claim users names no creator (tasks may have either label), and TESK API filters after listing; pages can be shorter. An internal, non-serialized flag onTesTaskLog(userIdFromLegacyLabel) tells the check which kind ofUSER_IDit has; clients can't set it.docs/access-control.md(new "Task creators" section, claim section updated),docs/configuration.md(the setting),docs/upgrading.md(what operators do about old tasks: transition setting, how to list and delete them, rollback note).Closes #119
Verification
Locally, in a Temurin 8 container (as CI):
./mvnw -B spotless:check checkstyle:check: passes../mvnw -B clean verify: 7393 unit tests and 83 integration tests pass, coverage checks met. New tests:CreatorLabelsTest,UserCreatorTest, list filtering inKubernetesClientWrapperTest(exact creator, old labels with and without the setting, managers), converter tests for the annotation and the old label,AuthIT(similar IDs, asublonger than 63 characters with|, old-label tasks),LegacyUserLabelsIT(the setting on), updated fixtures.mkdocs build --strict: passes.CreatorLabels#hashwith Guava'sHashing.sha256()instead ofMessageDigest, so that it has no unreachable branch, which codecov/patch had flagged) and a test for listed jobs without labels (d576a5f, the last partial branch that codecov/patch reported):./mvnw -B spotless:check checkstyle:check clean verifypasses again (7394 unit, 83 integration tests, coverage checks met; the hash test vectors are unchanged), and the changed lines have no uncovered line or branch in the JaCoCo reports.CreatorLabelsTest#isLegacy_falseWithTheAnnotation,UserCreatorTest#isCreatorOf_oldLabelNotWithTheAnnotation) and 84adae9 (docs and test names):./mvnw -B spotless:check checkstyle:check clean verifypasses (7396 unit, 83 integration tests, coverage checks met);mkdocs build --strictpasses.Review: round 1 (adversarial, quality): no high findings; medium (unused method, undocumented manual model change) and low findings fixed (constant renamed to
LABEL_LEGACY_USERID_KEY, docs on claim-user listing, deleting old tasks, rolling updates). Round 2: the quality reviewer found nothing; the adversarial review of round 2 isn't needed, as round 1 had no high or medium adversarial findings and the logic didn't change after it. The refactor 79072c3 was reviewed by both reviewers: no findings (same output for every input,Hashing.sha256()is stable API in Guava 33.8.0-jre). The test d576a5f adds only a test. 5d83a4d (from the Sourcery review) was reviewed by both reviewers: no high findings; the adversarial reviewer found nothing wrong in any caller, the quality reviewer's medium findings (docs didn't state the rule; the kubectl selector for old tasks can't see the annotation) and low ones (test names) were fixed in 84adae9, which changes only docs and tests, so no further round.Declined review findings
docs/upgrading.md(useRecreate, or accept it), and old tasks are covered by the transition setting.isLegacybranch, whichCreatorLabelsTestcovers, andcreatorIdis null there (covered too).🤖 Generated with Claude Code
Summary by Sourcery
Replace lossy creator labels with exact, hash-based task ownership metadata and add a controlled compatibility path for pre-existing tasks.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: