Skip to content

[main] fix(lightspeed): fix rag-content folder ownership in init container - #3134

Merged
openshift-merge-bot[bot] merged 1 commit into
redhat-developer:mainfrom
rm3l:cherry-pick/main/RHDHBUGS-3371--e2e-lightspeed-core-sidecar-crashes-with-permissionerror-on-k8s-eks-aks-deployments-2
Jul 2, 2026
Merged

[main] fix(lightspeed): fix rag-content folder ownership in init container#3134
openshift-merge-bot[bot] merged 1 commit into
redhat-developer:mainfrom
rm3l:cherry-pick/main/RHDHBUGS-3371--e2e-lightspeed-core-sidecar-crashes-with-permissionerror-on-k8s-eks-aks-deployments-2

Conversation

@rm3l

@rm3l rm3l commented Jul 2, 2026

Copy link
Copy Markdown
Member

Manual cherrypick of #3042

… in init container (redhat-developer#3042)

* fix(lightspeed): pre-create /data/vector_db/notebooks in init container

On EKS/AKS, the RAG init container copies /rag/. to /data/ but never
creates the notebooks subdirectory. At runtime, llama-stack tries to
write /rag-content/vector_db/notebooks/faiss_store.db (same volume,
mounted at /rag-content in the sidecar) and fails with PermissionError
because it cannot create the directory. OCP avoids this via fsGroup
defaults; EKS/AKS do not.

The fix pre-creates /data/vector_db/notebooks before the existing chmod
so the directory exists and is writable when the sidecar starts.

Fixes: RHDHBUGS-3371

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* fix(lightspeed): use --no-preserve=mode,ownership and fsGroup for notebooks permissions

Apply the same fix used in rhdh-chart:
- Use cp --no-preserve=mode,ownership so copied RAG files get the
  container's default permissions rather than inheriting restrictive
  ones from the source image
- Set podSecurityContext.fsGroup: 1001 so Kubernetes chowns volumes
  to GID 1001 on mount, matching how OCP handles this via SCCs on
  EKS/AKS where fsGroup is not set automatically

Together with the existing mkdir -p /data/vector_db/notebooks this
ensures the notebooks directory is writable on all Kubernetes flavours.

Fixes: RHDHBUGS-3371

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* fix(lightspeed): align init container permissions with rhdh-chart fix

Mirror the final fix from rhdh-chart (backstage 5.12.5):
- Remove podSecurityContext.fsGroup: 1001 added in previous commit;
  the chart does not set this on the deployment spec
- Replace 'chmod -R 777 /data/vector_db' with
  'chmod -R a+rwX /data/embeddings_model', matching the chart which
  only widens permissions on the embeddings_model directory and relies
  on --no-preserve=mode,ownership + mkdir -p for the rest

The operator volume mounts /data in the init container and /rag-content
in the sidecar from the same volume, so /data/embeddings_model maps to
/rag-content/embeddings_model -- identical to the chart fix.

Fixes: RHDHBUGS-3371

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* Update config/profile/rhdh/default-config/flavours/lightspeed/deployment.yaml

Co-authored-by: Armel Soro <armel@rm3l.org>

* chore: update release-1.10 to ubi9/go-toolset:9.8-1782736563 from ubi9/go-toolset:9.8-1782377916 [skip-build] [skip-e2e] (redhat-developer#3113)

Signed-off-by: rhdh-bot service account <rhdh-bot@redhat.com>

* chore: regenerate bundle manifests

Signed-off-by: Lucas <lyoon@redhat.com>

---------

Signed-off-by: rhdh-bot service account <rhdh-bot@redhat.com>
Signed-off-by: Lucas <lyoon@redhat.com>
Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Armel Soro <armel@rm3l.org>
Co-authored-by: rhdh-bot service account <rhdh-bot@redhat.com>
@rm3l
rm3l requested review from a team as code owners July 2, 2026 07:58
@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

@rm3l rm3l changed the title fix(lightspeed): fix rag-content folder ownership in init container [main] fix(lightspeed): fix rag-content folder ownership in init container Jul 2, 2026
@rhdh-qodo-merge

Copy link
Copy Markdown

PR Summary by Qodo

Fix Lightspeed RAG init container permissions for shared rag-content volume

🐞 Bug fix ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Prevent PermissionError on EKS/AKS by ensuring the notebooks directory exists before runtime.
• Copy RAG seed data without preserving restrictive source permissions.
• Tighten chmod behavior to only grant needed rwX on model/vector DB paths.
Diagram

graph TD
R["/rag (image data)"] --> C{{"cp --no-preserve"}} --> V[("Shared /data volume")] --> M["mkdir notebooks"] --> P["chmod a+rwX"] --> S["Llama-stack sidecar"]
S --> W["Write faiss_store.db"]
subgraph Legend
direction LR
_rect["Workload/Container"] ~~~ _dec{{"Operation"}} ~~~ _vol[("Volume")]
end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Set pod fsGroup / runAsGroup for the Lightspeed pod
  • ➕ Kubernetes enforces group ownership on mounted volumes; less reliance on chmod
  • ➕ More consistent across clusters where SCC/fsGroup defaults differ
  • ➖ May not be available/allowed under some restricted PSP/PSS policies
  • ➖ Still needs directory creation if the writer expects a subdir to exist
2. Replace inline shell with a small init script (ConfigMap or image entrypoint)
  • ➕ More readable and testable than a long sh -c one-liner
  • ➕ Easier to add error handling (set -euo pipefail), logging, and idempotency
  • ➖ Adds an additional artifact to maintain (script + mounting)
  • ➖ Slightly more moving parts in the deployment manifests

Recommendation: The PR’s approach (copy without preserving mode/ownership, explicitly mkdir the notebooks directory, and apply rwX permissions) is appropriate for a backport: it is minimal, targeted at the failure mode on EKS/AKS, and low risk. If the issue recurs across other volumes or clusters, consider adding an explicit fsGroup/runAsGroup to make volume permissions policy-driven instead of relying on chmod.

Files changed (5) +5 / -5

Bug fix (3) +3 / -3
rhdh-flavour-lightspeed-config_v1_configmap.yamlFix RAG init container copy + permissions for notebooks path +1/-1

Fix RAG init container copy + permissions for notebooks path

• Changes the init container command to copy RAG data without preserving mode/ownership, explicitly creates /data/vector_db/notebooks, and applies rwX permissions to embeddings_model and vector_db. This prevents runtime PermissionError when the sidecar writes FAISS state on EKS/AKS-style volume mounts.

bundle/rhdh/manifests/rhdh-flavour-lightspeed-config_v1_configmap.yaml

deployment.yamlUpdate Lightspeed init container RAG seed/permissions command +1/-1

Update Lightspeed init container RAG seed/permissions command

• Aligns the Lightspeed flavour deployment with the fixed init container command: cp --no-preserve, mkdir notebooks, and chmod a+rwX on required paths. Ensures the sidecar can create/write under the shared rag-content volume.

config/profile/rhdh/default-config/flavours/lightspeed/deployment.yaml

install.yamlPropagate Lightspeed RAG init container permission fix into dist install manifest +1/-1

Propagate Lightspeed RAG init container permission fix into dist install manifest

• Carries the same init container command fix into the rendered distribution install YAML so downstream installs get the corrected behavior. Prevents PermissionError on clusters without OpenShift-style default fsGroup behavior.

dist/rhdh/install.yaml

Other (2) +2 / -2
backstage-operator.clusterserviceversion.yamlRefresh CSV createdAt timestamp +1/-1

Refresh CSV createdAt timestamp

• Updates the generated ClusterServiceVersion metadata timestamp. No functional/operator behavior changes are introduced.

bundle/backstage.io/manifests/backstage-operator.clusterserviceversion.yaml

backstage-operator.clusterserviceversion.yamlRefresh RHDH CSV createdAt timestamp +1/-1

Refresh RHDH CSV createdAt timestamp

• Updates the generated ClusterServiceVersion metadata timestamp for the RHDH bundle. No functional/operator behavior changes are introduced.

bundle/rhdh/manifests/backstage-operator.clusterserviceversion.yaml

@rhdh-qodo-merge

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Remediation recommended

1. Overbroad RAG write perms 🐞 Bug ⛨ Security
Description
The Lightspeed init container recursively applies chmod -R a+rwX to both /data/embeddings_model
and the entire /data/vector_db tree, making the embedding model and prebuilt RAG indices
world-writable by any process in the pod. This enables tampering/corruption of the model and RAG
stores (including product docs), which can change retrieval results and undermine answer integrity.
Code

config/profile/rhdh/default-config/flavours/lightspeed/deployment.yaml[12]

+            - "echo 'Copying RAG data...'; cp -r --no-preserve=mode,ownership /rag/. /data/ && mkdir -p /data/vector_db/notebooks && chmod -R a+rwX /data/embeddings_model /data/vector_db && echo 'Copy complete.'"
Relevance

⭐⭐ Medium

No precedent on chmod/world-writable; least-privilege permission hardening was rejected in PR #2141;
security concerns sometimes partial (#2293).

PR-#2141
PR-#2293

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR changes the initContainer command to chmod -R a+rwX /data/embeddings_model /data/vector_db,
which grants write access broadly. The Lightspeed config shows distinct DB paths for product docs vs
notebooks and uses /rag-content/embeddings_model as the embedding model location, so broad write
permissions cover assets that are expected to be static inputs.

config/profile/rhdh/default-config/flavours/lightspeed/deployment.yaml[6-23]
config/profile/rhdh/default-config/flavours/lightspeed/configmap-files.yaml[163-218]
dist/rhdh/install.yaml[3283-3305]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The initContainer command makes `/data/embeddings_model` and all of `/data/vector_db` world-writable (`a+rwX`). This is broader than necessary and allows in-pod tampering of integrity-sensitive RAG assets.

## Issue Context
The configuration distinguishes between a product-docs vector store and a notebooks vector store, implying only the notebooks store needs write access.

## Fix Focus Areas
- config/profile/rhdh/default-config/flavours/lightspeed/deployment.yaml[12-12]
- dist/rhdh/install.yaml[3289-3296]
- bundle/rhdh/manifests/rhdh-flavour-lightspeed-config_v1_configmap.yaml[267-274]

## Suggested change
1. Keep creating the notebooks directory.
2. Restrict permissions by intent, e.g.:
  - Make embeddings model read-only: `chmod -R a+rX /data/embeddings_model`
  - Make product-docs vector DB read-only (or at least not world-writable): `chmod -R a+rX /data/vector_db/rhdh_product_docs`
  - Make only notebooks writable: `chmod -R a+rwX /data/vector_db/notebooks`

(Alternatively, prefer group-based permissions using `fsGroup` + `chmod -R g+rwX` instead of world-writable perms.)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@openshift-ci openshift-ci Bot added the lgtm label Jul 2, 2026
@openshift-merge-bot
openshift-merge-bot Bot merged commit fbb7af8 into redhat-developer:main Jul 2, 2026
11 checks passed
@rm3l
rm3l deleted the cherry-pick/main/RHDHBUGS-3371--e2e-lightspeed-core-sidecar-crashes-with-permissionerror-on-k8s-eks-aks-deployments-2 branch July 2, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants