Skip to content

fix: block system namespace creation - #2940

Open
krishhlogan wants to merge 1 commit into
tektoncd:mainfrom
krishhlogan:fix/block-system-namespace-repo-creation
Open

fix: block system namespace creation#2940
krishhlogan wants to merge 1 commit into
tektoncd:mainfrom
krishhlogan:fix/block-system-namespace-repo-creation

Conversation

@krishhlogan

@krishhlogan krishhlogan commented Aug 27, 2026

Copy link
Copy Markdown

📝 Description of the Change

Add validation in tkn pac to restrict repository creation in system namespaces (kube-, openshift-, tekton-*, tekton-pipelines, openshift-pipelines)

The checkSystemNamespace helper is called at two points:

  • When --namespace flag is passed explicitly
  • After the user selects a namespace via the interactive prompt

Behaviour by namespace:

  • openshift-pipelines, tekton-pipelines — error, not supported as targets
  • openshift-* prefix — error, system namespaces are not supported
  • tekton-* prefix — warning shown, user can still proceed
  • kube-* prefix — warning shown, user can still proceed

🔗 Linked GitHub Issue

Fixes #1350

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

AI assistance can be used for various tasks, such as code generation,
documentation, or testing.

Please indicate whether you have used AI assistance
for this PR and provide details if applicable.

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Important

Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Claude noreply@anthropic.com

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 27, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@theakshaypant theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @krishhlogan for picking this up!
request you to remove the jira references and sign the CLA.

@krishhlogan krishhlogan changed the title fix(SRVKP-13948): block system namespace creation fix: block system namespace creation Aug 27, 2026
@krishhlogan

Copy link
Copy Markdown
Author

done @theakshaypant

@theakshaypant theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @krishhlogan ! As a follow up to earlier request

  1. Please squash your commits into a single one
  2. Amend the message on the first commit top remove jira reference

@krishhlogan
krishhlogan force-pushed the fix/block-system-namespace-repo-creation branch from cbd211c to 60eea39 Compare August 31, 2026 05:41
@krishhlogan

Copy link
Copy Markdown
Author

done @theakshaypant

@theakshaypant

Copy link
Copy Markdown
Member

/ok-to-test

@theakshaypant theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks fine, only recommend adding a couple more test cases for completeness.

Comment thread pkg/cmd/tknpac/create/repository_test.go
Comment thread pkg/cmd/tknpac/create/repository.go Outdated
@zakisk

zakisk commented Sep 1, 2026

Copy link
Copy Markdown
Member

@krishhlogan can you please ensure always squashing your commits into one and rebasing with upstream/main

@zakisk
zakisk force-pushed the fix/block-system-namespace-repo-creation branch from 3f87590 to 1e1f7da Compare September 1, 2026 05:23
@zakisk

zakisk commented Sep 1, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.66%. Comparing base (aeed7ee) to head (97ceb08).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2940   +/-   ##
=======================================
  Coverage   80.66%   80.66%           
=======================================
  Files         164      164           
  Lines       13910    13910           
=======================================
  Hits        11221    11221           
  Misses       1967     1967           
  Partials      722      722           
Flag Coverage Δ
unit-tests 80.66% <ø> (ø)

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.

@krishhlogan

Copy link
Copy Markdown
Author

@krishhlogan can you please ensure always squashing your commits into one and rebasing with upstream/main

@zakisk Sure, will do! Thanks for the heads up

Comment thread pkg/cmd/tknpac/create/repository.go
Comment thread pkg/cmd/tknpac/create/repository.go
Comment thread pkg/cmd/tknpac/create/repository.go
  Prevent tkn pac create repo from creating repositories in
  system namespaces where the default service account is not
  auto-created and pipelines would fail.

  - openshift-pipelines, tektoncd-pipelines: return error
  - openshift-* prefix: return error (system namespaces)
  - kube-* prefix: show warning, allow with confirmation

  Signed-off-by: krishhlogan <kloganat@redhat.com>
  Assisted-by: Claude Sonnet 4.6 (via Claude Code)

fix: use correct tekton system namespace name

  Replace tektoncd-pipelines with tekton-pipelines which is the
  actual namespace used by Tekton Pipelines installation.

  Signed-off-by: krishhlogan <kloganat@redhat.com>

fix: warn on tekton- prefixed system namespaces

  Add warning for tekton-* namespaces (other than tekton-pipelines)
  similar to kube-* handling. tekton-pipelines remains an error.

  Signed-off-by: krishhlogan <kloganat@redhat.com>
@krishhlogan
krishhlogan force-pushed the fix/block-system-namespace-repo-creation branch from 1e1f7da to 97ceb08 Compare September 2, 2026 08:11
@chmouel
chmouel requested a balanced review from Copilot September 4, 2026 09:00
@chmouel

chmouel commented Sep 4, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@chmouel

chmouel commented Sep 4, 2026

Copy link
Copy Markdown
Member

/paco review

@pipelines-as-code

Copy link
Copy Markdown

Paco Review 🔍

This PR adds a checkSystemNamespace helper in the tknpac repository create command to prevent (or warn about) creating Pipelines-as-Code Repository CRs in Kubernetes/OpenShift/Tekton system namespaces, wiring it into both the flag-based and interactive-prompt namespace resolution paths in getOrCreateNamespace. It also adds a substantial set of table-driven tests covering the new hard-error and warning behaviors for each namespace prefix.

Review difficulty: 2/5 (Easy) — The change is small and localized to one file plus tests, with a straightforward helper function and two call sites.

1 new inline comment(s) found.

Reviewed commit: 97ceb08

@pipelines-as-code pipelines-as-code Bot added paco/review-easy Paco review difficulty security-review Flagged as security-sensitive by Paco labels Sep 4, 2026

@pipelines-as-code pipelines-as-code 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.

Paco inline comments -- see the Paco Review summary comment for the overview.

}
if strings.HasPrefix(ns, "openshift-") {
return fmt.Errorf("cannot create a repository in namespace %s as system namespaces are not supported", ns)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[MEDIUM] The system-namespace protection is applied inconsistently: any openshift--prefixed namespace is hard-blocked, but kube--prefixed namespaces (e.g. kube-system, kube-public, kube-node-lease — arguably the most sensitive Kubernetes system namespaces) and non-exact tekton--prefixed namespaces only produce a warning and still allow repository creation to proceed. If the intent of this change is to prevent accidental repository creation in system namespaces, kube- should likely be hard-blocked the same way openshift- is, rather than just warned about.

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.

🟡 Changes recommended

The exact reserved openshift namespace remains allowed and must be rejected.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds safeguards for repository creation in system namespaces.

Changes:

  • Validates explicit and interactively selected namespaces.
  • Rejects pipeline and openshift-* namespaces; warns for kube-* and tekton-*.
  • Adds unit tests for both selection paths.
File summaries
File Review
pkg/cmd/tknpac/create/repository.go Moderate (1 vote): Exact openshift namespace is not rejected. Nit (2 votes): Update the validation comment to accurately distinguish errors from warnings.
pkg/cmd/tknpac/create/repository_test.go Adds coverage for rejected and warned namespaces.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

if ns == "openshift-pipelines" || ns == "tekton-pipelines" {
return fmt.Errorf("namespace %s is not supported as a target for repositories", ns)
}
if strings.HasPrefix(ns, "openshift-") {
return repoName, repoNamespace, err
}

// checkSystemNamespace returns an error for system namespaces and prints a warning for kube-* prefixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

paco/review-easy Paco review difficulty security-review Flagged as security-sensitive by Paco

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check we are not creating repo in kube* or openshift* namespaces with tkn pac repo create

6 participants