Skip to content

NC | Lifecycle | An internal file/folder should be blocked for deletion by the lifecycle worker #9073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

romayalon
Copy link
Contributor

@romayalon romayalon commented Jun 10, 2025

Describe the Problem

An internal file/folder should be blocked for deletion by the lifecycle worker, we are not supposed to see an issue due to the whole flow but I added it in order to be extra safe on the filter func as well.

  1. POSIX flow - we shouldn't see this issue at all because list_objects() is used and should not be return an internal file.
  2. GPFS flow - also shouldn't happen because on the ILM policy we avoid internal directory/past versions and when seeing .folder file we convert the key to be the directory name.

Explain the Changes

  1. lifecycle_utils.build_lifecycle_filter() - returned false if the object key is inside the bucket temp uploads dir / any .versions/ dir or directory object (.folder).

Issues: Fixed #xxx / Gap #xxx

Testing Instructions:

  1. sudo jest --testRegex=jest_tests/test_nc_lifecycle.test
  • Doc added/updated
  • Tests added

Summary by CodeRabbit

  • Bug Fixes
    • Improved lifecycle filtering to prevent deletion of temporary files, folder marker objects, and versioned objects.
  • Tests
    • Added new test cases to verify deletion fails for internal and special system files and directories.
    • Enhanced test assertions for more flexible error checking.
  • Chores
    • Removed unnecessary debug logging from a CORS test case.

…by the lifecycle worker

Signed-off-by: Romy <35330373+romayalon@users.noreply.github.com>
Copy link

coderabbitai bot commented Jun 10, 2025

Walkthrough

The changes expand test coverage for object deletion with lifecycle filters, particularly adding negative test cases for internal and special files. Assertion helpers were updated for flexibility. The lifecycle filter logic was enhanced to exclude temporary, folder marker, and versioned objects. A debug log was removed from a CORS test.

Changes

File(s) Change Summary
src/test/unit_tests/jest_tests/test_nc_lifecycle.test.js Added negative tests for deletion of internal/special files; updated assertion helper to support dynamic key checks.
src/util/lifecycle_utils.js Enhanced build_lifecycle_filter to exclude temp, folder marker, and versioned objects.
src/test/unit_tests/test_s3_ops.js Removed a debug logging statement from a CORS test.

Poem

In the warren of code, new tests now appear,
Guarding the secrets that bunnies hold dear.
Filters grow wiser, skipping files that hide—
No temp nor versioned objects slip inside.
With logs trimmed and checks anew,
This rabbit hops on, proud of the view! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-10T14_41_48_758Z-debug-0.log

✨ Finishing Touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/test/unit_tests/jest_tests/test_nc_lifecycle.test.js (1)

235-246: Duplicate test case detected.

This test appears to be identical to the previous test (lines 221-232) with the same test description and logic. Consider either removing this duplicate or modifying it to test a different scenario.

Remove the duplicate test or modify it to test a different aspect:

