Skip to content

fix(webhook): prevent unlabeled ConfigMaps from bypassing validation - #453

Open
infernus01 wants to merge 1 commit into
tektoncd:mainfrom
infernus01:fix/webhook-validation
Open

infernus01 wants to merge 1 commit into
tektoncd:mainfrom
infernus01:fix/webhook-validation

Conversation

@infernus01

@infernus01 infernus01 commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Changes

Fixes a bug where unlabeled ConfigMaps could bypass webhook validation and get loaded by the controller without validation.

Problem

The webhook's objectSelector requires these labels:

 app.kubernetes.io/part-of: tekton-pruner
 pruner.tekton.dev/config-type: namespace

If a user creates a ConfigMap with the correct name (tekton-pruner-namespace-spec) but without labels, Kubernetes API server filters it out and never calls the webhook. The controller informer only checked cm.Name == "tekton-pruner-namespace-spec", so it would reconcile the unlabeled ConfigMap and load it via LoadNamespaceConfig() which had no label validation.

Solution

Implemented defense-in-depth with three validation layers:

Layer 1: Controller Informer Filter (pkg/reconciler/namespaceprunerconfig/controller.go)

  • Checks both ConfigMap name AND required labels
  • Logs warnings for unlabeled ConfigMaps
  • Prevents them from entering reconciliation queue

Layer 2: Config Loading Validation (pkg/config/config.go)

  • LoadGlobalConfig() validates labels before parsing
  • LoadNamespaceConfig() validates labels before parsing

Layer 3: Webhook (unchanged)

  • Validates labeled ConfigMaps against global limits
  • objectSelector ensures only labeled ConfigMaps reach webhook code

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • pre-commit Passed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

Controller now validates required labels before loading ConfigMaps, preventing unauthorized configuration overrides.

@tekton-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from infernus01 after the PR has been reviewed.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 8, 2026
@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.64%. Comparing base (570867a) to head (f65b3f2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #453      +/-   ##
==========================================
+ Coverage   55.67%   58.64%   +2.97%     
==========================================
  Files          19       19              
  Lines        1886     1966      +80     
==========================================
+ Hits         1050     1153     +103     
+ Misses        836      813      -23     
Flag Coverage Δ
unit-tests 58.64% <ø> (+2.97%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@infernus01 infernus01 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Oct 8, 2026
Signed-off-by: Shubham Bhardwaj <shubbhar@redhat.com>
@infernus01
infernus01 force-pushed the fix/webhook-validation branch from 93fadc2 to f65b3f2 Compare October 8, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants