Skip to content
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

feat(crypto): v2 volume encryption #3438

Merged
merged 3 commits into from
Jan 11, 2025
Merged

Conversation

mantissahz
Copy link
Contributor

Which issue(s) this PR fixes:

Issue # longhorn/longhorn#7355

What this PR does / why we need it:

Special notes for your reviewer:

Additional documentation or context

@mantissahz mantissahz requested a review from a team January 8, 2025 09:55
@mantissahz mantissahz self-assigned this Jan 8, 2025
Copy link

coderabbitai bot commented Jan 8, 2025

Walkthrough

The pull request introduces modifications across multiple files to enhance volume management, particularly for encrypted devices and data engine types. The changes focus on integrating Longhorn V2 engine support, updating crypto-related functions to handle different data engine types, and modifying validation logic for volume creation. The primary goal is to improve volume handling by adding more context-aware operations that can distinguish between different data engine versions.

Changes

File Change Summary
csi/crypto/crypto.go - Added Longhorn API import
- Updated VolumeMapper to accept dataEngine parameter
- Modified OpenVolume, CloseVolume, and ResizeEncryptoDevice to include dataEngine
- Introduced getEncryptVolumeName helper function
- Added logic to append -encrypted suffix for V2 engine volumes
csi/node_server.go - Enhanced logging to include dataEngine
- Updated method calls to crypto.VolumeMapper with dataEngine
- Improved handling of volume data engines in NodeStageVolume, NodeUnstageVolume, and NodeExpandVolume
webhook/resources/volume/validator.go - Removed error check for encrypted volumes with data engine v2
controller/share_manager_controller.go - Updated createPodManifest to accept dataEngine parameter
- Modified command-line arguments for the share manager pod to include --data-engine
- Adjusted call to createPodManifest in createShareManagerPod to pass dataEngine

Sequence Diagram

sequenceDiagram
    participant NodeServer
    participant CryptoModule
    participant Volume

    NodeServer->>CryptoModule: NodeStageVolume(volume, dataEngine)
    CryptoModule->>CryptoModule: VolumeMapper(volume, dataEngine)
    alt DataEngine is V2
        CryptoModule-->>CryptoModule: Append '-encrypted' to volume name
    end
    CryptoModule->>Volume: Open/Stage Volume
    Volume-->>CryptoModule: Volume Staged
    CryptoModule-->>NodeServer: Return Status
Loading

The sequence diagram illustrates the enhanced volume staging process, showing how the data engine type influences volume mapping and staging operations.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b68ae5 and c2e6291.

📒 Files selected for processing (4)
  • controller/share_manager_controller.go (2 hunks)
  • csi/crypto/crypto.go (5 hunks)
  • csi/node_server.go (6 hunks)
  • webhook/resources/volume/validator.go (0 hunks)
💤 Files with no reviewable changes (1)
  • webhook/resources/volume/validator.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (10)
csi/crypto/crypto.go (5)

11-15: LGTM! Well-structured import organization and clear constant definition.

The addition of the -encrypted suffix for V2 volumes helps avoid naming conflicts with the default dm device.

Also applies to: 20-21


76-82: LGTM! Clean implementation of V2 volume name handling.

The function correctly handles the V2 engine case by appending the -encrypted suffix to avoid naming conflicts with the default dm device.


Line range hint 108-127: LGTM! Good improvements to code clarity and consistency.

The changes:

  1. Add clear documentation for the devicePath parameter
  2. Use the getEncryptVolumeName helper for consistent volume name handling
  3. Maintain proper error handling

130-135: LGTM! Well-designed helper function.

Good encapsulation of the volume name logic in a reusable helper function, making the code more maintainable and reducing duplication.


Line range hint 138-167: LGTM! Consistent implementation across functions.

The changes to CloseVolume and ResizeEncryptoDevice maintain consistency with the V2 volume handling approach and properly use the getEncryptVolumeName helper.

csi/node_server.go (3)

