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(wren-ui): Added FE Support for MySQL SSL Connection #1072

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

ongdisheng
Copy link
Contributor

@ongdisheng ongdisheng commented Dec 29, 2024

Description

This PR introduces SSL connection handling for MySQL data source by adding a Select menu and an Upload component for Certificate Authority (CA) Certificate in the setup form. Meanwhile, existing logic has also been modified to include these fields when passing connection info to the engine. Fix #886

UI Screenshot

  1. When a client who requires SSL uploads the necessary CA certificate (VERIFY_CA), the connection succeeds:
  1. When a client who requires SSL attempts to connect without uploading CA certificate, the connection fails:

Summary by CodeRabbit

  • New Features

    • Added SSL configuration options for MySQL connections.
    • Introduced SSL mode selection (DISABLE, REQUIRE, VERIFY_CA).
    • Implemented SSL certificate upload functionality for MySQL data sources.
  • Improvements

    • Enhanced security configuration for database connections.
    • Added more granular SSL certificate handling in the UI.
  • Documentation

    • Updated error messages for SSL certificate requirements.

Copy link
Contributor

coderabbitai bot commented Dec 29, 2024

Walkthrough

The pull request introduces comprehensive SSL configuration support for MySQL data sources across the Wren UI application. The changes span multiple files, adding new enumerations for SSL modes, updating connection information interfaces, and enhancing the MySQL properties component to support SSL certificate uploads. The modifications enable users to configure different SSL modes (DISABLE, REQUIRE, VERIFY_CA) and upload SSL certificates when needed.

Changes

File Change Summary
wren-ui/src/apollo/server/types/sslMode.ts Added SSLMode enum with DISABLE, REQUIRE, and VERIFY_CA modes
wren-ui/src/utils/enum/sslMode.ts Added SSL_MODE enum with matching SSL mode constants
wren-ui/src/apollo/server/repositories/projectRepository.ts Extended MYSQL_CONNECTION_INFO interface with sslMode and optional sslCA
wren-ui/src/apollo/server/dataSource.ts Updated MySQL data source to handle SSL configuration and sensitive properties
wren-ui/src/components/pages/setup/dataSources/MySQLProperties.tsx Added SSL mode selection and certificate upload functionality
wren-ui/src/utils/error/dictionary.ts Added SSL certificate required error message

Assessment against linked issues

Objective Addressed Explanation
Add SSL configuration for MySQL
Support different SSL modes
Enable SSL certificate upload

Poem

🐰 A rabbit's tale of MySQL's SSL dance,
Certificates uploaded with careful glance,
Modes of security, VERIFY and REQUIRE,
Connections now safer, no need to perspire!
SSL magic sprinkled with coding delight 🔒


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ea9289 and 226eee2.

📒 Files selected for processing (1)
  • wren-ui/src/apollo/server/repositories/projectRepository.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • wren-ui/src/apollo/server/repositories/projectRepository.ts

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

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.

@ongdisheng
Copy link
Contributor Author

ongdisheng commented Dec 29, 2024

Hi, I’m exploring ways to allow users to select a file from their local system and display its absolute file path, instead of typing the path into the input box themselves. I’ve looked into the Ant Design Upload component, but it appears to only display the file name due to browser security restrictions. I’d greatly appreciate any suggestions or alternative approaches. Thank you! 😊

@ongdisheng ongdisheng closed this Dec 31, 2024
@wwwy3y3
Copy link
Member

wwwy3y3 commented Dec 31, 2024

hi @ongdisheng any reason you close this PR ? looks like a good contribution to me!

I'm thinking we should provide some options for users to pick instead of a Use SSL toggle. Just some quick thoughts:

SSL Mode
ref: https://dev.mysql.com/doc/refman/8.4/en/connection-options.html#option_general_ssl-mode

  • DISABLED: Establish an unencrypted connection.
  • REQUIRED: Establish an encrypted connection if the server supports encrypted connections. The connection attempt fails if an encrypted connection cannot be established.
  • VERIFY_CA: Like REQUIRED, but additionally verify the server Certificate Authority (CA) certificate against the configured CA certificates. The connection attempt fails if no valid matching CA certificates are found.

If users choose VERIFY_CA, we then show the upload inputs for them to upload CA.

cc @fredalai @andreashimin @onlyjackfrost chime in if you guys want.

I think you might want to work on some implementation on backend as well.

@ongdisheng ongdisheng reopened this Dec 31, 2024
@ongdisheng
Copy link
Contributor Author

Hi @wwwy3y3, thank you for the feedback! I closed the PR earlier as I felt the current implementation wasn't quite up to the mark. I’ve reopened it as a draft and will continue working on it 😊.

@ongdisheng ongdisheng marked this pull request as ready for review January 3, 2025 15:02
@ongdisheng ongdisheng changed the title feat(wren-ui): Added support for MySQL SSL connection feat(wren-ui): Added FE Support for MySQL SSL Connection Jan 3, 2025
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 (7)
wren-ui/src/apollo/server/types/index.ts (1)

7-7: Leverage strongly-typed imports for maintainability.

Exporting everything from ./sslMode is a valid approach for quick bundling. However, if the file grows, consider explicitly re-exporting only what's needed to maintain clarity and ensure only intended types or utilities are exposed.

wren-ui/src/utils/error/dictionary.ts (1)

