Skip to content

fix(validation): enforce stricter label validation#16852

Open
lobkovilya wants to merge 25 commits into
masterfrom
label-validation-2
Open

fix(validation): enforce stricter label validation#16852
lobkovilya wants to merge 25 commits into
masterfrom
label-validation-2

Conversation

@lobkovilya

@lobkovilya lobkovilya commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Motivation

Label validation on create/update was inconsistent across the K8s
webhook, REST API server, and KDS sync. Users could silently override
CP-computed labels, and kuma.io/origin mismatches were tolerated —
masking resources applied to the wrong control plane.

Implementation information

Introduces a single declarative registry of reserved labels in
pkg/core/resources/labels/ and reroutes every entry point through
it:

  • LabelSpec declares each label's Owner
    (ControlPlane/User/System) and its expected value.
  • Validate returns {Errors, Warnings}: errors reject (format,
    user-owned AllowedValues, strict kuma.io/origin mismatch);
    warnings cover CP-owned labels the user set wrong — accepted, then
    overridden by Compute.
  • Compute is authoritative: it force-sets/deletes CP-owned labels
    from the registry. The webhook defaulter skips it on Privileged
    contexts (KDS sync, GC, storage-version migration).

Supporting documentation

Fix #16049

lobkovilya added 17 commits June 2, 2026 12:48
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

🔍 Each of these sections need to be checked by the reviewer of the PR 🔍:
If something doesn't apply please check the box and add a justification if the reason is non obvious.

  • Is the PR title satisfactory? Is this part of a larger feature and should be grouped using > Changelog?
  • PR description is clear and complete. It Links to relevant issue as well as docs and UI issues
  • This will not break child repos: it doesn't hardcode values (.e.g "kumahq" as an image registry)
  • IPv6 is taken into account (.e.g: no string concatenation of host port)
  • Tests (Unit test, E2E tests, manual test on universal and k8s)
    • Don't forget ci/ labels to run additional/fewer tests
  • Does this contain a change that needs to be notified to users? In this case, UPGRADE.md should be updated.
  • Does it need to be backported according to the backporting policy? (this GH action will add "backport" label based on these file globs, if you want to prevent it from adding the "backport" label use no-backport-autolabel label)

Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
@lobkovilya lobkovilya changed the base branch from master to release-2.14 June 8, 2026 10:55
@lobkovilya lobkovilya marked this pull request as ready for review June 8, 2026 11:01
@lobkovilya lobkovilya requested a review from a team as a code owner June 8, 2026 11:01
@lobkovilya lobkovilya requested review from lukidzi and slonka June 8, 2026 11:01
@lobkovilya lobkovilya requested a review from Copilot June 8, 2026 12:41

Copilot AI left a comment

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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
@slonka

slonka commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@lobkovilya you could try running it on a subset without golden files but that would require you reset some stuff and then re-commit

@slonka slonka left a comment

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.

just found this, Ilya will adjust

// Privileged callers (K8s controllers, etc.) legitimately set
// OwnerSystem labels like kuma.io/managed-by. Drop them only on
// user paths, where any value is impersonation.
if !o.Privileged {

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.

updating an existing generated Workload or MeshService will silently drop labels like kuma.io/managed-by and kuma.io/deletion-grace-period-started-at

@lobkovilya lobkovilya changed the base branch from release-2.14 to master June 11, 2026 10:07
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