-        it('delete_multiple_objects - filter should fail on internal .versions file - versioning ENABLED bucket', async () => {
+        it('delete_multiple_objects - filter should fail on internal .versions file with explicit prefix - versioning ENABLED bucket', async () => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19d7a5a and fe6bac0.

📒 Files selected for processing (3)
  • src/test/unit_tests/jest_tests/test_nc_lifecycle.test.js (3 hunks)
  • src/test/unit_tests/test_s3_ops.js (0 hunks)
  • src/util/lifecycle_utils.js (1 hunks)
💤 Files with no reviewable changes (1)
  • src/test/unit_tests/test_s3_ops.js
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/util/lifecycle_utils.js (11)
src/endpoint/s3/ops/s3_put_object.js (2)
  • object_info (84-89)
  • config (9-9)
src/test/unit_tests/jest_tests/test_nc_lifecycle.test.js (1)
  • config (10-10)
src/test/unit_tests/test_s3_ops.js (1)
  • config (10-10)
src/manage_nsfs/health.js (1)
  • config (7-7)
src/test/system_tests/test_utils.js (1)
  • config (10-10)
src/util/http_utils.js (1)
  • config (19-19)
src/manage_nsfs/nc_lifecycle.js (1)
  • config (10-10)
src/cmd/manage_nsfs.js (1)
  • config (18-18)
src/sdk/namespace_fs.js (1)
  • config (13-13)
src/test/unit_tests/test_lifecycle.js (1)
  • config (20-20)
src/test/unit_tests/jest_tests/test_nc_lifecycle_posix_integration.test.js (1)
  • config (11-11)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: run-sanity-ssl-tests
  • GitHub Check: ceph-s3-tests
  • GitHub Check: warp-nc-tests
  • GitHub Check: run-sanity-tests
  • GitHub Check: warp-tests
  • GitHub Check: run-jest-unit-tests
  • GitHub Check: run-unit-tests-postgres
  • GitHub Check: run-package-lock-validation
  • GitHub Check: nsfs-ceph-s3-tests
  • GitHub Check: run-unit-tests
  • GitHub Check: run-nc-unit-tests
🔇 Additional comments (7)
src/util/lifecycle_utils.js (1)

151-154:

✅ Verification successful

Security enhancement correctly implemented.

The pre-filtering logic effectively prevents lifecycle operations from targeting internal system files, temporary files, and versioned objects. The placement before other filters ensures these exclusions take absolute precedence.

Please verify that the config constants are properly defined and have appropriate values:


🏁 Script executed:

#!/bin/bash
# Verify config constants used in the lifecycle filter
rg -A 2 -B 2 "NSFS_TEMP_DIR_NAME|NSFS_FOLDER_OBJECT_NAME" --type js

Length of output: 21209


Lifecycle filter constants verified and approved

Verified that the two config constants used in build_lifecycle_filter are correctly defined in config.js:

  • config.NSFS_TEMP_DIR_NAME = '.noobaa-nsfs'
  • config.NSFS_FOLDER_OBJECT_NAME = '.folder'

There is currently no config constant for the version‐path check ('.versions/'). To avoid a magic string, consider adding something like:

// in config.js
config.NSFS_VERSIONS_DIR_NAME = '.versions';

and updating the filter:

- if (object_info.key.includes('.versions/')) return false;
+ if (object_info.key.includes(`${config.NSFS_VERSIONS_DIR_NAME}/`)) return false;
src/test/unit_tests/jest_tests/test_nc_lifecycle.test.js (6)

95-102: Well-designed test for internal multipart upload file exclusion.

The test correctly creates a multipart upload, constructs the internal file path, and verifies that the lifecycle filter blocks deletion with an empty prefix filter.


104-111: Good coverage for explicit prefix targeting internal files.

This test ensures that even when the lifecycle filter explicitly targets the internal file path with a matching prefix, the deletion is still blocked. This validates the absolute nature of the internal file exclusion.


113-121: Effective test for folder object exclusion with empty prefix.

The test correctly creates a directory object and verifies that the associated .folder marker file is protected from lifecycle deletion, even with a broad empty prefix filter.


123-131: Comprehensive test for folder object exclusion with matching prefix.

This test validates that folder marker objects remain protected even when the lifecycle filter prefix specifically targets the directory path. This ensures robust protection of internal folder structures.


221-232: Excellent test coverage for versioned file protection.

The test properly sets up versioning, creates multiple versions, and verifies that internal .versions/ files are excluded from lifecycle deletion. The version file path construction is correct.


629-641: Helper function enhancement improves test flexibility.

The modification to accept an optional delete_objects_arr parameter and dynamically determine the assertion key makes the helper function more versatile for testing different object keys beyond the global key variable.

The logic correctly falls back to the global key when delete_objects_arr is not provided, maintaining backward compatibility with existing tests.

@romayalon romayalon requested review from guymguym and nadavMiz June 10, 2025 16:05
coderabbitai bot added a commit that referenced this pull request Jun 10, 2025
…dirs`

Docstrings generation was requested by @romayalon.

* #9073 (comment)

The following files were modified:

* `src/util/lifecycle_utils.js`
Copy link

coderabbitai bot commented Jun 10, 2025

Note

Generated docstrings for this pull request at #9074

@romayalon romayalon changed the title NC | Lifecycle | An internal file/folder should blocked for deletion by the lifecycle worker NC | Lifecycle | An internal file/folder should be blocked for deletion by the lifecycle worker Jun 10, 2025
@@ -148,6 +148,11 @@ function build_lifecycle_filter(params) {
* @param {Object} object_info
*/
return function(object_info) {
// fail if object is a temp file/part or a folder object or a versioned object
Copy link
Contributor

Choose a reason for hiding this comment

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

this logic is shared with list-object. and we would need to change in both cases in case there will be a new hidden file/folder added. maybe we should add a utility function to check if file is internal directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you explain why would we need to change in 2 different places if this function is shared?

Copy link
Contributor

Choose a reason for hiding this comment

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

they are both intended to ignore internal directories when going over files. if there is a new internal directory. we would need to ignore it in both

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, since both places using this function why would we need to change in 2 different places? or I don't get your point...

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean list-object in general regardless of lifecycle:

if (!ent.name.startsWith(prefix_ent) ||
    ent.name < marker_curr ||
    ent.name === this.get_bucket_tmpdir_name() ||
    (ent.name === config.NSFS_FOLDER_OBJECT_NAME && is_disabled_dir_content) ||
    this._is_hidden_version_path(ent.name)) {
    return;
}

@romayalon romayalon mentioned this pull request Jun 16, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants