Skip to content

Requiring TLS on remote MySQL connections from a cPanel host — beyond the default

cPanel installs MySQL with TLS available but not enforced. A remote MySQL grant accepted in cleartext exposes credentials to anyone on the network path.

Modern cPanel installs ship MySQL with TLS support enabled — the server generates a certificate at install time and the daemon offers STARTTLS to clients. What it doesn’t do is require TLS. A client that connects without negotiating TLS gets a cleartext connection, and the credentials cross the network unencrypted. For a remote MySQL grant that allows access from 203.0.113.42, that’s a one-tcpdump-away credential leak. Enforcement is per-user and requires the GRANT to specify it.

What’s happening

MySQL’s TLS lifecycle on cPanel:

  1. Server-side TLS: cPanel generates /var/lib/mysql/ca.pem, server-cert.pem, and server-key.pem on install. MySQL reads these via ssl_ca, ssl_cert, ssl_key in the config (or defaults to those paths). The daemon advertises TLS support to clients.
  2. Client-side: a client connecting with --ssl-mode=REQUIRED or --ssl=1 negotiates TLS. Without that, the connection goes cleartext.
  3. Per-user requirement: REQUIRE SSL on the GRANT forces the client to negotiate TLS. Without it, the server accepts cleartext from clients that don’t ask for TLS.

So even with TLS available, the deployment is only secure if both: clients are configured to ask for TLS, AND grants require it. The first protects against accidental cleartext; the second protects against the client config being wrong.

How to verify

mysql -e "SHOW VARIABLES LIKE 'have_ssl'"
mysql -e "SHOW VARIABLES LIKE 'ssl%'"
mysql -e "SELECT User, Host, ssl_type FROM mysql.user WHERE Host NOT IN ('localhost','127.0.0.1','::1')"
mysql -u remote_user -p -h 203.0.113.42 --ssl-mode=REQUIRED -e "SHOW STATUS LIKE 'Ssl_cipher'"
ls -la /var/lib/mysql/*.pem

have_ssl = YES means TLS is available. The ssl_type column shows what each user is required to negotiate (ANY, SSL, X509, SPECIFIED). Ssl_cipher non-empty means the connection actually negotiated TLS.

The fix

  1. Confirm server TLS works:
    mysql -e "SHOW STATUS LIKE 'Ssl_cipher'"
    mysql -e "SHOW VARIABLES LIKE 'have_openssl'"
    If have_openssl = YES and the cipher list isn’t empty, you’re set up.
  2. For each remote user, require SSL:
    ALTER USER 'acmecorp_app'@'203.0.113.42' REQUIRE SSL;
    FLUSH PRIVILEGES;
    This adds ssl_type = ANY to that user. Any future connection from this user must negotiate TLS or be rejected.
  3. For stricter posture, require an X.509 client certificate:
    ALTER USER 'acmecorp_app'@'203.0.113.42' REQUIRE X509;
    The client must present a valid certificate, signed by the server’s CA. This is mTLS — both sides authenticate cryptographically. Stronger but requires distributing client certs.
  4. For grants created via cPanel API, the REQUIRE clause isn’t directly exposed in UAPI. You have to ALTER USER after the API creates the grant. Script this as a post-create hook if it’s a regular workflow.
  5. For clients (PHP, applications), configure them to ask for TLS:
    • PHP/PDO: PDO::MYSQL_ATTR_SSL_CA and friends.
    • WP-CLI / mysql client: --ssl-mode=REQUIRED.
    • PHP/mysqli: mysqli_ssl_set() before connect.
    • Connection strings: ?sslmode=require in DSN-style.
  6. Test the enforcement: try to connect without TLS:
    mysql -u acmecorp_app -p -h server.example.com --ssl-mode=DISABLED -e "SELECT 1"
    Should return ERROR 1045: Access denied ... SSL connection error or similar. If the connection succeeds, REQUIRE SSL didn’t take effect.
  7. Verify the established connection is encrypted:
    mysql -u acmecorp_app -p -h server.example.com --ssl-mode=REQUIRED -e "SHOW STATUS LIKE 'Ssl_cipher'"
    Returns the cipher in use. Empty cipher means TLS wasn’t negotiated (somehow connected cleartext).
  8. Renew certificates before expiry. cPanel-generated certs have a 10-year validity. If you use Let’s Encrypt or a custom CA, automate renewal — an expired cert breaks all TLS-required connections.
  9. For 'user'@'%' grants (which you should not have — see remote MySQL article), REQUIRE SSL on them too. A % wildcard grant requiring TLS is still riskier than an IP-specific grant requiring TLS, but it’s better than cleartext.

For environments where Remote MySQL is used and credential exposure is a real concern, Stack Harbor’s environment management team enforces REQUIRE SSL on every non-localhost grant, automates certificate renewal, and audits cipher strength against current security baselines.