Skip to content

Fixing KMIP issues#1649

Merged
jackyalbo merged 1 commit intonoobaa:masterfrom
jackyalbo:jacky-rotate-kmip
Jul 7, 2025
Merged

Fixing KMIP issues#1649
jackyalbo merged 1 commit intonoobaa:masterfrom
jackyalbo:jacky-rotate-kmip

Conversation

@jackyalbo
Copy link
Contributor

@jackyalbo jackyalbo commented Jul 6, 2025

Explain the changes

  1. As some KMIP doesn't support any CryptographicLength, we will revert to saving only one key in KMIP. Once we will want to support rotating secrets we will need to find a better solution

Issues: Fixed #xxx / Gap #xxx

Testing Instructions:

  • Doc added/updated
  • Tests added

Summary by CodeRabbit

  • New Features

    • Enhanced secret management to support an active root key ID alongside the secret.
    • Enforced a fixed cryptographic key length of 256 bits for improved consistency.
  • Bug Fixes

    • Improved error messages to include more detailed information when operations fail.
  • Refactor

    • Simplified secret handling by removing special encoding and decoding logic for certain drivers.

@coderabbitai
Copy link

coderabbitai bot commented Jul 6, 2025

Walkthrough

A new constant for active key ID management was added to the KMIP client configuration. The KMIP secret storage logic was updated to support active root key IDs, enforce a fixed cryptographic length, and improve error handling and logging. Special handling for the "KMIPSecret" driver was removed from the versioned secret logic.

Changes

File(s) Change Summary
pkg/util/kms/kms_kmip.go Added NewActiveKeyID constant to KMIP client config options.
pkg/util/kms/kms_kmip_storage.go Introduced constant for cryptographic length, enhanced error reporting, added logic for active root key ID management, enforced fixed key length, and improved logging in secret storage methods.
pkg/util/kms/kms_version.go Removed all special handling for "KMIPSecret" driver in versioned secret logic, including decoding and marshaling; cleaned up unused imports.

Suggested labels

size/L

Suggested reviewers

  • liranmauda
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.

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.

As some KMIP doesn't support any CryptographicLength, we will revert to saving only one key in KMIP. Once we will want to support rotating secrets we will need to find a better solution

Signed-off-by: jackyalbo <jacky.albo@gmail.com>
@jackyalbo jackyalbo force-pushed the jacky-rotate-kmip branch from 6e79344 to 5b3aa9e Compare July 7, 2025 10:05
@jackyalbo jackyalbo marked this pull request as ready for review July 7, 2025 10:05
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)
pkg/util/kms/kms_kmip_storage.go (1)

331-337: Consider the architectural implications of partial rotation support.

While the PR description mentions reverting to single key storage, the code still maintains rotation-related structures (active key ID, map returns). If rotation support is not currently needed, consider whether a cleaner approach would be to fully remove rotation logic until a proper solution is designed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dc12226 and 5b3aa9e.

📒 Files selected for processing (3)
  • pkg/util/kms/kms_kmip.go (1 hunks)
  • pkg/util/kms/kms_kmip_storage.go (8 hunks)
  • pkg/util/kms/kms_version.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
pkg/util/kms/kms_version.go (1)
Learnt from: Neon-White
PR: noobaa/noobaa-operator#1636
File: pkg/backingstore/reconciler.go:718-724
Timestamp: 2025-06-25T15:28:44.080Z
Learning: In pkg/backingstore/reconciler.go, the switch refactor for S3Compatible.SignatureVersion and IBMCos.SignatureVersion maintains the same behavior as the original if-else if logic - when SignatureVersion is empty or unspecified, conn.AuthMethod is left unset. There was no default to V4 in the original code.
🧬 Code Graph Analysis (1)
pkg/util/kms/kms_kmip_storage.go (2)
pkg/util/kms/kms_kmip.go (2)
  • NewKMIPUniqueID (17-17)
  • NewActiveKeyID (18-18)
pkg/util/kms/kms_version.go (1)
  • ActiveRootKey (96-96)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: run-kms-kmip-test
  • GitHub Check: run-kms-key-rotate-test
  • GitHub Check: run-azure-vault-test
  • GitHub Check: cnpg-deployment-test
  • GitHub Check: run-operator-tests
  • GitHub Check: run-kms-tls-token-test
  • GitHub Check: run-cli-tests
  • GitHub Check: run-admission-test
  • GitHub Check: run-kms-dev-test
  • GitHub Check: run-hac-test
  • GitHub Check: golangci-lint
