Implement X.509 auth for MySQL and Keystone

Change-Id: I03618376d7ba44b11b6121a611fea87c8c3dd023
Related-PROD: PROD-22748
diff --git a/galera/server/database/ssl/keystone.yml b/galera/server/database/ssl/keystone.yml
new file mode 100644
index 0000000..bcaec18
--- /dev/null
+++ b/galera/server/database/ssl/keystone.yml
@@ -0,0 +1,4 @@
+parameters:
+  _param:
+    mysql_keystone_ssl_option:
+      - SSL: True
\ No newline at end of file
diff --git a/galera/server/database/x509/keystone.yml b/galera/server/database/x509/keystone.yml
new file mode 100644
index 0000000..0a790e7
--- /dev/null
+++ b/galera/server/database/x509/keystone.yml
@@ -0,0 +1,7 @@
+parameters:
+  _param:
+    mysql_keystone_client_ssl_x509_subject: '/C=cz/CN=mysql-keystone-client/L=Prague/O=Mirantis'
+    mysql_keystone_client_ssl_x509_issuer: '/C=cz/CN=Salt Master CA/L=Prague/O=Mirantis'
+    mysql_keystone_ssl_option:
+      - SUBJECT: ${_param:mysql_keystone_client_ssl_x509_subject}
+      - ISSUER: ${_param:mysql_keystone_client_ssl_x509_issuer}
\ No newline at end of file
diff --git a/keystone/server/cluster.yml b/keystone/server/cluster.yml
index c9642bd..24840fe 100644
--- a/keystone/server/cluster.yml
+++ b/keystone/server/cluster.yml
@@ -5,10 +5,13 @@
 - system.haproxy.proxy.listen.openstack.keystone.standalone
 - system.linux.system.users.keystone
 - system.keystone.server.fernet_rotation.cluster
+- system.salt.minion.cert.mysql.clients.openstack.keystone
 parameters:
   _param:
     keystone_tokens_expiration: 3600
     openstack_node_role: primary
+    openstack_mysql_x509_enabled: False
+    galera_ssl_enabled: False
   linux:
     system:
       package:
@@ -42,6 +45,13 @@
         name: keystone
         password: ${_param:mysql_keystone_password}
         user: keystone
+        x509:
+          enabled: ${_param:openstack_mysql_x509_enabled}
+          ca_file: ${_param:mysql_keystone_ssl_ca_file}
+          key_file: ${_param:mysql_keystone_client_ssl_key_file}
+          cert_file: ${_param:mysql_keystone_client_ssl_cert_file}
+        ssl:
+          enabled: ${_param:galera_ssl_enabled}
       tokens:
         engine: fernet
         expiration: ${_param:keystone_tokens_expiration}
diff --git a/keystone/server/single.yml b/keystone/server/single.yml
index e1131c0..d926c0d 100644
--- a/keystone/server/single.yml
+++ b/keystone/server/single.yml
@@ -2,6 +2,7 @@
 - service.keystone.server.single
 - system.linux.system.users.keystone
 - system.keystone.server.fernet_rotation.single
+- system.salt.minion.cert.mysql.clients.openstack.keystone
 parameters:
   _param:
     keystone_service_token: token
@@ -11,6 +12,8 @@
     mysql_keystone_password: password
     keystone_tokens_expiration: 3600
     openstack_node_role: primary
+    openstack_mysql_x509_enabled: False
+    galera_ssl_enabled: False
   linux:
     system:
       package:
@@ -41,6 +44,13 @@
         name: keystone
         password: ${_param:mysql_keystone_password}
         user: keystone
+        x509:
+          enabled: ${_param:openstack_mysql_x509_enabled}
+          ca_file: ${_param:mysql_keystone_ssl_ca_file}
+          key_file: ${_param:mysql_keystone_client_ssl_key_file}
+          cert_file: ${_param:mysql_keystone_client_ssl_cert_file}
+        ssl:
+          enabled: ${_param:galera_ssl_enabled}
       tokens:
         engine: fernet
         expiration: ${_param:keystone_tokens_expiration}
diff --git a/salt/minion/cert/mysql/clients/openstack/keystone.yml b/salt/minion/cert/mysql/clients/openstack/keystone.yml
new file mode 100644
index 0000000..c0fe71d
--- /dev/null
+++ b/salt/minion/cert/mysql/clients/openstack/keystone.yml
@@ -0,0 +1,27 @@
+parameters:
+  _param:
+    salt_minion_ca_host: cfg01.${_param:cluster_domain}
+    salt_minion_ca_authority: salt_master_ca
+    mysql_keystone_client_ssl_key_file: /etc/keystone/ssl/mysql/client-key.pem
+    mysql_keystone_client_ssl_cert_file: /etc/keystone/ssl/mysql/client-cert.pem
+    mysql_keystone_ssl_ca_file: /etc/keystone/ssl/mysql/ca-cert.pem
+  salt:
+    minion:
+      cert:
+        mysql-keystone-client:
+          host: ${_param:salt_minion_ca_host}
+          authority: ${_param:salt_minion_ca_authority}
+          common_name: mysql-keystone-client
+          signing_policy: cert_client
+          alternative_names: >
+            IP:${_param:cluster_local_address},
+            DNS:${_param:cluster_local_address},
+            DNS:${linux:system:name},
+            DNS:${linux:network:fqdn}
+          key_usage: "digitalSignature,nonRepudiation,keyEncipherment"
+          key_file: ${_param:mysql_keystone_client_ssl_key_file}
+          cert_file: ${_param:mysql_keystone_client_ssl_cert_file}
+          ca_file: ${_param:mysql_keystone_ssl_ca_file}
+          user: keystone
+          group: keystone
+          mode: 640