Skip to content
This repository was archived by the owner on May 28, 2021. It is now read-only.

Group replication SSL #115

Merged
merged 1 commit into from
May 30, 2018
Merged

Group replication SSL #115

merged 1 commit into from
May 30, 2018

Conversation

simonlord
Copy link

@simonlord simonlord commented May 29, 2018

  • SSL with autogenerated certs as standard (a feature of mysql, certs valid for 10 years)
  • Confirgurable with your own CA cert, tls cert and tls key via a tls secret

Limitations:

  • Currently not verifying server cert against ca cert (VERIFY_CA mode).
  • Only supports 1 server cert/key pair that will be mounted to all mysql containers
    • Really you'd want a new cert/key pair per pod and then turn on VERIFY_IDENTITY
      to enforce hostname/common name checking. This would require vault/cert-manager

Resolves: #89

Changelog:

Group communication connections as are now secured using SSL with support for specifying your own certificate [#115].

@simonlord simonlord requested review from prydie and owainlewis May 29, 2018 09:45
@prydie prydie added this to the 0.2.0 milestone May 29, 2018
Copy link

@prydie prydie left a comment

Choose a reason for hiding this comment

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

A few comments but looking good 👍

// SSLSecretRef allows a user to specify custom CA certificate, server certificate
// and server key for group replication ssl
// +optional
SSLSecretRef *corev1.LocalObjectReference `json:"sslSecretRef,omitempty"`
Copy link

Choose a reason for hiding this comment

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

Maybe it's bikeshedding but I'm not sure we made the right decision re {Foo}Ref I'd rather SSLSecret, RootPasswordSecret and MyCNF or similar. Probably out of scope though.

Copy link
Author

Choose a reason for hiding this comment

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

This should be a separate issue to do them all at once

Copy link
Member

Choose a reason for hiding this comment

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

Agree with you both. I'm not a huge fan. Let's do this afterwards.

LocalObjectReference: v1.LocalObjectReference{
Name: cluster.Spec.SSLSecretRef.Name,
},
Items: []v1.KeyToPath{
Copy link

Choose a reason for hiding this comment

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

Can we use a TLS secret?

Copy link
Author

Choose a reason for hiding this comment

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

If we can use it i'd like to - unfortunately we have to provide the CA cert file too for MySQL to be happy - tls secrets only have the server cert and key pair. Also it isn't tls, it's ssl still.

So we could 1) add a ca.crt field to the tls secret. 2) have the ca.crt in a different secret or 3) leave it how it is.

Thoughts?

Copy link

Choose a reason for hiding this comment

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

Ah, shame. I’d follow the naming scheme from the TLS secret and add the ca.crt as you suggest.

Copy link
Author

Choose a reason for hiding this comment

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

done

@@ -211,6 +219,10 @@ func mysqlServerContainer(cluster *api.MySQLCluster, mysqlServerImage string, ro
"--log-error-verbosity=3",
}

if cluster.RequiresCustomSSLSetup() {
args = append(args, "--ssl-ca=/etc/ssl/mysql/ca.crt", "--ssl-cert=/etc/ssl/mysql/server.crt", "--ssl-key=/etc/ssl/mysql/server.key")
Copy link

Choose a reason for hiding this comment

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

nit: would probably split into an arg per line

cacert: <base64'd Root CA certifacte>
servercert: <base64'd server certificate>
serverkey: <base64'd server private key>

Copy link

Choose a reason for hiding this comment

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

\n

}
}

if !hasExpectedVolumeMount {
Copy link

Choose a reason for hiding this comment

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

assert.True(t, hasExpectedVolumeMount, "Cluster is missing expected volume mount for custom ssl certs")

(github.com/stretchr/testify/assert)

},
}

if !cluster.RequiresCustomSSLSetup() {
Copy link

Choose a reason for hiding this comment

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

assert.True(t, cluster.RequiresCustomSSLSetup(), "Cluster with sslSecretRef should require custom ssl setup")

(github.com/stretchr/testify/assert)

cluster := &MySQLCluster{}
cluster.EnsureDefaults()

if cluster.RequiresCustomSSLSetup() {
Copy link

Choose a reason for hiding this comment

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

assert.False(t, cluster.RequiresCustomSSLSetup(), "Cluster without sslSecretRef should not require custom ssl setup")

(github.com/stretchr/testify/assert)

@simonlord simonlord force-pushed the group-replication-ssl branch 3 times, most recently from 1e98125 to a6bd303 Compare May 30, 2018 09:59
@simonlord simonlord changed the title WIP: Group replication SSL Group replication SSL May 30, 2018
@owainlewis owainlewis self-assigned this May 30, 2018
name: mysql-ssl-secret
type: Opaque
data:
ca.crt: <base64'd Root CA certifacte>
Copy link
Member

Choose a reason for hiding this comment

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

Typo certifact => certificate

@@ -95,6 +95,11 @@ type MySQLClusterSpec struct {
// ConfigRef allows a user to specify a custom configuration file for MySQL.
// +optional
ConfigRef *corev1.LocalObjectReference `json:"configRef,omitempty"`

// SSLSecretRef allows a user to specify custom CA certificate, server certificate
// and server key for group replication ssl
Copy link
Member

Choose a reason for hiding this comment

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

ssl => SSL

@@ -203,6 +208,13 @@ func (c *MySQLCluster) RequiresSecret() bool {
return c.Spec.SecretRef == nil
}

// RequiresCustomSSLSetup returns true is the user has provided a secret
// that contains CA cert, server cert and server key for group replication
// ssl support
Copy link
Member

Choose a reason for hiding this comment

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

ssl => SSL

@@ -84,3 +85,20 @@ func TestRequiresConfigMount(t *testing.T) {
t.Errorf("Cluster with configRef should require a config mount")
}
}

func TestRequiresCustomSSLSetup(t *testing.T) {
cluster := &MySQLCluster{}
Copy link
Member

Choose a reason for hiding this comment

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

Not relevant to this PR but I'd be in favour of abstracting this given how often it comes up in the codebase and how easy it would be to make a mistake by not setting defaults.

cluster := NewMySQLCluster() | NewMySQLClusterWithDefaults()

},
}

assert.True(t, cluster.RequiresCustomSSLSetup(), "Cluster with sslSecretRef should require custom ssl setup")
Copy link
Member

Choose a reason for hiding this comment

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

ssl => SSL

}
}

assert.True(t, hasExpectedVolumeMount, "Cluster is missing expected volume mount for custom ssl certs")
Copy link
Member

Choose a reason for hiding this comment

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

ssl => SSL

Copy link
Member

@owainlewis owainlewis left a comment

Choose a reason for hiding this comment

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

Looks good to me. Other than a minor typo this is good to go IMO

- SSL with autogenerated certs as standard (a feature of mysql, certs valid for 10 years)
- Confirgurable with your own CA cert, tls cert and tls key via a tls secret
@simonlord simonlord force-pushed the group-replication-ssl branch from a6bd303 to 72b2396 Compare May 30, 2018 10:50
Copy link

@prydie prydie left a comment

Choose a reason for hiding this comment

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

A couple of missing full stops but not reason enough to block merge. 👍

@prydie prydie merged commit d42c413 into master May 30, 2018
@prydie prydie deleted the group-replication-ssl branch May 30, 2018 11:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants