Skip to content

Commit bd0dd76

Browse files
authored
Merge pull request #39 from movabletype/mysql-9
feat: support MySQL 9 with caching_sha2_password
2 parents 2230e2e + 5726923 commit bd0dd76

7 files changed

Lines changed: 113 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88

9+
### Added
10+
11+
* Added support for mysql:9.x docker images.
12+
* Enable to use SSL connection to MySQL.
13+
914
### Changed
1015

1116
* Update default image version.

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export DOCKER_HTTPD_BUILD_CONTEXT
4242
export DOCKER_HTTPD_DOCKERFILE
4343
export DOCKER_HTTPD_IMAGE
4444
export DOCKER_MYSQL_IMAGE
45+
export DOCKER_MYSQL_COMMAND
4546
export DOCKER_MEMCACHED_IMAGE
4647
export DOCKER_LDAP_IMAGE
4748
export DOCKER_FTPD_IMAGE
@@ -94,15 +95,20 @@ fixup:
9495

9596
setup-mysql-volume:
9697
$(eval export DOCKER_MYSQL_VOLUME=$(shell echo ${DOCKER_MYSQL_IMAGE} | sed -e 's/\..*//; s/[^a-zA-Z0-9]//g'))
97-
98+
ifeq (${DOCKER_MYSQL_COMMAND},)
99+
$(eval export DOCKER_MYSQL_COMMAND=$(shell if echo ${DOCKER_MYSQL_IMAGE} | egrep -q '^mysql:(9|[1-9][0-9]+)$$'; then echo ''; else echo '--default-authentication-plugin=mysql_native_password'; fi))
100+
endif
98101

99102
ifneq (${SQL},)
100103
MYSQL_COMMAND_ARGS=-e '${SQL}'
101104
endif
102105

106+
update-ssl:
107+
${DOCKER} run --rm -v ${MAKEFILE_DIR}/ssl:/ssl -w /ssl --entrypoint /bin/sh alpine/openssl:latest generate-certs.sh
108+
103109
exec-mysql:
104110
opt=""; if ! [ -t 0 ] ; then opt="-T" ; fi; \
105-
${_DC} exec $$opt db mysql -uroot -ppassword -h127.0.0.1 ${MYSQL_COMMAND_ARGS}
111+
${_DC} exec $$opt db mysql -uroot -ppassword -hlocalhost ${MYSQL_COMMAND_ARGS}
106112

107113
# FIXME:
108114
exec-ldappasswd:
@@ -122,7 +128,7 @@ else
122128
ARCHIVE_FOR_SETUP=${ARCHIVE}
123129
endif
124130

125-
up-common: down fixup
131+
up-common: down fixup update-ssl
126132
${MAKE} down-mt-home-volume
127133
${DOCKER} volume create --label mt-dev-mt-home-tmp mt-dev-mt-home-tmp
128134

mt/mysql.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ services:
33
image: ${DOCKER_MYSQL_IMAGE:-mysql:8.0.32}
44
environment:
55
MYSQL_ROOT_PASSWORD: password
6-
command: --default-authentication-plugin=mysql_native_password
6+
command: ${DOCKER_MYSQL_COMMAND}
77
volumes:
8+
- "..:/mt-dev"
9+
- "./mysql/conf.d:/etc/mysql/conf.d"
810
- "${DOCKER_MYSQL_VOLUME:-mysql8}:/var/lib/mysql"
911
volumes:
1012
mariadb10:
1113
driver: local
14+
mysql9:
15+
driver: local
1216
mysql8:
1317
driver: local
1418
mysql5:

mt/mysql/conf.d/mt.cnf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[mysqld]
2+
ssl-ca=/mt-dev/ssl/certs/ca-cert.pem
3+
ssl-cert=/mt-dev/ssl/certs/server-cert.pem
4+
ssl-key=/mt-dev/ssl/certs/server-key.pem
5+
6+
[client]
7+
ssl-ca=/mt-dev/ssl/certs/ca-cert.pem
8+
ssl-cert=/mt-dev/ssl/certs/client-cert.pem
9+
ssl-key=/mt-dev/ssl/certs/client-key.pem

ssl/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
certs/
2+
index.txt
3+
serial

ssl/generate-certs.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
mkdir -p certs
4+
touch index.txt
5+
echo 1000 > serial
6+
7+
openssl genrsa -out certs/ca-key.pem 2048
8+
openssl req -new -x509 -nodes -days 3650 -key certs/ca-key.pem -out certs/ca-cert.pem \
9+
-subj "/C=JP/ST=Tokyo/L=Tokyo/O=MyOrganization/CN=MyCA"
10+
11+
openssl genrsa -out certs/server-key.pem 2048
12+
openssl req -new -key certs/server-key.pem -out certs/server-req.pem \
13+
-subj "/C=JP/ST=Tokyo/L=Tokyo/O=MyOrganization/CN=db"
14+
openssl x509 -req -in certs/server-req.pem -days 3650 \
15+
-CA certs/ca-cert.pem -CAkey certs/ca-key.pem -CAcreateserial \
16+
-out certs/server-cert.pem
17+
18+
openssl genrsa -out certs/client-key.pem 2048
19+
openssl req -new -key certs/client-key.pem -out certs/client-req.pem \
20+
-subj "/C=JP/ST=Tokyo/L=Tokyo/O=MyOrganization/CN=mysqlclient"
21+
openssl x509 -req -in certs/client-req.pem -days 3650 \
22+
-CA certs/ca-cert.pem -CAkey certs/ca-key.pem -CAcreateserial \
23+
-out certs/client-cert.pem

ssl/openssl.cnf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[ ca ]
2+
default_ca = CA_default
3+
4+
[ CA_default ]
5+
dir = .
6+
certs = $dir/certs
7+
crl_dir = $dir/crl
8+
new_certs_dir = $dir/newcerts
9+
database = $dir/index.txt
10+
serial = $dir/serial
11+
RANDFILE = $dir/private/.rand
12+
13+
private_key = $dir/private/ca-key.pem
14+
certificate = $dir/certs/ca-cert.pem
15+
16+
default_days = 3650
17+
default_crl_days = 30
18+
default_md = sha256
19+
preserve = no
20+
21+
policy = policy_match
22+
23+
[ policy_match ]
24+
countryName = optional
25+
stateOrProvinceName = optional
26+
organizationName = optional
27+
organizationalUnitName = optional
28+
commonName = supplied
29+
emailAddress = optional
30+
31+
[ req ]
32+
default_bits = 2048
33+
default_md = sha256
34+
default_keyfile = privkey.pem
35+
distinguished_name = req_distinguished_name
36+
x509_extensions = v3_ca
37+
req_extensions = v3_req
38+
39+
[ req_distinguished_name ]
40+
countryName = Country Name (2 letter code)
41+
countryName_default = JP
42+
stateOrProvinceName = State or Province Name (full name)
43+
stateOrProvinceName_default = Tokyo
44+
localityName = Locality Name (eg, city)
45+
localityName_default = Tokyo
46+
organizationName = Organization Name (eg, company)
47+
organizationName_default = MyOrganization
48+
commonName = Common Name (eg, YOUR name)
49+
commonName_max = 64
50+
51+
[ v3_ca ]
52+
subjectKeyIdentifier=hash
53+
authorityKeyIdentifier=keyid:always,issuer
54+
basicConstraints = critical,CA:true
55+
56+
[ v3_req ]
57+
basicConstraints = CA:FALSE
58+
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
59+
extendedKeyUsage = serverAuth, clientAuth

0 commit comments

Comments
 (0)