🔇 Additional comments (9)
pkg/util/kms/kms_kmip.go (1)

18-18: LGTM!

The new constant follows the established naming pattern and is properly integrated with the KMIP secret storage logic.

pkg/util/kms/kms_version.go (2)

106-121: LGTM! Good refactoring to centralize KMIP-specific logic.

The removal of special KMIP handling from the generic version interface is a clean architectural improvement. The encoding/decoding logic is now properly encapsulated within the KMIP storage implementation.


141-141: LGTM!

Consistent with the refactoring approach - the conversion to interface map is now straightforward without special encoding.

pkg/util/kms/kms_kmip_storage.go (6)

38-40: LGTM! Good practice to define the cryptographic length as a constant.

Using a constant for the 256-bit key length improves maintainability and aligns with AES-256 standards.


213-213: Good improvement to error reporting.

Including the reason and message from KMIP responses will significantly help with debugging failed operations.


266-275: Verify the handling of missing active key ID.

The code correctly handles the case when NewActiveKeyID is missing from the secret. However, ensure that this error condition is properly handled by callers, especially during initial setup or migration scenarios.


318-320: Good addition of cryptographic length validation.

This validation ensures that retrieved keys match the expected 256-bit length, preventing potential security issues from malformed keys.


372-372: Good fix for the cryptographic length issue.

Using the fixed constant instead of calculating from byte length addresses the main KMIP compatibility issue mentioned in the PR description.


272-272: Good security improvement in logging.

Logging only the secret name instead of the entire secret object prevents potential exposure of sensitive data in logs.

Also applies to: 280-280

Comment on lines +350 to +351
activeKey := plainText[ActiveRootKey].(string)
value := plainText[activeKey].(string)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add validation for required keys in the input map.

The code assumes ActiveRootKey exists in plainText and that its value is a valid key name that also exists in the map. Add validation to prevent potential panics.

Apply this diff to add validation:

-activeKey := plainText[ActiveRootKey].(string)
-value := plainText[activeKey].(string)
+activeKeyInterface, exists := plainText[ActiveRootKey]
+if !exists {
+    return secrets.NoVersion, fmt.Errorf("ActiveRootKey not found in plainText")
+}
+activeKey, ok := activeKeyInterface.(string)
+if !ok {
+    return secrets.NoVersion, fmt.Errorf("ActiveRootKey must be a string")
+}
+valueInterface, exists := plainText[activeKey]
+if !exists {
+    return secrets.NoVersion, fmt.Errorf("Active key %s not found in plainText", activeKey)
+}
+value, ok := valueInterface.(string)
+if !ok {
+    return secrets.NoVersion, fmt.Errorf("Secret value must be a string")
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
activeKey := plainText[ActiveRootKey].(string)
value := plainText[activeKey].(string)
- activeKey := plainText[ActiveRootKey].(string)
- value := plainText[activeKey].(string)
+ activeKeyInterface, exists := plainText[ActiveRootKey]
+ if !exists {
+ return secrets.NoVersion, fmt.Errorf("ActiveRootKey not found in plainText")
+ }
+ activeKey, ok := activeKeyInterface.(string)
+ if !ok {
+ return secrets.NoVersion, fmt.Errorf("ActiveRootKey must be a string")
+ }
+ valueInterface, exists := plainText[activeKey]
+ if !exists {
+ return secrets.NoVersion, fmt.Errorf("Active key %s not found in plainText", activeKey)
+ }
+ value, ok := valueInterface.(string)
+ if !ok {
+ return secrets.NoVersion, fmt.Errorf("Secret value must be a string")
+ }
🤖 Prompt for AI Agents
In pkg/util/kms/kms_kmip_storage.go around lines 350 to 351, the code assumes
the keys ActiveRootKey and the derived activeKey exist in the plainText map
without validation, which can cause panics. Add checks to verify that
ActiveRootKey exists in plainText and that its value is a string key present in
plainText before accessing them. If either key is missing or invalid, handle the
error gracefully to prevent panics.

@jackyalbo jackyalbo merged commit e0a3efa into noobaa:master Jul 7, 2025
16 of 17 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jul 15, 2025
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