TMAegis
More rules for tdsql

TMA-TDSQL-4.3

Ensure `secure_file_priv` Is Correctly Configured

MediumLevel 1Automatedtdsql

Description

secure_file_priv restricts the directory for file operations by LOAD DATA INFILE, SELECT ... INTO OUTFILE, and the LOAD_FILE() function. If unset or empty, MySQL can access arbitrary paths on the filesystem. Runs the mysql client against the TDSQL data node selected by TDSQL_MYSQL_OPTS (e.g. "-h10.0.0.5 -P4001 -utdsql_audit"); keep the password in ~/.my.cnf or a login path rather than MYSQL_PWD or the command line (see 1.4 and 1.5). Passes when secure_file_priv names a specific directory or is NULL (import/export disabled); an empty string fails.

How it is checked

Audit method: SQL query

sql_query
out=$(mysql ${TDSQL_MYSQL_OPTS:-} -NBe "SELECT CASE WHEN @@global.secure_file_priv IS NULL THEN 'compliant' WHEN @@global.secure_file_priv = '' THEN 'empty' ELSE 'compliant' END" 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 = /data/tdsql/secure/ (or NULL when import/export is not needed) in the [mysqld] section of my.cnf / the parameter template and restart the instance.

Properties

Operating systems
Any
Tags
tdsqlhardening
Reference
CIS Tencent TDSQL 10.3.22 Benchmark v1.0.0 - 4.3 Ensure `secure_file_priv` Is Correctly Configured

Check this host

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

shell
tmaegis scan --target tdsql