-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update TLS test to drive our require_secure_transport
- Assert that require_secure_transport is enabled (tls.required is enabled) - Assert that TLS < v1.2 are disallowed (tls.enforce_tls_v1_2 is enabled) - Assert that TLS connections otherwise succeed [#177349859](https://www.pivotaltracker.com/story/show/177349859)
- Loading branch information
Showing
3 changed files
with
59 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
This test suite verifies TLS behavior of a PXC deployment. | ||
|
||
The assumes are that the deployment was deployed with: | ||
|
||
- spec.tls.required = true, rejecting any plaintext connections | ||
- spec.tls.enforce_tls_v1_2 = true; rejecting attempts by clients to use old TLS protocol versions | ||
|
||
This test will fail if either plaintext connections are allowed or older TLS versions are allowed in the environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,55 @@ | ||
package tls_test | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
helpers "github.com/cloudfoundry/pxc-release/specs/test_helpers" | ||
) | ||
|
||
var _ = Describe("Tls", func() { | ||
It("tests all the connections are TLS", func() { | ||
var _ = Describe("TLS", func() { | ||
var ( | ||
rootPassword string | ||
proxyHost string | ||
) | ||
BeforeEach(func() { | ||
var err error | ||
rootPassword, err = helpers.GetMySQLAdminPassword() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
proxyHost, err = helpers.FirstProxyHost(helpers.BoshDeployment) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
It("requires a secure transport for client connections", func() { | ||
dsn := fmt.Sprintf("root:%s@tcp(%s:3306)/?tls=false", rootPassword, proxyHost) | ||
db, err := sql.Open("mysql", dsn) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = db.Ping() | ||
Expect(err).To(MatchError(`Error 3159: Connections using insecure transport are prohibited while --require_secure_transport=ON.`)) | ||
}) | ||
|
||
It("requires TLSv1.2 for connections", func() { | ||
dsn := fmt.Sprintf("root:%s@tcp(%s:3306)/?tls=deprecated-tls11", rootPassword, proxyHost) | ||
db, err := sql.Open("mysql", dsn) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = db.Ping() | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
|
||
query := `SELECT sbt.variable_value AS tls_version, t2.variable_value AS cipher, | ||
processlist_user AS user, processlist_host AS host | ||
FROM performance_schema.status_by_thread AS sbt | ||
JOIN performance_schema.threads AS t ON t.thread_id = sbt.thread_id | ||
JOIN performance_schema.status_by_thread AS t2 ON t2.thread_id = t.thread_id | ||
WHERE sbt.variable_name = 'Ssl_version' and t2.variable_name = 'Ssl_cipher' ORDER BY tls_version` | ||
rows, err := mysqlConn.Query(query) | ||
It("accepts valid TLS connections", func() { | ||
// certificates aren't setup such that we can do proper TLS verification | ||
// This test exists to prove TLS < v1.2, fails but normal TLS connections succeed | ||
dsn := fmt.Sprintf("root:%s@tcp(%s:3306)/?tls=skip-verify", rootPassword, proxyHost) | ||
db, err := sql.Open("mysql", dsn) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
var ( | ||
tls_version string | ||
cipher string | ||
user string | ||
host string | ||
) | ||
|
||
defer rows.Close() | ||
for rows.Next() { | ||
err = rows.Scan(&tls_version, &cipher, &user, &host) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(user).NotTo(BeNil()) | ||
Expect(host).NotTo(BeNil()) | ||
|
||
if !(host == "localhost" || host == "127.0.0.1") { | ||
Expect(tls_version).To(MatchRegexp("TLSv1\\.[1,2,3]")) | ||
Expect(cipher).To(MatchRegexp("ECDHE-RSA.+")) | ||
} | ||
} | ||
err = db.Ping() | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) |