fix(LWLP-1476): make cargo home group-writable for OCP non-root conta… - #424
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe Rust build script now recursively grants group-write access to the copied Cargo home, allowing OpenShift containers running with arbitrary UIDs and GID 0 to create the registry cache at runtime. Sequence diagram for group-writable Cargo home in OCP containerssequenceDiagram
participant Build as Rust build script
participant Rootfs as manylinux-rootfs
actor User as OCP container user
participant Cargo as Cargo
Build->>Rootfs: cp -r CARGO_HOME
Build->>Rootfs: chmod -R g+w PREFIX/cargo/
User->>Cargo: Run cargo with GID 0
Cargo->>Rootfs: Create registry cache
Rootfs-->>Cargo: Write permitted
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="builder/build_scripts/build-rust.sh" line_range="54" />
<code_context>
+# OCP runs containers with an arbitrary UID but GID 0. Make the cargo home
+# group-writable so non-root users can create the registry cache at runtime.
+chmod -R g+w /manylinux-rootfs"${PREFIX}"/cargo/
+
# Create wrapper scripts that set environment variables
</code_context>
<issue_to_address>
**🚨 issue (security):** The recursive mode change makes every file under the Cargo home, including the `cargo`, `rustc`, and `rustup` executables and installed toolchain contents, group-writable. Any container process running with GID 0 can replace those executables or sources, so subsequent builds or commands execute attacker-controlled content instead of only allowing registry-cache writes.
**Triggers:** When multiple users or workloads share the image and one of them can run with GID 0.
**Suggested fix:** Restrict group write access to the runtime cache directories, or at minimum exclude executable and toolchain files from the recursive permission change.
```suggestion
mkdir -p /manylinux-rootfs"${PREFIX}"/cargo/{registry,git}
chmod -R g+w /manylinux-rootfs"${PREFIX}"/cargo/{registry,git}/
```
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and the recursive chmod changes the container's permission boundary: any process running with GID 0 can modify the Cargo registry and cache, potentially replacing dependencies or build inputs used by later cargo operations. Reverting prevents the permission change in future images but does not undo files already modified in running containers, and the overly broad access would not necessarily produce an operational failure.
Blocking findings: builder/build_scripts/build-rust.sh:54
Instead of making the entire cargo home group-writable (which would include executables like cargo, rustc, rustup), only open the runtime cache directories that cargo actually writes to at runtime (registry/ and git/). Addresses security review comment on PR calungaproject#424. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Ales Raszka <araszka@redhat.com>
|
Change itself LGTM, @Allda can you just squash the commits before merging? |
… containers
OCP runs containers with an arbitrary UID but GID 0. The cargo home at
/opt/_internal/rust-${RUST_VERSION}/cargo/ was created by rustup with
default 755 permissions (root-owned, group read-only), causing cargo to
fail with Permission denied when trying to create the registry cache at
runtime.
Restrict group write access to only the runtime cache directories
(registry/ and git/) so non-root container users with GID 0 can write
the cargo registry cache without making executables group-writable.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Ales Raszka <araszka@redhat.com>
928b8b1 to
42920af
Compare
|
@jvulgan done |
OCP runs containers with an arbitrary UID but GID 0. The cargo home at /opt/_internal/rust-${RUST_VERSION}/cargo/ was created by rustup with default 755 permissions (root-owned, group read-only), causing cargo to fail with Permission denied when trying to create the registry cache at runtime.
Add chmod -R g+w after copying the cargo home to manylinux-rootfs so non-root container users with GID 0 can write to it.
Summary by Sourcery
Enable Cargo cache creation for non-root OpenShift containers by making the runtime cache directories group-writable.
Bug Fixes:
Build: