TMAegis
More rules for mysql

TMA-MYSQL-4.7

Ensure the 'secure_file_priv' is Configured Correctly

MediumLevel 1Automatedmysql

Description

The secure_file_priv option restricts to paths used by LOAD DATA INFILE or SELECT local_file. It is recommended that this option be set to a file system location that contains only resources expected to be loaded by MySQL. Fails only when secure_file_priv is an empty string (import/export allowed everywhere). Runs mysql -NBe with the client defaults: put an administrative account in ~/.my.cnf (mode 0600) or a mysql_config_editor login path, not MYSQL_PWD (see 1.4/1.6).

How it is checked

Audit method: SQL query

sql_query
out=$(mysql -NBe "SELECT IF(@@global.secure_file_priv IS NULL OR @@global.secure_file_priv <> '', 'compliant', 'noncompliant')" 2>/dev/null) || exit 1; printf '%s\n' "$out"
Expected output
compliant

How it is fixed

Fix method: Guidance or infrastructure patch

Set secure_file_priv=<path_to_load_directory> (or remove the empty setting) under [mysqld] in /etc/my.cnf (or /etc/mysql/mysql.conf.d/mysqld.cnf), then restart MySQL.

Properties

Operating systems
Any
Tags
mysqldatabaseconfiguration
Reference
CIS Oracle MySQL Community Server 8.4 Benchmark v1.1.0 - 4.7 Ensure the 'secure_file_priv' is Configured Correctly

Check this host

Run this on a machine you are allowed to audit. The scan is read-only.

shell
tmaegis scan --target mysql