491-492: LGTM! Good integration of dataEngine handling.

The changes:

  1. Add helpful logging of the dataEngine
  2. Properly use dataEngine in crypto operations
  3. Maintain consistent error handling

Also applies to: 519-534


632-644: LGTM! Proper cleanup handling for encrypted volumes.

The changes correctly handle volume cleanup with V2 engine support while maintaining proper error handling and logging.


Line range hint 825-853: LGTM! Well-implemented volume expansion support.

The changes properly handle volume expansion with V2 engine support, including proper crypto device handling and error management.

controller/share_manager_controller.go (2)

1414-1419: LGTM! Clean function signature update.

The addition of the dataEngine parameter aligns with the V2 engine support requirements.


1420-1421: LGTM! Proper command argument handling.

The addition of the --data-engine argument ensures the share manager pod has the necessary engine information.

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

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.

@mantissahz mantissahz force-pushed the issue7355 branch 2 times, most recently from 76e1361 to cc5802d Compare January 8, 2025 10:02
@mantissahz mantissahz marked this pull request as ready for review January 9, 2025 02:48
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 (4)
csi/crypto/crypto.go (2)

Line range hint 103-120: Consider consolidating volume name handling

The volume name handling logic is duplicated between OpenVolume and CloseVolume. Consider extracting this to a helper function.

