Skip to content

feat(juicefs): clean fuse cache when JuiceFSRuntime shutdown#5650

Open
Sumitsh28 wants to merge 1 commit intofluid-cloudnative:masterfrom
Sumitsh28:fuse_cache
Open

feat(juicefs): clean fuse cache when JuiceFSRuntime shutdown#5650
Sumitsh28 wants to merge 1 commit intofluid-cloudnative:masterfrom
Sumitsh28:fuse_cache

Conversation

@Sumitsh28
Copy link

Ⅰ. Describe what this PR does

This PR implements the cleanup of the Fuse client cache during the JuiceFSRuntime shutdown process. Previously, only the Worker cache was removed, which could leave residual cache data on the nodes.

Specific changes:

  • Updated cleanupCache in pkg/ddc/juicefs/shutdown.go to iterate through Fuse pods and clean their cache directories after cleaning the Worker cache.
  • Added a helper function getFuseCacheDirs to correctly identify Fuse-specific cache paths, respecting both TieredStore configurations and Fuse-specific option overrides (e.g., cache-dir in fuse.options).

Ⅱ. Does this pull request fix one issue?

fixes #5230

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

  • Updated pkg/ddc/juicefs/shutdown_test.go:
  • Added unit tests for getFuseCacheDirs to verify cache path resolution with various configurations.
  • Updated TestJuiceFSEngine_cleanupCache to mock Fuse pods and verify that Fuse cache cleanup is triggered.

Ⅳ. Describe how to verify it

Run the unit tests for the JuiceFS package:

go test -v ./pkg/ddc/juicefs

Signed-off-by: Sumitsh28 <sumit.off28@gmail.com>
@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Feb 1, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign zwwhdls for approval by writing /assign @zwwhdls in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Sumitsh28, 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 enhances the JuiceFSRuntime shutdown process by ensuring that not only the Worker cache but also the Fuse client cache is properly cleaned up. This prevents residual cache data from accumulating on nodes, leading to a more robust and efficient resource management for JuiceFS deployments. The changes involve modifying the cache cleanup logic and introducing a new utility function to correctly identify Fuse-specific cache directories.

Highlights

  • Fuse Cache Cleanup: Implemented logic to clean up Fuse client cache directories during JuiceFSRuntime shutdown, addressing previous incomplete cache removal.
  • Dynamic Fuse Cache Path Resolution: Introduced getFuseCacheDirs to accurately identify Fuse cache paths, respecting both TieredStore configurations and fuse.options overrides like cache-dir.
  • Enhanced Shutdown Process: The cleanupCache function now systematically iterates through both Worker and Fuse pods to ensure all relevant cache data is removed.
  • Comprehensive Unit Testing: New unit tests were added for getFuseCacheDirs and existing tests for cleanupCache were updated to cover the Fuse cache cleanup scenarios.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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-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-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.

@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Feb 1, 2026

Hi @Sumitsh28. Thanks for your PR.

I'm waiting for a fluid-cloudnative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 1, 2026

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 enhances the JuiceFSRuntime shutdown process by adding cleanup for the Fuse client cache. However, it introduces critical security vulnerabilities related to command injection in the getUUID function via user-controlled metadata URLs, and path traversal due to insufficient validation of user-supplied cache directories and UUIDs during path construction for cache deletion. Additionally, the implementation introduces significant code duplication in pkg/ddc/juicefs/shutdown.go regarding cache cleanup and directory retrieval logic, which should be refactored for better maintainability.

if len(fusePods) > 0 {
// If UUID was not found from workers (e.g. workers already down), try to get it from fuse
if uuid == "" {
uuid, err = j.getUUID(fusePods[0], common.JuiceFSFuseContainer)
Copy link
Contributor

Choose a reason for hiding this comment

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

security-critical critical

The call to j.getUUID at this line triggers a critical command injection vulnerability. The getUUID function retrieves a source value from a ConfigMap and interpolates it directly into a shell command string via operations.JuiceFileUtils.GetStatus. This allows for Remote Code Execution (RCE) if an attacker injects shell metacharacters into the metadata URL. This also contributes to significant code duplication with the worker cache cleanup logic, which could be refactored into a shared helper function for better maintainability.

fuseOptions := runtime.Spec.Fuse.Options
for k, v := range fuseOptions {
if k == "cache-dir" {
cacheDirs = append(cacheDirs, strings.Split(v, ":")...)
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The cache-dir option from fuse.options is split and appended to cacheDirs without sufficient validation. This introduces a path traversal vulnerability where a user could provide a path to a sensitive directory, potentially leading to arbitrary file deletion during cleanupCache. User-supplied paths must be validated to ensure they remain within expected boundaries. Additionally, the getFuseCacheDirs function is nearly identical to getCacheDirs, leading to code duplication. Consider creating a generic helper function to avoid this.


cacheDirsToBeDeleted := []string{}
for _, cacheDir := range fuseCacheDirs {
cacheDirsToBeDeleted = append(cacheDirsToBeDeleted, filepath.Join(cacheDir, uuid, "raw/chunks"))
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The cache cleanup logic is vulnerable to path traversal. The code constructs paths for deletion using filepath.Join(cacheDir, uuid, "raw/chunks"). Both cacheDir and uuid are influenced by user-provided configuration (e.g., fuse.options["cache-dir"] and the metadata source in Enterprise Edition).

An attacker can provide malicious values containing path traversal sequences (e.g., ../../../../etc) to point the deletion command to unintended locations. Although DeleteCacheDirs checks for a raw/chunks suffix, an attacker could still delete arbitrary directories that end with this suffix or create such a directory structure to facilitate deletion of sensitive data.

Note that this also affects the path construction on line 152.

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.

[FEATURES] clean fuse cache when JuiceFSRuntime shutdown

1 participant