Repository navigation
fix: encode team names in Kubernetes labels - #217
Conversation
Team names can be any text without a colon (e.g. the percent-encoded BioHackCloud%20Admins of LS Login), but were written as they are into the label creator-group-name and the list selector, so Kubernetes refused tasks (422, a 500 for the client) and listing broke. The label is now the name if it is a valid label value (as before, so existing tasks keep their teams), otherwise sha256- and a hash of it; the annotation creator-group-name holds the full name. The team of a task is the annotation if the label matches it, otherwise the label. The list selector uses the same label values. Closes #216 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Move the javadoc of putCreator back, define the annotation key as the label key, drop the empty value from the label pattern, test the 63-character boundary and a team named like a hash label, and show operators how to select hashed teams with kubectl. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Reviewer's GuideImplementationAdd the shared group-label encoding and recovery logic, then use it when writing task metadata, reading task groups, and filtering jobs by group.
Build user group selectors from the same safe label values used when tasks are labelled.
Define the group annotation key alongside the label key and document their roles.
Update test fixtures to write group metadata through the new helper and expose the taskmaster fixture for reuse.
DocumentationExplain how group names are stored and recovered, and how to select tasks with hashed group labels after upgrading.
TestsVerify group-label validity, hashing, annotations, legacy-label fallback, and distinction between a group name and a hash-like label.
Cover safe selectors for invalid group names and task metadata conversion for both user-derived and tag-provided groups.
Exercise end-to-end task creation, retrieval, and listing for group names and creator IDs that are not valid label values.
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 #217 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 54 55 +1
Lines 2506 2515 +9
Branches 291 287 -4
=========================================
+ Hits 2506 2515 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit f34aa8a #216 fix: encode team names in Kubernetes labels · 6 of 6 met
|
There was a problem hiding this comment.
Hey - I've found 3 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/config/security/User.java" line_range="182" />
<code_context>
if (isMember() || isManager()) {
+ // the groups' label values, which are valid in a selector whatever the names are
+ Set<String> allTeskGroups = new LinkedHashSet<>();
+ this.teskMemberedGroups.forEach(group -> allTeskGroups.add(GroupLabels.value(group)));
+ this.teskManagedGroups.forEach(group -> allTeskGroups.add(GroupLabels.value(group)));
StringBuilder sb = new StringBuilder();
</code_context>
<issue_to_address>
**Members see another team’s tasks**
When a team is named exactly `sha256-` plus the first 32 hex digits of another team’s name hash, and a member of that team lists tasks, the selector for a member of a team whose name is `sha256-` plus another team’s truncated hash selects both teams’ tasks. `listAllTaskmasterJobsForUser` filters managers and creators, but not members, so the member receives tasks from the unrelated team in list responses.
After label selection, also filter member-visible jobs by the full team name from `GroupLabels.groupName`.
</issue_to_address>
### Comment 2
<location path="src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/GroupLabels.java" line_range="44" />
<code_context>
+ if (groupName.length() <= MAX_LENGTH && LABEL_VALUE.matcher(groupName).matches()) {
+ return groupName;
+ }
+ return HASH_PREFIX + CreatorLabels.hash(groupName);
+ }
+
</code_context>
<issue_to_address>
**New tasks fail on old replicas**
When a rolling deployment routes requests for newly created hashed-team tasks to an old API replica, the old replica ignores the full name in the annotation and cannot interpret the hashed label as the team name, so its selectors omit the tasks and its authorization checks deny members and managers access.
Keep old replicas from receiving requests for tasks with the new hashed representation until they can interpret it.
Also at `src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/GroupLabels.java:52-53`, `src/main/java/uk/ac/ebi/tsc/tesk/config/security/User.java:182-183`.
</issue_to_address>
### Comment 3
<location path="src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/GroupLabels.java" line_range="53" />
<code_context>
+ return;
+ }
+ metadata.putLabelsItem(LABEL_GROUPNAME_KEY, value(groupName));
+ metadata.putAnnotationsItem(ANN_GROUPNAME_KEY, groupName);
+ }
+
</code_context>
<issue_to_address>
**Extremely long teams still fail creation**
When a team name is large enough that its annotation, together with the object’s other annotations, exceeds Kubernetes’ annotation-size limit, `GroupLabels.put` stores the full team name without a size check, so a name that pushes the object’s annotations over Kubernetes’ 256 KiB limit causes taskmaster Job creation to be rejected despite its valid hashed label.
Reject oversized names before making Kubernetes calls with a clear client error, or store the full name somewhere that does not count against the annotation limit.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and the new label-to-annotation mapping is used both to select tasks and to decide whether a user may see them; if it associates a task with the wrong team, users could gain access to task details. Reverting restores the old filtering behavior, but any access or disclosure that already occurred cannot be undone.
Blocking findings: src/main/java/uk/ac/ebi/tsc/tesk/config/security/User.java:182, src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/GroupLabels.java:44, src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/GroupLabels.java:53
Set date-released to 2026-11-24, the planned tag day, and add the changes merged since the first prep commit to the curated notes: owner-only task visibility (#218, #219), team names in labels (#216, #217) and audiences per service client (#215, #220; #220 is expected to merge before the tag); the merge of dev put them into the upgrade intro. The notes link the upgrade notes of the v2.1.0 tag, which never move, instead of the latest docs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5
Summary
Team names can be any text without
:(e.g.BioHackCloud%20Admins, a direct subgroup of the environment group as LS Login gives it, with the space percent-encoded), but TESK API wrote them as they are into the labelcreator-group-nameof the taskmaster's job and ConfigMap and into the list selector. Kubernetes refused such tasks (422, a500for the client), and listing broke for the same users.Same approach as for the creator (#119):
GroupLabels: the labelcreator-group-nameis the team name if it is a valid label value (unchanged, so existing tasks keep their teams), otherwisesha256-plus the first 32 hex digits of its SHA-256; the annotationcreator-group-nameholds the full name;logs[0].metadata.GROUP_NAME, used to authorise getting and cancelling tasks, and the list filter for team admins) is the annotation if the label matches it, otherwise the label (tasks created before, label only);User.getLabelSelectorselects by the same label values, so no team name can change the selector.No groups are filtered out: which groups count as teams is unchanged (direct subgroups of the environment group). Team names with commas still can't work, as the groups claim is split at commas (unchanged, out of scope).
Docs:
docs/access-control.md(Task creators) anddocs/upgrading.md(To 2.1.0; after a downgrade, tasks of teams with hashed labels are visible to super admins only).Closes #216
Verification
Run in an
eclipse-temurin:21-jdkcontainer (the host has no JDK 21 compiler), Maven caches in the clone:./mvnw -B spotless:check checkstyle:check: 0 violations./mvnw -B clean verify: 18715 unit tests and 144 integration tests pass, JaCoCo coverage checks metmkdocs build --strict: OKGroupLabelsTest,TesKubernetesConverterMinimalTest.groupNamesThatAreNoLabelValues(invalid label value),UserCreatorTest.labelSelector_groupNamesThatAreNoLabelValues(raw names in the selector),KubernetesClientWrapperTest.listAllTaskmasterJobsForUser_groupNamesThatAreNoLabelValues, andAuthIT.groupNamesThatAreNoLabelValues_createGetAndListTasks(500instead of200), with names such asBioHackCloud%20Admins,BioHackCloud Admins, Unicode, selector characters, names over 63 characters, and asubover 63 characters with|.CI: all checks pass (Lint, Test, Docs, Smoke test, Scan image, CodeQL, Codecov patch/project, CI passed); image push is skipped on PRs. One run of Scan image failed while downloading Maven in the image build (network) and passed on re-run.
Review
Full lane (authorisation-related), two rounds of adversarial and quality review. Fixed: misplaced javadoc, the annotation key defined as the label key, the label pattern without the empty value, tests at the 63/64-character boundary and for a team named like a hash label,
kubectlselection of hashed teams in the upgrade notes.Declined review findings
Return no team for a
sha256-label without a matching annotation (adversarial, noted as not a finding): the label is the fallback for tasks created before the annotation; a mismatch needs write access to Kubernetes, andisGroupManager/isGroupMembercompare full names, so a hash label matches only a team literally named like it.Assert the unhashed 63-character case in the new boundary test (quality, low):
value_validNamesStayAsTheyArealready covers it.Sourcery: a member of a team named
sha256-<hash of X>lists tasks of team X: the member selector always includes the own creator hash, so at most the member's own tasks of X are listed; get and cancel compare full names.Sourcery: old replicas during a rolling update can't read hashed teams: such tasks couldn't exist before (Kubernetes refused them); during the rollout only super admins see them on old replicas, as documented for a downgrade.
Sourcery: team names large enough to exceed the 256 KiB annotation limit: names come from the identity provider's user info, and the task JSON annotation is already far larger.
Open questions
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqN5w1v5t1QRTKU7ad5