Skip to content

fix: include validation for forbidden namespaces#32

Merged
tekton-robot merged 1 commit intotektoncd:mainfrom
anithapriyanatarajan:annotation-labels-fix
Nov 6, 2025
Merged

fix: include validation for forbidden namespaces#32
tekton-robot merged 1 commit intotektoncd:mainfrom
anithapriyanatarajan:annotation-labels-fix

Conversation

@anithapriyanatarajan
Copy link
Contributor

Changes

This pull request introduces a new validation to prevent namespace-level configuration from being created in certain forbidden namespaces, specifically those prefixed with kube-, openshift-, or tekton-. The changes include the implementation of the validation logic, updates to the admission webhook, and tests to ensure correct enforcement.

  • Added a new function validateNamespaceForConfig in pkg/webhook/configmapvalidation.go that checks if a namespace starts with kube-, openshift-, or tekton- and returns an error if so. This prevents creation of namespace-level configs in these forbidden namespaces.
  • Updated the Admit method in ValidateConfigMap to invoke validateNamespaceForConfig for namespace-level configs and reject requests in forbidden namespaces, returning a detailed error response.

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

NONE

/kind fix

@tekton-robot
Copy link

@anithapriyanatarajan: The label(s) kind/fix cannot be applied, because the repository doesn't have them.

Details

In response to this:

Changes

This pull request introduces a new validation to prevent namespace-level configuration from being created in certain forbidden namespaces, specifically those prefixed with kube-, openshift-, or tekton-. The changes include the implementation of the validation logic, updates to the admission webhook, and tests to ensure correct enforcement.

  • Added a new function validateNamespaceForConfig in pkg/webhook/configmapvalidation.go that checks if a namespace starts with kube-, openshift-, or tekton- and returns an error if so. This prevents creation of namespace-level configs in these forbidden namespaces.
  • Updated the Admit method in ValidateConfigMap to invoke validateNamespaceForConfig for namespace-level configs and reject requests in forbidden namespaces, returning a detailed error response.

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

NONE

/kind fix

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 6, 2025
@infernus01
Copy link
Member

/retest

@anithapriyanatarajan anithapriyanatarajan force-pushed the annotation-labels-fix branch 2 times, most recently from 45cf987 to f8dfe4f Compare November 6, 2025 07:07
@infernus01
Copy link
Member

/lgtm

@tekton-robot tekton-robot added lgtm Indicates that a PR is ready to be merged. and removed lgtm Indicates that a PR is ready to be merged. labels Nov 6, 2025
Signed-off-by: Anitha Natarajan <anataraj@redhat.com>
@infernus01
Copy link
Member

infernus01 commented Nov 6, 2025

There's a contradiction between the webhook configuration and validation code. This means the validation logic never executes because the webhook is never called. Let's remove tekton-pipelines and default from the exclusion list to allow code-level validation to properly reject these configs with appropriate error messages.
Edit: you already did, thanks

@infernus01
Copy link
Member

/approve

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: infernus01

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 6, 2025
@infernus01
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 6, 2025
@tekton-robot tekton-robot merged commit 8d4c38a into tektoncd:main Nov 6, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants