Skip to content

[dashboard] fix listing namespaces as unprivileged user - #1456

Merged
Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
fix-users
Sep 25, 2025
Merged

Andrei Kvapil (kvaps) merged 1 commit into
mainfrom
fix-users

Conversation

@kvaps

@kvaps Andrei Kvapil (kvaps) commented Sep 24, 2025 •

Copy link
Copy Markdown
Member

Signed-off-by: Andrei Kvapil [email protected]

What this PR does

Release note

[]

Summary by CodeRabbit

  • Improvements

    • Updated namespace data source to a new API, ensuring tenant namespaces display correctly and stay in sync.
  • Bug Fixes

    • Improved reliability of streamed requests by removing problematic headers, preventing errors during form-based operations.
  • Chores

    • Adjusted image build process to apply patches during build, enabling quicker delivery of fixes without altering runtime behavior.

@coderabbitai

coderabbitai Bot commented Sep 24, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds a patch-application step to the Dockerfile build for the openapi-ui-k8s-bff image. Introduces a patch changing formPrepare behavior: filters out host and content-length headers and switches the namespaces fetch from /api/v1/namespaces to /apis/core.cozystack.io/v1alpha1/tenantnamespaces.

Changes

Cohort / File(s) Summary
Image build pipeline
packages/system/dashboard/images/openapi-ui-k8s-bff/Dockerfile
Copies patches into builder and applies all .diff patches via git apply before environment setup and npm install/build steps.
BFF formPrepare endpoint patch
packages/system/dashboard/images/openapi-ui-k8s-bff/patches/namespaces.diff
In formPrepare: removes host and content-length headers from forwarded headers; changes namespaces fetch path to /apis/core.cozystack.io/v1alpha1/tenantnamespaces; retains existing error handling and subsequent logic.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as UI Client
  participant B as BFF (formPrepare)
  participant K as K8s API

  U->>B: POST /forms/prepare (request)
  note right of B: Filter headers<br/>- remove host<br/>- remove content-length
  B->>K: GET /apis/core.cozystack.io/v1alpha1/tenantnamespaces
  K-->>B: 200 OK (tenant namespaces JSON)
  B-->>U: 200 OK (prepared form data)

  alt Error from K8s API
    K-->>B: 4xx/5xx
    B-->>U: Error response (preserves existing handling)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Suggested reviewers

  • lllamnyp
  • klinch0

Poem

Thump-thump! I patch with gentle might,
Headers trimmed, requests take flight.
New paths hop where namespaces grow,
A tidy burrow for data flow.
Docker hums, the build hops through—
Carrot commits, and CI too. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “[dashboard] fix listing namespaces as unprivileged user” directly reflects the core change of updating the dashboard’s namespace fetching logic (including endpoint and header adjustments) to support unprivileged users, and it is concise, specific, and contextually accurate.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-users

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello Andrei Kvapil (@kvaps), I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue preventing unprivileged users from listing namespaces within the dashboard. It achieves this by implementing a new patching system within the openapi-ui-k8s-bff Docker image. This system applies a patch that modifies the API endpoint for fetching namespaces to a tenant-specific one, granting appropriate access. Additionally, a fix for an HTTP content-length header causing stream abortion is included.

Highlights

  • Patching Mechanism: A new mechanism has been introduced in the openapi-ui-k8s-bff Dockerfile to apply custom patches during the image build process, allowing for flexible modifications to the upstream project.
  • Namespace Listing Fix: The API endpoint used for listing namespaces has been updated from /api/v1/namespaces to /apis/core.cozystack.io/v1alpha1/tenantnamespaces. This change specifically addresses the issue where unprivileged users were unable to view namespaces in the dashboard.
  • HTTP Header Issue Resolution: The content-length header is now explicitly deleted from filtered headers when making API requests, resolving an issue where this header was causing 'stream has been aborted' errors.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request addresses an issue where unprivileged users cannot list namespaces in the dashboard. The fix involves switching from listing all Kubernetes namespaces to querying a new custom resource, tenantnamespaces, for which all authenticated users have read permissions. The changes include patching the openapi-ui-k8s-bff service to use this new endpoint. My review found the core logic of the fix to be sound. I have one suggestion to improve the robustness of the Docker build process to prevent potential failures in the future.

RUN wget -O- https://github.com/PRO-Robotech/openapi-ui-k8s-bff/archive/${COMMIT_REF}.tar.gz | tar xzf - --strip-components=1

COPY patches /patches
RUN git apply /patches/*.diff

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.

medium

The command git apply /patches/*.diff can fail if there are no .diff files in the /patches directory because the shell glob *.diff would not expand, passing the literal string to git apply and causing the build to fail. To make the build process more robust for future maintenance (e.g., when all patches are removed), it's better to use a command that handles the absence of patch files gracefully.

RUN ls /patches/*.diff >/dev/null 2>&1 && git apply /patches/*.diff || :

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb653e5 and c81a1aa.

📒 Files selected for processing (2)
  • packages/system/dashboard/images/openapi-ui-k8s-bff/Dockerfile (1 hunks)
  • packages/system/dashboard/images/openapi-ui-k8s-bff/patches/namespaces.diff (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (1)
packages/system/dashboard/images/openapi-ui-k8s-bff/patches/namespaces.diff (1)

7-19: Validate TenantNamespace payload expectations

Switching to tenantnamespaces means we’re now delivering a custom resource while still typing it as TBuiltinResources. Please double-check that the downstream logic only relies on fields that the TenantNamespace objects actually expose (e.g., metadata.name) so we don’t hit runtime surprises in the form pipeline.

Comment on lines +10 to +11
COPY patches /patches
RUN git apply /patches/*.diff

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.

⚠️ Potential issue

Initialize a git repo before applying patches

Right after untarring the source we’re in a plain directory without .git. git apply will fail with “not a git repository” here, so the current Docker build breaks. Please initialize (and optionally clean up) a repo before applying the patches.

Apply this diff:

 COPY patches /patches
-RUN git apply /patches/*.diff
+RUN git init \
+ && git apply /patches/*.diff \
+ && rm -rf .git
🤖 Prompt for AI Agents
In packages/system/dashboard/images/openapi-ui-k8s-bff/Dockerfile around lines
10 to 11, the Docker build runs git apply against a directory without a .git
repo which causes “not a git repository” errors; initialize a repo before
applying patches by running git init, add the files (git add -A) and create an
initial commit (git commit -m "init") so git apply can succeed, then apply the
patches (git apply /patches/*.diff) and optionally remove or clean up the .git
directory (rm -rf .git) afterwards if you don’t want the repo left in the image.

@kvaps
Andrei Kvapil (kvaps) merged commit b25aa10 into main Sep 25, 2025
19 of 20 checks passed
@kvaps
Andrei Kvapil (kvaps) deleted the fix-users branch September 25, 2025 12:31
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.

1 participant