PortGate

Blueprints · Docker & Databases

Production 25 min · MySQL / MariaDB

MySQL 8.4 and MariaDB 11 production hardening

Binds the server to localhost, disables LOAD DATA LOCAL, requires TLS for TCP clients, and rotates mariabackup snapshots.

Live config

Baked-in protections

Step 1 · ini

Server settings

/root/portgate-blueprints/99-portgate.cnf

Works for MariaDB and MySQL. Put it in the server conf.d directory.

[mysqld]
bind-address = 127.0.0.1
local_infile = 0
require_secure_transport = ON
skip_name_resolve = 1

Step 2 · bash

Backup rotation

/root/portgate-blueprints/mariadb-backup.sh

Not run by the bundle. mariabackup must be installed and the backup user must already exist.

#!/bin/sh
set -eu
STAMP="$(date +%Y%m%d%H%M%S)"
TARGET="/var/backups/mariadb/$STAMP"
mkdir -p "$TARGET"
mariabackup --backup --target-dir="$TARGET" --databases="app"
find /var/backups/mariadb -mindepth 1 -maxdepth 1 -type d -mtime +14 -exec rm -rf {} +

Step 3 · bash

Reload when the server exists

/root/portgate-blueprints/mysql-apply.sh

Copies the snippet into the distro conf directory and does not reload. Add TLS certificates before you reload or require_secure_transport will reject clients.

#!/bin/sh
set -eu
if [ -d /etc/mysql/mariadb.conf.d ]; then
  install -m 644 /root/portgate-blueprints/99-portgate.cnf /etc/mysql/mariadb.conf.d/99-portgate.cnf
elif [ -d /etc/mysql/mysql.conf.d ]; then
  install -m 644 /root/portgate-blueprints/99-portgate.cnf /etc/mysql/mysql.conf.d/99-portgate.cnf
else
  echo "MySQL or MariaDB is not installed. The cnf file is under /root/portgate-blueprints."
  exit 0
fi
echo "Add ssl_cert and ssl_key, then reload the server. This script did not reload it. Database: app"