+func getEncryptVolumeName(volume, dataEngine string) string {
+    if dataEngine == string(longhorn.DataEngineTypeV2) {
+        return volume + mapperV2VolumeSuffix
+    }
+    return volume
+}

 func OpenVolume(volume, dataEngine, devicePath, passphrase string) error {
-    encryptVolumeName := volume
-    if dataEngine == string(longhorn.DataEngineTypeV2) {
-        encryptVolumeName = volume + mapperV2VolumeSuffix
-    }
+    encryptVolumeName := getEncryptVolumeName(volume, dataEngine)
     logrus.Infof("Opening device %s with LUKS on %s", devicePath, encryptVolumeName)

128-140: Use consistent error handling

The error handling in CloseVolume could be improved to match the pattern in OpenVolume where errors are logged with context.

 func CloseVolume(volume, dataEngine string) error {
     namespaces := []lhtypes.Namespace{lhtypes.NamespaceMnt, lhtypes.NamespaceIpc}
     nsexec, err := lhns.NewNamespaceExecutor(lhtypes.ProcessNone, lhtypes.HostProcDirectory, namespaces)
     if err != nil {
         return err
     }

-    encryptVolumeName := volume
-    if dataEngine == string(longhorn.DataEngineTypeV2) {
-        encryptVolumeName = volume + mapperV2VolumeSuffix
-    }
+    encryptVolumeName := getEncryptVolumeName(volume, dataEngine)
     logrus.Infof("Closing LUKS device %s", encryptVolumeName)
     _, err = nsexec.LuksClose(encryptVolumeName, lhtypes.LuksTimeout)
+    if err != nil {
+        logrus.WithError(err).Warnf("Failed to close LUKS device %s", encryptVolumeName)
+    }
     return err
 }
webhook/resources/volume/validator.go (1)

170-171: LGTM: Clear validation for V2 volume limitations

The validation correctly prevents the use of backing images with V2 volumes. The error message is clear and descriptive.

However, consider adding a comment explaining why backing images are not supported for V2 volumes to help future maintainers.

 if types.IsDataEngineV2(volume.Spec.DataEngine) {
+    // Backing images are not supported for V2 volumes due to architectural limitations
+    // in the current implementation of the V2 data engine.
     if volume.Spec.BackingImage != "" {
         return werror.NewInvalidError("backing image is not supported for data engine v2", "")
     }
csi/node_server.go (1)

519-519: Consider adding error recovery for crypto operations

The crypto device operations could benefit from additional error recovery mechanisms. If OpenVolume fails, we might want to attempt cleanup.

+func (ns *NodeServer) cleanupCryptoDevice(volumeID, dataEngine string) {
+    if err := crypto.CloseVolume(volumeID, dataEngine); err != nil {
+        ns.log.WithError(err).Warnf("Failed to cleanup crypto device for volume %s", volumeID)
+    }
+}

 if err := crypto.OpenVolume(volumeID, dataEngine, devicePath, passphrase); err != nil {
+    ns.cleanupCryptoDevice(volumeID, dataEngine)
     return nil, status.Error(codes.Internal, err.Error())
 }

Also applies to: 529-529, 534-534

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e11c082 and 6827312.

📒 Files selected for processing (3)
  • csi/crypto/crypto.go (4 hunks)
  • csi/node_server.go (6 hunks)
  • webhook/resources/volume/validator.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (6)
csi/crypto/crypto.go (3)

13-13: LGTM: Clean addition of V2 support

The import of the Longhorn API package and the addition of the V2 volume suffix constant are well-placed and follow the existing pattern.

Also applies to: 18-18


74-77: LGTM: Clear data engine type handling

The VolumeMapper function now correctly handles different data engine types by appending the -encrypted suffix for V2 volumes. The implementation is clean and straightforward.


144-145: Verify error handling in ResizeEncryptoDevice

The function checks if the device is open but doesn't verify if it's a V2 volume before proceeding. Consider adding validation for V2 volume support.

csi/node_server.go (3)

491-492: LGTM: Enhanced logging with data engine info

Good addition of data engine information in the log message for better debugging.


632-644: LGTM: Improved crypto device cleanup logic

The changes properly handle crypto device cleanup based on data engine type and shared access requirements.


Line range hint 825-853: Verify volume expansion support for V2 volumes

The code handles encrypted volume expansion, but we should verify if V2 volumes support this operation.

✅ Verification successful

V2 volumes support encrypted volume expansion

The implementation in csi/node_server.go is engine-agnostic and works for both V1 and V2 volumes. The code only checks if the volume is encrypted and handles the crypto operations accordingly, using the dataEngine parameter only for constructing the appropriate mapper path.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if volume expansion is supported for V2 volumes
# by looking for any restrictions or validations in the codebase.

rg "DataEngineTypeV2.*expansion" 

Length of output: 34


Script:

#!/bin/bash
# Search for V2 volume handling and expansion-related code
rg "DataEngineTypeV2" -A 5 -B 5

# Search for volume expansion validations
rg "NodeExpandVolume|ControllerExpandVolume" -A 10

# Search for data engine type checks during expansion
rg "dataEngine.*expand|expand.*dataEngine" -A 5 -B 5

Length of output: 116265

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: 1

🧹 Nitpick comments (1)
csi/crypto/crypto.go (1)

Line range hint 103-117: Enhance error message clarity

While the implementation is correct, the error message could be more informative for debugging purposes.

Consider including the data engine type in the error message:

-		logrus.WithError(err).Warnf("Failed to open LUKS device %s", devicePath)
+		logrus.WithError(err).Warnf("Failed to open LUKS device %s (engine: %s)", devicePath, dataEngine)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6827312 and b37ffa7.

📒 Files selected for processing (3)
  • csi/crypto/crypto.go (4 hunks)
  • csi/node_server.go (6 hunks)
  • webhook/resources/volume/validator.go (0 hunks)
💤 Files with no reviewable changes (1)
  • webhook/resources/volume/validator.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • csi/node_server.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (5)
csi/crypto/crypto.go (5)

13-13: LGTM! Clean addition of imports and constants

The new import and constant are well-structured and necessary for V2 engine support.

Also applies to: 18-18


124-129: LGTM! Well-structured helper function

Clean implementation that properly encapsulates the volume name logic for different engine types.


132-132: LGTM! Clean adaptation for V2 engine support

The changes maintain consistency with the rest of the implementation while properly supporting V2 volumes.

Also applies to: 139-141


Line range hint 74-156: Verify path handling security

While the implementation looks secure, let's ensure proper path handling throughout the crypto operations.

Let's check for potential path traversal vulnerabilities:

✅ Verification successful

Path handling implementation is secure

The crypto operations use proper path handling throughout:

  • All paths are constructed using path.Join
  • Fixed /dev/mapper prefix with proper validation
  • Standard library path cleaning prevents directory traversal
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for path validation and sanitization
rg -A 5 "path\.(Clean|Join|Base)" csi/
# Check for direct path concatenation
rg -A 5 "\/.*\+" csi/

Length of output: 2744


Script:

#!/bin/bash
# Check for path-related constants in crypto package
rg -A 2 "const.*[Pp]ath|var.*[Pp]ath" csi/crypto/
# Check for mapper-related constants
rg -A 2 "const.*mapper|var.*mapper" csi/crypto/

Length of output: 101


Script:

#!/bin/bash
# Get the complete crypto.go file content
cat csi/crypto/crypto.go

# Search for variable declarations and imports
rg -p "^(var|import|const)" csi/crypto/

Length of output: 7298


74-77: LGTM! Verify volume name validation

The V2 engine path construction logic is clean and consistent. The -encrypted suffix addition is properly handled.

Let's verify that volume names are properly validated upstream to prevent path traversal:

✅ Verification successful

Volume name validation is secure against path traversal

The implementation is safe because:

  • Volume names are validated using strict regex ^[a-z0-9][a-z0-9_.-]+$
  • Path construction uses path.Join with fixed prefix/suffix
  • Validation occurs in webhook before reaching the mapper
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for volume name validation in the codebase
rg -A 5 "func.*[Vv]alidate.*[Vv]olume[Nn]ame" 

Length of output: 47


Script:

#!/bin/bash
# Search for volume name patterns in CRD definitions and validation contexts
rg -g '*.yaml' -g '*.go' -A 5 'volume.*name.*pattern|volume.*name.*validation'

# Search for volume name usage in crypto context
rg -g '*.go' -A 5 'volume.*name.*=|volume.*:=|volume\s+string'

# Search for general name validation patterns
ast-grep --pattern 'func $_(volume string) $$ { $$$ }'

Length of output: 68340


Script:

#!/bin/bash
# Search for ValidateName implementation
rg -g '*.go' -A 10 'func ValidateName'

# Search for volume name validation usage in crypto context
rg -g '*.go' -B 5 -A 5 'util\.ValidateName.*volume'

Length of output: 11211

@mantissahz mantissahz requested review from derekbit and a team January 9, 2025 05:16
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 (2)
csi/crypto/crypto.go (2)

20-20: Add documentation for the V2 volume suffix constant

Please add a comment explaining why V2 volumes require the "-encrypted" suffix and how it prevents naming conflicts with the default dm device.


120-122: Ensure consistent device path usage in logs and operations

The logging message uses devicePath but the actual operation uses encryptVolumeName. Consider updating the log message to include both for better debugging:

-  logrus.Infof("Opening device %s with LUKS on %s", devicePath, encryptVolumeName)
+  logrus.Infof("Opening device %s with LUKS using mapper name %s", devicePath, encryptVolumeName)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b37ffa7 and ebdf655.

📒 Files selected for processing (2)
  • csi/crypto/crypto.go (5 hunks)
  • csi/node_server.go (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • csi/node_server.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (4)
csi/crypto/crypto.go (4)

76-82: Well-documented V2 volume mapping implementation!

The implementation correctly handles the V2 engine case with clear documentation explaining the naming strategy.


129-134: Clean and focused helper function implementation!

The function follows the single responsibility principle and handles the V2 engine case correctly.


Line range hint 150-164: Solid implementation with proper error handling!

The implementation correctly uses the encrypted volume name and includes comprehensive error checking.


Line range hint 76-164: Consider adding input validation for dataEngine parameter

While the implementation is secure, consider adding validation for the dataEngine parameter in public functions to ensure it's not empty and contains a valid engine type. This would prevent potential issues with undefined behavior.

Example validation:

func VolumeMapper(volume, dataEngine string) string {
+       if dataEngine == "" {
+               logrus.Warn("Empty dataEngine parameter, defaulting to non-V2 behavior")
+               return path.Join(mapperFilePathPrefix, volume)
+       }
+       if !types.IsValidDataEngineType(longhorn.DataEngineType(dataEngine)) {
+               logrus.Warnf("Invalid dataEngine type %s, defaulting to non-V2 behavior", dataEngine)
+               return path.Join(mapperFilePathPrefix, volume)
+       }
        if types.IsDataEngineV2(longhorn.DataEngineType(dataEngine)) {

Let's verify if the types package has the necessary validation function:

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)
csi/crypto/crypto.go (1)

Line range hint 108-122: Improve error logging clarity.

The error message uses devicePath while the operation uses encryptVolumeName, which could make debugging harder. Consider including both in the error message.

-        logrus.WithError(err).Warnf("Failed to open LUKS device %s", devicePath)
+        logrus.WithError(err).Warnf("Failed to open LUKS device %s (encrypted name: %s)", devicePath, encryptVolumeName)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebdf655 and 86dd762.

📒 Files selected for processing (3)
  • csi/crypto/crypto.go (5 hunks)
  • csi/node_server.go (6 hunks)
  • webhook/resources/volume/validator.go (0 hunks)
💤 Files with no reviewable changes (1)
  • webhook/resources/volume/validator.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • csi/node_server.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (6)
csi/crypto/crypto.go (6)

11-15: LGTM! Clean import additions and well-defined constant.

The new imports and constant are appropriately added to support V2 data engine functionality.

Also applies to: 20-20


76-82: LGTM! Well-documented V2 volume handling.

The function correctly handles the V2 engine case with clear comments explaining the naming conflict resolution strategy.


129-134: LGTM! Well-designed helper function.

Clean implementation that centralizes the V2 volume naming logic and promotes code reuse.


137-146: LGTM! Consistent implementation.

The changes follow the same pattern as other functions and correctly handle V2 volumes.


Line range hint 150-164: LGTM! Successfully addressed previous review feedback.

The implementation now correctly uses the encrypted volume name, resolving the previous review comment about potential V2 volume issues.


Line range hint 1-1: Consider adding unit tests for V2 volume handling.

The changes look good, but it would be beneficial to add unit tests specifically covering the V2 volume name handling scenarios.

Would you like me to help generate unit tests for the V2 volume handling cases?

🧰 Tools
🪛 Gitleaks (8.21.2)

22-22: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

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 (2)
csi/crypto/crypto.go (2)

20-20: Add documentation for the new constant.

Please add a comment explaining the purpose of mapperV2VolumeSuffix and why it's needed for V2 volumes.


Line range hint 108-127: Consider improving error handling for LUKS operations.

While the function correctly handles V2 volumes, the error logging could be more descriptive:

-    logrus.WithError(err).Warnf("Failed to open LUKS device %s", attachingVolumeHostPath)
+    logrus.WithError(err).Warnf("Failed to open LUKS device %s with name %s", attachingVolumeHostPath, encryptVolumeName)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0542357 and 3c4c7ea.

📒 Files selected for processing (3)
  • controller/share_manager_controller.go (2 hunks)
  • csi/crypto/crypto.go (5 hunks)
  • csi/node_server.go (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • csi/node_server.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (4)
csi/crypto/crypto.go (3)

76-82: LGTM! Well-structured V2 volume handling.

The function correctly handles the naming conflict between V2 volumes and their encrypted counterparts by appending the -encrypted suffix. The comment explains the rationale clearly.


130-135: LGTM! Clean helper function implementation.

The getEncryptVolumeName helper function is well-implemented and encapsulates the V2 volume name logic cleanly.


164-165: Verify error handling in ResizeEncryptoDevice.

The function uses the correct encrypted volume name, but ensure that all error paths are properly handled in the upstream code.

Run this script to check for potential error handling issues:

✅ Verification successful

Error handling in ResizeEncryptoDevice is properly implemented

All error paths are properly handled and propagated:

  • Device open check errors
  • Namespace executor creation errors
  • LUKS resize operation errors
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check error handling patterns in resize operations
rg -A 5 "ResizeEncryptoDevice.*error" 

Length of output: 435


Script:

#!/bin/bash
# Get complete implementation of ResizeEncryptoDevice
ast-grep --pattern 'func ResizeEncryptoDevice($$$) error {
  $$$
}'

# Check LuksResize error handling patterns
rg -B 2 -A 2 "LuksResize.*err.*"

Length of output: 1764

controller/share_manager_controller.go (1)

1414-1420: LGTM! Clean integration of data engine parameter.

The function signature update and argument passing are implemented correctly. The dataEngine parameter is properly propagated to the share manager daemon.

derekbit
derekbit previously approved these changes Jan 10, 2025
Copy link
Member

@derekbit derekbit left a comment

Choose a reason for hiding this comment

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

In general, LGTM.

One minor issue is the convention of the cli option naming

@derekbit
Copy link
Member

@mergify backport v1.8.x

Copy link

mergify bot commented Jan 11, 2025

backport v1.8.x

✅ Backports have been created

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)
csi/crypto/crypto.go (1)

76-82: Consider adding error handling for invalid dataEngine

While the code handles V2 engine correctly, it might be worth adding validation for the dataEngine parameter to handle invalid values gracefully.

 func VolumeMapper(volume, dataEngine string) string {
+    if dataEngine == "" {
+        logrus.Warnf("Empty dataEngine provided for volume %v, defaulting to non-V2 path", volume)
+        return path.Join(mapperFilePathPrefix, volume)
+    }
     if types.IsDataEngineV2(longhorn.DataEngineType(dataEngine)) {
         // v2 volume will use a dm device as default to control IO path when attaching.
         // This dm device will be created with the same name as the volume name.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c4c7ea and 8b68ae5.

📒 Files selected for processing (4)
  • controller/share_manager_controller.go (2 hunks)
  • csi/crypto/crypto.go (5 hunks)
  • csi/node_server.go (6 hunks)
  • webhook/resources/volume/validator.go (0 hunks)
💤 Files with no reviewable changes (1)
  • webhook/resources/volume/validator.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • csi/node_server.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build binaries
  • GitHub Check: Summary
🔇 Additional comments (8)
csi/crypto/crypto.go (6)

11-15: LGTM: Required imports added for V2 engine support

The new imports are necessary for handling the data engine types and Longhorn API.


20-20: LGTM: Clear constant definition

The mapperV2VolumeSuffix constant is well-defined and its purpose is clear from the context.


Line range hint 108-127: LGTM: Improved OpenVolume function with clear documentation

The function has been updated correctly to handle V2 volumes and includes clear documentation about the devicePath parameter.


130-135: LGTM: Well-structured helper function

The getEncryptVolumeName helper function is well-designed and encapsulates the V2 volume naming logic.


138-149: LGTM: CloseVolume function updated consistently

The function has been updated to use the new helper function for encrypted volume names.


Line range hint 151-166: LGTM: ResizeEncryptoDevice function updated consistently

The function has been updated to handle V2 volumes correctly.

controller/share_manager_controller.go (2)

1414-1419: LGTM: Clear function signature update

The function signature has been updated to include the dataEngine parameter while maintaining good organization of parameters.


1420-1420: LGTM: Data engine argument added correctly

The data engine information is properly passed to the share manager daemon.

ref: longhorn/longhorn 7355

Signed-off-by: James Lu <james.lu@suse.com>
when opening and closing a luks2 format device.

ref: longhorn/longhorn 7355

Signed-off-by: James Lu <james.lu@suse.com>
ref: longhorn/longhorn 7355

Signed-off-by: James Lu <james.lu@suse.com>
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.

3 participants