Skip to content

*: move config file option require_secure_transport to sysvar#34261

Merged
ti-chi-bot merged 11 commits intopingcap:masterfrom
Alkaagr81:require_secure_transport
May 17, 2022
Merged

*: move config file option require_secure_transport to sysvar#34261
ti-chi-bot merged 11 commits intopingcap:masterfrom
Alkaagr81:require_secure_transport

Conversation

@Alkaagr81
Copy link
Collaborator

@Alkaagr81 Alkaagr81 commented Apr 26, 2022

What problem does this PR solve?

Issue Number: ref #33769

Fixes #26065

Problem Summary:

The option require-secure-transport has historically been a config option. But based on requirements from cloud & PM it should instead be a sysvar.

What is changed and how it works?

Remove them from the config list and add them to global sysvars.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility
    Previously, if TLS certificates were provided by in configuration they were not validated unless require-secure-transport was set. They are now always validated, and the tidb-server will refuse to start if they are invalid. This helps prevent a misconfiguration where TLS downgrades could occur, and duplicates Fail server startup when opening TLS context fails #26065 (it does not affect users who specify no TLS certs).

This might be a bit confusing during upgrade for users who have previously set require-secure-transport (most users haven't). It needs to be documented in the release notes that it has been replaced with the system variable require_secure_transport.

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

The TiDB configuration file option `require-secure-transport` and command line flag have been replaced by the system variable `require_secure_transport`. This change makes it easier to modify this setting on a cluster wide basis.

@Alkaagr81 Alkaagr81 requested a review from a team as a code owner April 26, 2022 18:00
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 26, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • dveeden
  • morgo

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Details

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 26, 2022
@Alkaagr81
Copy link
Collaborator Author

Alkaagr81 commented Apr 26, 2022

Please review @morgo

ts.runTestLoadDataForListColumnPartition2(t)
}

func TestInvalidTLS(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

to check for the invalid server credential

@sre-bot
Copy link
Contributor

sre-bot commented Apr 26, 2022

)

// RequireSecureTransport Process global variables
var RequireSecureTransport = atomic.NewBool(false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added util/tls package to remove the import dependency to add the atomic value.

@morgo morgo requested review from dveeden and morgo April 26, 2022 19:26
@morgo morgo added the compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. label Apr 27, 2022
Copy link
Contributor

@dveeden dveeden left a comment

Choose a reason for hiding this comment

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

So the -require-secure-transport flag gets removed as well? I think that's good. However this doesn't seem to be noted in the release notes line of the description of this PR.

Looks like we need to be more careful when switching this on on a running server as it seems to allow one to set global require_secure_transport=on when TLS is not enabled. This leaves UNIX sockets as the remaining option. But we probably don't check if we actually listen on a UNIX socket. This would lock us out of the server completely.

Also this seems not to work as intended with UNIX sockets:

[dvaneeden@dve-carbon ~]$ mysql -u root -S /tmp/tidb-4000.sock 
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.

A possible fix would be to only allow one to set this variable from a secure (TLS or socket) connection.

@morgo
Copy link
Contributor

morgo commented Apr 28, 2022

So the -require-secure-transport flag gets removed as well? I think that's good. However this doesn't seem to be noted in the release notes line of the description of this PR.

I'm not sure I understand this point. The release note is:

The TiDB configuration file option `require-secure-transport` has been replaced by the system variable `require_secure_transport`. This change makes it easier to modify this setting on a cluster wide basis.

(Replaced does imply removal).

[dvaneeden@dve-carbon ~]$ mysql -u root -S /tmp/tidb-4000.sock 
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.

OK that's a bug we'll need to fix. I think we can do it in this PR.

A possible fix would be to only allow one to set this variable from a secure (TLS or socket) connection.

Agree

@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 28, 2022
@dveeden
Copy link
Contributor

dveeden commented May 2, 2022

So the -require-secure-transport flag gets removed as well? I think that's good. However this doesn't seem to be noted in the release notes line of the description of this PR.

I'm not sure I understand this point. The release note is:

The TiDB configuration file option `require-secure-transport` has been replaced by the system variable `require_secure_transport`. This change makes it easier to modify this setting on a cluster wide basis.

(Replaced does imply removal).

Without this PR the require secure transport feature can be enabled by:

With this PR the only option is:

  • Setting the require_secure_transport global variable to ON

I think the changelog entry correctly states that the configuration file option gets replaced by the global variable. However it doesn't say anything about the replacement/removal of the flag for the tidb-server binary.

@morgo
Copy link
Contributor

morgo commented May 2, 2022

I think the changelog entry correctly states that the configuration file option gets replaced by the global variable. However it doesn't say anything about the replacement/removal of the flag for the tidb-server binary.

OK! I understand now. I've changed the release note message to:

The TiDB configuration file option require-secure-transport and command line flag have been replaced by the system variable require_secure_transport.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 2, 2022
@morgo
Copy link
Contributor

morgo commented May 3, 2022

@Alkaagr81 please fix conflicts. Thx!

@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 3, 2022
@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels May 10, 2022
@Alkaagr81 Alkaagr81 requested review from dveeden and morgo May 10, 2022 22:39
Copy link
Contributor

@dveeden dveeden left a comment

Choose a reason for hiding this comment

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

Somehow it looks like it is not considering a socket connection as secure when setting the variable.

mysql> \s
--------------
mysql  Ver 8.0.29 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		407
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.7.25-TiDB-v6.1.0-alpha-439-g0db763f3a TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/tmp/tidb.sock
Binary data as:		Hexadecimal
Uptime:			44 sec

Threads: 0  Questions: 0  Slow queries: 0  Opens: 0  Flush tables: 0  Open tables: 0  Queries per second avg: 0.000
--------------

mysql> set global require_secure_transport=1;
ERROR 1105 (HY000): require_secure_transport can only be set to ON if the connection issuing the change is secure

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 17, 2022
@morgo
Copy link
Contributor

morgo commented May 17, 2022

Somehow it looks like it is not considering a socket connection as secure when setting the variable.

I actually thought that was a good behavior, since it requires you to prove connection security is configured correctly. This helps reduce misconfiguration/lockouts. We can revisit in future if required.

@morgo
Copy link
Contributor

morgo commented May 17, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

DetailsCommit hash: 0db763f

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 17, 2022
@ti-chi-bot ti-chi-bot merged commit d2ada35 into pingcap:master May 17, 2022
@dveeden
Copy link
Contributor

dveeden commented May 18, 2022

Somehow it looks like it is not considering a socket connection as secure when setting the variable.

I actually thought that was a good behavior, since it requires you to prove connection security is configured correctly. This helps reduce misconfiguration/lockouts. We can revisit in future if required.

I see your point, and this would indeed ensure TLS is working before we enable require_secure_transport, which is good. However this means it is a bit inconsistent: sockets are are considered secure when the setting is enabled, but not when setting it. Maybe we should update the message to say that setting the variable requires TLS instead of saying that it requires a secure connection.

Happy to see this merged, this is very useful.

"alter-primary-key": {}, // use NONCLUSTERED keyword instead
"enable-streaming": {},
"performance.mem-profile-interval": {},
"require-secure-transport": {},
Copy link
Member

Choose a reason for hiding this comment

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

It should be 'security.require-secure-transport', see #34771

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fail server startup when opening TLS context fails

6 participants