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

[Enhancement] Enforce SSL connection from the client when SSL is enabled on the server #56176

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

Conversation

rstyp
Copy link

@rstyp rstyp commented Feb 21, 2025

Why I'm doing:

Even when SSL is enabled on server, JDBC clients can still connect without SSL by default, as the server allows connections with or without SSL.

What I'm doing:

Introducing a new boolean config flag to enforce secure connections from clients. When flag is set to true, If clients are connecting without SSL, server refuses client connections

Fixes #56175

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.4
    • 3.3
    • 3.2
    • 3.1
    • 3.0

@rstyp rstyp requested review from a team as code owners February 21, 2025 19:21
@CLAassistant
Copy link

CLAassistant commented Feb 21, 2025

CLA assistant check
All committers have signed the CLA.

* Allow only encrypted connections from clients
**/
@ConfField
public static boolean require_secure_transport = false;
Copy link
Author

Choose a reason for hiding this comment

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

Similar config as in MySql server

@@ -106,6 +106,7 @@ public enum ErrorCode {
ERR_NO_SUCH_QUERY(1365, new byte[] {'4', '2', '0', '0', '0'}, "Unknown query id: %s"),

ERR_CANNOT_USER(1396, new byte[] {'H', 'Y', '0', '0', '0'}, "Operation %s failed for %s"),
ERR_SECURE_TRANSPORT_REQUIRED(1403, new byte[] {'0', '8', '0', '0', '4'}, "Server rejected the insecure connection"),
Copy link

@stevenzwu stevenzwu Feb 21, 2025

Choose a reason for hiding this comment

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

how did we choose the error code 1403?

From the comment in this class, it seems that we should find the corresponding error code for MySQL server/protocol.

// Try our best to compatible with MySQL's

With that, should this be the error code?

Error number: 3159; Symbol: [ER_SECURE_TRANSPORT_REQUIRED](https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html#error_er_secure_transport_required); SQLSTATE: HY000

Message: Connections using insecure transport are prohibited while --require_secure_transport=ON.

With the [require_secure_transport](https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_require_secure_transport) system variable, clients can connect only using secure transports. Qualifying connections are those using SSL, a Unix socket file, or shared memory.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, @stevenzwu, for checking. I’ll revisit the error code.

@@ -20,6 +20,7 @@ public enum NegotiateState {
READ_AUTH_SWITCH_PKG_FAILED("read auth switch package failed"),
ENABLE_SSL_FAILED("enable ssl failed"),
READ_SSL_AUTH_PKG_FAILED("read ssl auth package failed"),
SERVER_REJECTED_INSECURE_CONNECTION("server rejected the insecure connection"),
Copy link

@stevenzwu stevenzwu Feb 21, 2025

Choose a reason for hiding this comment

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

nit: maybe remove server for consistency with other state enum msg, as the state is used by server. so it is implicitly assumed

INSECURE_CONNECTION_REJECTED(" insecure connection rejected"),

@@ -139,6 +139,13 @@ public static NegotiateResult negotiate(ConnectContext context) throws IOExcepti
return new NegotiateResult(null, NegotiateState.READ_FIRST_AUTH_PKG_FAILED);
}

if (Config.require_secure_transport && !authPacket.isSSLConnRequest()) {
LOG.debug("server refused insecure client connection");

Choose a reason for hiding this comment

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

this should be warn

@rstyp rstyp changed the title Enforce SSL connection from the client when SSL is enabled on the server [Enhancement] Enforce SSL connection from the client when SSL is enabled on the server Feb 21, 2025
@@ -139,6 +139,13 @@ public static NegotiateResult negotiate(ConnectContext context) throws IOExcepti
return new NegotiateResult(null, NegotiateState.READ_FIRST_AUTH_PKG_FAILED);
}

if (Config.require_secure_transport && !authPacket.isSSLConnRequest()) {
LOG.warn("Copy string literal text to the clipboard");

Choose a reason for hiding this comment

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

error msg should be updated

Copy link

@stevenzwu stevenzwu left a comment

Choose a reason for hiding this comment

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

left one nit comment for log msg. otherwise, LGTM

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
D Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 4 / 8 (50.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/mysql/MysqlProto.java 1 5 20.00% [143, 144, 145, 146]
🔵 com/starrocks/common/Config.java 1 1 100.00% []
🔵 com/starrocks/mysql/NegotiateState.java 1 1 100.00% []
🔵 com/starrocks/common/ErrorCode.java 1 1 100.00% []

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@gengjun-git gengjun-git self-assigned this Feb 25, 2025
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.

Enforce SSL connection from the client when SSL is enabled on the server
5 participants