52-54: Provide additional clarity for SSL certificate requirements.

The new SSL_CERT.REQUIRED message is straightforward. To further assist users, consider including details on valid file formats or maximum file sizes (if applicable). This can reduce confusion about acceptable certificate files during upload.

wren-ui/src/components/pages/setup/dataSources/MySQLProperties.tsx (2)

13-63: Consider improving file upload error handling and applying optional chaining.
The UploadSSL component is well-structured, but there are points you might refine:

  1. Potential file-read failures: The readFileContent function does not handle errors. Consider adding reader.onerror to handle read failures gracefully.
  2. Optional chaining: Instead of using onChange && onChange(...) at lines 41 and 49, you can use optional chaining (onChange?.(...)) in TypeScript/modern JS for cleaner code.
  3. File size or type checks: If large or invalid files are a concern, consider validating them in the onUploadChange event.

Below is a suggested diff snippet for optional chaining:

-  onChange && onChange(fileContent);
+  onChange?.(fileContent);
-  onChange && onChange(undefined);
+  onChange?.(undefined);
🧰 Tools
🪛 Biome (1.9.4)

[error] 41-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 49-49: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


149-176: Enhance user guidance and default behaviors for SSL mode.

  1. User feedback: When users select a mode other than DISABLE, consider giving tooltips or descriptions to clarify what REQUIRE vs. VERIFY_CA does.
  2. Conditional display: The conditional rendering for sslCA is correct but ensure it matches any server constraints (e.g., do you also need a client certificate or key?).
  3. Preview uploaded file: If needed, allow users to confirm they uploaded the correct SSL certificate by showing a truncated snippet of file content or the file name.

Would you like help implementing additional user feedback or advanced upload validations?

wren-ui/src/apollo/server/dataSource.ts (1)

111-125: Verify base64 encoding and SSL property usage.
This block correctly includes sslMode and optionally base64-encodes sslCA before returning. A few considerations:

  • Condition checks: If you add more SSL-related fields (e.g., sslKey or sslCert) in the future, ensure consistent logic for each field.
  • Validate usage: Confirm that downstream code expects a base64 string for sslCA.
wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts (2)

48-49: Clarify SSL usage in test data.
You’ve specified sslMode: SSLMode.VERIFY_CA and sslCA: 'encrypted-certificate-string'. Make sure tests also cover other modes for completeness (e.g., SSLMode.DISABLE, SSLMode.REQUIRE).


191-202: Check for consistent property naming and transformations.
Here, you map sslCA to sslCA (base64-encoded). For uniformity, confirm that other SSL props (e.g., sslKey) follow a similar approach to keep your code symmetrical.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8933479 and 1ea9289.

📒 Files selected for processing (9)
  • wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts (3 hunks)
  • wren-ui/src/apollo/server/dataSource.ts (1 hunks)
  • wren-ui/src/apollo/server/repositories/projectRepository.ts (1 hunks)
  • wren-ui/src/apollo/server/types/index.ts (1 hunks)
  • wren-ui/src/apollo/server/types/sslMode.ts (1 hunks)
  • wren-ui/src/components/pages/setup/dataSources/MySQLProperties.tsx (2 hunks)
  • wren-ui/src/utils/enum/index.ts (1 hunks)
  • wren-ui/src/utils/enum/sslMode.ts (1 hunks)
  • wren-ui/src/utils/error/dictionary.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • wren-ui/src/apollo/server/types/sslMode.ts
  • wren-ui/src/utils/enum/sslMode.ts
🧰 Additional context used
🪛 Biome (1.9.4)
wren-ui/src/components/pages/setup/dataSources/MySQLProperties.tsx

[error] 41-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 49-49: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (6)
wren-ui/src/utils/enum/index.ts (1)

10-10: Centralize enum usage.

Similarly, re-exporting all from sslMode makes the enum easily accessible throughout the codebase. As the codebase evolves, ensure repeated or conflicting enum definitions are consolidated to maintain consistency.

wren-ui/src/components/pages/setup/dataSources/MySQLProperties.tsx (2)

1-6: Ensure consistent import usage and check for unused imports.
These imports look fine for the newly introduced features, such as Upload and Ant Design icons. Verify that each imported item (e.g., Button, Select) is actually used in this file.


68-69: Ensure SSL mode state updates are fully validated.
The sslMode state and onSSLModeChange function are straightforward. Double-check that all form validations (e.g., required certificates on certain modes) are handled or triggered consistently in your parent form logic.

wren-ui/src/apollo/server/dataSource.ts (1)

105-105: Add an extra safeguard for sensitive properties.
By adding sslCA to sensitiveProps, you ensure that it will be encrypted at rest. Confirm that your logs or error outputs do not inadvertently display sslCA values in plaintext.

wren-ui/src/apollo/server/adaptors/tests/ibisAdaptor.test.ts (2)

9-9: Consolidate or differentiate imports as needed.
The new SSLMode import is straightforward. If multiple modules import the same enumerations, ensure they reference a shared location for consistency.


181-184: Consider verifying decryption fails gracefully if sslCA is invalid.
Currently, you mock decryption to always succeed with an sslCA string. Test how your code behaves if decryption fails or the certificate data is malformed.

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.

MySQL SSL Connection Requirement for Data Source Configuration
2 participants