Skip to content

fix: encode team names in Kubernetes labels - #217

Merged
uniqueg merged 3 commits into
devfrom
fix/216-group-label-values
Nov 23, 2026
Merged

uniqueg merged 3 commits into
devfrom
fix/216-group-label-values

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

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 label creator-group-name of the taskmaster's job and ConfigMap and into the list selector. Kubernetes refused such tasks (422, a 500 for the client), and listing broke for the same users.

Same approach as for the creator (#119):

  • new GroupLabels: the label creator-group-name is the team name if it is a valid label value (unchanged, so existing tasks keep their teams), otherwise sha256- plus the first 32 hex digits of its SHA-256; the annotation creator-group-name holds the full name;
  • the team of a task (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.getLabelSelector selects 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) and docs/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-jdk container (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 met
  • mkdocs build --strict: OK
  • Regression tests fail on the old code: GroupLabelsTest, TesKubernetesConverterMinimalTest.groupNamesThatAreNoLabelValues (invalid label value), UserCreatorTest.labelSelector_groupNamesThatAreNoLabelValues (raw names in the selector), KubernetesClientWrapperTest.listAllTaskmasterJobsForUser_groupNamesThatAreNoLabelValues, and AuthIT.groupNamesThatAreNoLabelValues_createGetAndListTasks (500 instead of 200), with names such as BioHackCloud%20Admins, BioHackCloud Admins, Unicode, selector characters, names over 63 characters, and a sub over 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, kubectl selection 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, and isGroupManager/isGroupMember compare 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_validNamesStayAsTheyAre already 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

uniqueg and others added 3 commits November 23, 2026 02:53
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
@uniqueg uniqueg self-assigned this Nov 23, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Add the shared group-label encoding and recovery logic, then use it when writing task metadata, reading task groups, and filtering jobs by group.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/GroupLabels.java L1-75
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java L554-572 (+4 small edits)
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapper.java L32, L283-289, L296 (removed lines)

Build user group selectors from the same safe label values used when tasks are labelled.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/User.java L18, L176 (removed lines), L180-183

Define the group annotation key alongside the label key and document their roles.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java L121-132

Update test fixtures to write group metadata through the new helper and expose the taskmaster fixture for reuse.

  • src/integration-test/java/uk/ac/ebi/tsc/tesk/MockUtil.java L21, L92-96

Documentation

Explain how group names are stored and recovered, and how to select tasks with hashed group labels after upgrading.

  • docs/access-control.md L157-175
  • docs/upgrading.md L40-54

Tests

Verify group-label validity, hashing, annotations, legacy-label fallback, and distinction between a group name and a hash-like label.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/GroupLabelsTest.java L1-144

Cover safe selectors for invalid group names and task metadata conversion for both user-derived and tag-provided groups.

  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserCreatorTest.java L16, L82-101
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverterMinimalTest.java L720-770 (+3 small edits)

Exercise end-to-end task creation, retrieval, and listing for group names and creator IDs that are not valid label values.

  • src/integration-test/java/uk/ac/ebi/tsc/tesk/AuthIT.java L32, L830-911

Other changes

Files not grouped.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapperTest.java L579-586, L625-658 (+2 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b87b051) to head (f34aa8a).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 23, 2026 02:13
@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit f34aa8a

#216 fix: encode team names in Kubernetes labels · 6 of 6 met

# Requirement Status Notes
1 Keep valid team names as label values; use a hash for invalid names and store the full name in the annotation. ✅ Met GroupLabels.put applies this to both the taskmaster Job and ConfigMap.
2 Resolve a task's team from the annotation when it matches the label; otherwise use the label for tasks created before the annotation. ✅ Met GroupLabels.groupName implements the fallback, and the converter uses it for task log metadata used in authorization.
3 Use the same label values in list selectors and filter listed tasks by the full team name. ✅ Met User.getLabelSelector encodes each group, and list filtering resolves the job's full group name before checking manager access.
4 Keep the existing team-group model; team names containing commas remain unsupported. ✅ Met The change leaves group extraction unchanged and does not add filtering; the existing comma-splitting limitation remains documented in the PR description.
5 Add regression tests for awkward team names and an unusual user ID. ✅ Met Tests cover spaces, percent signs, Unicode, long names, selector characters, and a long ID containing a separator.
6 Document the team-label behavior in docs/access-control.md. ✅ Met The documentation describes the label, annotation, fallback for older tasks, and GROUP_NAME output.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit 82ab28c into dev Nov 23, 2026
68 of 70 checks passed
@uniqueg
uniqueg deleted the fix/216-group-label-values branch November 23, 2026 02:28
uniqueg added a commit that referenced this pull request Nov 23, 2026
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
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.

fix: encode team names in Kubernetes labels

1 participant