Skip to content

[BUGFIX] use client config for tls dialer #2938

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 2 commits into
base: main
Choose a base branch
from

Conversation

kpango
Copy link
Collaborator

@kpango kpango commented Apr 14, 2025

Description

Related Issue

Versions

  • Vald Version: v1.7.16
  • Go Version: v1.24.2
  • Rust Version: v1.86.0
  • Docker Version: v28.0.4
  • Kubernetes Version: v1.32.3
  • Helm Version: v3.17.2
  • NGT Version: v2.3.14
  • Faiss Version: v1.10.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

  • Chores
    • Updated secure connection setups across multiple integrations to use a refined TLS client configuration method. These improvements modernize underlying security practices and ensure consistency without changing existing behaviors.
    • Simplified TLS binding conditions in the GRPCClient, enhancing configuration flexibility while maintaining security defaults.
    • Enhanced TLS client configuration by allowing the use of a certificate file when a CA file is not available, improving flexibility and robustness.

Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

📝 Walkthrough

Walkthrough

The pull request updates the TLS configuration instantiation in several internal configuration files. In each Opts method of the Cassandra, MySQL, Net, and Redis structs, the call to create a TLS configuration has been changed from using tls.New(...) to using tls.NewClientConfig(...). The parameters passed to the TLS configuration remain the same, and the error handling logic is unchanged. Additionally, the Bind method in the GRPCClient struct has been simplified by reducing the conditional checks for TLS configuration, allowing for a simpler configuration process. Furthermore, the NewClientConfig function in the TLS package has been enhanced to handle certificate files more flexibly.

Changes

File(s) Change Summary
internal/config/cassandra.go, internal/config/mysql.go, internal/config/net.go, internal/config/redis.go Replaced calls to tls.New(...) with tls.NewClientConfig(...) in the Opts methods. Parameters, certificate/key/CA paths, and error handling remain unchanged.
internal/config/grpc.go Simplified conditional checks in the Bind method of the GRPCClient struct regarding TLS configuration, reducing the conditions for invoking g.TLS.Bind().
internal/tls/tls.go Enhanced NewClientConfig to handle cases where a certificate file is specified, and improved error handling in NewX509CertPool to check for nil content before appending.

Sequence Diagram(s)

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@vdaas-ci
Copy link
Collaborator

[WARNING:INTCFG] Changes in interal/config may require you to change Helm charts. Please check.

Copy link

cloudflare-workers-and-pages bot commented Apr 14, 2025

Deploying vald with  Cloudflare Pages  Cloudflare Pages

Latest commit: e37f4d5
Status: ✅  Deploy successful!
Preview URL: https://fda0de9f.vald.pages.dev
Branch Preview URL: https://bugfix-internal-tls-use-clie.vald.pages.dev

View logs

@vdaas-ci
Copy link
Collaborator

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 14, 2025
Copy link

codecov bot commented Apr 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 17.79%. Comparing base (96661e0) to head (e37f4d5).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2938   +/-   ##
=======================================
  Coverage   17.79%   17.79%           
=======================================
  Files         124      124           
  Lines       14208    14208           
=======================================
  Hits         2528     2528           
  Misses      11388    11388           
  Partials      292      292           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kpango kpango force-pushed the bugfix/internal-tls/use-client-config-for-dialer branch from 5c904a3 to c960b5f Compare April 14, 2025 08:59
coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 14, 2025
Signed-off-by: kpango <kpango@vdaas.org>
@kpango kpango force-pushed the bugfix/internal-tls/use-client-config-for-dialer branch from c960b5f to 4a7b41c Compare April 14, 2025 09:20
This commit fixes the style issues introduced in 4a7b41c according to the output
from Gofumpt and Prettier.

Details: #2938
Copy link
Contributor

@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)
internal/tls/tls.go (1)

124-124: Added defensive nil check for certificate content

The additional check for c != nil provides an extra safety layer, although there's already a check on line 116 that returns if c == nil.

Since there's already an error check at line 116 that returns if c == nil, the redundant check could be removed to simplify the code:

-	if c != nil && !pool.AppendCertsFromPEM(c) {
+	if !pool.AppendCertsFromPEM(c) {
 		err = errors.ErrCertificationFailed
 	}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c960b5f and e37f4d5.

📒 Files selected for processing (6)
  • internal/config/cassandra.go (1 hunks)
  • internal/config/grpc.go (1 hunks)
  • internal/config/mysql.go (1 hunks)
  • internal/config/net.go (1 hunks)
  • internal/config/redis.go (1 hunks)
  • internal/tls/tls.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • internal/config/net.go
  • internal/config/redis.go
  • internal/config/cassandra.go
  • internal/config/grpc.go
  • internal/config/mysql.go
⏰ Context from checks skipped due to timeout of 90000ms (59)
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: runner / go build
  • GitHub Check: CodeQL Analyze (rust)
  • GitHub Check: build / build
  • GitHub Check: build / build
  • GitHub Check: build / build
🔇 Additional comments (1)
internal/tls/tls.go (1)

81-110:

✅ Verification successful

Verified that the client config function properly handles certificates

The NewClientConfig function now handles both CA certificates and client certificates with proper error checking. This change aligns with the PR objective to fix TLS dialer configuration by using proper client configuration.

Let's check how this function is being used elsewhere in the codebase:


🏁 Script executed:

#!/bin/bash
# Check how the NewClientConfig function is being used in the codebase
rg "tls\.NewClientConfig" --type go

Length of output: 1186


Final Verification: The NewClientConfig function correctly handles both CA and client certificates as intended.

The updated implementation properly checks for errors and chooses between CA certificate and client certificate configuration. Additionally, our search confirms that the function is invoked in multiple parts of the codebase (e.g., in internal/net/dialer_test.go and various configuration files), and there are no inconsistencies with its usage.

Comment on lines +93 to +98
} else if c.cert != "" {
pool, err := NewX509CertPool(c.cert)
if err != nil {
return nil, err
}
c.cfg.RootCAs = pool
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhanced flexibility for TLS client configuration

This change allows using the certificate file as a root CA source when a specific CA file isn't provided. This is a good improvement for scenarios where self-signed certificates are used or when the same certificate serves multiple purposes.

Consider adding a comment explaining this fallback behavior to improve code maintainability:

 	} else if c.cert != "" {
+		// Fallback to using the cert file for RootCAs when CA file is not provided
 		pool, err := NewX509CertPool(c.cert)
 		if err != nil {
 			return nil, err
 		}
 		c.cfg.RootCAs = pool
 	}
📝 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
} else if c.cert != "" {
pool, err := NewX509CertPool(c.cert)
if err != nil {
return nil, err
}
c.cfg.RootCAs = pool
} else if c.cert != "" {
// Fallback to using the cert file for RootCAs when CA file is not provided
pool, err := NewX509CertPool(c.cert)
if err != nil {
return nil, err
}
c.cfg.RootCAs = pool
}

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.

2 participants