Skip to content

Add an option to use SSL certifications generated from specific host (Create certificaitons in CI) #1310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
# Fedora latest stable version
- {distro: fedora, image: 'fedora:latest'}
# Fedora development version
- {distro: fedora, image: 'fedora:rawhide', ssl_cert_dir: '/tmp/mysql2'}
- {distro: fedora, image: 'fedora:rawhide', ssl_cert_dir: '/tmp/mysql2', ssl_cert_host: 'localhost'}
# On the fail-fast: true, it cancels all in-progress jobs
# if any matrix job fails unlike Travis fast_finish.
fail-fast: false
Expand All @@ -29,8 +29,9 @@ jobs:
# https://bugzilla.redhat.com/show_bug.cgi?id=1900021
- run: |
docker run \
--add-host=mysql2gem.example.com:127.0.0.1 \
--add-host=${{ matrix.ssl_cert_host || 'mysql2gem.example.com' }}:127.0.0.1 \
-t \
-e TEST_RUBY_MYSQL2_SSL_CERT_DIR="${{ matrix.ssl_cert_dir || '' }}" \
-e TEST_RUBY_MYSQL2_SSL_CERT_HOST="${{ matrix.ssl_cert_host || '' }}" \
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
mysql2
1 change: 1 addition & 0 deletions ci/Dockerfile_fedora
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN dnf -yq install \
make \
mariadb-connector-c-devel \
mariadb-server \
openssl \
redhat-rpm-config \
ruby-devel \
rubygem-bigdecimal \
Expand Down
7 changes: 7 additions & 0 deletions ci/container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ set -eux
ruby -v
bundle install --path vendor/bundle --without development

# Regenerate the SSL certification files from the specified host.
if [ -n "${TEST_RUBY_MYSQL2_SSL_CERT_HOST}" ]; then
pushd spec/ssl
bash gen_certs.sh
popd
fi

# Start mysqld service.
bash ci/setup_container.sh

Expand Down
2 changes: 1 addition & 1 deletion spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def connect(*args)

let(:option_overrides) do
{
'host' => 'mysql2gem.example.com', # must match the certificates
'host' => ssl_cert_host, # must match the certificates
:sslkey => "#{ssl_cert_dir}/client-key.pem",
:sslcert => "#{ssl_cert_dir}/client-cert.pem",
:sslca => "#{ssl_cert_dir}/ca-cert.pem",
Expand Down
13 changes: 13 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ def ssl_cert_dir
@ssl_cert_dir
end

# A host used to create the certificates pem files.
def ssl_cert_host
return @ssl_cert_host if @ssl_cert_host

host = ENV['TEST_RUBY_MYSQL2_SSL_CERT_HOST']
@ssl_cert_host = if host && !host.empty?
host
else
'mysql2gem.example.com'
end
@ssl_cert_host
end

config.before(:suite) do
begin
new_client
Expand Down
6 changes: 5 additions & 1 deletion spec/ssl/gen_certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

set -eux

# TEST_RUBY_MYSQL2_SSL_CERT_HOST: custom host for the SSL certificates.
SSL_CERT_HOST=${TEST_RUBY_MYSQL2_SSL_CERT_HOST:-mysql2gem.example.com}
echo "Generating the SSL certifications from the host ${SSL_CERT_HOST}.."

echo "
[ ca ]
# January 1, 2015
Expand Down Expand Up @@ -30,7 +34,7 @@ commonName_default = ca_mysql2gem
" >> ca.cnf

echo "
commonName_default = mysql2gem.example.com
commonName_default = ${SSL_CERT_HOST}
" >> cert.cnf

# Generate a set of certificates
Expand Down